summaryrefslogtreecommitdiffstats
path: root/src/low-can-binding-new.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-24 11:10:02 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-24 11:12:55 +0000
commit5c0c41e87ed5d1a2de7d336465c3beb3987a299f (patch)
tree7ac1dcf406354f489c095664739a3a15d754601d /src/low-can-binding-new.cpp
parentec6579686e46f39205547a5a54efe3c9e671aee8 (diff)
Remove socket read management by systemd event
loop and use classic thread with a blocking read Change-Id: Iac5428009b57c727bb32bd4893bc3fe282ba35c7 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/low-can-binding-new.cpp')
-rw-r--r--src/low-can-binding-new.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/low-can-binding-new.cpp b/src/low-can-binding-new.cpp
index 3686c6b..13571f2 100644
--- a/src/low-can-binding-new.cpp
+++ b/src/low-can-binding-new.cpp
@@ -23,6 +23,65 @@
* Subscription and unsubscription
*
*********************************************************************************/
+static int subscribe_unsubscribe_signal(struct afb_req request, const std::string& sig)
+{
+ int ret;
+
+ // TODO: lock the subscribed_signals when insert/remove
+ const auto& ss_i = subscribed_signals.find(sig);
+ if (ss_i != subscribed_signals.end())
+ {
+ if(!afb_event_is_valid(ss_i->second))
+ {
+ if(!subscribe)
+ {
+ NOTICE(binder_interface, "Event isn't valid, it can't be unsubscribed.");
+ ret = 1;
+ }
+ else
+ {
+ ss_i->second = afb_daemon_make_event(binder_interface->daemon, ss_i->first.c_str());
+ if (!afb_event_is_valid(ss_i->second))
+ {
+ ERROR(binder_interface, "Can't create an event, something goes wrong.");
+ ret = 0;
+ }
+ }
+ }
+ }
+ else
+ {
+ subscribed_signals[sig] = afb_daemon_make_event(binder_interface->daemon, sig);
+ if (!afb_event_is_valid(ss_i->second))
+ {
+ ERROR(binder_interface, "Can't create an event, something goes wrong.");
+ ret = 0;
+ }
+ }
+
+ if (((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, subscribed_signals[sig])) < 0)
+ {
+ ERROR(binder_interface, "Operation goes wrong for signal: %s", sig);
+ ret = 0;
+ }
+ else
+ ret = 1;
+
+ return ret;
+}
+
+static int subscribe_signals(struct afb_req request, const std::vector<std::string>& signals)
+{
+ int ret = 0;
+
+ for(const auto& signal_i : signals)
+ {
+ ret = subscribe_signal(request, subscribe, signal_i);
+ if(ret == 0)
+ return ret;
+ }
+ return ret;
+}
std::vector<std::string> get_name(struct afb_req request)
{