-/********************************************************************************
-*
-* Event management
-*
-*********************************************************************************/
-
-/********************************************************************************
-*
-* Subscription and unsubscription
-*
-*********************************************************************************/
-
-static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe, const CanSignal& sig)
+#include <map>
+#include <queue>
+#include <mutex>
+#include <vector>
+#include <thread>
+#include <time.h>
+#include <linux/can.h>
+#include <json-c/json.h>
+
+#include "openxc.pb.h"
+#include "configuration.hpp"
+#include "can/can-bus.hpp"
+#include "can/can-signals.hpp"
+#include "can/can-message.hpp"
+#include "utils/timer.hpp"
+#include "utils/signals.hpp"
+#include "diagnostic/diagnostic-message.hpp"
+#include "utils/openxc-utils.hpp"
+
+extern "C"
+{
+ #include <afb/afb-service-itf.h>
+};
+
+// Interface between the daemon and the binding
+const struct afb_binding_interface *binder_interface;
+
+///******************************************************************************
+///
+/// Subscription and unsubscription
+///
+///*******************************************************************************/
+
+static int make_subscription_unsubscription(struct afb_req request, const std::string& sig_name, std::map<std::string, struct afb_event>& s, bool subscribe)
+{
+ /* Make the subscription or unsubscription to the event */
+ if (((subscribe ? afb_req_subscribe : afb_req_unsubscribe)(request, s[sig_name])) < 0)
+ {
+ ERROR(binder_interface, "make_subscription_unsubscription: Operation goes wrong for signal: %s", sig_name.c_str());
+ return 0;
+ }
+ return 1;
+
+}
+
+static int create_event_handle(const std::string& sig_name, std::map<std::string, struct afb_event>& s)
+{
+ s[sig_name] = afb_daemon_make_event(binder_interface->daemon, sig_name.c_str());
+ if (!afb_event_is_valid(s[sig_name]))
+ {
+ ERROR(binder_interface, "create_event_handle: Can't create an event for %s, something goes wrong.", sig_name.c_str());
+ return 0;
+ }
+ return 1;
+}
+
+static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe, const std::string& sig)