aboutsummaryrefslogtreecommitdiffstats
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-07-04 18:27:20 +0200
commit0769ea71247396bfdac0dfbb56477c83b9e60de6 (patch)
tree75bee6bc3f0741422f4cbfe208801ff1d5434a81
parentcd20405fde8b9aeca2db3077d959cc970bd48105 (diff)
Add objects directly from JSON argument
There was only possible to add objects at runtime using another JSON file located somewhere in the filesystem. Now, it is also possible to load directly from a JSON passed in the request. Change-Id: I77ab639593ecb3d73239244d11ee3da599caf1b4 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-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