LP#1729610: extend backlog queue to C apps
[opensrf-equinox.git] / src / c-apps / osrf_cslow.c
diff --git a/src/c-apps/osrf_cslow.c b/src/c-apps/osrf_cslow.c
new file mode 100644 (file)
index 0000000..108977a
--- /dev/null
@@ -0,0 +1,58 @@
+#include <opensrf/osrf_app_session.h>
+#include <opensrf/osrf_application.h>
+#include <opensrf/osrf_json.h>
+#include <opensrf/log.h>
+
+#define MODULENAME "opensrf.cslow"
+
+int osrfAppInitialize();
+int osrfAppChildInit();
+int osrfCSlowWait( osrfMethodContext* );
+
+
+int osrfAppInitialize() {
+
+       osrfAppRegisterMethod( 
+                       MODULENAME, 
+                       "opensrf.cslow.wait", 
+                       "osrfCSlowWait", 
+                       "Wait specified number of seconds, then return that number", 1, 0 );
+
+       return 0;
+}
+
+int osrfAppChildInit() {
+       return 0;
+}
+
+int osrfCSlowWait( osrfMethodContext* ctx ) {
+       if( osrfMethodVerifyContext( ctx ) ) {
+               osrfLogError( OSRF_LOG_MARK,  "Invalid method context" );
+               return -1;
+       }
+
+       const jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
+
+       if( x ) {
+
+               char* a = jsonObjectToSimpleString(x);
+
+               if( a ) {
+
+                       unsigned int pause = atoi(a);
+                       sleep(pause);
+
+                       jsonObject* resp = jsonNewNumberObject(pause);
+                       osrfAppRespondComplete( ctx, resp );
+                       jsonObjectFree(resp);
+
+                       free(a);
+                       return 0;
+               }
+       }
+
+       return -1;
+}
+
+
+