added a socket class to wrap the C socket API.
[apps/agl-service-can-low-level.git] / src / low-can-binding.cpp
index 13452a4..79b1691 100644 (file)
@@ -40,13 +40,9 @@ extern "C"
        #include <afb/afb-service-itf.h>
 };
 
-/*
- *     Interface between the daemon and the binding
- */
+// Interface between the daemon and the binding
 const struct afb_binding_interface *binder_interface;
 
-can_bus_t *can_bus_handler;
-
 /********************************************************************************
 *
 *              Subscription and unsubscription
@@ -82,7 +78,7 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe,
 
        std::lock_guard<std::mutex> subscribed_signals_lock(get_subscribed_signals_mutex());
        std::map<std::string, struct afb_event>& s = get_subscribed_signals();
-       if (s.find(sig) != s.end() && !afb_event_is_valid(s[std::string(sig)]))
+       if (s.find(sig) != s.end() && !afb_event_is_valid(s[sig]))
        {
                if(!subscribe)
                {
@@ -90,12 +86,14 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe,
                        ret = -1;
                }
                else
+               {
                        /* Event it isn't valid annymore, recreate it */
                        ret = create_event_handle(sig, s);
+               }
        }
        else
        {
-               /* Event don't exist , so let's create it */
+               /* Event doesn't exist , so let's create it */
                struct afb_event empty_event = {nullptr, nullptr};
                subscribed_signals[sig] = empty_event;
                ret = create_event_handle(sig, s);
@@ -222,16 +220,14 @@ extern "C"
        */
        int afbBindingV1ServiceInit(struct afb_service service)
        {
-               int fd_conf;
-               fd_conf = afb_daemon_rootdir_open_locale(binder_interface->daemon, "can_buses.json", O_RDONLY, NULL);
+               configuration_t config;
 
-               /* Initialize the CAN bus handler */
-               can_bus_handler = new can_bus_t(fd_conf);
+               can_bus_manager = config.get_can_bus_manager();
 
                /* Open CAN socket */
-               if(can_bus_handler->init_can_dev() == 0)
+               if(can_bus_manager.init_can_dev() == 0)
                {
-                       can_bus_handler->start_threads();
+                       can_bus_manager.start_threads();
                        return 0;
                }
                ERROR(binder_interface, "There was something wrong with CAN device Initialization. Check your config file maybe");