aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-05-17 23:36:23 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-05-17 23:40:04 +0200
commit65bc678960567038ca4d07d1f9c5784b6c7a7834 (patch)
tree2540a9bcfb1f1c14f68a8cdb2647fdc47793c5a3
parentc4777bafebe62dc60c00f0dbd656112598267ccd (diff)
improves plugin interface
This commit improves the names and the organisation of the plugin interface for the developpers. Change-Id: Iaf191efbf8fd5d248884304b648258f0770ec5f5 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--include/afb/afb-plugin.h127
-rw-r--r--plugins/afm-main-plugin/afm-main-plugin.c32
-rw-r--r--plugins/audio/audio-api.c14
-rw-r--r--plugins/media/media-api.c14
-rw-r--r--plugins/radio/radio-api.c14
-rw-r--r--plugins/samples/ClientCtx.c14
-rw-r--r--plugins/samples/HelloWorld.c14
-rw-r--r--plugins/samples/SamplePost.c14
-rw-r--r--plugins/session/token-api.c14
-rw-r--r--src/afb-api-so.c34
10 files changed, 179 insertions, 112 deletions
diff --git a/include/afb/afb-plugin.h b/include/afb/afb-plugin.h
index 2cfe6289..d3f6423d 100644
--- a/include/afb/afb-plugin.h
+++ b/include/afb/afb-plugin.h
@@ -20,89 +20,140 @@
#include <afb/afb-req-itf.h>
#include <afb/afb-evmgr-itf.h>
-/* Plugin Type */
-enum AFB_pluginE
+/*
+ * Definition of the versions of the plugin.
+ * The definition uses hashes.
+ */
+enum AFB_plugin_version
+{
+ AFB_PLUGIN_VERSION_1 = 123456789 /* version 1 */
+};
+
+/*
+ * Enum for Session/Token/Authentication middleware.
+ * This enumeration is valid for plugins of type 1
+ */
+enum AFB_session_v1
{
- AFB_PLUGIN_JSON = 123456789,
-/* AFB_PLUGIN_JSCRIPT = 987654321, */
- AFB_PLUGIN_RAW = 987123546
+ AFB_SESSION_NONE = 0, /* no session and no authentification required */
+ AFB_SESSION_CREATE = 1, /* requires authentification and first call of the session */
+ AFB_SESSION_CLOSE = 2, /* closes the session after authentification */
+ AFB_SESSION_RENEW = 4, /* refreshes the token after authentification */
+ AFB_SESSION_CHECK = 8, /* enforce authentification */
+ AFB_SESSION_MASK = 15 /* convenient mask used internally, bit-or of the previous masks */
};
-/* Enum for Session/Token/Authentication middleware */
-enum AFB_sessionE
+/*
+ * Description of one verb of the API provided by the plugin
+ * This enumeration is valid for plugins of type 1
+ */
+struct AFB_verb_desc_v1
{
- AFB_SESSION_NONE = 0,
- AFB_SESSION_CREATE = 1,
- AFB_SESSION_CLOSE = 2,
- AFB_SESSION_RENEW = 4,
- AFB_SESSION_CHECK = 8,
- AFB_SESSION_MASK = 15
+ const char *name; /* name of the verb */
+ enum AFB_session_v1 session; /* authorisation and session requirements of the verb */
+ void (*callback)(struct afb_req req); /* callback function implementing the verb */
+ const char *info; /* textual description of the verb */
};
-/* API definition */
-struct AFB_restapi
+/*
+ * Description of the plugins of type 1
+ */
+struct AFB_plugin_desc_v1
{
- const char *name;
- enum AFB_sessionE session;
- void (*callback)(struct afb_req req);
- const char *info;
+ const char *info; /* textual information about the plugin */
+ const char *prefix; /* required prefix name for the plugin */
+ const struct AFB_verb_desc_v1 *verbs; /* array of descriptions of verbs terminated by a NULL name */
};
-/* Plugin definition */
+/*
+ * Description of a plugin
+ */
struct AFB_plugin
{
- enum AFB_pluginE type;
- const char *info;
- const char *prefix;
- const struct AFB_restapi *apis;
+ enum AFB_plugin_version type; /* type of the plugin */
+ union {
+ struct AFB_plugin_desc_v1 v1; /* description of the plugin of type 1 */
+ };
};
-/* config mode */
+/*
+ * config mode
+ */
enum AFB_Mode {
- AFB_MODE_LOCAL = 0,
- AFB_MODE_REMOTE,
- AFB_MODE_GLOBAL
+ AFB_MODE_LOCAL = 0, /* run locally */
+ AFB_MODE_REMOTE, /* run remotely */
+ AFB_MODE_GLOBAL /* run either remotely or locally (DONT USE! reserved for future) */
};
+/* declaration of features of libsystemd */
struct sd_event;
struct sd_bus;
+/*
+ * Definition of the facilities provided by the daemon.
+ */
struct afb_daemon_itf {
- struct afb_evmgr (*get_evmgr)(void *closure);
- struct sd_event *(*get_event_loop)(void *closure);
- struct sd_bus *(*get_user_bus)(void *closure);
- struct sd_bus *(*get_system_bus)(void *closure);
+ struct afb_evmgr (*get_evmgr)(void *closure); /* get the event manager */
+ struct sd_event *(*get_event_loop)(void *closure); /* get the common systemd's event loop */
+ struct sd_bus *(*get_user_bus)(void *closure); /* get the common systemd's user d-bus */
+ struct sd_bus *(*get_system_bus)(void *closure); /* get the common systemd's system d-bus */
};
+/*
+ * Structure for accessing daemon.
+ * See also: afb_daemon_get_evmgr, afb_daemon_get_event_loop, afb_daemon_get_user_bus, afb_daemon_get_system_bus
+ */
struct afb_daemon {
- const struct afb_daemon_itf *itf;
- void *closure;
+ const struct afb_daemon_itf *itf; /* the interfacing functions */
+ void *closure; /* the closure when calling these functions */
};
+/*
+ * Interface between the daemon and the plugin.
+ */
struct AFB_interface
{
- int verbosity;
- enum AFB_Mode mode;
- struct afb_daemon daemon;
+ struct afb_daemon daemon; /* access to the daemon facilies */
+ int verbosity; /* level of verbosity */
+ enum AFB_Mode mode; /* run mode (local or remote) */
};
-extern const struct AFB_plugin *pluginRegister (const struct AFB_interface *interface);
+/*
+ * The function for registering the plugin to AFB
+ */
+extern const struct AFB_plugin *pluginAfbV1Register (const struct AFB_interface *interface);
+/*
+ * Retrieves the event sender of AFB
+ * 'daemon' MUST be the daemon given in interface when activating the plugin.
+ */
static inline struct afb_evmgr afb_daemon_get_evmgr(struct afb_daemon daemon)
{
return daemon.itf->get_evmgr(daemon.closure);
}
+/*
+ * Retrieves the common systemd's event loop of AFB
+ * 'daemon' MUST be the daemon given in interface when activating the plugin.
+ */
static inline struct sd_event *afb_daemon_get_event_loop(struct afb_daemon daemon)
{
return daemon.itf->get_event_loop(daemon.closure);
}
+/*
+ * Retrieves the common systemd's user/session d-bus of AFB
+ * 'daemon' MUST be the daemon given in interface when activating the plugin.
+ */
static inline struct sd_bus *afb_daemon_get_user_bus(struct afb_daemon daemon)
{
return daemon.itf->get_user_bus(daemon.closure);
}
+/*
+ * Retrieves the common systemd's system d-bus of AFB
+ * 'daemon' MUST be the daemon given in interface when activating the plugin.
+ */
static inline struct sd_bus *afb_daemon_get_system_bus(struct afb_daemon daemon)
{
return daemon.itf->get_system_bus(daemon.closure);
diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c
index 705efcb0..41e55404 100644
--- a/plugins/afm-main-plugin/afm-main-plugin.c
+++ b/plugins/afm-main-plugin/afm-main-plugin.c
@@ -45,7 +45,7 @@ static const char _terminate_[] = "terminate";
static const char _uninstall_[] = "uninstall";
static const char _uri_[] = "uri";
-static const struct AFB_interface *interface;
+static const struct AFB_interface *afb_interface;
static struct afb_evmgr evmgr;
static struct jbus *jbus;
@@ -96,7 +96,7 @@ static struct json_object *embed(const char *tag, struct json_object *obj)
static void embed_call_void_callback(int status, struct json_object *obj, struct memo *memo)
{
- if (interface->verbosity)
+ if (afb_interface->verbosity)
fprintf(stderr, "(afm-main-plugin) %s(true) -> %s\n", memo->method,
obj ? json_object_to_json_string(obj) : "NULL");
if (obj == NULL) {
@@ -127,7 +127,7 @@ static void embed_call_void(struct afb_req request, const char *method)
static void call_appid_callback(int status, struct json_object *obj, struct memo *memo)
{
- if (interface->verbosity)
+ if (afb_interface->verbosity)
fprintf(stderr, "(afm-main-plugin) %s -> %s\n", memo->method,
obj ? json_object_to_json_string(obj) : "NULL");
if (obj == NULL) {
@@ -171,7 +171,7 @@ static void call_runid(struct afb_req request, const char *method)
return;
}
obj = jbus_call_sj_sync(jbus, method, id);
- if (interface->verbosity)
+ if (afb_interface->verbosity)
fprintf(stderr, "(afm-main-plugin) %s(%s) -> %s\n", method, id,
obj ? json_object_to_json_string(obj) : "NULL");
if (obj == NULL) {
@@ -210,7 +210,7 @@ static void start(struct afb_req request)
/* get the mode */
mode = afb_req_value(request, _mode_);
if (mode == NULL || !strcmp(mode, _auto_)) {
- mode = interface->mode == AFB_MODE_REMOTE ? _remote_ : _local_;
+ mode = afb_interface->mode == AFB_MODE_REMOTE ? _remote_ : _local_;
}
/* create the query */
@@ -222,7 +222,7 @@ static void start(struct afb_req request)
/* calls the service */
obj = jbus_call_sj_sync(jbus, _start_, query);
- if (interface->verbosity)
+ if (afb_interface->verbosity)
fprintf(stderr, "(afm-main-plugin) start(%s) -> %s\n", query,
obj ? json_object_to_json_string(obj) : "NULL");
free(query);
@@ -287,7 +287,7 @@ static void install(struct afb_req request)
}
obj = jbus_call_sj_sync(jbus, _install_, query);
- if (interface->verbosity)
+ if (afb_interface->verbosity)
fprintf(stderr, "(afm-main-plugin) install(%s) -> %s\n", query,
obj ? json_object_to_json_string(obj) : "NULL");
free(query);
@@ -311,7 +311,7 @@ static void uninstall(struct afb_req request)
call_appid(request, _uninstall_);
}
-static const struct AFB_restapi plug_apis[] =
+static const struct AFB_verb_desc_v1 verbs[] =
{
{_runnables_, AFB_SESSION_CHECK, runnables, "Get list of runnable applications"},
{_detail_ , AFB_SESSION_CHECK, detail, "Get the details for one application"},
@@ -327,20 +327,22 @@ static const struct AFB_restapi plug_apis[] =
};
static const struct AFB_plugin plug_desc = {
- .type = AFB_PLUGIN_JSON,
- .info = "Application Framework Master Service",
- .prefix = "afm-main",
- .apis = plug_apis
+ .type = AFB_PLUGIN_VERSION_1,
+ .v1 = {
+ .info = "Application Framework Master Service",
+ .prefix = "afm-main",
+ .verbs = verbs
+ }
};
-const struct AFB_plugin *pluginRegister(const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Register(const struct AFB_interface *itf)
{
int rc;
struct sd_bus *sbus;
/* records the interface */
- assert (interface == NULL);
- interface = itf;
+ assert (afb_interface == NULL);
+ afb_interface = itf;
evmgr = afb_daemon_get_evmgr(itf->daemon);
/* creates the jbus for accessing afm-user-daemon */
diff --git a/plugins/audio/audio-api.c b/plugins/audio/audio-api.c
index c486d1c1..4eeed92d 100644
--- a/plugins/audio/audio-api.c
+++ b/plugins/audio/audio-api.c
@@ -330,7 +330,7 @@ static void ping (struct afb_req request) { /* AFB_SESSION_NONE */
afb_req_success (request, NULL, "Audio - Ping success");
}
-static const struct AFB_restapi pluginApis[]= {
+static const struct AFB_verb_desc_v1 verbs[]= {
{"init" , AFB_SESSION_CHECK, init , "Audio API - init"},
{"volume" , AFB_SESSION_CHECK, volume , "Audio API - volume"},
{"channels", AFB_SESSION_CHECK, channels , "Audio API - channels"},
@@ -341,13 +341,15 @@ static const struct AFB_restapi pluginApis[]= {
};
static const struct AFB_plugin pluginDesc = {
- .type = AFB_PLUGIN_JSON,
- .info = "Application Framework Binder - Audio plugin",
- .prefix = "audio",
- .apis = pluginApis
+ .type = AFB_PLUGIN_VERSION_1,
+ .v1 = {
+ .info = "Application Framework Binder - Audio plugin",
+ .prefix = "audio",
+ .verbs = verbs
+ }
};
-const struct AFB_plugin *pluginRegister (const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Entry (const struct AFB_interface *itf)
{
return &pluginDesc;
}
diff --git a/plugins/media/media-api.c b/plugins/media/media-api.c
index 91676d4c..dace151f 100644
--- a/plugins/media/media-api.c
+++ b/plugins/media/media-api.c
@@ -301,7 +301,7 @@ static void ping (struct afb_req request) { /* AFB_SESSION_NONE */
}
-static const struct AFB_restapi pluginApis[]= {
+static const struct AFB_verb_desc_v1 verbs[]= {
{"init" , AFB_SESSION_CHECK, init , "Media API - init" },
{"list" , AFB_SESSION_CHECK, list , "Media API - list" },
{"select" , AFB_SESSION_CHECK, selecting , "Media API - select" },
@@ -315,13 +315,15 @@ static const struct AFB_restapi pluginApis[]= {
};
static const struct AFB_plugin pluginDesc = {
- .type = AFB_PLUGIN_JSON,
- .info = "Application Framework Binder - Media plugin",
- .prefix = "media",
- .apis = pluginApis
+ .type = AFB_PLUGIN_VERSION_1,
+ .v1 = {
+ .info = "Application Framework Binder - Media plugin",
+ .prefix = "media",
+ .verbs = verbs
+ }
};
-const struct AFB_plugin *pluginRegister (const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Entry (const struct AFB_interface *itf)
{
return &pluginDesc;
}
diff --git a/plugins/radio/radio-api.c b/plugins/radio/radio-api.c
index e4a89ba6..3ef098a9 100644
--- a/plugins/radio/radio-api.c
+++ b/plugins/radio/radio-api.c
@@ -316,7 +316,7 @@ static void ping (struct afb_req request) { /* AFB_SESSION_NONE */
}
-static const struct AFB_restapi pluginApis[]= {
+static const struct AFB_verb_desc_v1 verbs[]= {
{"init" , AFB_SESSION_CHECK, init , "Radio API - init"},
{"power" , AFB_SESSION_CHECK, power , "Radio API - power"},
{"mode" , AFB_SESSION_CHECK, mode , "Radio API - mode"},
@@ -328,13 +328,15 @@ static const struct AFB_restapi pluginApis[]= {
};
static const struct AFB_plugin pluginDesc = {
- .type = AFB_PLUGIN_JSON,
- .info = "Application Framework Binder - Radio plugin",
- .prefix = "radio",
- .apis = pluginApis
+ .type = AFB_PLUGIN_VERSION_1,
+ .v1 = {
+ .info = "Application Framework Binder - Radio plugin",
+ .prefix = "radio",
+ .verbs = verbs
+ }
};
-const struct AFB_plugin *pluginRegister (const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Entry (const struct AFB_interface *itf)
{
initRadioPlugin();
return &pluginDesc;
diff --git a/plugins/samples/ClientCtx.c b/plugins/samples/ClientCtx.c
index bf26937f..6b7eb631 100644
--- a/plugins/samples/ClientCtx.c
+++ b/plugins/samples/ClientCtx.c
@@ -87,7 +87,7 @@ static void myClose (struct afb_req request)
// NOTE: this sample does not use session to keep test a basic as possible
// in real application most APIs should be protected with AFB_SESSION_CHECK
-static const struct AFB_restapi pluginApis[]= {
+static const struct AFB_verb_desc_v1 verbs[]= {
{"create", AFB_SESSION_CREATE, myCreate , "Create a new session"},
{"action", AFB_SESSION_CHECK , myAction , "Use Session Context"},
{"close" , AFB_SESSION_CLOSE , myClose , "Free Context"},
@@ -95,13 +95,15 @@ static const struct AFB_restapi pluginApis[]= {
};
static const struct AFB_plugin plugin_desc = {
- .type = AFB_PLUGIN_JSON,
- .info = "Sample of Client Context Usage",
- .prefix = "context",
- .apis = pluginApis,
+ .type = AFB_PLUGIN_VERSION_1,
+ .v1 = {
+ .info = "Sample of Client Context Usage",
+ .prefix = "context",
+ .verbs = verbs,
+ }
};
-const struct AFB_plugin *pluginRegister (const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Register (const struct AFB_interface *itf)
{
return &plugin_desc;
}
diff --git a/plugins/samples/HelloWorld.c b/plugins/samples/HelloWorld.c
index 4795dd36..35b95cab 100644
--- a/plugins/samples/HelloWorld.c
+++ b/plugins/samples/HelloWorld.c
@@ -78,7 +78,7 @@ static void pingJson (struct afb_req request) {
// NOTE: this sample does not use session to keep test a basic as possible
// in real application most APIs should be protected with AFB_SESSION_CHECK
-static const struct AFB_restapi pluginApis[]= {
+static const struct AFB_verb_desc_v1 verbs[]= {
{"ping" , AFB_SESSION_NONE, pingSample , "Ping Application Framework"},
{"pingfail" , AFB_SESSION_NONE, pingFail , "Fails"},
{"pingnull" , AFB_SESSION_NONE, pingNull , "Return NULL"},
@@ -89,13 +89,15 @@ static const struct AFB_restapi pluginApis[]= {
};
static const struct AFB_plugin plugin_desc = {
- .type = AFB_PLUGIN_JSON,
- .info = "Minimal Hello World Sample",
- .prefix = "hello",
- .apis = pluginApis
+ .type = AFB_PLUGIN_VERSION_1,
+ .v1 = {
+ .info = "Minimal Hello World Sample",
+ .prefix = "hello",
+ .verbs = verbs
+ }
};
-const struct AFB_plugin *pluginRegister (const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Register (const struct AFB_interface *itf)
{
interface = itf;
return &plugin_desc;
diff --git a/plugins/samples/SamplePost.c b/plugins/samples/SamplePost.c
index 1d3069e8..b61b91c4 100644
--- a/plugins/samples/SamplePost.c
+++ b/plugins/samples/SamplePost.c
@@ -76,7 +76,7 @@ static void UploadImage (struct afb_req request)
// NOTE: this sample does not use session to keep test a basic as possible
// in real application upload-xxx should be protected with AFB_SESSION_CHECK
-static const struct AFB_restapi pluginApis[]= {
+static const struct AFB_verb_desc_v1 verbs[]= {
{"ping" , AFB_SESSION_NONE , getPingTest ,"Ping Rest Test Service"},
{"upload-json" , AFB_SESSION_NONE , GetJsonByPost ,"Demo for Json Buffer on Post"},
{"upload-image" , AFB_SESSION_NONE , UploadImage ,"Demo for file upload"},
@@ -86,13 +86,15 @@ static const struct AFB_restapi pluginApis[]= {
};
static const struct AFB_plugin plugin_desc = {
- .type = AFB_PLUGIN_JSON,
- .info = "Sample with Post Upload Files",
- .prefix = "post",
- .apis = pluginApis
+ .type = AFB_PLUGIN_VERSION_1,
+ .v1 = {
+ .info = "Sample with Post Upload Files",
+ .prefix = "post",
+ .verbs = verbs
+ }
};
-const struct AFB_plugin *pluginRegister (const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Register (const struct AFB_interface *itf)
{
return &plugin_desc;
};
diff --git a/plugins/session/token-api.c b/plugins/session/token-api.c
index fd312608..a8167c42 100644
--- a/plugins/session/token-api.c
+++ b/plugins/session/token-api.c
@@ -99,7 +99,7 @@ static void clientGetPing (struct afb_req request) {
}
-static const struct AFB_restapi pluginApis[]= {
+static const struct AFB_verb_desc_v1 verbs[]= {
{"ping" , AFB_SESSION_NONE , clientGetPing ,"Ping Rest Test Service"},
{"create" , AFB_SESSION_CREATE, clientContextCreate ,"Request Client Context Creation"},
{"refresh" , AFB_SESSION_RENEW , clientContextRefresh,"Refresh Client Context Token"},
@@ -109,13 +109,15 @@ static const struct AFB_restapi pluginApis[]= {
};
static const struct AFB_plugin plugin_desc = {
- .type = AFB_PLUGIN_JSON,
- .info = "Application Framework Binder Service",
- .prefix = "token",
- .apis = pluginApis
+ .type = AFB_PLUGIN_VERSION_1,
+ .v1 = {
+ .info = "Application Framework Binder Service",
+ .prefix = "token",
+ .verbs = verbs
+ }
};
-const struct AFB_plugin *pluginRegister (const struct AFB_interface *itf)
+const struct AFB_plugin *pluginAfbV1Register (const struct AFB_interface *itf)
{
return &plugin_desc;
}
diff --git a/src/afb-api-so.c b/src/afb-api-so.c
index 72599e5b..cc3447ab 100644
--- a/src/afb-api-so.c
+++ b/src/afb-api-so.c
@@ -48,7 +48,7 @@ struct api_so_desc {
static int api_timeout = 15;
-static const char plugin_register_function[] = "pluginRegister";
+static const char plugin_register_function[] = "pluginAfbV1Entry";
static void afb_api_so_evmgr_push(struct api_so_desc *desc, const char *name, struct json_object *object)
{
@@ -58,7 +58,7 @@ static void afb_api_so_evmgr_push(struct api_so_desc *desc, const char *name, st
assert(desc->plugin != NULL);
length = strlen(name);
event = alloca(length + 2 + desc->apilength);
- memcpy(event, desc->plugin->prefix, desc->apilength);
+ memcpy(event, desc->plugin->v1.prefix, desc->apilength);
event[desc->apilength] = '/';
memcpy(event + desc->apilength + 1, name, length + 1);
ctxClientEventSend(NULL, event, object);
@@ -93,7 +93,7 @@ static void monitored_call(int signum, struct monitoring *data)
data->action(data->req);
}
-static void call_check(struct afb_req req, struct afb_context *context, const struct AFB_restapi *verb)
+static void call_check(struct afb_req req, struct afb_context *context, const struct AFB_verb_desc_v1 *verb)
{
struct monitoring data;
@@ -128,21 +128,21 @@ static void call_check(struct afb_req req, struct afb_context *context, const st
static void call(struct api_so_desc *desc, struct afb_req req, struct afb_context *context, const char *verb, size_t lenverb)
{
- const struct AFB_restapi *v;
+ const struct AFB_verb_desc_v1 *v;
- v = desc->plugin->apis;
+ v = desc->plugin->v1.verbs;
while (v->name && (strncasecmp(v->name, verb, lenverb) || v->name[lenverb]))
v++;
if (v->name)
call_check(req, context, v);
else
- afb_req_fail_f(req, "unknown-verb", "verb %.*s unknown within api %s", (int)lenverb, verb, desc->plugin->prefix);
+ afb_req_fail_f(req, "unknown-verb", "verb %.*s unknown within api %s", (int)lenverb, verb, desc->plugin->v1.prefix);
}
int afb_api_so_add_plugin(const char *path)
{
struct api_so_desc *desc;
- struct AFB_plugin *(*pluginRegisterFct) (const struct AFB_interface *interface);
+ struct AFB_plugin *(*pluginAfbV1RegisterFct) (const struct AFB_interface *interface);
desc = calloc(1, sizeof *desc);
if (desc == NULL) {
@@ -158,8 +158,8 @@ int afb_api_so_add_plugin(const char *path)
}
/* retrieves the register function */
- pluginRegisterFct = dlsym(desc->handle, plugin_register_function);
- if (!pluginRegisterFct) {
+ pluginAfbV1RegisterFct = dlsym(desc->handle, plugin_register_function);
+ if (!pluginAfbV1RegisterFct) {
ERROR("plugin [%s] is not an AFB plugin", path);
goto error3;
}
@@ -172,39 +172,39 @@ int afb_api_so_add_plugin(const char *path)
desc->interface.daemon.closure = desc;
/* init the plugin */
- desc->plugin = pluginRegisterFct(&desc->interface);
+ desc->plugin = pluginAfbV1RegisterFct(&desc->interface);
if (desc->plugin == NULL) {
ERROR("plugin [%s] register function failed. continuing...", path);
goto error3;
}
/* check the returned structure */
- if (desc->plugin->type != AFB_PLUGIN_JSON) {
+ if (desc->plugin->type != AFB_PLUGIN_VERSION_1) {
ERROR("plugin [%s] invalid type %d...", path, desc->plugin->type);
goto error3;
}
- if (desc->plugin->prefix == NULL || *desc->plugin->prefix == 0) {
+ if (desc->plugin->v1.prefix == NULL || *desc->plugin->v1.prefix == 0) {
ERROR("plugin [%s] bad prefix...", path);
goto error3;
}
- if (desc->plugin->info == NULL || *desc->plugin->info == 0) {
+ if (desc->plugin->v1.info == NULL || *desc->plugin->v1.info == 0) {
ERROR("plugin [%s] bad description...", path);
goto error3;
}
- if (desc->plugin->apis == NULL) {
+ if (desc->plugin->v1.verbs == NULL) {
ERROR("plugin [%s] no APIs...", path);
goto error3;
}
/* records the plugin */
- desc->apilength = strlen(desc->plugin->prefix);
- if (afb_apis_add(desc->plugin->prefix, (struct afb_api){
+ desc->apilength = strlen(desc->plugin->v1.prefix);
+ if (afb_apis_add(desc->plugin->v1.prefix, (struct afb_api){
.closure = desc,
.call = (void*)call}) < 0) {
ERROR("plugin [%s] can't be registered...", path);
goto error3;
}
- NOTICE("plugin %s loaded with API prefix %s", path, desc->plugin->prefix);
+ NOTICE("plugin %s loaded with API prefix %s", path, desc->plugin->v1.prefix);
return 0;
error3: