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