From 9e1689a7d789022182a69b4711bd2526ba069117 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 5 Oct 2005 14:05:12 +0000 Subject: [PATCH] slight C api change, method options are now passed as a single OR'ed group of option flags added some info logging to system git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@544 9efc2488-bf62-4759-914b-345cdb29e865 --- bin/opensrf_all | 15 ++++++-- src/Makefile | 3 +- src/c-apps/osrf_dbmath.c | 12 ++---- src/c-apps/osrf_math.c | 12 ++---- src/c-apps/osrf_version.c | 4 +- src/libstack/Makefile | 2 +- src/libstack/opensrf.c | 84 +++-------------------------------------- src/libstack/osrf_application.c | 71 +++++++++++++++++----------------- src/libstack/osrf_application.h | 43 +++++++++------------ src/libstack/osrf_system.c | 6 ++- 10 files changed, 86 insertions(+), 166 deletions(-) diff --git a/bin/opensrf_all b/bin/opensrf_all index 10eda5b..be84350 100755 --- a/bin/opensrf_all +++ b/bin/opensrf_all @@ -36,6 +36,7 @@ BOOTSTRAP="$ETCDIR/bootstrap.conf"; # opensrf config is here JSERVER="1"; ROUTER="1"; OPENSRF="1"; +OPENSRFC="1"; JSERVERSOCK="$PREFIX/var/sock/jserver.sock"; # jabber server socket file JSERVERLOG="$LOGDIR/jserver.log" # jabber server log @@ -85,9 +86,16 @@ function startRouter { } function startOpenSRF { - "$BINDIR/opensrf_ctl" start "$BOOTSTRAP"; -} + "$BINDIR/opensrf_ctl" start "$BOOTSTRAP"; + + if [ ! -z "$OPENSRFC" ]; then + echo "Starting OpenSRF-C..."; + # localhost will need to be changed... + "$BINDIR/opensrf-c" localhost "$ETCDIR//opensrf_core.xml" "opensrf" + echo "OpenSRF-C started OK"; + fi +} function makeMeGo { @@ -113,8 +121,8 @@ function makeMeGo { startOpenSRF; echo "OpenSRF started OK"; fi + return 0; - } @@ -122,6 +130,7 @@ function stopMe { echo "Stopping OpenSRF..."; "$BINDIR/opensrf_ctl" stop; + killall -9 opensrf-c; sleep 1; echo "Stopping The Router..."; diff --git a/src/Makefile b/src/Makefile index 864b0fc..10f9a17 100644 --- a/src/Makefile +++ b/src/Makefile @@ -89,6 +89,7 @@ opensrf-install: objson-install @echo $@ cp $(TMPDIR)/$(LIBOPENSRF) $(LIBDIR)/$(LIBOPENSRF) cp $(OPENSRF_HEADERS) $(INCLUDEDIR)/opensrf/ + cp libstack/opensrf $(BINDIR)/opensrf-c make -C c-apps install @@ -101,7 +102,7 @@ objson/libobjson.so: prep # -------------------------------------------------------------------------------- libstack/opensrf.o: libstack/opensrf.c libstack/opensrf: libstack/opensrf.o - $(CC) $(CFLAGS) $(LDFLAGS) -lxml2 -lopensrf -lobjson libstack/opensrf.o -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) -lJudy -lxml2 -lopensrf -lobjson libstack/opensrf.o -o $@ router: libopensrf.so diff --git a/src/c-apps/osrf_dbmath.c b/src/c-apps/osrf_dbmath.c index d05a138..b9d8c80 100644 --- a/src/c-apps/osrf_dbmath.c +++ b/src/c-apps/osrf_dbmath.c @@ -16,29 +16,25 @@ int osrfAppInitialize() { MODULENAME, "add", "osrfMathRun", - "Addss two numbers", - "[ num1, num2 ]", 2, 0 ); + "Addss two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "sub", "osrfMathRun", - "Subtracts two numbers", - "[ num1, num2 ]", 2, 0 ); + "Subtracts two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "mult", "osrfMathRun", - "Multiplies two numbers", - "[ num1, num2 ]", 2, 0 ); + "Multiplies two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "div", "osrfMathRun", - "Divides two numbers", - "[ num1, num2 ]", 2, 0 ); + "Divides two numbers", 2, 0 ); return 0; } diff --git a/src/c-apps/osrf_math.c b/src/c-apps/osrf_math.c index fc2bc44..a9b955f 100644 --- a/src/c-apps/osrf_math.c +++ b/src/c-apps/osrf_math.c @@ -17,30 +17,26 @@ int osrfAppInitialize() { "add", /* the name of the method */ "osrfMathRun", /* the symbol that runs the method */ "Adds two numbers", /* description of the method */ - "( num1, num2 )", /* description of the method params */ 2, /* the minimum number of params required to run the method */ - 0 ); /* streaming method? yes / no */ + 0 ); /* method options, 0 for not special options */ osrfAppRegisterMethod( MODULENAME, "sub", "osrfMathRun", - "Subtracts two numbers", - "( num1, num2 )", 2, 0 ); + "Subtracts two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "mult", "osrfMathRun", - "Multiplies two numbers", - "( num1, num2 )", 2, 0 ); + "Multiplies two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "div", "osrfMathRun", - "Divides two numbers", - "( num1, num2 )", 2, 0 ); + "Divides two numbers", 2, 0 ); return 0; } diff --git a/src/c-apps/osrf_version.c b/src/c-apps/osrf_version.c index ac0e3fb..a2187f0 100644 --- a/src/c-apps/osrf_version.c +++ b/src/c-apps/osrf_version.c @@ -19,8 +19,8 @@ int osrfAppInitialize() { "osrfVersion", "The data for a service/method/params combination will be retrieved " "from the necessary server and the MD5 sum of the total values received " - "will be returned", - "( serviceName, methodName, [param1, ...] )", 2, 0 ); + "will be returned. PARAMS( serviceName, methodName, [param1, ...] )", + 2, 0 ); return 0; } diff --git a/src/libstack/Makefile b/src/libstack/Makefile index 8399594..badde68 100644 --- a/src/libstack/Makefile +++ b/src/libstack/Makefile @@ -60,4 +60,4 @@ osrf_hash.o: osrf_hash.c osrf_hash.h clean: - /bin/rm -f *.o libopensrf_stack.so xml_utils.h xml_utils.c + /bin/rm -f *.o libopensrf_stack.so xml_utils.h xml_utils.c opensrf diff --git a/src/libstack/opensrf.c b/src/libstack/opensrf.c index 995fa84..8bbf880 100644 --- a/src/libstack/opensrf.c +++ b/src/libstack/opensrf.c @@ -2,84 +2,8 @@ #include "osrf_hash.h" #include "osrf_list.h" -//static void _free(void* i) { free(i); } -//static void _hfree(char* c, void* i) { free(i); } - int main( int argc, char* argv[] ) { - /* - osrfHash* list = osrfNewHash(); - list->freeItem = _hfree; - - char* x = strdup("X"); - char* y = strdup("Y"); - char* z = strdup("Z"); - osrfHashSet( list, x, "test1" ); - osrfHashSet( list, y, "test2" ); - osrfHashSet( list, z, "test3" ); - - char* q = (char*) osrfHashGet( list, "test1" ); - printf( "%s\n", q ); - - q = (char*) osrfHashGet( list, "test2" ); - printf( "%s\n", q ); - - q = (char*) osrfHashGet( list, "test3" ); - printf( "%s\n", q ); - - osrfHashIterator* itr = osrfNewHashIterator(list); - char* val; - - while( (val = osrfHashIteratorNext(itr)) ) - printf("Iterated item: %s\n", val ); - - osrfHashIteratorReset(itr); - while( (val = osrfHashIteratorNext(itr)) ) - printf("Iterated item: %s\n", val ); - - printf( "Count: %lu\n", osrfHashGetCount(list)); - - osrfHashIteratorFree(itr); - - osrfHashFree(list); - - exit(1); - - osrfList* list = osrfNewList(); - list->freeItem = _free; - - char* x = strdup("X"); - char* y = strdup("Y"); - char* z = strdup("Z"); - osrfListSet( list, x, 0 ); - osrfListSet( list, y, 2 ); - osrfListSet( list, z, 4 ); - - char* q = (char*) osrfListGetIndex( list, 4 ); - printf( "%s\n", q ); - - osrfListIterator* itr = osrfNewListIterator( list ); - char* val; - - while( (val = osrfListIteratorNext(itr)) ) - printf("Found val: %s\n", val ); - - osrfListIteratorReset(itr); - printf("\n"); - while( (val = osrfListIteratorNext(itr)) ) - printf("Found val: %s\n", val ); - - osrfListIteratorFree(itr); - - printf( "Count: %lu\n", osrfListGetCount(list)); - - osrfListFree(list); - - exit(1); - */ - - - if( argc < 4 ) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; @@ -88,9 +12,11 @@ int main( int argc, char* argv[] ) { fprintf(stderr, "Loading OpenSRF host %s with bootstrap config %s " "and config context %s\n", argv[1], argv[2], argv[3] ); - char* host = strdup( argv[1] ); - char* config = strdup( argv[2] ); - char* context = strdup( argv[3] ); + /* these must be strdup'ed because init_proc_title / set_proc_title + are evil and overwrite the argv memory */ + char* host = strdup( argv[1] ); + char* config = strdup( argv[2] ); + char* context = strdup( argv[3] ); init_proc_title( argc, argv ); set_proc_title( "OpenSRF System" ); diff --git a/src/libstack/osrf_application.c b/src/libstack/osrf_application.c index 0feb9b8..9f962e5 100644 --- a/src/libstack/osrf_application.c +++ b/src/libstack/osrf_application.c @@ -59,14 +59,7 @@ int osrfAppRegisterApplication( char* appName, char* soFile ) { int osrfAppRegisterMethod( char* appName, char* methodName, - char* symbolName, char* notes, char* params, int argc, int streaming ) { - - return _osrfAppRegisterMethod(appName, methodName, - symbolName, notes, params, argc, streaming, 0 ); -} - -int _osrfAppRegisterMethod( char* appName, char* methodName, - char* symbolName, char* notes, char* params, int argc, int streaming, int system ) { + char* symbolName, char* notes, int argc, int options ) { if( !appName || ! methodName ) return -1; @@ -76,15 +69,16 @@ int _osrfAppRegisterMethod( char* appName, char* methodName, debug_handler("Registering method %s for app %s", methodName, appName ); osrfMethod* method = _osrfAppBuildMethod( - methodName, symbolName, notes, params, argc, system, 0 ); - method->streaming = streaming; + methodName, symbolName, notes, argc, options ); + method->options = options; /* plug the method into the list of methods */ osrfHashSet( app->methods, method, method->name ); - if( streaming ) { /* build the atomic counterpart */ + if( options & OSRF_METHOD_STREAMING ) { /* build the atomic counterpart */ + int newops = options | OSRF_METHOD_ATOMIC; osrfMethod* atomicMethod = _osrfAppBuildMethod( - methodName, symbolName, notes, params, argc, system, 1 ); + methodName, symbolName, notes, argc, newops ); osrfHashSet( app->methods, atomicMethod, atomicMethod->name ); } @@ -94,50 +88,46 @@ int _osrfAppRegisterMethod( char* appName, char* methodName, osrfMethod* _osrfAppBuildMethod( char* methodName, - char* symbolName, char* notes, char* params, int argc, int sysmethod, int atomic ) { + char* symbolName, char* notes, int argc, int options ) { osrfMethod* method = safe_malloc(sizeof(osrfMethod)); if(methodName) method->name = strdup(methodName); if(symbolName) method->symbol = strdup(symbolName); if(notes) method->notes = strdup(notes); - if(params) method->paramNotes = strdup(params); method->argc = argc; - method->sysmethod = sysmethod; - method->atomic = atomic; - method->cachable = 0; + method->options = options; - if(atomic) { /* add ".atomic" to the end of the name */ + if(options & OSRF_METHOD_ATOMIC) { /* add ".atomic" to the end of the name */ char mb[strlen(method->name) + 8]; sprintf(mb, "%s.atomic", method->name); free(method->name); method->name = strdup(mb); - method->streaming = 1; + method->options |= OSRF_METHOD_STREAMING; } - debug_handler("Built method %s", method->name ); - return method; } int __osrfAppRegisterSysMethods( char* app ) { - _osrfAppRegisterMethod( + osrfAppRegisterMethod( app, OSRF_SYSMETHOD_INTROSPECT, NULL, "Return a list of methods whose names have the same initial " - "substring as that of the provided method name", - "( methodNameSubstring )", 1, 1 , 1); + "substring as that of the provided method name PARAMS( methodNameSubstring )", + 1, OSRF_METHOD_SYSTEM | OSRF_METHOD_STREAMING ); - _osrfAppRegisterMethod( + osrfAppRegisterMethod( app, OSRF_SYSMETHOD_INTROSPECT_ALL, NULL, - "Returns a complete list of methods", "()", 0, 1, 1 ); + "Returns a complete list of methods. PARAMS()", 0, + OSRF_METHOD_SYSTEM | OSRF_METHOD_STREAMING ); - _osrfAppRegisterMethod( + osrfAppRegisterMethod( app, OSRF_SYSMETHOD_ECHO, NULL, - "Echos all data sent to the server back to the client", - "([a, b, ...])", 0, 1, 1); + "Echos all data sent to the server back to the client. PARAMS([a, b, ...])", 0, + OSRF_METHOD_SYSTEM | OSRF_METHOD_STREAMING ); return 0; } @@ -199,7 +189,7 @@ int osrfAppRunMethod( char* appName, char* methodName, int retcode = 0; - if( method->sysmethod ) { + if( method->options & OSRF_METHOD_SYSTEM ) { retcode = __osrfAppRunSystemMethod(&context); } else { @@ -235,7 +225,7 @@ int osrfAppRespondComplete( osrfMethodContext* context, jsonObject* data ) { int _osrfAppRespond( osrfMethodContext* ctx, jsonObject* data, int complete ) { if(!(ctx && ctx->method)) return -1; - if( ctx->method->atomic ) { + if( ctx->method->options & OSRF_METHOD_ATOMIC ) { osrfLog( OSRF_DEBUG, "Adding responses to stash for atomic method %s", ctx->method ); @@ -245,7 +235,9 @@ int _osrfAppRespond( osrfMethodContext* ctx, jsonObject* data, int complete ) { } - if( !ctx->method->atomic && ! ctx->method->cachable ) { + if( !(ctx->method->options & OSRF_METHOD_ATOMIC) && + !(ctx->method->options & OSRF_METHOD_CACHABLE) ) { + if(complete) osrfAppRequestRespondComplete( ctx->session, ctx->request, data ); else @@ -265,7 +257,7 @@ int __osrfAppPostProcess( osrfMethodContext* ctx, int retcode ) { osrfLog( OSRF_DEBUG, "Postprocessing method %s with retcode %d", ctx->method->name, retcode ); - if(ctx->responses) { /* we have cached responses to return */ + if(ctx->responses) { /* we have cached responses to return (no responses have been sent) */ osrfAppRequestRespondComplete( ctx->session, ctx->request, ctx->responses ); jsonObjectFree(ctx->responses); @@ -294,15 +286,20 @@ int osrfAppRequestRespondException( osrfAppSession* ses, int request, char* msg, static void __osrfAppSetIntrospectMethod( osrfMethodContext* ctx, osrfMethod* method, jsonObject* resp ) { if(!(ctx && resp)) return; + jsonObjectSetKey(resp, "api_name", jsonNewObject(method->name)); jsonObjectSetKey(resp, "method", jsonNewObject(method->symbol)); jsonObjectSetKey(resp, "service", jsonNewObject(ctx->session->remote_service)); jsonObjectSetKey(resp, "notes", jsonNewObject(method->notes)); jsonObjectSetKey(resp, "argc", jsonNewNumberObject(method->argc)); - jsonObjectSetKey(resp, "params", jsonNewObject(method->paramNotes) ); - jsonObjectSetKey(resp, "sysmethod", jsonNewNumberObject(method->sysmethod) ); - jsonObjectSetKey(resp, "atomic", jsonNewNumberObject(method->atomic) ); - jsonObjectSetKey(resp, "cachable", jsonNewNumberObject(method->cachable) ); + + jsonObjectSetKey(resp, "sysmethod", + jsonNewNumberObject( (method->options & OSRF_METHOD_SYSTEM) ? 1 : 0 )); + jsonObjectSetKey(resp, "atomic", + jsonNewNumberObject( (method->options & OSRF_METHOD_ATOMIC) ? 1 : 0 )); + jsonObjectSetKey(resp, "cachable", + jsonNewNumberObject( (method->options & OSRF_METHOD_CACHABLE) ? 1 : 0 )); + jsonObjectSetClass(resp, "method"); } diff --git a/src/libstack/osrf_application.h b/src/libstack/osrf_application.h index 4dea5a2..78868d8 100644 --- a/src/libstack/osrf_application.h +++ b/src/libstack/osrf_application.h @@ -67,17 +67,16 @@ #define OSRF_SYSMETHOD_ECHO "opensrf.system.echo" #define OSRF_SYSMETHOD_ECHO_ATOMIC "opensrf.system.echo.atomic" -//#define OSRF_METHOD_ATOMIC 1 -//#define OSRF_METHOD_CACHABLE 2 +#define OSRF_METHOD_SYSTEM 1 +#define OSRF_METHOD_STREAMING 2 +#define OSRF_METHOD_ATOMIC 4 +#define OSRF_METHOD_CACHABLE 8 struct _osrfApplicationStruct { - //char* name; /* the name of our application */ void* handle; /* the lib handle */ osrfHash* methods; - //struct _osrfMethodStruct* methods; /* list of methods */ -// struct _osrfApplicationStruct* next; /* next application */ }; typedef struct _osrfApplicationStruct osrfApplication; @@ -87,12 +86,15 @@ struct _osrfMethodStruct { char* symbol; /* the symbol name (function) */ char* notes; /* public method documentation */ int argc; /* how many args this method expects */ - char* paramNotes; /* Description of the params expected for this method */ -// struct _osrfMethodStruct* next; /* nest method in the list */ - int sysmethod; /* true if this is a system method */ - int streaming; /* true if this is a streamable method */ - int atomic; /* true if the method is an atomic method */ - int cachable; /* true if the method is cachable */ + //char* paramNotes; /* Description of the params expected for this method */ + int options; /* describes the various options for this method */ + + /* + int sysmethod; + int streaming; + int atomic; + int cachable; + */ }; typedef struct _osrfMethodStruct osrfMethod; @@ -117,33 +119,22 @@ int osrfAppRegisterApplication( char* appName, char* soFile ); /** Register a method + Any method with the OSRF_METHOD_STREAMING option set will have a ".atomic" + version of the method registered automatically @param appName The name of the application that implements the method @param methodName The fully qualified name of the method @param symbolName The symbol name (function) that implements the method @param notes Public documentation for this method. - @params params String description description of the params expected @params argc The number of arguments this method expects @param streaming True if this is a streaming method that requires an atomic version @return 0 on success, -1 on error */ int osrfAppRegisterMethod( char* appName, char* methodName, - char* symbolName, char* notes, char* params, int argc, int streaming ); + char* symbolName, char* notes, int argc, int options ); -int _osrfAppRegisterMethod( char* appName, char* methodName, - char* symbolName, char* notes, char* params, int argc, int streaming, int system ); osrfMethod* _osrfAppBuildMethod( char* methodName, - char* symbolName, char* notes, char* params, int argc, int sysmethod, int streaming ); - -/** - Registher a method - @param appName The name of the application that implements the method - @params desc The method description - @return 0 on success, -1 on error - */ -/* -int osrfAppRegisterMethod( char* appName, osrfMethodDescription* desc ); -*/ + char* symbolName, char* notes, int argc, int options ); /** Finds the given app in the list of apps diff --git a/src/libstack/osrf_system.c b/src/libstack/osrf_system.c index d6c9e85..eac1c69 100644 --- a/src/libstack/osrf_system.c +++ b/src/libstack/osrf_system.c @@ -103,6 +103,7 @@ int osrfSystemBootstrap( char* hostname, char* configfile, char* contextNode ) { } else { + fprintf(stderr, " * Running application %s\n", appname); if( osrfAppRegisterApplication( appname, libfile ) == 0 ) osrf_prefork_run(appname); @@ -114,7 +115,8 @@ int osrfSystemBootstrap( char* hostname, char* configfile, char* contextNode ) { /** daemonize me **/ - /* let our children do their thing */ + /* background and let our children do their thing */ + daemonize(); while(1) { signal(SIGCHLD, __osrfSystemSignalHandler); sleep(10000); @@ -215,3 +217,5 @@ void __osrfSystemSignalHandler( int sig ) { /** relaunch the server **/ } + + -- 2.11.0