1 #include "opensrf/osrf_app_session.h"
2 #include "opensrf/osrf_application.h"
3 #include "objson/object.h"
7 int osrfMathRun( osrfMethodDispatcher* );
11 osrfAppRegisterMethod( "opensrf.math", "add", "osrfMathRun", "send 2 numbers and I'll add them", 2 );
12 osrfAppRegisterMethod( "opensrf.math", "sub", "osrfMathRun", "send 2 numbers and I'll divide them", 2 );
13 osrfAppRegisterMethod( "opensrf.math", "mult", "osrfMathRun", "send 2 numbers and I'll multiply them", 2 );
14 osrfAppRegisterMethod( "opensrf.math", "div", "osrfMathRun", "send 2 numbers and I'll subtract them", 2 );
22 int osrfMathRun( osrfMethodDispatcher* d ) {
24 OSRF_METHOD_VERIFY_DISPATCHER(d);
26 jsonObject* x = jsonObjectGetIndex(params, 0);
27 jsonObject* y = jsonObjectGetIndex(params, 1);
31 char* a = jsonObjectToSimpleString(x);
32 char* b = jsonObjectToSimpleString(y);
36 jsonObject* new_params = jsonParseString("[]");
37 jsonObjectPush(new_params, jsonNewObject(a));
38 jsonObjectPush(new_params, jsonNewObject(b));
42 osrfAppSession* ses = osrfAppSessionClientInit("opensrf.dbmath");
43 int req_id = osrfAppSessionMakeRequest( ses, new_params, method->name, 1, NULL );
44 osrf_message* omsg = osrfAppSessionRequestRecv( ses, req_id, 60 );
47 osrfAppRequestRespond( session, request, omsg->_result_content );
48 osrf_message_free(omsg);