]> git.evergreen-ils.org Git - working/Evergreen.git/blob - OpenSRF/src/libstack/osrf_application.h
2921952aba0716cf000b4a50881d869a22b2ac6e
[working/Evergreen.git] / OpenSRF / src / libstack / osrf_application.h
1
2 #include <stdio.h>
3 #include <dlfcn.h>
4 #include "opensrf/utils.h"
5 #include "opensrf/logging.h"
6 #include "objson/object.h"
7 #include "osrf_app_session.h"
8
9 /** 
10   This macro verifies methods receive the correct parameters 
11   */
12
13 #define _OSRF_METHOD_VERIFY_CONTEXT(d) \
14         if(!d) return -1; \
15         if(!d->session) { osrfLog( OSRF_ERROR, "Session is NULL in app reqeust" ); return -1; }\
16         if(!d->method) { osrfLog( OSRF_ERROR, "Method is NULL in app reqeust" ); return -1; }\
17         if(!d->params) { osrfLog( OSRF_ERROR, "Params is NULL in app reqeust %s", d->method->name ); return -1; }\
18         if( d->params->type != JSON_ARRAY ) { \
19                 osrfLog( OSRF_ERROR, "'params' is not a JSON array for method %s", d->method->name);\
20                 return -1; }\
21         if( !d->method->name ) { osrfLog(OSRF_ERROR, "Method name is NULL"); return -1; } 
22
23
24 #ifdef OSRF_LOG_PARAMS 
25 #define OSRF_METHOD_VERIFY_CONTEXT(d) \
26         _OSRF_METHOD_VERIFY_CONTEXT(d); \
27         char* __j = jsonObjectToJSON(d->params);\
28         if(__j) { \
29                 osrfLog( OSRF_DEBUG, "[%s:%s] params: %s", d->session->remote_service, d->method->name, __j);\
30                 free(__j); \
31         } 
32 #else
33 #define OSRF_METHOD_VERIFY_CONTEXT(d) _OSRF_METHOD_VERIFY_CONTEXT(d); 
34 #endif
35
36
37         
38
39         
40
41 struct _osrfApplicationStruct {
42         char* name; /* the name of our application */
43         void* handle; /* the lib handle */
44         struct _osrfMethodStruct* methods;      /* list of methods */
45         struct _osrfApplicationStruct* next; /* next application */
46 };
47 typedef struct _osrfApplicationStruct osrfApplication;
48
49
50 struct _osrfMethodStruct {
51         char* name;                             /* the method name */
52         char* symbol;                   /* the symbol name (function) */
53         char* notes;                    /* public method documentation */
54         int argc;                               /* how many args this method expects */
55         void* methodHandle;     /* cached version of the method handle */
56         struct _osrfMethodStruct* next;
57 }; 
58 typedef struct _osrfMethodStruct osrfMethod;
59
60 struct _osrfMethodContextStruct {
61         osrfAppSession* session;
62         osrfMethod* method;
63         jsonObject* params;
64         int request;
65 };
66 typedef struct _osrfMethodContextStruct osrfMethodContext;
67
68
69 /** 
70   Register an application
71   @param appName The name of the application
72   @param soFile The library (.so) file that implements this application
73   @return 0 on success, -1 on error
74   */
75 int osrfAppRegisterApplication( char* appName, char* soFile );
76
77 /**
78   Register a method
79   @param appName The name of the application that implements the method
80   @param methodName The fully qualified name of the method
81   @param symbolName The symbol name (function) that implements the method
82   @param notes Public documentation for this method.
83   @params argc The number of arguments this method expects 
84   @return 0 on success, -1 on error
85   */
86 int osrfAppRegisterMethod( char* appName, 
87                 char* methodName, char* symbolName, char* notes, int argc );
88
89 /**
90   Finds the given app in the list of apps
91   @param name The name of the application
92   @return The application pointer or NULL if there is no such application
93   */
94 osrfApplication* _osrfAppFindApplication( char* name );
95
96 /**
97   Finds the given method for the given app
98   @param appName The application
99   @param methodName The method to find
100   @return A method pointer or NULL if no such method 
101   exists for the given application
102   */
103 osrfMethod* _osrfAppFindMethod( char* appName, char* methodName );
104
105 /**
106   Finds the given method for the given app
107   @param app The application object
108   @param methodName The method to find
109   @return A method pointer or NULL if no such method 
110   exists for the given application
111   */
112 osrfMethod* __osrfAppFindMethod( osrfApplication* app, char* methodName );
113
114
115 /**
116   Runs the specified method for the specified application.
117   @param appName The name of the application who's method to run
118   @param methodName The name of the method to run
119   @param ses The app session attached to this request
120   @params reqId The request id for this request
121   @param params The method parameters
122   */
123 int osrfAppRunMethod( char* appName, char* methodName, 
124                 osrfAppSession* ses, int reqId, jsonObject* params );
125
126