X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=bindings%2Fsamples%2FHelloWorld.c;h=0f58a43b26d3a2d14504b6916f75c1f132ee3363;hb=b67e18b39830a01750721787bf3bdc5d71983144;hp=e2f38ee491e7ede8cb1601ad5cb11bbf2439b9c4;hpb=4dc768d67031aa99e2b885a0df7e643fdd1fa80c;p=src%2Fapp-framework-binder.git diff --git a/bindings/samples/HelloWorld.c b/bindings/samples/HelloWorld.c index e2f38ee4..0f58a43b 100644 --- a/bindings/samples/HelloWorld.c +++ b/bindings/samples/HelloWorld.c @@ -109,6 +109,13 @@ static int event_push(struct json_object *args, const char *tag) return e ? afb_event_push(e->event, json_object_get(args)) : -1; } +static int event_broadcast(struct json_object *args, const char *tag) +{ + struct event *e; + e = event_get(tag); + return e ? afb_event_broadcast(e->event, json_object_get(args)) : -1; +} + // Sample Generic Ping Debug API static void ping(afb_req request, json_object *jresp, const char *tag) { @@ -359,6 +366,31 @@ static void exitnow (afb_req request) exit(code); } +static void broadcast(afb_req request) +{ + const char *tag = afb_req_value(request, "tag"); + const char *name = afb_req_value(request, "name"); + const char *data = afb_req_value(request, "data"); + json_object *object = data ? json_tokener_parse(data) : NULL; + + if (tag != NULL) { + pthread_mutex_lock(&mutex); + if (0 > event_broadcast(object, tag)) + afb_req_fail(request, "failed", "broadcast error"); + else + afb_req_success(request, NULL, NULL); + pthread_mutex_unlock(&mutex); + } else if (name != NULL) { + if (0 > afb_daemon_broadcast_event(name, object)) + afb_req_fail(request, "failed", "broadcast error"); + else + afb_req_success(request, NULL, NULL); + } else { + afb_req_fail(request, "failed", "bad arguments"); + } + json_object_put(object); +} + static int preinit() { NOTICE("hello binding comes to live"); @@ -395,6 +427,7 @@ static const afb_verb_v2 verbs[]= { { "call", call , NULL, AFB_SESSION_NONE }, { "callsync", callsync , NULL, AFB_SESSION_NONE }, { "verbose", verbose , NULL, AFB_SESSION_NONE }, + { "broadcast", broadcast , NULL, AFB_SESSION_NONE }, { "exit", exitnow , NULL, AFB_SESSION_NONE }, { NULL} };