4 #include "opensrf/utils.h"
5 #include "opensrf/logging.h"
6 #include "objson/object.h"
7 #include "osrf_app_session.h"
9 #define OSRF_METHOD_CHECK_PARAMS(x,y) \
10 if( ! x || ! y ) return -1; \
11 if(y->type != JSON_ARRAY ) return -1; \
12 char* __j = jsonObjectToJSON(y);\
14 debug_handler("Service: %s | Params: %s", x->remote_service, __j);free(__j);}
18 This macro verifies methods receive the correct parameters
19 It also creates local variables "session", "method",
20 "params", and "request"
23 #define OSRF_METHOD_VERIFY_DISPATCHER(__d) \
26 osrfAppSession* session = __d->session; \
27 osrfMethod* method = __d->method; \
28 jsonObject* params = __d->params; \
29 int request = __d->request; \
31 if( !(session && method && params) ) return -1; \
32 if( !params->type == JSON_ARRAY ) return -1; \
33 if( !method->name ) return -1; \
35 char* __j = jsonObjectToJSON(params);\
37 debug_handler("Service: %s | Params: %s", session->remote_service, __j);free(__j);}
43 struct _osrfApplicationStruct {
44 char* name; /* the name of our application */
45 void* handle; /* the lib handle */
46 struct _osrfMethodStruct* methods; /* list of methods */
47 struct _osrfApplicationStruct* next; /* next application */
49 typedef struct _osrfApplicationStruct osrfApplication;
52 struct _osrfMethodStruct {
53 char* name; /* the method name */
54 char* symbol; /* the symbol name (function) */
55 char* notes; /* public method documentation */
56 int argc; /* how many args this method expects */
57 void* methodHandle; /* cached version of the method handle */
58 struct _osrfMethodStruct* next;
60 typedef struct _osrfMethodStruct osrfMethod;
62 struct _osrfMethodDispatcherStruct {
63 osrfAppSession* session;
68 typedef struct _osrfMethodDispatcherStruct osrfMethodDispatcher;
72 Register an application
73 @param appName The name of the application
74 @param soFile The library (.so) file that implements this application
75 @return 0 on success, -1 on error
77 int osrfAppRegisterApplication( char* appName, char* soFile );
81 @param appName The name of the application that implements the method
82 @param methodName The fully qualified name of the method
83 @param symbolName The symbol name (function) that implements the method
84 @param notes Public documentation for this method.
85 @params argc The number of arguments this method expects
86 @return 0 on success, -1 on error
88 int osrfAppRegisterMethod( char* appName,
89 char* methodName, char* symbolName, char* notes, int argc );
92 Finds the given app in the list of apps
93 @param name The name of the application
94 @return The application pointer or NULL if there is no such application
96 osrfApplication* _osrfAppFindApplication( char* name );
99 Finds the given method for the given app
100 @param appName The application
101 @param methodName The method to find
102 @return A method pointer or NULL if no such method
103 exists for the given application
105 osrfMethod* _osrfAppFindMethod( char* appName, char* methodName );
108 Finds the given method for the given app
109 @param app The application object
110 @param methodName The method to find
111 @return A method pointer or NULL if no such method
112 exists for the given application
114 osrfMethod* __osrfAppFindMethod( osrfApplication* app, char* methodName );
118 Runs the specified method for the specified application.
119 @param appName The name of the application who's method to run
120 @param methodName The name of the method to run
121 @param ses The app session attached to this request
122 @params reqId The request id for this request
123 @param params The method parameters
125 int osrfAppRunMethod( char* appName, char* methodName,
126 osrfAppSession* ses, int reqId, jsonObject* params );