@@ -61,41 +61,41 @@ class GateIO
61
61
class ClientAliveTracker {
62
62
public:
63
63
ClientAliveTracker (const std::chrono::milliseconds& echoIntervalMs, const std::chrono::milliseconds& clientTimeoutMs)
64
- : m_echoIntervalMs (echoIntervalMs), m_clientTimeoutMs (clientTimeoutMs) {
64
+ : m_echo_interval_ms (echoIntervalMs), m_client_timeout_ms (clientTimeoutMs) {
65
65
reset ();
66
66
}
67
67
ClientAliveTracker ()=default ;
68
68
69
- void onClientActivity () {
70
- m_lastClientActivityTime = std::chrono::high_resolution_clock::now ();
69
+ void on_client_activity () {
70
+ m_last_client_activity_time = std::chrono::high_resolution_clock::now ();
71
71
}
72
72
73
- void onEchoSent () {
74
- m_lastEchoSentTime = std::chrono::high_resolution_clock::now ();
73
+ void on_echo_sent () {
74
+ m_last_echo_sent_time = std::chrono::high_resolution_clock::now ();
75
75
}
76
76
77
- bool isTimeToSentEcho () const {
78
- return (durationSinceLastClientActivityMs () > m_echoIntervalMs ) && (durationSinceLastEchoSentMs () > m_echoIntervalMs );
77
+ bool is_time_to_sent_echo () const {
78
+ return (duration_since_last_client_activity_ms () > m_echo_interval_ms ) && (durationSinceLastEchoSentMs () > m_echo_interval_ms );
79
79
}
80
- bool isClientTimeout () const { return durationSinceLastClientActivityMs () > m_clientTimeoutMs ; }
80
+ bool is_client_timeout () const { return duration_since_last_client_activity_ms () > m_client_timeout_ms ; }
81
81
82
82
void reset () {
83
- onClientActivity ();
83
+ on_client_activity ();
84
84
}
85
85
86
86
private:
87
- std::chrono::high_resolution_clock::time_point m_lastClientActivityTime ;
88
- std::chrono::high_resolution_clock::time_point m_lastEchoSentTime ;
89
- std::chrono::milliseconds m_echoIntervalMs ;
90
- std::chrono::milliseconds m_clientTimeoutMs ;
87
+ std::chrono::high_resolution_clock::time_point m_last_client_activity_time ;
88
+ std::chrono::high_resolution_clock::time_point m_last_echo_sent_time ;
89
+ std::chrono::milliseconds m_echo_interval_ms ;
90
+ std::chrono::milliseconds m_client_timeout_ms ;
91
91
92
- std::chrono::milliseconds durationSinceLastClientActivityMs () const {
92
+ std::chrono::milliseconds duration_since_last_client_activity_ms () const {
93
93
auto now = std::chrono::high_resolution_clock::now ();
94
- return std::chrono::duration_cast<std::chrono::milliseconds>(now - m_lastClientActivityTime );
94
+ return std::chrono::duration_cast<std::chrono::milliseconds>(now - m_last_client_activity_time );
95
95
}
96
96
std::chrono::milliseconds durationSinceLastEchoSentMs () const {
97
97
auto now = std::chrono::high_resolution_clock::now ();
98
- return std::chrono::duration_cast<std::chrono::milliseconds>(now - m_lastEchoSentTime );
98
+ return std::chrono::duration_cast<std::chrono::milliseconds>(now - m_last_echo_sent_time );
99
99
}
100
100
};
101
101
@@ -109,34 +109,34 @@ class GateIO
109
109
class TLogger {
110
110
public:
111
111
TLogger () {
112
- m_logLevel = static_cast <int >(LogLevel::Info);
112
+ m_log_level = static_cast <int >(LogLevel::Info);
113
113
}
114
114
~TLogger () {}
115
115
116
116
template <typename ... Args>
117
117
void queue (LogLevel logLevel, Args&&... args) {
118
- if (static_cast <int >(logLevel) <= m_logLevel ) {
119
- std::unique_lock<std::mutex> lock (m_logStreamMutex );
118
+ if (static_cast <int >(logLevel) <= m_log_level ) {
119
+ std::unique_lock<std::mutex> lock (m_log_stream_mutex );
120
120
if (logLevel == LogLevel::Error) {
121
- m_logStream << " ERROR:" ;
121
+ m_log_stream << " ERROR:" ;
122
122
}
123
- ((m_logStream << ' ' << std::forward<Args>(args)), ...);
124
- m_logStream << " \n " ;
123
+ ((m_log_stream << ' ' << std::forward<Args>(args)), ...);
124
+ m_log_stream << " \n " ;
125
125
}
126
126
}
127
127
128
128
void flush () {
129
- std::unique_lock<std::mutex> lock (m_logStreamMutex );
130
- if (!m_logStream .str ().empty ()) {
131
- VTR_LOG (m_logStream .str ().c_str ());
132
- m_logStream .str (" " );
129
+ std::unique_lock<std::mutex> lock (m_log_stream_mutex );
130
+ if (!m_log_stream .str ().empty ()) {
131
+ VTR_LOG (m_log_stream .str ().c_str ());
132
+ m_log_stream .str (" " );
133
133
}
134
134
}
135
135
136
136
private:
137
- std::stringstream m_logStream ;
138
- std::mutex m_logStreamMutex ;
139
- std::atomic<int > m_logLevel ;
137
+ std::stringstream m_log_stream ;
138
+ std::mutex m_log_stream_mutex ;
139
+ std::atomic<int > m_log_level ;
140
140
};
141
141
142
142
const int LOOP_INTERVAL_MS = 100 ;
@@ -152,7 +152,7 @@ class GateIO
152
152
GateIO& operator =(GateIO&&) = delete ;
153
153
154
154
// Check if the port listening process is currently running
155
- bool isRunning () const { return m_isRunning .load (); }
155
+ bool is_running () const { return m_is_running .load (); }
156
156
157
157
/* *
158
158
* @brief Transfers ownership of received tasks to the caller.
@@ -205,27 +205,27 @@ class GateIO
205
205
void stop ();
206
206
207
207
private:
208
- int m_portNum = -1 ;
208
+ int m_port_num = -1 ;
209
209
210
- std::atomic<bool > m_isRunning ; // is true when started
210
+ std::atomic<bool > m_is_running ; // is true when started
211
211
212
212
std::thread m_thread; // thread to execute socket IO work
213
213
214
- std::mutex m_tasksMutex ; // we used single mutex to guard both vectors m_receivedTasks and m_sendTasks
215
- std::vector<TaskPtr> m_receivedTasks ; // tasks from client (requests)
216
- std::vector<TaskPtr> m_sendTasks ; // tasks to client (responses)
214
+ std::mutex m_tasks_mutex ; // we used single mutex to guard both vectors m_received_tasks and m_sendTasks
215
+ std::vector<TaskPtr> m_received_tasks ; // tasks from client (requests)
216
+ std::vector<TaskPtr> m_send_tasks ; // tasks to client (responses)
217
217
218
218
TLogger m_logger;
219
219
220
- void startListening (); // thread worker function
220
+ void start_listening (); // thread worker function
221
221
222
222
// / helper functions to be executed inside startListening
223
- ActivityStatus checkClientConnection (sockpp::tcp6_acceptor& tcpServer , std::optional<sockpp::tcp6_socket>& clientOpt );
224
- ActivityStatus handleSendingData (sockpp::tcp6_socket& client);
225
- ActivityStatus handleReceivingData (sockpp::tcp6_socket& client, comm::TelegramBuffer& telegramBuff , std::string& receivedMessage );
226
- ActivityStatus handleTelegrams (std::vector<comm::TelegramFramePtr>& telegramFrames , comm::TelegramBuffer& telegramBuff );
227
- ActivityStatus handleClientAliveTracker (sockpp::tcp6_socket& client, std::unique_ptr<ClientAliveTracker>& clientAliveTrackerPtr );
228
- void handleActivityStatus (ActivityStatus status, std::unique_ptr<ClientAliveTracker>& clientAliveTrackerPtr , bool & isCommunicationProblemDetected );
223
+ ActivityStatus check_client_connection (sockpp::tcp6_acceptor& tcp_server , std::optional<sockpp::tcp6_socket>& client_opt );
224
+ ActivityStatus handle_sending_data (sockpp::tcp6_socket& client);
225
+ ActivityStatus handle_receiving_data (sockpp::tcp6_socket& client, comm::TelegramBuffer& telegram_buff , std::string& received_message );
226
+ ActivityStatus handle_telegrams (std::vector<comm::TelegramFramePtr>& telegram_frames , comm::TelegramBuffer& telegram_buff );
227
+ ActivityStatus handle_client_alive_tracker (sockpp::tcp6_socket& client, std::unique_ptr<ClientAliveTracker>& client_alive_tracker_ptr );
228
+ void handle_activity_status (ActivityStatus status, std::unique_ptr<ClientAliveTracker>& client_alive_tracker_ptr , bool & is_communication_problem_detected );
229
229
// /
230
230
};
231
231
0 commit comments