summaryrefslogtreecommitdiffstats
path: root/binding/binding-api.c
diff options
context:
space:
mode:
authorLi, Xiaoming <lixm.fnst@cn.fujitsu.com>2020-06-22 11:07:30 +0800
committerLi Xiaoming <lixm.fnst@cn.fujitsu.com>2020-07-21 12:31:15 +0000
commitabb024ffcbf800a51dc7a7c513611141d82b2a3b (patch)
treed527d9ffb743460058ef3f275cd063efcb65a9d8 /binding/binding-api.c
parent0c6f41e5965d0013cd871659c52c9abb1057550c (diff)
The test folder should rest in the root of a package. Bug-AGL: SPEC-2807 Change-Id: I6e44e68f40aaf58d2c59973e6a2413947dcb4eaf Signed-off-by: Li, Xiaoming <lixm.fnst@cn.fujitsu.com>
Diffstat (limited to 'binding/binding-api.c')
-rw-r--r--binding/binding-api.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/binding/binding-api.c b/binding/binding-api.c
new file mode 100644
index 0000000..5221cda
--- /dev/null
+++ b/binding/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
+};