Make a global variable to a configuration object.
authorRomain Forlot <romain.forlot@iot.bzh>
Wed, 8 Mar 2017 11:55:47 +0000 (12:55 +0100)
committerRomain Forlot <romain.forlot@iot.bzh>
Thu, 16 Mar 2017 16:10:39 +0000 (17:10 +0100)
With afb interface, it will be the last global variable
needed as it regroup all needed stuff to other class and
functions.

Change-Id: I3d82b6f748ff22a9a975d15ab9df51f63005737f
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
src/low-can-binding.cpp
src/low-can-binding.hpp
src/utils/signals.hpp

index ad73de1..6bce723 100644 (file)
@@ -22,7 +22,6 @@
 #include <mutex>
 #include <vector>
 #include <thread>
-#include <fcntl.h>
 #include <linux/can.h>
 #include <json-c/json.h>
 #include <systemd/sd-event.h>
 #include "utils/timer.hpp"
 #include "utils/signals.hpp"
 #include "utils/openxc-utils.hpp"
-#include "configuration.hpp"
 
 // Interface between the daemon and the binding
 const struct afb_binding_interface *binder_interface;
+configuration_t *config;
 
 /********************************************************************************
 *
@@ -216,9 +215,9 @@ extern "C"
        */
        int afbBindingV1ServiceInit(struct afb_service service)
        {
-               configuration_t config;
+               config = new configuration_t();
 
-               can_bus_manager = config.get_can_bus_manager();
+               can_bus_t can_bus_manager = config->get_can_bus_manager();
 
                /* Open CAN socket */
                if(can_bus_manager.init_can_dev() == 0)
@@ -226,6 +225,7 @@ extern "C"
                        can_bus_manager.start_threads();
                        return 0;
                }
+
                ERROR(binder_interface, "There was something wrong with CAN device Initialization. Check your config file maybe");
                return 1;
        }
index 2c84989..1509c2a 100644 (file)
@@ -19,6 +19,9 @@
 #pragma once
 
 #include <cstddef>
+
+#include "configuration.hpp"
+
 extern "C"
 {
        #include <afb/afb-binding.h>
@@ -26,4 +29,6 @@ extern "C"
 
 extern "C" struct afb_binding_interface;
 
-extern const struct afb_binding_interface *binder_interface;
\ No newline at end of file
+extern const struct afb_binding_interface *binder_interface;
+
+extern configuration_t *config;
\ No newline at end of file
index e575bd1..cee5505 100644 (file)
 #include <fnmatch.h>
 
 #include "openxc.pb.h"
+#include "configuration.hpp"
 #include "can/can-signals.hpp"
 #include "obd2/obd2-signals.hpp"
 
+#include "low-can-binding.hpp"
+
 extern std::mutex subscribed_signals_mutex;
 std::mutex& get_subscribed_signals_mutex();
 
@@ -61,7 +64,7 @@ void lookup_signals_by_id(const double key, std::vector<T>& signals, std::vector
 {
        for(T& s : signals)
        {
-               if(get_signal_id(s) == key)
+               if(config->get_signal_id(s) == key)
                {
                        found_signals.push_back(&s);
                }
@@ -73,7 +76,7 @@ void lookup_signals_by_id(const double key, std::vector<T>& signals, std::vector
 {
        for(const T& s : signals)
        {
-               if(get_signal_id(s) == key)
+               if(config->get_signal_id(s) == key)
                {
                        found_signals_name.push_back(s.generic_name);
                }