From 07f57e23b57fa1fcabddc5f4074e47bcdd669d29 Mon Sep 17 00:00:00 2001 From: Clément Bénier Date: Thu, 13 Sep 2018 14:09:34 +0200 Subject: txc-binding: migration to AFB_BINDING_VERSION 3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit txc-binding.c is moving to version 3 in order to be compatible with app-afb-test fix some typo error: - rename txc api into txc-binding - wrong path files Change-Id: I9c59cbc59a457611fbf495a64f116170ef7898d8 Signed-off-by: Clément Bénier --- test/afb-test/fixtures/sig_incomplete.json | 2 +- test/afb-test/fixtures/sig_test.json | 4 +- test/afb-test/fixtures/sig_testInvalid.json | 4 +- test/afb-test/fixtures/txc-binding/CMakeLists.txt | 2 + test/afb-test/fixtures/txc-binding/txc-binding.c | 45 +++++++++++++--------- .../tests/signal-composer_BasicAPITest.lua | 12 +++--- 6 files changed, 39 insertions(+), 30 deletions(-) (limited to 'test/afb-test') diff --git a/test/afb-test/fixtures/sig_incomplete.json b/test/afb-test/fixtures/sig_incomplete.json index 8949096..7495491 100644 --- a/test/afb-test/fixtures/sig_incomplete.json +++ b/test/afb-test/fixtures/sig_incomplete.json @@ -1,7 +1,7 @@ { "signals": [ { - "event": "txc/vehicle_speed", + "event": "txc-binding/vehicle_speed", "retention": 30, "unit": "km/h", "getSignalsArgs": { diff --git a/test/afb-test/fixtures/sig_test.json b/test/afb-test/fixtures/sig_test.json index f430d8c..f925977 100644 --- a/test/afb-test/fixtures/sig_test.json +++ b/test/afb-test/fixtures/sig_test.json @@ -2,7 +2,7 @@ "signals": [ { "uid": "vehicle_speedTest1", - "event": "txc/vehicle_speed", + "event": "txc-binding/vehicle_speed", "retention": 30, "unit": "km/h", "getSignalsArgs": { @@ -18,7 +18,7 @@ }, { "uid": "engine_speedTest2", - "event": "txc/engine_speed", + "event": "txc-binding/engine_speed", "retention": 30, "unit": "rpm", "getSignalsArgs": { diff --git a/test/afb-test/fixtures/sig_testInvalid.json b/test/afb-test/fixtures/sig_testInvalid.json index 39e92c9..0943e58 100644 --- a/test/afb-test/fixtures/sig_testInvalid.json +++ b/test/afb-test/fixtures/sig_testInvalid.json @@ -2,7 +2,7 @@ "signals": [ { "uid": "invalidSignal", - "event": "txc/invalidSignal", + "event": "txc-binding/invalidSignal", "retention": -1, "unit": "invalidSignal", "getSignalsArgs": { @@ -17,4 +17,4 @@ } } ] -} \ No newline at end of file +} diff --git a/test/afb-test/fixtures/txc-binding/CMakeLists.txt b/test/afb-test/fixtures/txc-binding/CMakeLists.txt index fbc65f3..7c8e19c 100644 --- a/test/afb-test/fixtures/txc-binding/CMakeLists.txt +++ b/test/afb-test/fixtures/txc-binding/CMakeLists.txt @@ -20,6 +20,8 @@ # Add target to project dependency list PROJECT_TARGET_ADD(txc-binding) + add_definitions(-DAFB_BINDING_VERSION=3) + # Define project Targets add_library(${TARGET_NAME} MODULE txc-binding.c) diff --git a/test/afb-test/fixtures/txc-binding/txc-binding.c b/test/afb-test/fixtures/txc-binding/txc-binding.c index c9a5a68..94b3e77 100644 --- a/test/afb-test/fixtures/txc-binding/txc-binding.c +++ b/test/afb-test/fixtures/txc-binding/txc-binding.c @@ -35,7 +35,7 @@ CTLP_LUA_REGISTER("txc-binding"); struct signal { const char *name; - struct afb_event event; + afb_event_t event; }; static int playing; @@ -96,10 +96,17 @@ static void send_trace(const char *name, struct json_object *object) } } +struct playTracesArgs { + struct json_object* jArgs; + afb_api_t apiHandle; +}; + static void *play_traces(void *opaque) { int len, fd; - struct json_object *args = opaque; + struct playTracesArgs *ptArgs = (struct playTracesArgs*)opaque; + struct json_object *args = ptArgs->jArgs; + afb_api_t apiHandle = ptArgs->apiHandle; struct json_tokener *tokener = NULL; struct json_object *object; char line[1024]; @@ -135,7 +142,7 @@ static void *play_traces(void *opaque) info = "can't find filename"; goto end; } - fd = afb_daemon_rootdir_open_locale(json_object_get_string(object), O_RDONLY, NULL); + fd = afb_api_rootdir_open_locale(apiHandle, json_object_get_string(object), O_RDONLY, NULL); if (fd < 0) { info = "can't open the file"; goto end; @@ -213,7 +220,6 @@ end: return NULL; } - CTLP_CAPI (start, source, argsJ, eventJ) { struct json_object *args, *a; @@ -226,7 +232,7 @@ CTLP_CAPI (start, source, argsJ, eventJ) afb_req_fail(source->request, "error", "argument 'filename' is missing"); return -1; } - fd = afb_daemon_rootdir_open_locale(json_object_get_string(a), O_RDONLY, NULL); + fd = afb_api_rootdir_open_locale(source->api, json_object_get_string(a), O_RDONLY, NULL); if (fd < 0) { afb_req_fail(source->request, "error", "argument 'filename' is not a readable file"); return -1; @@ -250,7 +256,8 @@ CTLP_CAPI (start, source, argsJ, eventJ) /* valid then try to start */ playing = 1; stoping = 0; - if (pthread_create(&tid, NULL, play_traces, json_object_get(args)) != 0) { + struct playTracesArgs ptArgs = { json_object_get(args), source->api}; + if (pthread_create(&tid, NULL, play_traces, &ptArgs) != 0) { playing = 0; afb_req_fail(source->request, "error", "can't start to play"); return -1; @@ -269,12 +276,12 @@ CTLP_CAPI (stop, source, argsJ, eventJ) return 0; } -static int subscribe_unsubscribe_sig(struct afb_req request, int subscribe, struct signal *sig) +static int subscribe_unsubscribe_sig(afb_api_t apiHandle, afb_req_t request, int subscribe, struct signal *sig) { if (!afb_event_is_valid(sig->event)) { if (!subscribe) return 1; - sig->event = afb_daemon_make_event(sig->name); + sig->event = afb_api_make_event(apiHandle, sig->name); if (!afb_event_is_valid(sig->event)) { return 0; } @@ -287,33 +294,33 @@ static int subscribe_unsubscribe_sig(struct afb_req request, int subscribe, stru return 1; } -static int subscribe_unsubscribe_all(struct afb_req request, int subscribe) +static int subscribe_unsubscribe_all(afb_api_t apiHandle, afb_req_t request, int subscribe) { int i, n, e; n = sizeof signals / sizeof * signals; e = 0; for (i = 0 ; i < n ; i++) - e += !subscribe_unsubscribe_sig(request, subscribe, &signals[i]); + e += !subscribe_unsubscribe_sig(apiHandle, request, subscribe, &signals[i]); return e == 0; } -static int subscribe_unsubscribe_name(struct afb_req request, int subscribe, const char *name) +static int subscribe_unsubscribe_name(afb_api_t apiHandle, afb_req_t request, int subscribe, const char *name) { struct signal *sig; if (0 == strcmp(name, "*")) - return subscribe_unsubscribe_all(request, subscribe); + return subscribe_unsubscribe_all(apiHandle, request, subscribe); sig = getsig(name); if (sig == NULL) { return 0; } - return subscribe_unsubscribe_sig(request, subscribe, sig); + return subscribe_unsubscribe_sig(apiHandle, request, subscribe, sig); } -static void subscribe_unsubscribe(struct afb_req request, int subscribe) +static void subscribe_unsubscribe(afb_api_t apiHandle, afb_req_t request, int subscribe) { int ok, i; size_t n; @@ -322,15 +329,15 @@ static void subscribe_unsubscribe(struct afb_req request, int subscribe) /* makes the subscription/unsubscription */ args = afb_req_json(request); if (args == NULL || !json_object_object_get_ex(args, "event", &a)) { - ok = subscribe_unsubscribe_all(request, subscribe); + ok = subscribe_unsubscribe_all(apiHandle, request, subscribe); } else if (json_object_get_type(a) != json_type_array) { - ok = subscribe_unsubscribe_name(request, subscribe, json_object_get_string(a)); + ok = subscribe_unsubscribe_name(apiHandle, request, subscribe, json_object_get_string(a)); } else { n = json_object_array_length(a); ok = 0; for (i = 0 ; i < n ; i++) { x = json_object_array_get_idx(a, i); - if (subscribe_unsubscribe_name(request, subscribe, json_object_get_string(x))) + if (subscribe_unsubscribe_name(apiHandle, request, subscribe, json_object_get_string(x))) ok++; } ok = (ok == n); @@ -346,11 +353,11 @@ static void subscribe_unsubscribe(struct afb_req request, int subscribe) } CTLP_CAPI (subscribe, source, argsJ, eventJ){ - subscribe_unsubscribe(source->request, 1); + subscribe_unsubscribe(source->api, source->request, 1); return 0; } CTLP_CAPI (unsubscribe, source, argsJ, eventJ){ - subscribe_unsubscribe(source->request, 0); + subscribe_unsubscribe(source->api, source->request, 0); return 0; } \ No newline at end of file diff --git a/test/afb-test/tests/signal-composer_BasicAPITest.lua b/test/afb-test/tests/signal-composer_BasicAPITest.lua index b5ebb62..30c4f3a 100644 --- a/test/afb-test/tests/signal-composer_BasicAPITest.lua +++ b/test/afb-test/tests/signal-composer_BasicAPITest.lua @@ -79,7 +79,7 @@ _AFT.testVerbStatusSuccess(testPrefix.."addObjectsDirect","signal-composer","add signals= { { uid= "vehicle_speedTest3", - event= "txc/vehicle_speed", + event= "txc-binding/vehicle_speed", retention= 30, unit= "km/h", getSignalsArgs= { @@ -95,7 +95,7 @@ _AFT.testVerbStatusSuccess(testPrefix.."addObjectsDirect","signal-composer","add }, { uid= "engine_speedTest4", - event= "txc/engine_speed", + event= "txc-binding/engine_speed", retention= 30, unit= "rpm", getSignalsArgs= { @@ -113,7 +113,7 @@ _AFT.testVerbStatusError(testPrefix.."addObjectsDirect_InvalidSignal","signal-co signals= { { uid= "invalidSignal", - event= "txc/invalidSignal", + event= "txc-binding/invalidSignal", retention= -1, unit= "invalidSignal", getSignalsArgs= { @@ -137,7 +137,7 @@ _AFT.testVerbStatusError(testPrefix.."addObjectsDirect_MissingField","signal-com { signals= { { - event= "txc/invalidSignal2", + event= "txc-binding/invalidSignal2", retention= 30, unit= "km/h", getSignalsArgs= { @@ -157,11 +157,11 @@ _AFT.testVerbStatusError(testPrefix.."addObjectsDirect_MissingField","signal-com --[[ This tests the 'addObjects' verb of the signal-composer API, this is by passing the path of a json containing signals This one has invalid values for most of its field, the binding should not be able to add it ]] -_AFT.testVerbStatusError(testPrefix.."addObjectsByFile_InvalidSignal","signal-composer","addObjects",{file = _AFT.bindingRootDir.."var/sig_testInvalid.json"}); +_AFT.testVerbStatusError(testPrefix.."addObjectsByFile_InvalidSignal","signal-composer","addObjects",{file = _AFT.bindingRootDir.."/var/sig_testInvalid.json"}); --[[ This tests the 'addObjects' verb of the signal-composer API, this is by passing the path of a json containing signals This one is missing the mandatory 'uid' field, the binding should not be able to add it ]] -_AFT.testVerbStatusError(testPrefix.."addObjectsByFile_Missingfield","signal-composer","addObjects",{file = _AFT.bindingRootDir.."var/sig_incomplete.json"}); +_AFT.testVerbStatusError(testPrefix.."addObjectsByFile_Missingfield","signal-composer","addObjects",{file = _AFT.bindingRootDir.."/var/sig_incomplete.json"}); -- This tests the 'subscribe' verb of the signal-composer API, with a non existing signal, it should reply with an error _AFT.testVerbStatusError(testPrefix.."subscribeNonExistingSignal","signal-composer","subscribe",{ signal = "notASignal"}); -- cgit 1.2.3-korg