aboutsummaryrefslogtreecommitdiffstats
path: root/src/low-can-binding.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-15 16:44:59 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-15 16:45:40 +0000
commit54595b88520c3caea40fac61ed79f2dcb57b7062 (patch)
treee9bfd9082af968e1e16667cb49b7aaa99d40529b /src/low-can-binding.cpp
parent914a47b69953ec321e35109841f2564286224631 (diff)
Fixed subscribe/unsubscribe operations.
Change-Id: I79c2f32801bf72e12b3e2da45e2eb2939cb5f85e Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/low-can-binding.cpp')
-rw-r--r--src/low-can-binding.cpp36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp
index b6098907..af86786d 100644
--- a/src/low-can-binding.cpp
+++ b/src/low-can-binding.cpp
@@ -121,22 +121,42 @@ static int connect_to_event_loop(CanBus &CanBus_handler)
*
*********************************************************************************/
-static int subscribe_unsubscribe_sig(struct afb_req request, int subscribe, struct signal *sig)
-{
- if (!afb_event_is_valid(sig->event)) {
+static int subscribe_unsubscribe_signal(struct afb_req request, int subscribe, std::map<CanSignal, struct afb_event>::iterator *s_sig)
+ {
+ if (!afb_event_is_valid(s_sig->second)) {
if (!subscribe)
return 1;
- sig->event = afb_daemon_make_event(afbitf->daemon, sig->name);
- if (!afb_event_is_valid(sig->event)) {
+ sig->event = afb_daemon_make_event(afbitf->daemon, s_sig->first->genericName);
+ if (!afb_event_is_valid(s_sig->second)) {
return 0;
}
}
- if (((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, sig->event)) < 0) {
+ if (((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, s_sig->second)) < 0) {
return 0;
}
return 1;
+ }
+
+static int subscribe_unsubscribe_signals(struct afb_req request, int subscribe, std:vector<CanSignal> *signals)
+{
+ std::vector<CanSignal>::iterator signal_i;
+ std::map <CanSignal, struct afb_event>::iterator s_signal_i;
+
+ for(signal_i=signals.begin(); signal_i != signals.end(); signal_i++)
+ {
+ s_signal_i = subscribed_signals.find(signal_i);
+ if(s_signal_i != subscribed_signals.end())
+ subscribe_unsubscribe_signal(request, subscribe, s_signal_i);
+ else
+ {
+ std::map <CanSignal, struct afb_event>::iterator it = subscribed_signals.begin();
+ it = subscribed_signals.insert(it, std::pair<CanSignal, struct afb_event>(signal_i, NULL);
+ subscribe_unsubscribe_signal(request, subscribe, it);
+ }
+ return 0;
+ }
}
static int subscribe_unsubscribe_all(struct afb_req request, int subscribe)
@@ -152,12 +172,12 @@ static int subscribe_unsubscribe_all(struct afb_req request, int subscribe)
static int subscribe_unsubscribe_name(struct afb_req request, int subscribe, const char *name)
{
- struct signal *sig;
+ std::vector <CanSignal> *sig;
if (0 == strcmp(name, "*"))
return subscribe_unsubscribe_all(request, subscribe);
- sig = getSignal(name);
+ find_signals(name, sig);
if (sig == NULL) {
return 0;
}