aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-19 01:17:28 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commitf4fba8a2744991ff8c5cb8af4a67c7d9456f1057 (patch)
tree352231c9342344599ec2af08ef82495deefb238f /plugins
parent9f61a83961cdbf133fdeb80cb978e6c79f4a9547 (diff)
Modification about conf definition
- Argument for each signal subscription. (getSignalsArgs) - differentiation between Signal as raw signal from another API and virtual signal depending upon other signals - changing way to specify function with uri that specify everythings that could be needed to invoke a function. Change-Id: I8917c5ae3c2c1e3fa48ddfdda41fc75eaba32bb7 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/low-can.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/plugins/low-can.cpp b/plugins/low-can.cpp
index 1f528a5..8b573ba 100644
--- a/plugins/low-can.cpp
+++ b/plugins/low-can.cpp
@@ -77,15 +77,18 @@ CTLP_ONLOAD(plugin, bAppHandle)
}
CTLP_CAPI (subscribeToLow, source, argsJ, eventJ, context) {
- json_object* signalArrayJ = NULL, *subscribeArgsJ = NULL, *subscribeFilterJ = NULL, *responseJ = NULL;
- const char* unit = NULL;
+ json_object* dependsArrayJ = nullptr, *subscribeArgsJ = nullptr, *subscribeFilterJ = nullptr, *responseJ = nullptr, *filterJ = nullptr;
+ const char *id = nullptr, *event = nullptr, *unit = nullptr;
double frequency = 0;
int err = 0;
- err = wrap_json_unpack(eventJ, "{so,s?s,s?F !}",
- "signal", &signalArrayJ,
+ err = wrap_json_unpack(eventJ, "{ss,s?s,s?o,s?s,s?F,s?o !}",
+ "id", &id,
+ "event", &event,
+ "depends", &dependsArrayJ,
"unit", &unit,
- "frequency", &frequency);
+ "frequency", &frequency,
+ "getSignalsArgs", &filterJ);
if(err)
{
AFB_ERROR("Problem to unpack JSON object eventJ: %s",
@@ -93,29 +96,27 @@ CTLP_CAPI (subscribeToLow, source, argsJ, eventJ, context) {
return err;
}
- if(frequency > 0)
+ if(frequency > 0 && !filterJ)
+ {wrap_json_pack(&subscribeFilterJ, "{sf}", "frequency", frequency);}
+ else
+ {subscribeFilterJ = filterJ;}
+
+ std::string eventStr = std::string(event);
+ std::string lowEvent = eventStr.substr(eventStr.find("/")+1);
+ err = wrap_json_pack(&subscribeArgsJ, "{ss, so*}",
+ "event", lowEvent.c_str(),
+ "filter", subscribeFilterJ);
+ if(err)
{
- wrap_json_pack(&subscribeFilterJ, "{sf}", "frequency", frequency);
+ AFB_ERROR("Error building subscription query object");
+ return err;
}
-
- for (int idx = 0; idx < json_object_array_length(signalArrayJ); idx++)
+ AFB_DEBUG("Calling subscribe with %s", json_object_to_json_string_ext(subscribeArgsJ, JSON_C_TO_STRING_PRETTY));
+ err = afb_service_call_sync("low-can", "subscribe", subscribeArgsJ, &responseJ);
+ if(err)
{
- json_object* aSignalJ = json_object_array_get_idx(signalArrayJ, idx);
- err = wrap_json_pack(&subscribeArgsJ, "{ss, so*}",
- "event", json_object_get_string(aSignalJ),
- "filter", subscribeFilterJ);
- if(err)
- {
- AFB_ERROR("Error building subscription query object");
- return err;
- }
- AFB_DEBUG("Calling subscribe with %s", json_object_to_json_string_ext(subscribeArgsJ, JSON_C_TO_STRING_PRETTY));
- err = afb_service_call_sync("low-can", "subscribe", subscribeArgsJ, &responseJ);
- if(err)
- {
- AFB_ERROR("Can't find api 'low-can'");
- return err;
- }
+ AFB_ERROR("Can't find api 'low-can'");
+ return err;
}
return err;