Fix: clear pointer vector before fill it.
[apps/agl-service-can-low-level.git] / src / can-bus.hpp
index 302514d..f7cb312 100644 (file)
@@ -36,6 +36,8 @@
 
 #define CAN_ACTIVE_TIMEOUT_S 30
 
+class can_bus_dev_t;
+
 /** 
  * @class can_bus_t
  * @brief Object used to handle decoding and manage event queue to be pushed.
@@ -73,14 +75,14 @@ class can_bus_t {
 
                std::condition_variable new_can_message_; /*!< condition_variable use to wait until there is a new CAN message to read*/
                std::mutex can_message_mutex_; /*!< mutex protecting the can_message_q_ queue.*/
-               bool has_can_message_; /*!< boolean members that control whether or not there is can_message into the queue */
                std::queue <can_message_t> can_message_q_; /*!< queue that'll store can_message_t to decoded */
 
                std::condition_variable new_decoded_can_message_; /*!< condition_variable use to wait until there is a new vehicle message to read from the queue vehicle_message_q_*/
                std::mutex decoded_can_message_mutex_;  /*!< mutex protecting the vehicle_message_q_ queue.*/
-               bool has_vehicle_message_; /*!< boolean members that control whether or not there is openxc_VehicleMessage into the queue */
                std::queue <openxc_VehicleMessage> vehicle_message_q_; /*!< queue that'll store openxc_VehicleMessage to pushed */
 
+               std::map<std::string, std::shared_ptr<can_bus_dev_t>> can_devices_m_; /*!< Can device map containing all can_bus_dev_t objects initialized during init_can_dev function*/
+
        public:
                /**
                 * @brief Class constructor
@@ -88,7 +90,7 @@ class can_bus_t {
                 * @param struct afb_binding_interface *interface between daemon and binding
                 * @param int file handle to the json configuration file.
                 */
-               can_bus_t(int& conf_file);
+               can_bus_t(int conf_file);
                
                /**
                 * @brief Will initialize can_bus_dev_t objects after reading 
@@ -152,14 +154,19 @@ class can_bus_t {
                void push_new_can_message(const can_message_t& can_msg);                
                
                /**
-                * @brief Return a boolean telling if there is any can_message into the queue
+                * @brief return can_message_mutex_ member
                 *
-                * @return true if there is at least a can_message_t, false if not.
+                * @return  return can_message_mutex_ member
                 */
                std::mutex& get_can_message_mutex();
+               
+               /**
+                * @brief return new_can_message_ member
+                *
+                * @return  return new_can_message_ member
+                */
                std::condition_variable& get_new_can_message();
 
-
                /**
                 * @brief Return first openxc_VehicleMessage on the queue 
                 *
@@ -173,8 +180,16 @@ class can_bus_t {
                 * @param the const reference openxc_VehicleMessage object to push into the queue
                 */
                void push_new_vehicle_message(const openxc_VehicleMessage& v_msg);
+
+               /**
+                * @brief Return a map with the can_bus_dev_t initialized
+                *
+                * @return map can_bus_dev_m_ map
+                */
+               std::map<std::string, std::shared_ptr<can_bus_dev_t>> get_can_devices();
 };
 
+
 /**
  * @class can_bus_dev_t 
  *
@@ -252,7 +267,7 @@ class can_bus_dev_t {
                * @param const struct afb_binding_interface* interface pointer. Used to be able to log 
                *  using application framework logger.
                */
-               canfd_frame read();
+               std::pair<struct canfd_frame&, size_t> read();
                
                /**
                * @brief Send a can message from a can_message_t object.
@@ -264,13 +279,7 @@ class can_bus_dev_t {
                int send_can_message(can_message_t& can_msg);
 };
 
-/**
- * @brief Return an array of the metadata for the 2 CAN buses you want to
- * monitor. The size of this array is fixed at 2.
- */
-can_bus_dev_t getCanBuses();
-
-/**
+/** TODO: implement this function as method into can_bus class
  * @fn void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
  * @brief Pre initialize actions made before CAN bus initialization
  *
@@ -282,7 +291,7 @@ can_bus_dev_t getCanBuses();
  */
 void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
 
-/**
+/** TODO: implement this function as method into can_bus class
  * @fn void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
  * @brief Post-initialize actions made after CAN bus initialization
  *
@@ -294,7 +303,7 @@ void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, con
  */
 void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
 
-/**
+/** TODO: implement this function as method into can_bus class
  * @fn bool isBusActive(can_bus_dev_t* bus);
  * @brief Check if the device is connected to an active CAN bus, i.e. it's
  * received a message in the recent past.
@@ -304,31 +313,12 @@ void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, co
  */
 bool isBusActive(can_bus_dev_t* bus);
 
-/**
+/** TODO: implement this function as method into can_bus class
+ *
  * @fn void logBusStatistics(can_bus_dev_t* buses, const int busCount);
  * @brief Log transfer statistics about all active CAN buses to the debug log.
  *
  * @param[in] buses - an array of active CAN buses.
  * @param[in] busCount - the length of the buses array.
  */
-void logBusStatistics(can_bus_dev_t* buses, const int busCount);
-
-/**
- * @fn void can_decode_message(can_bus_t& can_bus);
- *
- * @brief Thread function used to decode can messages read into the can_message_q_
- *
- * @param[in] can_bus_t object used to pop can_message_q_ queue and fill decoded message
- * into vehicle_message_q_ queue.
- */
-void can_decode_message(can_bus_t& can_bus);
-
-/**
- * @fn void can_decode_message(can_bus_t& can_bus);
- *
- * @brief Thread function used to push afb_event
- *
- * @param[in] can_bus_t object used to pop can_message_q_ queue and fill decoded message
- * into vehicle_message_q_ queue.
- */
-void can_event_push(can_bus_t& can_bus);
\ No newline at end of file
+void logBusStatistics(can_bus_dev_t* buses, const int busCount);
\ No newline at end of file