diff options
author | José Bollo <jose.bollo@iot.bzh> | 2016-03-30 13:55:50 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2016-03-30 13:55:50 +0200 |
commit | ca208671cc79bbc05c574df788035878e5d39382 (patch) | |
tree | f5a61c22b3d650e20b21295706320602da1f3d19 /plugins | |
parent | 8ca3d16606a99ef91d01a623dbe5ce1331688953 (diff) |
refactoring
Change-Id: I8dd46cf7fa57962e20e02f0fe34b3ffaa4c94f08
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/media/media-api.c | 2 | ||||
-rw-r--r-- | plugins/radio/radio-api.c | 12 | ||||
-rw-r--r-- | plugins/samples/ClientCtx.c | 21 | ||||
-rw-r--r-- | plugins/samples/HelloWorld.c | 2 | ||||
-rw-r--r-- | plugins/samples/SamplePost.c | 1 | ||||
-rw-r--r-- | plugins/session/token-api.c | 5 |
6 files changed, 21 insertions, 22 deletions
diff --git a/plugins/media/media-api.c b/plugins/media/media-api.c index 92e195a9..4e064bc2 100644 --- a/plugins/media/media-api.c +++ b/plugins/media/media-api.c @@ -33,7 +33,7 @@ STATIC mediaCtxHandleT* initMediaCtx () { } /* called when client session dies [e.g. client quits for more than 15mns] */ -STATIC void freeMedia (void *context, void *handle) { +STATIC void freeMedia (void *context) { free (context); } diff --git a/plugins/radio/radio-api.c b/plugins/radio/radio-api.c index ea17eb51..bdb1768f 100644 --- a/plugins/radio/radio-api.c +++ b/plugins/radio/radio-api.c @@ -26,6 +26,8 @@ /* ------ LOCAL HELPER FUNCTIONS --------- */ +static pluginHandleT *the_radio = NULL; + /* detect new radio devices */ STATIC void updateRadioDevList(pluginHandleT *handle) { @@ -116,9 +118,9 @@ STATIC AFB_error releaseRadio (pluginHandleT *handle, radioCtxHandleT *ctx) { } /* called when client session dies [e.g. client quits for more than 15mns] */ -STATIC void freeRadio (void *context, void *handle) { +STATIC void freeRadio (void *context) { - releaseRadio (handle, context); + releaseRadio (the_radio, context); free (context); } @@ -140,7 +142,7 @@ STATIC json_object* init (AFB_request *request) { /* AFB_SESSION_CHECK */ STATIC json_object* power (AFB_request *request) { /* AFB_SESSION_CHECK */ - pluginHandleT *handle = (pluginHandleT*)request->handle; + pluginHandleT *handle = the_radio; radioCtxHandleT *ctx = (radioCtxHandleT*)request->context; const char *value = getQueryValue (request, "value"); json_object *jresp; @@ -325,8 +327,8 @@ PUBLIC AFB_plugin* pluginRegister () { plugin->prefix = "radio"; plugin->apis = pluginApis; - plugin->handle = initRadioPlugin(); plugin->freeCtxCB = (AFB_freeCtxCB)freeRadio; - return (plugin); + radio = initRadioPlugin(); + return plugin; }; diff --git a/plugins/samples/ClientCtx.c b/plugins/samples/ClientCtx.c index b2479f50..b59400e1 100644 --- a/plugins/samples/ClientCtx.c +++ b/plugins/samples/ClientCtx.c @@ -56,7 +56,9 @@ typedef struct { } MyClientContextT; - +// Plugin handle should not be in stack (malloc or static) +STATIC MyPluginHandleT global_handle; + // This function is call at session open time. Any client trying to // call it with an already open session will be denied. // Ex: http://localhost:1234/api/context/create?token=123456789 @@ -64,7 +66,7 @@ STATIC json_object* myCreate (AFB_request *request) { json_object *jresp; MyClientContextT *ctx= malloc (sizeof (MyClientContextT)); - MyPluginHandleT *handle = (MyPluginHandleT*) request->handle; + MyPluginHandleT *handle = (MyPluginHandleT*) &global_handle; // store something in our plugin private client context ctx->count = 0; @@ -82,7 +84,7 @@ STATIC json_object* myCreate (AFB_request *request) { // ex: http://localhost:1234/api/context/action?token=xxxxxx-xxxxxx-xxxxx-xxxxx-xxxxxx STATIC json_object* myAction (AFB_request *request) { json_object* jresp; - MyPluginHandleT *handle = (MyPluginHandleT*) request->handle; + MyPluginHandleT *handle = (MyPluginHandleT*) &global_handle; MyClientContextT *ctx= (MyClientContextT*) request->context; // store something in our plugin private client context @@ -98,7 +100,7 @@ STATIC json_object* myAction (AFB_request *request) { // ex: http://localhost:1234/api/context/close?token=xxxxxx-xxxxxx-xxxxx-xxxxx-xxxxxx STATIC json_object* myClose (AFB_request *request) { json_object* jresp; - MyPluginHandleT *handle = (MyPluginHandleT*) request->handle; + MyPluginHandleT *handle = (MyPluginHandleT*) &global_handle; MyClientContextT *ctx= (MyClientContextT*) request->context; // store something in our plugin private client context @@ -109,8 +111,9 @@ STATIC json_object* myClose (AFB_request *request) { return jresp; } -STATIC void freeCtxCB (MyClientContextT *ctx, MyPluginHandleT *handle, char *uuid) { - fprintf (stderr, "FreeCtxCB uuid=[%s] Plugin=[%s] count=[%d]", uuid, (char*)handle->anythingYouWant, ctx->count); +STATIC void freeCtxCB (MyClientContextT *ctx) { + MyPluginHandleT *handle = (MyPluginHandleT*) &global_handle; + fprintf (stderr, "FreeCtxCB Plugin=[%s] count=[%d]", (char*)handle->anythingYouWant, ctx->count); free (ctx); // Note: handle should be free it is a static resource attached to plugin and not to session @@ -127,19 +130,15 @@ STATIC AFB_restapi pluginApis[]= { PUBLIC AFB_plugin *pluginRegister () { - // Plugin handle should not be in stack (malloc or static) - STATIC MyPluginHandleT handle; - AFB_plugin *plugin = malloc (sizeof (AFB_plugin)); plugin->type = AFB_PLUGIN_JSON; plugin->info = "Sample of Client Context Usage"; plugin->prefix = "context"; plugin->apis = pluginApis; - plugin->handle = &handle; plugin->freeCtxCB= (AFB_freeCtxCB) freeCtxCB; // feed plugin handle before returning from registration - handle.anythingYouWant = "My Plugin Handle"; + global_handle.anythingYouWant = "My Plugin Handle"; return (plugin); }; diff --git a/plugins/samples/HelloWorld.c b/plugins/samples/HelloWorld.c index 05bec957..067365dd 100644 --- a/plugins/samples/HelloWorld.c +++ b/plugins/samples/HelloWorld.c @@ -30,7 +30,7 @@ STATIC json_object* pingSample (AFB_request *request) { if (len == 0) strcpy (query,"NoSearchQueryList"); // check if we have some post data - if (request->post == NULL) request->post->data="NoData"; + if (request->post != NULL) request->post->data="NoData"; // return response to caller response = jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon %d query={%s} PostData: \'%s\' ", pingcount++, query, request->post); diff --git a/plugins/samples/SamplePost.c b/plugins/samples/SamplePost.c index 22acd095..d29fb05a 100644 --- a/plugins/samples/SamplePost.c +++ b/plugins/samples/SamplePost.c @@ -123,7 +123,6 @@ PUBLIC AFB_plugin *pluginRegister () { plugin->info = "Sample with Post Upload Files"; plugin->prefix= "post"; // url base plugin->apis = pluginApis; - plugin->handle= (void*) "What ever you want"; return (plugin); }; diff --git a/plugins/session/token-api.c b/plugins/session/token-api.c index 7073dac0..9a078328 100644 --- a/plugins/session/token-api.c +++ b/plugins/session/token-api.c @@ -91,8 +91,8 @@ STATIC json_object* clientGetPing (AFB_request *request) { // This function is call when Client Session Context is removed // Note: when freeCtxCB==NULL standard free/malloc is called -STATIC void clientContextFree(void *context, char* uuid) { - fprintf (stderr,"Plugin[token] Closing Session uuid=[%s]\n", uuid); +STATIC void clientContextFree(void *context) { + fprintf (stderr,"Plugin[token] Closing Session\n"); free (context); } @@ -111,7 +111,6 @@ PUBLIC AFB_plugin *pluginRegister () { plugin->info = "Application Framework Binder Service"; plugin->prefix= "token"; // url base plugin->apis = pluginApis; - plugin->handle= (void*) "What ever you want"; plugin->freeCtxCB= (void*) clientContextFree; return (plugin); |