aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-21 07:42:46 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-21 11:00:03 +0000
commitef610b379f59f89350f6f9dd8ff11a00066e2c05 (patch)
treecadab1177137db9b0f0f1c5f35f9281a83266ec0
parentcba9b59fab054d3a33a4d58ed227fc3d4b6f6d9d (diff)
Handle error in returning a vector by returning
an empty vector. Fix: typo Change-Id: Ibe859d3e67f6eea96b50e04cd230657be56a18c6 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--src/can-utils.cpp23
-rw-r--r--src/can-utils.hpp14
2 files changed, 19 insertions, 18 deletions
diff --git a/src/can-utils.cpp b/src/can-utils.cpp
index 71788856..d2ddb1d9 100644
--- a/src/can-utils.cpp
+++ b/src/can-utils.cpp
@@ -153,8 +153,8 @@ can_message_t can_bus_dev_t::next_can_message()
if(! can_message_q_.empty())
{
can_message_t can_msg = can_message_q_.front();
- can_message_q_.pop()
- return &can_msg;
+ can_message_q_.pop();
+ return can_msg;
}
has_can_message_ = false;
@@ -210,17 +210,18 @@ void can_bus_t::start_threads()
* params[std::ifstream& conf_file] conf_file ifstream to the JSON configuration
* file located at the rootdir of the binding
*/
-int init_can_dev()
+int can_bus_t::init_can_dev()
{
std::vector<std::string> devices_name;
- int i, t, ret;
+ int i, ret;
+ size_t t;
- devices_name = read_conf(conf_file_);
+ devices_name = read_conf();
- if (devices_name)
+ if (! devices_name.empty())
{
t = devices_name.size();
- i=0
+ i=0;
for(const auto& device : devices_name)
{
@@ -242,7 +243,7 @@ int init_can_dev()
*
* @return[std:vector<std::string>] return a vector of device name
*/
-std::vector<std::string> read_conf()
+std::vector<std::string> can_bus_t::read_conf()
{
std::vector<std::string> ret;
json_object jo, canbus;
@@ -262,7 +263,7 @@ std::vector<std::string> read_conf()
if (jo == NULL || !json_object_object_get_ex(&jo, "canbus", &&canbus))
{
ERROR(interface_, "Can't find canbus node in the configuration file. Please review it.");
- ret = nullptr;
+ ret.clear();
}
else if (json_object_get_type(canbus) != json_type_array)
ret.push_back(json_object_get_string(a));
@@ -273,10 +274,10 @@ std::vector<std::string> read_conf()
for (i = 0 ; i < n ; i++)
ret.push_back(json_object_get_string(json_object_array_get_idx(a, i)));
}
- return ret;
+ return ret;
}
ERROR(interface_, "Problem at reading the conf file");
- return nullptr;
+ return ret.clear();
}
/**
diff --git a/src/can-utils.hpp b/src/can-utils.hpp
index ee87790e..d1310a6d 100644
--- a/src/can-utils.hpp
+++ b/src/can-utils.hpp
@@ -50,13 +50,6 @@ extern "C"
#define CAN_ACTIVE_TIMEOUT_S 30
/**
- * @brief Function representing thread activated by can bus objects
- */
-void can_reader(can_bus_dev_t& can_bus);
-void can_decode_message(can_bus_t& can_bus);
-void can_event_push(can_bus_t& can_bus);
-
-/**
* @brief The type signature for a CAN signal decoder.
*
* @desc A SignalDecoder transforms a raw floating point CAN signal into a number,
@@ -399,3 +392,10 @@ bool isBusActive(can_bus_dev_t* bus);
* busCount - the length of the buses array.
*/
void logBusStatistics(can_bus_dev_t* buses, const int busCount);
+
+/**
+ * @brief Function representing thread activated by can bus objects
+ */
+void can_reader(can_bus_dev_t& can_bus);
+void can_decode_message(can_bus_t& can_bus);
+void can_event_push(can_bus_t& can_bus); \ No newline at end of file