diff options
author | Shoichi Hiramatsu <hiramatsu_sh@micware.co.jp> | 2020-04-06 22:16:50 +0900 |
---|---|---|
committer | Shoichi Hiramatsu <hiramatsu_sh@micware.co.jp> | 2020-04-09 14:09:32 +0900 |
commit | 0c6f41e5965d0013cd871659c52c9abb1057550c (patch) | |
tree | 6ac47c8435aa3ba5b3dce0e32a7d75d96a5e592f /binding/src/binding-api.c | |
parent | 19a59202d0d3e2a2abdf64e6f8b74506443fd61b (diff) |
Check in demonstration POI bindingjellyfish_9.99.1jellyfish/9.99.19.99.1
Bug-AGL: SPEC-3291
Signed-off-by: Shoichi Hiramatsu <hiramatsu_sh@micware.co.jp>
Change-Id: Iac3488f240f7ae1c19fa6c650bcfcd240e88224a
Diffstat (limited to 'binding/src/binding-api.c')
-rw-r--r-- | binding/src/binding-api.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/binding/src/binding-api.c b/binding/src/binding-api.c new file mode 100644 index 0000000..5221cda --- /dev/null +++ b/binding/src/binding-api.c @@ -0,0 +1,65 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "binding-api.h" + +#include <stdlib.h> +#include <stdio.h> + +const afb_verb_t verbs[] = { + { .verb = POIAPI_BINDING_VERB_SEND_REQUEST, .callback = send_request }, + { .verb = POIAPI_BINDING_VERB_REQUEST_PROCESSED, .callback = request_processed }, + { .verb = POIAPI_BINDING_VERB_SUBSCRIBE_REQUESTS, .callback = subscribe_requests }, + { .verb = POIAPI_BINDING_VERB_UNSUBSCRIBE_REQUESTS, .callback = unsubscribe_requests }, + { .verb = POIAPI_BINDING_VERB_SUBSCRIBE_RESPONSES, .callback = subscribe_responses }, + { .verb = POIAPI_BINDING_VERB_UNSUBSCRIBE_RESPONSES, .callback = unsubscribe_responses }, + { .verb = NULL } +}; + +afb_event_t gEventRequestReceived; +afb_event_t gEventResponseReceived; + +int init(afb_api_t api) +{ + gEventRequestReceived = afb_api_make_event(api, POIAPI_BINDING_EVENT_REQUEST_RECEIVED); + gEventResponseReceived = afb_api_make_event(api, POIAPI_BINDING_EVENT_RESPONSE_RECEIVED); + if (afb_event_is_valid(gEventRequestReceived) && afb_event_is_valid(gEventResponseReceived)) { + + json_object *args = json_object_new_object(); + // TODO Set Version + json_object *appid = json_object_new_string("poi-service@0.1"); + json_object_object_add(args, "id", appid); + + char *err; + char *info; + json_object *response; + + // Launch poiservice + afb_api_call_sync(api, "afm-main", "start", args, &response, &err, &info); + + if (err) { + AFB_API_ERROR(api, "ERROR %s", err); + free(err); + } + if (info) { + AFB_API_INFO(api, "INFO %s", info); + free(info); + } + + json_object_put(response); + + return 0; + } + else { + AFB_API_ERROR(api, "Can't create events"); + return -1; + } +} + +const afb_binding_t afbBindingExport = { + .api = POIAPI_BINDING_API_NAME, + .verbs = verbs, + .init = init, + .noconcurrency = 0 +}; |