Code Review
/
apps
/
agl-service-can-low-level.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Change all old struct name to the new class.
[apps/agl-service-can-low-level.git]
/
src
/
low-can-binding.cpp
diff --git
a/src/low-can-binding.cpp
b/src/low-can-binding.cpp
index
13452a4
..
9357490
100644
(file)
--- a/
src/low-can-binding.cpp
+++ b/
src/low-can-binding.cpp
@@
-22,12
+22,12
@@
#include <mutex>
#include <vector>
#include <thread>
#include <mutex>
#include <vector>
#include <thread>
-#include <fcntl.h>
#include <linux/can.h>
#include <json-c/json.h>
#include <systemd/sd-event.h>
#include "openxc.pb.h"
#include <linux/can.h>
#include <json-c/json.h>
#include <systemd/sd-event.h>
#include "openxc.pb.h"
+#include "configuration.hpp"
#include "can/can-bus.hpp"
#include "can/can-signals.hpp"
#include "can/can-message.hpp"
#include "can/can-bus.hpp"
#include "can/can-signals.hpp"
#include "can/can-message.hpp"
@@
-40,12
+40,9
@@
extern "C"
#include <afb/afb-service-itf.h>
};
#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;
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<std::mutex> subscribed_signals_lock(get_subscribed_signals_mutex());
std::map<std::string, struct afb_event>& s = get_subscribed_signals();
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[s
td::string(sig)
]))
+ if (s.find(sig) != s.end() && !afb_event_is_valid(s[s
ig
]))
{
if(!subscribe)
{
{
if(!subscribe)
{
@@
-90,12
+87,14
@@
static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe,
ret = -1;
}
else
ret = -1;
}
else
+ {
/* Event it isn't valid annymore, recreate it */
ret = create_event_handle(sig, s);
/* Event it isn't valid annymore, recreate it */
ret = create_event_handle(sig, s);
+ }
}
else
{
}
else
{
- /* Event don't exist , so let's create it */
+ /* Event do
es
n'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);
struct afb_event empty_event = {nullptr, nullptr};
subscribed_signals[sig] = empty_event;
ret = create_event_handle(sig, s);
@@
-110,12
+109,12
@@
static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe,
}
/**
}
/**
- * @fn static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe, const std::vector<
CanSignal
>& signals)
+ * @fn static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe, const std::vector<
can_signal_t
>& signals)
* @brief subscribe to all signals in the vector signals
*
* @param[in] afb_req request : contain original request use to subscribe or unsubscribe
* @param[in] subscribe boolean value used to chose between a subscription operation or an unsubscription
* @brief subscribe to all signals in the vector signals
*
* @param[in] afb_req request : contain original request use to subscribe or unsubscribe
* @param[in] subscribe boolean value used to chose between a subscription operation or an unsubscription
- * @param[in]
CanSignal vector with CanSignal
to subscribe
+ * @param[in]
can_signal_t vector with can_signal_t
to subscribe
*
* @return Number of correctly subscribed signal
*/
*
* @return Number of correctly subscribed signal
*/
@@
-222,18
+221,17
@@
extern "C"
*/
int afbBindingV1ServiceInit(struct afb_service service)
{
*/
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 */
/* 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;
}
return 0;
}
+
ERROR(binder_interface, "There was something wrong with CAN device Initialization. Check your config file maybe");
return 1;
}
ERROR(binder_interface, "There was something wrong with CAN device Initialization. Check your config file maybe");
return 1;
}