summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-04-18 17:08:26 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-04-19 11:50:40 +0200
commit469e619ac45402471ea7d8c792ffc06e79346ef2 (patch)
tree40f1fc0f7a12c701f99e4823c9d927c9961e268e
parent86b1d3c36dc486c0721fc319a63cef4839b617b5 (diff)
prepares event propagation
Change-Id: Ib824c6dea1837cc1cbb70a2c82363c9b0a0517d4 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--include/afb-evmgr-itf.h (renamed from include/afb-poll-itf.h)22
-rw-r--r--include/afb-plugin.h28
-rw-r--r--include/afb-pollmgr-itf.h61
-rw-r--r--plugins/afm-main-plugin/afm-main-plugin.c37
-rw-r--r--plugins/samples/ClientCtx.c1
-rw-r--r--plugins/samples/HelloWorld.c1
-rw-r--r--plugins/samples/SamplePost.c1
-rw-r--r--plugins/session/token-api.c1
-rw-r--r--src/afb-api-so.c66
-rw-r--r--src/afb-apis.c20
10 files changed, 163 insertions, 75 deletions
diff --git a/include/afb-poll-itf.h b/include/afb-evmgr-itf.h
index b70eb993..2268ec90 100644
--- a/include/afb-poll-itf.h
+++ b/include/afb-evmgr-itf.h
@@ -17,13 +17,19 @@
#pragma once
-struct afb_pollitf
-{
- int (*wait)(int timeout, void *pollclosure);
- void *(*open)(int fd, void *closure, void *pollclosure);
- int (*on_readable)(void *hndl, void (*cb)(void *closure));
- int (*on_writable)(void *hndl, void (*cb)(void *closure));
- void (*on_hangup)(void *hndl, void (*cb)(void *closure));
- void (*close)(void *hndl);
+struct json_object;
+
+struct afb_evmgr_itf {
+ void (*push)(void *evmgr, const char *name, struct json_object *object);
+};
+
+struct afb_evmgr {
+ const struct afb_evmgr_itf *itf;
+ void *closure;
};
+static inline void afb_evmgr_push(struct afb_evmgr mgr, const char *name, struct json_object *object)
+{
+ return mgr.itf->push(mgr.closure, name, object);
+}
+
diff --git a/include/afb-plugin.h b/include/afb-plugin.h
index 2c9935e6..c7252d64 100644
--- a/include/afb-plugin.h
+++ b/include/afb-plugin.h
@@ -17,7 +17,9 @@
#pragma once
-struct afb_req;
+#include "afb-req-itf.h"
+#include "afb-pollmgr-itf.h"
+#include "afb-evmgr-itf.h"
/* Plugin Type */
enum AFB_pluginE
@@ -63,13 +65,33 @@ enum AFB_Mode {
AFB_MODE_GLOBAL
};
+struct afb_daemon_itf {
+ struct afb_evmgr (*get_evmgr)(void *closure);
+ struct afb_pollmgr (*get_pollmgr)(void *closure);
+};
+
+struct afb_daemon {
+ const struct afb_daemon_itf *itf;
+ void *closure;
+};
+
struct AFB_interface
{
int verbosity;
enum AFB_Mode mode;
- const struct afb_pollitf *pollitf;
- void *pollclosure;
+ struct afb_daemon daemon;
};
extern const struct AFB_plugin *pluginRegister (const struct AFB_interface *interface);
+static inline struct afb_evmgr afb_daemon_get_evmgr(struct afb_daemon daemon)
+{
+ return daemon.itf->get_evmgr(daemon.closure);
+}
+
+static inline struct afb_pollmgr afb_daemon_get_pollmgr(struct afb_daemon daemon)
+{
+ return daemon.itf->get_pollmgr(daemon.closure);
+}
+
+
diff --git a/include/afb-pollmgr-itf.h b/include/afb-pollmgr-itf.h
new file mode 100644
index 00000000..c3a62c17
--- /dev/null
+++ b/include/afb-pollmgr-itf.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 IoT.bzh
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+struct afb_pollmgr_itf
+{
+ int (*wait)(int timeout, void *pollclosure);
+ void *(*open)(int fd, void *closure, void *pollclosure);
+ int (*on_readable)(void *hndl, void (*cb)(void *closure));
+ int (*on_writable)(void *hndl, void (*cb)(void *closure));
+ void (*on_hangup)(void *hndl, void (*cb)(void *closure));
+ void (*close)(void *hndl);
+};
+
+struct afb_pollmgr
+{
+ const struct afb_pollmgr_itf *itf;
+ void *closure;
+};
+
+static inline int afb_pollmgr_wait(struct afb_pollmgr pollmgr, int timeout)
+{
+ return pollmgr.itf->wait(timeout, pollmgr.closure);
+}
+
+static inline void *afb_pollmgr_open(struct afb_pollmgr pollmgr, int fd, void *closure)
+{
+ return pollmgr.itf->open(fd, closure, pollmgr.closure);
+}
+
+static inline int afb_pollmgr_on_readable(struct afb_pollmgr pollmgr, void *hndl, void (*cb)(void *closure))
+{
+ return pollmgr.itf->on_readable(hndl, cb);
+}
+
+static inline int afb_pollmgr_on_writable(struct afb_pollmgr pollmgr, void *hndl, void (*cb)(void *closure))
+{
+ return pollmgr.itf->on_writable(hndl, cb);
+}
+
+static inline void afb_pollmgr_on_hangup(struct afb_pollmgr pollmgr, void *hndl, void (*cb)(void *closure))
+{
+ pollmgr.itf->on_hangup(hndl, cb);
+}
+
+
diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c
index 2d350df2..d7ef198d 100644
--- a/plugins/afm-main-plugin/afm-main-plugin.c
+++ b/plugins/afm-main-plugin/afm-main-plugin.c
@@ -18,17 +18,17 @@
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include <json.h>
#include "afb-plugin.h"
-#include "afb-req-itf.h"
-#include "afb-poll-itf.h"
#include "utils-sbus.h"
#include "utils-jbus.h"
static const char _auto_[] = "auto";
static const char _continue_[] = "continue";
+static const char _changed_[] = "changed";
static const char _detail_[] = "detail";
static const char _id_[] = "id";
static const char _install_[] = "install";
@@ -46,9 +46,15 @@ static const char _uninstall_[] = "uninstall";
static const char _uri_[] = "uri";
static const struct AFB_interface *interface;
+static struct afb_evmgr evmgr;
static struct jbus *jbus;
+static void application_list_changed(const char *data, void *closure)
+{
+ afb_evmgr_push(evmgr, "application-list-changed", NULL);
+}
+
static struct json_object *embed(const char *tag, struct json_object *obj)
{
struct json_object *result;
@@ -285,19 +291,24 @@ static struct sbus_itf sbusitf;
const struct AFB_plugin *pluginRegister(const struct AFB_interface *itf)
{
+ int rc;
+ struct afb_pollmgr pollmgr;
struct sbus *sbus;
/* records the interface */
assert (interface == NULL);
+ interface = itf;
+ evmgr = afb_daemon_get_evmgr(itf->daemon);
/* creates the sbus for session */
- sbusitf.wait = itf->pollitf->wait;
- sbusitf.open = itf->pollitf->open;
- sbusitf.on_readable = itf->pollitf->on_readable;
- sbusitf.on_writable = itf->pollitf->on_writable;
- sbusitf.on_hangup = itf->pollitf->on_hangup;
- sbusitf.close = itf->pollitf->close;
- sbus = sbus_session(&sbusitf, itf->pollclosure);
+ pollmgr = afb_daemon_get_pollmgr(itf->daemon);
+ sbusitf.wait = pollmgr.itf->wait;
+ sbusitf.open = pollmgr.itf->open;
+ sbusitf.on_readable = pollmgr.itf->on_readable;
+ sbusitf.on_writable = pollmgr.itf->on_writable;
+ sbusitf.on_hangup = pollmgr.itf->on_hangup;
+ sbusitf.close = pollmgr.itf->close;
+ sbus = sbus_session(&sbusitf, pollmgr.closure);
if (sbus == NULL) {
fprintf(stderr, "ERROR: %s:%d: can't connect to DBUS session\n", __FILE__, __LINE__);
return NULL;
@@ -310,7 +321,13 @@ const struct AFB_plugin *pluginRegister(const struct AFB_interface *itf)
return NULL;
}
-
+ /* records the signal handler */
+ rc = jbus_on_signal_s(jbus, _changed_, application_list_changed, NULL);
+ if (rc < 0) {
+ jbus_unref(jbus);
+ return NULL;
+ }
+
return &plug_desc;
}
diff --git a/plugins/samples/ClientCtx.c b/plugins/samples/ClientCtx.c
index 2d5ebfe1..24cb4f30 100644
--- a/plugins/samples/ClientCtx.c
+++ b/plugins/samples/ClientCtx.c
@@ -20,7 +20,6 @@
#include <json.h>
#include "afb-plugin.h"
-#include "afb-req-itf.h"
typedef struct {
/*
diff --git a/plugins/samples/HelloWorld.c b/plugins/samples/HelloWorld.c
index d02fd117..bf809cc3 100644
--- a/plugins/samples/HelloWorld.c
+++ b/plugins/samples/HelloWorld.c
@@ -20,7 +20,6 @@
#include <json.h>
#include "afb-plugin.h"
-#include "afb-req-itf.h"
// Sample Generic Ping Debug API
static void ping(struct afb_req request, json_object *jresp, const char *tag)
diff --git a/plugins/samples/SamplePost.c b/plugins/samples/SamplePost.c
index 6def3b9c..f484d131 100644
--- a/plugins/samples/SamplePost.c
+++ b/plugins/samples/SamplePost.c
@@ -21,7 +21,6 @@
#include <json.h>
#include "afb-plugin.h"
-#include "afb-req-itf.h"
// Sample Generic Ping Debug API
diff --git a/plugins/session/token-api.c b/plugins/session/token-api.c
index 7633b950..91f9cd8f 100644
--- a/plugins/session/token-api.c
+++ b/plugins/session/token-api.c
@@ -20,7 +20,6 @@
#include <json.h>
#include "afb-plugin.h"
-#include "afb-req-itf.h"
// Dummy sample of Client Application Context
typedef struct {
diff --git a/src/afb-api-so.c b/src/afb-api-so.c
index 093a8a93..60af72ef 100644
--- a/src/afb-api-so.c
+++ b/src/afb-api-so.c
@@ -33,7 +33,8 @@
#include "afb-plugin.h"
#include "afb-req-itf.h"
-#include "afb-poll-itf.h"
+#include "afb-pollmgr-itf.h"
+#include "afb-evmgr-itf.h"
#include "session.h"
#include "afb-apis.h"
@@ -41,17 +42,19 @@
#include "verbose.h"
#include "utils-upoll.h"
+extern __thread sigjmp_buf *error_handler;
+
struct api_so_desc {
- struct AFB_plugin *plugin; /* descriptor */
- void *handle; /* context of dlopen */
- struct AFB_interface interface;
+ struct AFB_plugin *plugin; /* descriptor */
+ void *handle; /* context of dlopen */
+ struct AFB_interface interface; /* interface */
};
static int api_timeout = 15;
static const char plugin_register_function[] = "pluginRegister";
-static const struct afb_pollitf upollitf = {
+static const struct afb_pollmgr_itf pollmgr_itf = {
.wait = (void*)upoll_wait,
.open = (void*)upoll_open,
.on_readable = (void*)upoll_on_readable,
@@ -60,6 +63,29 @@ static const struct afb_pollitf upollitf = {
.close = (void*)upoll_close
};
+static void afb_api_so_evmgr_push(struct api_so_desc *desc, const char *name, struct json_object *object)
+{
+}
+
+static const struct afb_evmgr_itf evmgr_itf = {
+ .push = (void*)afb_api_so_evmgr_push
+};
+
+static struct afb_evmgr afb_api_so_get_evmgr(struct api_so_desc *desc)
+{
+ return (struct afb_evmgr){ .itf = &evmgr_itf, .closure = desc };
+}
+
+static struct afb_pollmgr afb_api_so_get_pollmgr(struct api_so_desc *desc)
+{
+ return (struct afb_pollmgr){ .itf = &pollmgr_itf, .closure = NULL };
+}
+
+static const struct afb_daemon_itf daemon_itf = {
+ .get_evmgr = (void*)afb_api_so_get_evmgr,
+ .get_pollmgr = (void*)afb_api_so_get_pollmgr
+};
+
static void free_context(struct api_so_desc *desc, void *context)
{
void (*cb)(void*);
@@ -71,9 +97,6 @@ static void free_context(struct api_so_desc *desc, void *context)
free(context);
}
-
-// Check of apiurl is declare in this plugin and call it
-extern __thread sigjmp_buf *error_handler;
static void trapping_call(struct afb_req req, void(*cb)(struct afb_req))
{
volatile int signum, timerset;
@@ -82,7 +105,6 @@ static void trapping_call(struct afb_req req, void(*cb)(struct afb_req))
struct sigevent sevp;
struct itimerspec its;
- // save context before calling the API
timerset = 0;
older = error_handler;
signum = setjmp(jmpbuf);
@@ -155,8 +177,6 @@ static void call(struct api_so_desc *desc, struct afb_req req, const char *verb,
afb_req_fail_f(req, "unknown-verb", "verb %.*s unknown within api %s", (int)lenverb, verb, desc->plugin->prefix);
}
-
-
int afb_api_so_add_plugin(const char *path)
{
struct api_so_desc *desc;
@@ -187,8 +207,8 @@ int afb_api_so_add_plugin(const char *path)
/* init the interface */
desc->interface.verbosity = 0;
desc->interface.mode = AFB_MODE_LOCAL;
- desc->interface.pollitf = &upollitf;
- desc->interface.pollclosure = NULL;
+ desc->interface.daemon.itf = &daemon_itf;
+ desc->interface.daemon.closure = desc;
/* init the plugin */
desc->plugin = pluginRegisterFct(&desc->interface);
@@ -327,23 +347,3 @@ int afb_api_so_add_pathset(const char *pathset)
};
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/afb-apis.c b/src/afb-apis.c
index 1cc0648a..0af3b42c 100644
--- a/src/afb-apis.c
+++ b/src/afb-apis.c
@@ -18,28 +18,14 @@
#define _GNU_SOURCE
+#include <stdlib.h>
#include <stdio.h>
-#include <assert.h>
#include <string.h>
-#include <dirent.h>
-#include <dlfcn.h>
-#include <unistd.h>
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <time.h>
-#include <sys/syscall.h>
-#include <setjmp.h>
-
-#include "afb-plugin.h"
-#include "afb-req-itf.h"
-#include "afb-poll-itf.h"
#include "session.h"
-#include "afb-apis.h"
#include "verbose.h"
-#include "utils-upoll.h"
+#include "afb-apis.h"
+#include "afb-req-itf.h"
struct api_desc {
struct afb_api api;