]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/libstack/osrf_application.h
added CONNECT handling
[OpenSRF.git] / 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   It also creates local variables "session", "method",
12   "params", and "request" 
13   */
14
15 #define OSRF_METHOD_VERIFY_CONTEXT(__d) \
16         if(!__d) return -1; \
17         \
18         osrfAppSession* session = __d->session; \
19         osrfMethod*     method = __d->method; \
20         jsonObject* params = __d->params; \
21         int request = __d->request; \
22         \
23         if( !(session && method && params) ) return -1; \
24         if( !params->type == JSON_ARRAY ) return -1; \
25         if( !method->name ) return -1; \
26         \
27         char* __j = jsonObjectToJSON(params);\
28         if(__j) { \
29                 debug_handler("Service: %s | Params: %s", session->remote_service, __j);free(__j);}
30
31         
32
33         
34
35 struct _osrfApplicationStruct {
36         char* name; /* the name of our application */
37         void* handle; /* the lib handle */
38         struct _osrfMethodStruct* methods;      /* list of methods */
39         struct _osrfApplicationStruct* next; /* next application */
40 };
41 typedef struct _osrfApplicationStruct osrfApplication;
42
43
44 struct _osrfMethodStruct {
45         char* name;                             /* the method name */
46         char* symbol;                   /* the symbol name (function) */
47         char* notes;                    /* public method documentation */
48         int argc;                               /* how many args this method expects */
49         void* methodHandle;     /* cached version of the method handle */
50         struct _osrfMethodStruct* next;
51 }; 
52 typedef struct _osrfMethodStruct osrfMethod;
53
54 struct _osrfMethodContextStruct {
55         osrfAppSession* session;
56         osrfMethod* method;
57         jsonObject* params;
58         int request;
59 };
60 typedef struct _osrfMethodContextStruct osrfMethodContext;
61
62
63 /** 
64   Register an application
65   @param appName The name of the application
66   @param soFile The library (.so) file that implements this application
67   @return 0 on success, -1 on error
68   */
69 int osrfAppRegisterApplication( char* appName, char* soFile );
70
71 /**
72   Register a method
73   @param appName The name of the application that implements the method
74   @param methodName The fully qualified name of the method
75   @param symbolName The symbol name (function) that implements the method
76   @param notes Public documentation for this method.
77   @params argc The number of arguments this method expects 
78   @return 0 on success, -1 on error
79   */
80 int osrfAppRegisterMethod( char* appName, 
81                 char* methodName, char* symbolName, char* notes, int argc );
82
83 /**
84   Finds the given app in the list of apps
85   @param name The name of the application
86   @return The application pointer or NULL if there is no such application
87   */
88 osrfApplication* _osrfAppFindApplication( char* name );
89
90 /**
91   Finds the given method for the given app
92   @param appName The application
93   @param methodName The method to find
94   @return A method pointer or NULL if no such method 
95   exists for the given application
96   */
97 osrfMethod* _osrfAppFindMethod( char* appName, char* methodName );
98
99 /**
100   Finds the given method for the given app
101   @param app The application object
102   @param methodName The method to find
103   @return A method pointer or NULL if no such method 
104   exists for the given application
105   */
106 osrfMethod* __osrfAppFindMethod( osrfApplication* app, char* methodName );
107
108
109 /**
110   Runs the specified method for the specified application.
111   @param appName The name of the application who's method to run
112   @param methodName The name of the method to run
113   @param ses The app session attached to this request
114   @params reqId The request id for this request
115   @param params The method parameters
116   */
117 int osrfAppRunMethod( char* appName, char* methodName, 
118                 osrfAppSession* ses, int reqId, jsonObject* params );
119
120