]> git.evergreen-ils.org Git - working/Evergreen.git/blob - OpenSRF/src/libstack/osrf_application.h
1724f804df067bc3c398af904f236810295d9827
[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 #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);\
13         if(__j) { \
14                 debug_handler("Service: %s | Params: %s", x->remote_service, __j);free(__j);}
15
16
17 /** 
18   This macro verifies methods receive the correct parameters 
19   It also creates local variables "session", "method",
20   "params", and "request" 
21   */
22
23 #define OSRF_METHOD_VERIFY_DISPATCHER(__d) \
24         if(!__d) return -1; \
25         \
26         osrfAppSession* session = __d->session; \
27         osrfMethod*     method = __d->method; \
28         jsonObject* params = __d->params; \
29         int request = __d->request; \
30         \
31         if( !(session && method && params) ) return -1; \
32         if( !params->type == JSON_ARRAY ) return -1; \
33         if( !method->name ) return -1; \
34         \
35         char* __j = jsonObjectToJSON(params);\
36         if(__j) { \
37                 debug_handler("Service: %s | Params: %s", session->remote_service, __j);free(__j);}
38
39         
40
41         
42
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 */
48 };
49 typedef struct _osrfApplicationStruct osrfApplication;
50
51
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;
59 }; 
60 typedef struct _osrfMethodStruct osrfMethod;
61
62 struct _osrfMethodDispatcherStruct {
63         osrfAppSession* session;
64         osrfMethod* method;
65         jsonObject* params;
66         int request;
67 };
68 typedef struct _osrfMethodDispatcherStruct osrfMethodDispatcher;
69
70
71 /** 
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
76   */
77 int osrfAppRegisterApplication( char* appName, char* soFile );
78
79 /**
80   Register a method
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
87   */
88 int osrfAppRegisterMethod( char* appName, 
89                 char* methodName, char* symbolName, char* notes, int argc );
90
91 /**
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
95   */
96 osrfApplication* _osrfAppFindApplication( char* name );
97
98 /**
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
104   */
105 osrfMethod* _osrfAppFindMethod( char* appName, char* methodName );
106
107 /**
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
113   */
114 osrfMethod* __osrfAppFindMethod( osrfApplication* app, char* methodName );
115
116
117 /**
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
124   */
125 int osrfAppRunMethod( char* appName, char* methodName, 
126                 osrfAppSession* ses, int reqId, jsonObject* params );
127
128