changed around the status method some
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 12 Sep 2005 22:20:08 +0000 (22:20 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 12 Sep 2005 22:20:08 +0000 (22:20 +0000)
added the framework for processing 'system' method (introspect, etc.)
implemented opensrf.system.method.all

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@535 9efc2488-bf62-4759-914b-345cdb29e865

src/libstack/Makefile
src/libstack/osrf_app_session.c
src/libstack/osrf_app_session.h
src/libstack/osrf_application.c
src/libstack/osrf_application.h
src/libstack/osrf_log.c
src/libstack/osrf_stack.c

index a6e5c00..1ff362a 100644 (file)
@@ -1,5 +1,5 @@
 
-CFLAGS +=  -DASSUME_STATELESS  -rdynamic -fno-strict-aliasing
+CFLAGS +=  -DASSUME_STATELESS  -DOSRF_LOG_PARAMS -rdynamic -fno-strict-aliasing
 LDLIBS += -lxml2 -lobjson -ldl -lmemcache
 
 TARGETS = osrf_message.o \
index 559053a..83a1644 100644 (file)
@@ -757,11 +757,11 @@ int osrfAppRequestRespondComplete(
 
 
 
-int osrfAppSessionStatus( osrfAppSession* ses, int type, int reqId, char* message ) {
+int osrfAppSessionStatus( osrfAppSession* ses, int type, char* name, int reqId, char* message ) {
 
        if(ses) {
                osrf_message* msg = osrf_message_init( STATUS, reqId, 1);
-               osrf_message_set_status_info( msg, "Server Error", message, type );
+               osrf_message_set_status_info( msg, name, message, type );
                _osrf_app_session_send( ses, msg ); 
                osrf_message_free( msg );
                return 0;
index 84a7c09..8489cf2 100644 (file)
@@ -225,7 +225,7 @@ int osrfAppSessionSendBatch( osrf_app_session*, osrf_message* msgs[], int size )
 int osrfAppRequestRespond( osrfAppSession* ses, int requestId, jsonObject* data ); 
 int osrfAppRequestRespondComplete( osrfAppSession* ses, int requestId, jsonObject* data ); 
 
-int osrfAppSessionStatus( osrfAppSession* ses, int type, int reqId, char* message );
+int osrfAppSessionStatus( osrfAppSession* ses, int type, char* name, int reqId, char* message );
 
 
 #endif
index cb2c16e..4aa3369 100644 (file)
@@ -1,5 +1,6 @@
-
 #include "osrf_application.h"
+#include "osrf_log.h"
+#include "objson/object.h"
 
 osrfApplication* __osrfAppList = NULL; 
 
@@ -114,6 +115,10 @@ int osrfAppRunMethod( char* appName, char* methodName, osrfAppSession* ses, int
        osrfMethod* method;
        osrfMethodContext context;
 
+       context.session = ses;
+       context.params = params;
+       context.request = reqId;
+
        /* this is the method we're gonna run */
        int (*meth) (osrfMethodContext*);       
 
@@ -123,9 +128,25 @@ int osrfAppRunMethod( char* appName, char* methodName, osrfAppSession* ses, int
        if( !(app = _osrfAppFindApplication(appName)) )
                return warning_handler( "Application not found: %s", appName );
 
-       if( !(method = __osrfAppFindMethod( app, methodName )) )
+       
+       if( !(method = __osrfAppFindMethod( app, methodName )) ) {
+               /* see if the unfound method is a system method */
+               info_handler("Method %s not found, checking to see if it's a system method...", methodName );
+               osrfMethod meth;
+               meth.name = methodName;
+               context.method = &meth;
+               int sysres = __osrfAppRunSystemMethod(&context);
+               if(sysres == 0) return 0;
+               if(sysres > 0) {
+                       osrfAppSessionStatus( ses, OSRF_STATUS_COMPLETE,  "osrfConnectStatus", reqId, "Request Complete" );
+                       return 0;
+               }
                return warning_handler( "NOT FOUND: app %s / method %s", appName, methodName );
+       }
 
+
+       context.method = method;
+       
        /* open the method */
        *(void **) (&meth) = dlsym(app->handle, method->symbol);
 
@@ -134,25 +155,55 @@ int osrfAppRunMethod( char* appName, char* methodName, osrfAppSession* ses, int
                                "for method %s and app %s", method->symbol, method->name, app->name );
        }
 
-       context.session = ses;
-       context.method = method;
-       context.params = params;
-       context.request = reqId;
-
        /* run the method */
        int ret = (*meth) (&context);
 
        debug_handler("method returned %d", ret );
 
-
        if(ret == -1) {
-               osrfAppSessionStatus( ses, OSRF_STATUS_INTERNALSERVERERROR, 
-                                       reqId, "An unknown server error occurred" );
+               osrfAppSessionStatus( ses, OSRF_STATUS_INTERNALSERVERERROR,  
+                       "Server Error", reqId, "An unknown server error occurred" );
                return -1;
        }
 
+       if( ret > 0 ) 
+               osrfAppSessionStatus( ses, OSRF_STATUS_COMPLETE,  "osrfConnectStatus", reqId, "Request Complete" );
+
        return 0;
 }
 
 
 
+int __osrfAppRunSystemMethod(osrfMethodContext* ctx) {
+       OSRF_METHOD_VERIFY_CONTEXT(ctx);
+
+       if( !strcmp(ctx->method->name, OSRF_SYSMETHOD_INTROSPECT_ALL )) {
+
+               jsonObject* resp = NULL;
+               osrfApplication* app = _osrfAppFindApplication( ctx->session->remote_service );
+               if(app) {
+                       osrfMethod* method = app->methods;
+                       while(method) {
+                               resp = jsonNewObject(NULL);
+                               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));
+                               osrfAppRequestRespond(ctx->session, ctx->request, resp);
+                               method = method->next;
+                               jsonObjectSetClass(resp, "method");
+                               jsonObjectFree(resp);
+                       }
+                       return 1;
+               }
+
+               return -1;
+       }
+
+       return -1;
+}
+
+
+
+
index 2921952..23e5a30 100644 (file)
@@ -6,6 +6,7 @@
 #include "objson/object.h"
 #include "osrf_app_session.h"
 
+
 /** 
   This macro verifies methods receive the correct parameters 
   */
@@ -26,7 +27,7 @@
        _OSRF_METHOD_VERIFY_CONTEXT(d); \
        char* __j = jsonObjectToJSON(d->params);\
        if(__j) { \
-               osrfLog( OSRF_DEBUG, "[%s:%s] params: %s", d->session->remote_service, d->method->name, __j);\
+               osrfLog( OSRF_INFO, "[%s:%s] params: %s", d->session->remote_service, d->method->name, __j);\
                free(__j); \
        } 
 #else
 #endif
 
 
+
+
+#define OSRF_SYSMETHOD_INTROSPECT "opensrf.system.method"
+#define OSRF_SYSMETHOD_INTROSPECT_ALL "opensrf.system.method.all"
+
+
        
 
        
@@ -124,3 +131,14 @@ int osrfAppRunMethod( char* appName, char* methodName,
                osrfAppSession* ses, int reqId, jsonObject* params );
 
 
+/**
+  Trys to run the requested method as a system method.
+  A system method is a well known method that all
+  servers implement.  
+  @param context The current method context
+  @return 0 if the method is run, -1 otherwise
+  */
+int __osrfAppRunSystemMethod(osrfMethodContext* context);
+
+
+
index a39de32..2bdb2dc 100644 (file)
@@ -59,6 +59,9 @@ void osrfLog( enum OSRF_LOG_LEVEL level, char* msg, ... ) {
        VA_LIST_TO_STRING(msg);
        fprintf(file, "[%s.%s %d %d] %s\n", timebuf, millis + 2, getpid(), level, VA_BUF );
        fclose(file);
+
+       if( level == OSRF_ERROR )
+               fprintf(stderr, "[%s.%s %d %d] %s\n", timebuf, millis + 2, getpid(), level, VA_BUF );
 }
 
 
index c69529f..4fb3955 100644 (file)
@@ -201,8 +201,8 @@ osrf_message* _do_server( osrf_app_session* session, osrf_message* msg ) {
                                return NULL;
 
                case CONNECT:
-                               osrfAppSessionStatus( session, 
-                                               OSRF_STATUS_OK, msg->thread_trace, "Connection Successful" );
+                               osrfAppSessionStatus( session, OSRF_STATUS_OK, 
+                                               "osrfConnectStatus", msg->thread_trace, "Connection Successful" );
                                return NULL;
 
                case REQUEST: