Code Review
/
src
/
app-framework-binder.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
afb-stub-ws: Safe handling of deconnections
[src/app-framework-binder.git]
/
bindings
/
samples
/
ave.c
diff --git
a/bindings/samples/ave.c
b/bindings/samples/ave.c
index
e6b195b
..
ce01c6d
100644
(file)
--- a/
bindings/samples/ave.c
+++ b/
bindings/samples/ave.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2015
, 2016, 2017
"IoT.bzh"
+ * Copyright (C) 2015
-2018
"IoT.bzh"
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@
-21,6
+21,7
@@
#include <json-c/json.h>
#include <json-c/json.h>
+#define AFB_BINDING_WANT_DYNAPI
#define AFB_BINDING_VERSION 0
#include <afb/afb-binding.h>
#define AFB_BINDING_VERSION 0
#include <afb/afb-binding.h>
@@
-29,7
+30,7
@@
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
struct event
{
struct event *next;
struct event
{
struct event *next;
-
struct
afb_eventid *eventid;
+ afb_eventid *eventid;
char tag[1];
};
char tag[1];
};
@@
-147,7
+148,7
@@
static void pingBug (afb_request *request)
static void pingEvent(afb_request *request)
{
json_object *query = afb_request_json(request);
static void pingEvent(afb_request *request)
{
json_object *query = afb_request_json(request);
- afb_dynapi_broadcast_event(request->
dyn
api, "event", json_object_get(query));
+ afb_dynapi_broadcast_event(request->api, "event", json_object_get(query));
ping(request, json_object_get(query), "event");
}
ping(request, json_object_get(query), "event");
}
@@
-219,7
+220,7
@@
static void eventadd (afb_request *request)
pthread_mutex_lock(&mutex);
if (tag == NULL || name == NULL)
afb_request_fail(request, "failed", "bad arguments");
pthread_mutex_lock(&mutex);
if (tag == NULL || name == NULL)
afb_request_fail(request, "failed", "bad arguments");
- else if (0 != event_add(request->
dyn
api, tag, name))
+ else if (0 != event_add(request->api, tag, name))
afb_request_fail(request, "failed", "creation error");
else
afb_request_success(request, NULL, NULL);
afb_request_fail(request, "failed", "creation error");
else
afb_request_success(request, NULL, NULL);
@@
-305,7
+306,7
@@
static void call (afb_request *request)
if (object == NULL)
afb_request_fail(request, "failed", "bad arguments");
else
if (object == NULL)
afb_request_fail(request, "failed", "bad arguments");
else
- afb_dynapi_call(request->
dyn
api, api, verb, object, callcb, afb_request_addref(request));
+ afb_dynapi_call(request->api, api, verb, object, callcb, afb_request_addref(request));
}
static void callsync (afb_request *request)
}
static void callsync (afb_request *request)
@@
-319,7
+320,7
@@
static void callsync (afb_request *request)
if (object == NULL)
afb_request_fail(request, "failed", "bad arguments");
else {
if (object == NULL)
afb_request_fail(request, "failed", "bad arguments");
else {
- rc = afb_dynapi_call_sync(request->
dyn
api, api, verb, object, &result);
+ rc = afb_dynapi_call_sync(request->api, api, verb, object, &result);
if (rc >= 0)
afb_request_success(request, result, NULL);
else {
if (rc >= 0)
afb_request_success(request, result, NULL);
else {
@@
-379,7
+380,7
@@
static void broadcast(afb_request *request)
afb_request_success(request, NULL, NULL);
pthread_mutex_unlock(&mutex);
} else if (name != NULL) {
afb_request_success(request, NULL, NULL);
pthread_mutex_unlock(&mutex);
} else if (name != NULL) {
- if (0 > afb_dynapi_broadcast_event(request->
dyn
api, name, object))
+ if (0 > afb_dynapi_broadcast_event(request->api, name, object))
afb_request_fail(request, "failed", "broadcast error");
else
afb_request_success(request, NULL, NULL);
afb_request_fail(request, "failed", "broadcast error");
else
afb_request_success(request, NULL, NULL);
@@
-415,7
+416,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),
{
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
}
// NOTE: this sample does not use session to keep test a basic as possible
@@
-447,13
+448,13
@@
static const struct {
{ .verb=NULL}
};
{ .verb=NULL}
};
-static void pingoo(
afb_req
req)
+static void pingoo(
struct afb_req_x1
req)
{
{
- json_object *args = afb_req_json(req);
- afb_req_
success_f(req, json_object_get(args)
, "You reached pingoo \\o/ nice args: %s", json_object_to_json_string(args));
+ json_object *args = afb_req_
x1_
json(req);
+ afb_req_
x1_reply_f(req, json_object_get(args), NULL
, "You reached pingoo \\o/ nice args: %s", json_object_to_json_string(args));
}
}
-static const afb_verb_v2 verbsv2[]= {
+static const
struct
afb_verb_v2 verbsv2[]= {
{ .verb="pingoo", .callback=pingoo },
{ .verb="ping", .callback=pingoo },
{ .verb=NULL}
{ .verb="pingoo", .callback=pingoo },
{ .verb="ping", .callback=pingoo },
{ .verb=NULL}
@@
-461,12
+462,12
@@
static const afb_verb_v2 verbsv2[]= {
static const char *apis[] = { "ave", "hi", "salut", NULL };
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;
{
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);
afb_dynapi_on_init(dynapi, init);
afb_dynapi_on_event(dynapi, onevent);
@@
-483,7
+484,9
@@
int afbBindingVdyn(afb_dynapi *dynapi)
int i, rc;
for (i = 0; apis[i] ; i++) {
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, 0, build_api, (void*)apis[i]);
+ if (rc < 0)
+ AFB_DYNAPI_ERROR(dynapi, "can't create API %s", apis[i]);
}
return 0;
}
}
return 0;
}