initial event handler
[src/app-framework-binder.git] / src / afb-api-so.c
index 60af72e..88246b5 100644 (file)
@@ -46,6 +46,7 @@ extern __thread sigjmp_buf *error_handler;
 
 struct api_so_desc {
        struct AFB_plugin *plugin;      /* descriptor */
+       size_t apilength;
        void *handle;                   /* context of dlopen */
        struct AFB_interface interface; /* interface */
 };
@@ -65,6 +66,16 @@ static const struct afb_pollmgr_itf pollmgr_itf = {
 
 static void afb_api_so_evmgr_push(struct api_so_desc *desc, const char *name, struct json_object *object)
 {
+       size_t length;
+       char *event;
+
+       assert(desc->plugin != NULL);
+       length = strlen(name);
+       event = alloca(length + 2 + desc->apilength);
+       memcpy(event, desc->plugin->prefix, desc->apilength);
+       event[desc->apilength] = '/';
+       memcpy(event + desc->apilength + 1, name, length + 1);
+       ctxClientEventSend(NULL, event, object);
 }
 
 static const struct afb_evmgr_itf evmgr_itf = {
@@ -86,17 +97,6 @@ static const struct afb_daemon_itf daemon_itf = {
        .get_pollmgr = (void*)afb_api_so_get_pollmgr
 };
 
-static void free_context(struct api_so_desc *desc, void *context)
-{
-       void (*cb)(void*);
-
-       cb = desc->plugin->freeCtxCB;
-       if (cb)
-               cb(context);
-       else
-               free(context);
-}
-
 static void trapping_call(struct afb_req req, void(*cb)(struct afb_req))
 {
        volatile int signum, timerset;
@@ -159,7 +159,6 @@ static void call_check(struct afb_req req, const struct AFB_restapi *verb)
                break;
        }
        trapping_call(req, verb->callback);
-
        if (verb->session == AFB_SESSION_CLOSE)
                afb_req_session_close(req);
 }
@@ -236,10 +235,10 @@ int afb_api_so_add_plugin(const char *path)
        }
 
        /* records the plugin */
+       desc->apilength = strlen(desc->plugin->prefix);
        if (afb_apis_add(desc->plugin->prefix, (struct afb_api){
                        .closure = desc,
-                       .call = (void*)call,
-                       .free_context = (void*)free_context}) < 0) {
+                       .call = (void*)call}) < 0) {
                fprintf(stderr, "ERROR: plugin [%s] can't be registered...\n", path);
                goto error3;
        }