diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-09-27 10:12:35 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-09-27 13:05:37 +0200 |
commit | 663632686bc2cc1f2d2ce24ace1d76325d44e4d9 (patch) | |
tree | db9fe7754dcd074adcccd7b31c6ca448f740ab88 /signal-composer-binding/signal-composer.cpp | |
parent | c6fd6abed4c4d52835b4bb4aba68f415da908a1b (diff) |
Fix wrong JSON unpack type
This correct the retention value extraction as an 'int' instead
of a Json object. Also made 'api' field mandatory.
Format and improve log messages.
Change-Id: I00b337839a49fc1952be8589b48bf1a38b863549
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal-composer.cpp')
-rw-r--r-- | signal-composer-binding/signal-composer.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp index 13bfd64..3b631c3 100644 --- a/signal-composer-binding/signal-composer.cpp +++ b/signal-composer-binding/signal-composer.cpp @@ -107,7 +107,7 @@ int Composer::loadOneSourceAPI(json_object* sourceJ) const char *uid, *api, *info; int retention = 0; - int err = wrap_json_unpack(sourceJ, "{ss,s?s,s?o,s?o,s?o,s?i,s?o !}", + int err = wrap_json_unpack(sourceJ, "{ss,ss,s?o,s?o,s?o,s?o,s?i !}", "uid", &uid, "api", &api, "info", &info, @@ -118,7 +118,7 @@ int Composer::loadOneSourceAPI(json_object* sourceJ) "retention", &retention); if (err) { - AFB_ERROR("Missing something api|[info]|[init]|[getSignals] in %s", json_object_get_string(sourceJ)); + AFB_ERROR("Missing or incorrect field uid|api|[info]|[init]|[getSignals]|[onReceived]|[retention] in %s", json_object_get_string(sourceJ)); return err; } @@ -167,14 +167,18 @@ int Composer::loadSourcesAPI(AFB_ApiT apihandle, CtlSectionT* section, json_obje { std::size_t count = 1; json_object *sigCompJ = nullptr; - // add the signal composer itself as source - wrap_json_pack(&sigCompJ, "{ss,ss,ss}", - "uid", "Signal-Composer-service", - "api", afbBindingV2.api, - "info", "Api on behalf the virtual signals are sent"); - if(json_object_is_type(sourcesJ, json_type_array)) - json_object_array_add(sourcesJ, sigCompJ); + // add the signal composer itself as source if not already done + if(! composer.getSourceAPI("Signal-Composer-service")) + { + wrap_json_pack(&sigCompJ, "{ss,ss,ss}", + "uid", "Signal-Composer-service", + "api", afbBindingV2.api, + "info", "Api on behalf the virtual signals are sent"); + + if(json_object_is_type(sourcesJ, json_type_array)) + json_object_array_add(sourcesJ, sigCompJ); + } if (json_object_get_type(sourcesJ) == json_type_array) { @@ -189,8 +193,13 @@ int Composer::loadSourcesAPI(AFB_ApiT apihandle, CtlSectionT* section, json_obje } else { - if ((err = composer.loadOneSourceAPI(sourcesJ))) return err; - if (sigCompJ && (err = composer.loadOneSourceAPI(sigCompJ))) return err; + if (err = composer.loadOneSourceAPI(sourcesJ)) + return err; + if (sigCompJ) + { + if (err = composer.loadOneSourceAPI(sigCompJ)) + return err; + } } AFB_NOTICE("%ld new sources added to service", count); } @@ -283,10 +292,8 @@ int Composer::loadOneSignal(json_object* signalJ) dependsV.push_back(sourceStr); } if(!src) { - if (!sourcesListV_.empty()) - src = *sourcesListV_.rbegin(); - else if (!newSourcesListV_.empty()) - src = *newSourcesListV_.rbegin(); + if ( ! sourcesListV_.empty() || ! newSourcesListV_.empty()) + src = getSourceAPI("signal-composer"); else { AFB_WARNING("Signal '%s' not correctly attached to its source. Abort this one", json_object_to_json_string(signalJ)); |