summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal-composer-binding.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-04-09 18:42:49 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-04-09 18:42:49 +0200
commit8bb53b8cb99e3d95c58226996f32c7cd6a10ba73 (patch)
tree75bee6bc3f0741422f4cbfe208801ff1d5434a81 /signal-composer-binding/signal-composer-binding.cpp
parentcd20405fde8b9aeca2db3077d959cc970bd48105 (diff)
Add objects directly from JSON argumentflounder_5.99.1flounder/5.99.15.99.1
Change-Id: I77ab639593ecb3d73239244d11ee3da599caf1b4 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal-composer-binding.cpp')
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index c7ca567..fb99c89 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -168,31 +168,38 @@ void unsubscribe(afb_req request)
}
/// @brief verb that loads JSON configuration (old SigComp.json file now)
+
void addObjects(afb_req request)
{
Composer& composer = Composer::instance();
json_object *sourcesJ = nullptr,
- *signalsJ = nullptr;
+ *signalsJ = nullptr,
+ *objectsJ = nullptr;
const char* filepath = afb_req_value(request, "file");
if(filepath)
{
- json_object *fileJ = json_object_from_file(filepath);
- if(!fileJ)
+ objectsJ = json_object_from_file(filepath);
+ if(!objectsJ)
{
json_object* responseJ = ScanForConfig(CONTROL_CONFIG_PATH, CTL_SCAN_RECURSIVE, filepath, ".json");
filepath = ConfigSearch(nullptr, responseJ);
if(filepath)
- {fileJ = json_object_from_file(filepath);}
+ {objectsJ = json_object_from_file(filepath);}
}
+ }
+ else
+ {objectsJ = afb_req_json(request);}
- json_object_object_get_ex(fileJ, "sources", &sourcesJ);
- json_object_object_get_ex(fileJ, "signals", &signalsJ);
+ if(objectsJ)
+ {
+ json_object_object_get_ex(objectsJ, "sources", &sourcesJ);
+ json_object_object_get_ex(objectsJ, "signals", &signalsJ);
if( sourcesJ && composer.loadSources(sourcesJ))
{
afb_req_fail_f(request, "Loading 'sources' configuration or subscription error", "Error code: -2");
- json_object_put(fileJ);
+ json_object_put(objectsJ);
return;
}
if(signalsJ)
@@ -202,11 +209,11 @@ void addObjects(afb_req request)
else
{
afb_req_fail_f(request, "Loading 'signals' configuration or subscription error", "Error code: -2");
- json_object_put(fileJ);
+ json_object_put(objectsJ);
return;
}
}
- json_object_put(fileJ);
+ json_object_put(objectsJ);
afb_req_success(request, NULL, NULL);
}
else