Change content target and use a testing
[apps/low-level-can-service.git] / src / can-utils.hpp
index 4d41f21..76dc75b 100644 (file)
 
 #pragma once
 
-#include <map>
 #include <queue>
-#include <vector>
-#include <cstdio>
-#include <string>
 #include <thread>
-#include <fcntl.h>
-#include <unistd.h>
-#include <net/if.h>
-#include <sys/ioctl.h>
 #include <linux/can.h>
-#include <sys/socket.h>
-#include <json-c/json.h>
-#include <linux/can/raw.h>
 
 #include "timer.hpp"
 #include "openxc.pb.h"
-
-extern "C"
-{
-       #include <afb/afb-binding.h>
-}
+#include "low-can-binding.hpp"
 
 // TODO actual max is 32 but dropped to 24 for memory considerations
 #define MAX_ACCEPTANCE_FILTERS 24
@@ -98,11 +83,6 @@ typedef enum CanMessageFormat CanMessageFormat;
  *
  * @brief A compact representation of a single CAN message, meant to be used in in/out
  * buffers.
- *
- * param[in] 
- * param[in] 
- * param[in] 
- * @param[in]
  */
 
 /*************************
@@ -118,8 +98,6 @@ typedef struct CanMessage CanMessage;
 */
 class can_message_t {
        private:
-               const struct afb_binding_interface* interface_; /*!< afb_binding_interface interface between daemon and binding */ 
-
                uint32_t id_; /*!< uint32_t id - The ID of the message. */
                uint8_t length_; /*!<  uint8_t length - the length of the data array (max 8). */
                CanMessageFormat format_; /*!< CanMessageFormat format - the format of the message's ID.*/
@@ -130,10 +108,8 @@ class can_message_t {
                 * @brief Class constructor
                 *
                 * Constructor about can_message_t class.
-                *
-                * @param interface - const structafb_binding_interface pointer
                 */
-               can_message_t(const struct afb_binding_interface* interface);
+               can_message_t();
 
                /**
                 * @brief Retrieve id_ member value.
@@ -245,7 +221,9 @@ class can_bus_t {
                int conf_file_; /*!< conf_file_ - configuration file handle used to initialize can_bus_dev_t objects.*/
                
                std::thread th_decoding_; /*!< thread that'll handle decoding a can frame */
+               bool is_decoding_; /*!< boolean member controling thread while loop*/
                std::thread th_pushing_; /*!<  thread that'll handle pushing decoded can frame to subscribers */
+               bool is_pushing_; /*!< boolean member controling thread while loop*/
 
                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 */
@@ -254,15 +232,13 @@ class can_bus_t {
                std::queue <openxc_VehicleMessage> vehicle_message_q_; /*!< queue that'll store openxc_VehicleMessage to pushed */
 
        public:
-               const struct afb_binding_interface *interface_; /*!< interface_ - afb_binding_interface pointer to the binder. Used to log messages */
-
                /**
                 * @brief Class constructor
                 *
                 * @param struct afb_binding_interface *interface between daemon and binding
                 * @param int file handle to the json configuration file.
                 */
-               can_bus_t(const struct afb_binding_interface *interface, int& conf_file);
+               can_bus_t(int& conf_file);
                
                /**
                 * @brief Will initialize can_bus_dev_t objects after reading 
@@ -284,6 +260,32 @@ class can_bus_t {
                 */
                void start_threads();
 
+               /**
+                * @brief Will stop all threads holded by can_bus_t object
+                *  which are decoding and pushing threads.
+                */
+               void stop_threads();
+
+               /**
+                * @brief Telling if the decoding thread is running.
+                *  This is the boolean value on which the while loop
+                *  take its condition. Set it to false will stop the 
+                *  according thread.
+                *
+                * @return true if decoding thread is running, false if not.
+                */
+               bool is_decoding();
+
+               /**
+                * @brief Telling if the pushing thread is running
+                *  This is the boolean value on which the while loop
+                *  take its condition. Set it to false will stop the 
+                *  according thread.
+                *
+                * @return true if pushing thread is running, false if not.
+                */
+               bool is_pushing();
+
                /**
                 * @brief Return first can_message_t on the queue 
                 *
@@ -356,15 +358,30 @@ class can_bus_dev_t {
                 *
                 * @return 
                 */
-               int open(const struct afb_binding_interface* interface);
+               int open();
+               
+               /**
+                * @brief Open the can socket and returning it 
+                *
+                * @return 
+                */
                int close();
+               
+               /**
+                * @brief Telling if the reading thread is running
+                *  This is the boolean value on which the while loop
+                *  take its condition. Set it to false will stop the 
+                *  according thread.
+                *
+                * @return true if reading thread is running, false if not.
+                */
                bool is_running();
                
                /**
                * @brief start reading threads and set flag is_running_
                *
                * @param can_bus_t reference can_bus_t. it will be passed to the thread 
-               *  to allow using afb_binding_interface and can_bus_t queue.
+               *  to allow using can_bus_t queue.
                */
                void start_reading(can_bus_t& can_bus);
 
@@ -374,7 +391,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(const struct afb_binding_interface *interface);
+               canfd_frame read();
                
                /**
                * @brief Send a can message from a can_message_t object.
@@ -383,7 +400,7 @@ class can_bus_dev_t {
                * @param const struct afb_binding_interface* interface pointer. Used to be able to log 
                *  using application framework logger.
                */
-               int send_can_message(can_message_t& can_msg, const struct afb_binding_interface* interface);
+               int send_can_message(can_message_t& can_msg);
 };
 
 /**
@@ -526,8 +543,7 @@ void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, con
 
 /**
  * @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 and before the
- * event loop connection.
+ * @brief Post-initialize actions made after CAN bus initialization
  *
  * @param[in] bus - A CanBus struct defining the bus's metadata
  * @param[in] writable - configure the controller in a writable mode. If false, it will be