X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Flow-can-binding.cpp;h=46dcbf26ac14e252d9783224b343e2ec50308bba;hb=ccd244c10988cd59d6f0b35e1b83a5eebd7bfb01;hp=13452a4c8fc253cffc3791d37aad4d384b28a804;hpb=609bb7b10984e6a04f4a1ec977ab695835ffcdae;p=apps%2Flow-level-can-service.git diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp index 13452a4..46dcbf2 100644 --- a/src/low-can-binding.cpp +++ b/src/low-can-binding.cpp @@ -22,12 +22,12 @@ #include #include #include -#include #include #include #include #include "openxc.pb.h" +#include "configuration.hpp" #include "can/can-bus.hpp" #include "can/can-signals.hpp" #include "can/can-message.hpp" @@ -40,12 +40,9 @@ extern "C" #include }; -/* - * 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; +configuration_t *config; /******************************************************************************** * @@ -82,7 +79,7 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe, std::lock_guard subscribed_signals_lock(get_subscribed_signals_mutex()); std::map& 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 +87,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,18 +221,17 @@ 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); + config = new configuration_t(); - /* Initialize the CAN bus handler */ - can_bus_handler = new can_bus_t(fd_conf); + can_bus_t& 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"); return 1; }