1 #ifndef OSRF_APPLICATION_H
2 #define OSRF_APPLICATION_H
5 @file osrf_application.h
6 @brief Routines to load and manage shared object libraries.
8 Every method of a service is implemented by a C function. In a few cases those
9 functions are generic to all services. In other cases they are loaded and executed from
10 a shared object library that is specific to the application offering the service, A
11 registry maps method names to function names so that we can call the right function.
13 Each such function has a similar signature:
15 int method_name( osrfMethodContext* ctx );
17 The return value is negative in case of an error. A return code of zero implies that
18 the method has already sent the client a STATUS message to say that it is finished.
19 A return code greater than zero implies that the method has not sent such a STATUS
20 message, so we need to do so after the method returns.
22 Any arguments passed to the method are bundled together in a jsonObject inside the
25 An application's shared object may also implement any or all of three standard functions:
27 - int osrfAppInitialize( void ) Called when an application is registered
28 - int osrfAppChildInit( void ) Called when a server drone is spawned
29 - void osrfAppChildExit( void ) Called when a server drone terminates
31 osrfAppInitialize() and osrfAppChild return zero if successful, and non-zero if not.
34 #include <opensrf/utils.h>
35 #include <opensrf/log.h>
36 #include <opensrf/osrf_app_session.h>
37 #include <opensrf/osrf_hash.h>
38 #include <opensrf/string_array.h>
40 #include <opensrf/osrf_json.h>
49 All OpenSRF methods take the signature
50 int methodName( osrfMethodContext* );
51 If a negative number is returned, it means an unknown error occured and an exception
52 will be returned to the client automatically.
53 If a positive number is returned, it means that libopensrf should send a 'Request Complete'
54 message following any messages sent by the method.
55 If 0 is returned, it tells libopensrf that the method completed successfully and
56 there is no need to send any further data to the client.
59 /** This macro verifies that methods receive the correct parameters */
60 /** TODO: deprecate me, since I no longer server a purpose */
61 #define OSRF_METHOD_VERIFY_CONTEXT(d) osrfMethodVerifyContext(d)
65 @brief Macros that get OR'd together to form method options.
69 @brief Notes that the method may return more than one result.
71 For a @em streaming method, we register both an atomic method and a non-atomic method.
73 #define OSRF_METHOD_STREAMING 2
75 @brief Notes that a previous result to the same call may be available in memcache.
77 Before calling the registered function, a cachable method checks memcache for a previously
78 determined result for the same call. If no such result is available, it calls the
79 registered function and caches the new result before returning.
81 This caching is not currently implemented for C methods.
83 #define OSRF_METHOD_CACHABLE 8
87 char* name; /**< Method name. */
88 char* symbol; /**< Symbol name (function name) within the shared object. */
89 char* notes; /**< Public method documentation. */
90 int argc; /**< The minimum number of arguments for the method. */
91 //char* paramNotes; /**< Description of the params expected for this method. */
92 int options; /**< Bit switches setting various options for this method. */
93 void* userData; /**< Opaque pointer to application-specific data. */
94 size_t max_bundle_size; /**< How big a buffer to use for non-atomic methods */
95 size_t max_chunk_size; /**< Maximum content size per message; 0 means no limit */
106 osrfAppSession* session; /**< Pointer to the current application session. */
107 osrfMethod* method; /**< Pointer to the requested method. */
108 jsonObject* params; /**< Parameters to the method. */
109 int request; /**< Request id. */
110 jsonObject* responses; /**< Array of cached responses. */
113 int osrfAppRegisterApplication( const char* appName, const char* soFile );
115 int osrfAppRegisterMethod( const char* appName, const char* methodName,
116 const char* symbolName, const char* notes, int argc, int options );
118 int osrfAppRegisterExtendedMethod( const char* appName, const char* methodName,
119 const char* symbolName, const char* notes, int argc, int options, void* );
121 int osrfMethodSetBundleSize( const char* appName, const char* methodName, size_t max_bundle_size );
123 osrfMethod* _osrfAppFindMethod( const char* appName, const char* methodName );
125 int osrfAppRunMethod( const char* appName, const char* methodName,
126 osrfAppSession* ses, int reqId, jsonObject* params );
128 int osrfAppRequestRespondException( osrfAppSession* ses, int request, const char* msg, ... );
130 int osrfAppRespond( osrfMethodContext* context, const jsonObject* data );
132 int osrfAppRespondComplete( osrfMethodContext* context, const jsonObject* data );
134 int osrfAppRunChildInit(const char* appname);
136 void osrfAppRunExitCode( void );
138 int osrfMethodVerifyContext( osrfMethodContext* ctx );