Communication Library for Autonomous Systems v1.0
Reliable and secure communication library for autonomous vehicle systems
Loading...
Searching...
No Matches
traits.h
Go to the documentation of this file.
1#ifndef TRAITS_H
2#define TRAITS_H
3
4#include <string>
5#include <fstream>
6
7// Helper function to get the interface name
8inline std::string get_interface_name() {
9 std::string interface_name = "test-dummy0"; // Default
10 std::ifstream iface_file("tests/logs/current_test_iface");
11 if (iface_file) {
12 std::getline(iface_file, interface_name);
13 if (!interface_name.empty()) {
14 return interface_name;
15 }
16 }
17 return interface_name;
18}
19
20// Foward Declarations
21template <typename NIC>
22class Protocol;
23class Agent;
24class AgentStub;
25template <typename Engine>
26class NIC;
27class SocketEngine;
28class Debug;
29template <typename Channel>
30class Communicator;
31template <typename Protocol>
32class Message;
33class CAN;
34class Gateway;
35class Clock;
37class RSU;
38template <typename Protocol_T>
40template <typename V, size_t N>
42
43// Traits definition
44template <typename T>
45struct Traits {
46 static const bool debugged = false;
47};
48
49// Traits for SocketEngine class
50template<>
51struct Traits<SocketEngine> : public Traits<void>
52{
53 static const bool debugged = false;
54 static constexpr const char* DEFAULT_INTERFACE_NAME = "test-dummy0";
55
56 static const char* INTERFACE_NAME() {
57 static std::string interface_name = get_interface_name();
58 return interface_name.c_str();
59 }
60};
61
62// Traits for dual-engine NIC
63template <typename Engine>
64struct Traits<NIC<Engine>> : public Traits<void>
65{
66 static const bool debugged = false;
67 static const unsigned int SEND_BUFFERS = 512;
68 static const unsigned int RECEIVE_BUFFERS = 512;
69};
70
71// Traits for Protocol with dual-engine NIC
72template <>
73struct Traits<Protocol<NIC<SocketEngine>>> : public Traits<void>
74{
75 static const bool debugged = false;
76 static const unsigned int ETHERNET_PROTOCOL_NUMBER = 888; // Example value
77};
78
79// Traits for Communicator class
80template<typename Channel>
81struct Traits<Communicator<Channel>> : public Traits<void>
82{
83 static const bool debugged = false;
84};
85
86// Traits for message class
87template <typename Protocol>
88struct Traits<Message<Protocol>> : public Traits<void>
89{
90 static const bool debugged = false;
91 static constexpr unsigned int MAC_SIZE = 16;
92};
93
94template <>
95struct Traits<CAN> : public Traits<void>
96{
97 static const bool debugged = false;
98};
99
100template <>
101struct Traits<AgentStub> : public Traits<void>
102{
103 static const bool debugged = false;
104};
105
106template <>
107struct Traits<Agent> : public Traits<void>
108{
109 static const bool debugged = false;
110};
111
112// Traits for Gateway class
113template<>
114struct Traits<Gateway> : public Traits<void>
115{
116 static const bool debugged = false;
117};
118
119// Traits for Clock class
120template<>
121struct Traits<Clock> : public Traits<void>
122{
123 static const bool debugged = false;
124};
125
126// Traits for LeaderKeyStorage class
127template<>
128struct Traits<LeaderKeyStorage> : public Traits<void>
129{
130 static const bool debugged = false;
131};
132
133// Traits for RSU class
134template<>
135struct Traits<RSU> : public Traits<void>
136{
137 static const bool debugged = true;
138};
139
140// Traits for VehicleRSUManager class
141template<typename Protocol_T>
142struct Traits<VehicleRSUManager<Protocol_T>> : public Traits<void>
143{
144 static const bool debugged = false;
145};
146
147template <typename V, unsigned int S>
148struct Traits<StaticSizeHashedCache<V, S>> : public Traits<void>
149{
150 static const bool debugged = false;
151};
152
153// Traits for Debug class
154template<>
155struct Traits<Debug> : public Traits<void>
156{
157 static const bool error = false;
158 static const bool warning = false;
159 static const bool info = true;
160 static const bool trace = false;
161};
162
163#endif // TRAITS_H
EPOS-inspired Agent implementation using composition over inheritance.
Definition agent.h:35
Definition bus.h:52
Thread-safe singleton for PTP clock synchronization.
Definition clock.h:56
Definition communicator.h:16
Definition debug.h:17
Definition gateway.h:18
Thread-safe singleton for leader key storage.
Definition leaderKeyStorage.h:25
Template class for network messages with Clock integration.
Definition message.h:31
Definition nic.h:28
Definition protocol.h:29
Definition rsu.h:17
Definition socketEngine.h:27
A hash cache with a static size, using linear probing for collision resolution.
Definition static_size_hashed_cache.h:15
Definition vehicleRSUManager.h:33
Select_Debug<(Traits< T >::debugged &&Traits< Debug >::error)> db(Debug_Error l)
Definition debug.h:166
static const char * INTERFACE_NAME()
Definition traits.h:56
Definition traits.h:45
static const bool debugged
Definition traits.h:46
std::string get_interface_name()
Definition traits.h:8