#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);
+}
+
#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
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);
+}
+
+
--- /dev/null
+/*
+ * 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);
+}
+
+
#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";
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;
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;
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;
}
#include <json.h>
#include "afb-plugin.h"
-#include "afb-req-itf.h"
typedef struct {
/*
#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)
#include <json.h>
#include "afb-plugin.h"
-#include "afb-req-itf.h"
// Sample Generic Ping Debug API
#include <json.h>
#include "afb-plugin.h"
-#include "afb-req-itf.h"
// Dummy sample of Client Application Context
typedef struct {
#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"
#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,
.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*);
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;
struct sigevent sevp;
struct itimerspec its;
- // save context before calling the API
timerset = 0;
older = error_handler;
signum = setjmp(jmpbuf);
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;
/* 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);
};
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#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;