summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-09-22 18:35:13 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-10-09 14:08:33 +0200
commit2b037bbfd58046219d9cd083ae9422b9fc200ad4 (patch)
tree20670c3ed14dfc86b65ff64ff7f53e32aa6d7d8f
parenta4dcf977a6b9e517a0b32949b5967a6de5064f13 (diff)
Add wrappers for accesses to internals
Change-Id: I6144b0ab21418dc98792f0eeef695f3df0fc11d3 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--bindings/samples/ave.c12
-rw-r--r--include/afb/afb-dynapi.h17
-rw-r--r--include/afb/afb-request.h20
3 files changed, 42 insertions, 7 deletions
diff --git a/bindings/samples/ave.c b/bindings/samples/ave.c
index e6b195b8..6c3bf92c 100644
--- a/bindings/samples/ave.c
+++ b/bindings/samples/ave.c
@@ -29,7 +29,7 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
struct event
{
struct event *next;
- struct afb_eventid *eventid;
+ afb_eventid *eventid;
char tag[1];
};
@@ -415,7 +415,7 @@ static void onevent(afb_dynapi *dynapi, const char *event, struct json_object *o
{
AFB_DYNAPI_NOTICE(dynapi, "received event %s(%s) by AVE(%s)",
event, json_object_to_json_string(object),
- (const char*)dynapi->userdata);
+ (const char*)afb_dynapi_get_userdata(dynapi));
}
// NOTE: this sample does not use session to keep test a basic as possible
@@ -461,12 +461,12 @@ static const afb_verb_v2 verbsv2[]= {
static const char *apis[] = { "ave", "hi", "salut", NULL };
-static int api_preinit(void *closure, afb_dynapi *dynapi)
+static int build_api(void *closure, afb_dynapi *dynapi)
{
int i, rc;
- dynapi->userdata = closure;
- AFB_DYNAPI_NOTICE(dynapi, "dynamic binding AVE(%s) comes to live", (const char*)dynapi->userdata);
+ afb_dynapi_set_userdata(dynapi, closure);
+ AFB_DYNAPI_NOTICE(dynapi, "dynamic binding AVE(%s) comes to live", (const char*)afb_dynapi_get_userdata(dynapi));
afb_dynapi_on_init(dynapi, init);
afb_dynapi_on_event(dynapi, onevent);
@@ -483,7 +483,7 @@ int afbBindingVdyn(afb_dynapi *dynapi)
int i, rc;
for (i = 0; apis[i] ; i++) {
- rc = afb_dynapi_new_api(dynapi, apis[i], NULL, api_preinit, (void*)apis[i]);
+ rc = afb_dynapi_new_api(dynapi, apis[i], NULL, build_api, (void*)apis[i]);
}
return 0;
}
diff --git a/include/afb/afb-dynapi.h b/include/afb/afb-dynapi.h
index edae4915..dfdcdb24 100644
--- a/include/afb/afb-dynapi.h
+++ b/include/afb/afb-dynapi.h
@@ -19,6 +19,21 @@
#include "afb-dynapi-itf.h"
+static inline const char *afb_dynapi_name(struct afb_dynapi *dynapi)
+{
+ return dynapi->apiname;
+}
+
+static inline void *afb_dynapi_get_userdata(struct afb_dynapi *dynapi)
+{
+ return dynapi->userdata;
+}
+
+static inline void afb_dynapi_set_userdata(struct afb_dynapi *dynapi, void *userdata)
+{
+ dynapi->userdata = userdata;
+}
+
/*
* Send a message described by 'fmt' and following parameters
* to the journal for the verbosity 'level'.
@@ -188,7 +203,7 @@ static inline void afb_dynapi_call(
const char *api,
const char *verb,
struct json_object *args,
- void (*callback)(void*closure, int status, struct json_object *result, struct afb_dynapi *dynapi),
+ void (*callback)(void *closure, int status, struct json_object *result, struct afb_dynapi *dynapi),
void *callback_closure)
{
dynapi->itf->call(dynapi, api, verb, args, callback, callback_closure);
diff --git a/include/afb/afb-request.h b/include/afb/afb-request.h
index 678922b3..fcab03c3 100644
--- a/include/afb/afb-request.h
+++ b/include/afb/afb-request.h
@@ -19,6 +19,26 @@
#include "afb-request-itf.h"
+static inline struct afb_dynapi *afb_request_get_dynapi(struct afb_request *request)
+{
+ return request->dynapi;
+}
+
+static inline void *afb_request_get_vcbdata(struct afb_request *request)
+{
+ return request->vcbdata;
+}
+
+static inline const char *afb_request_get_api(struct afb_request *request)
+{
+ return request->api;
+}
+
+static inline const char *afb_request_get_verb(struct afb_request *request)
+{
+ return request->verb;
+}
+
/*
* Gets from the request 'request' the argument of 'name'.
* Returns a PLAIN structure of type 'struct afb_arg'.