summaryrefslogtreecommitdiff
path: root/src/components/connection_handler/include/connection_handler/heartbeat_monitor.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/connection_handler/include/connection_handler/heartbeat_monitor.h')
-rw-r--r--src/components/connection_handler/include/connection_handler/heartbeat_monitor.h33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/components/connection_handler/include/connection_handler/heartbeat_monitor.h b/src/components/connection_handler/include/connection_handler/heartbeat_monitor.h
index 9b641ce01..0233e269d 100644
--- a/src/components/connection_handler/include/connection_handler/heartbeat_monitor.h
+++ b/src/components/connection_handler/include/connection_handler/heartbeat_monitor.h
@@ -72,39 +72,50 @@ class HeartBeatMonitor: public threads::ThreadDelegate {
/**
* \brief Thread exit procedure.
*/
- virtual bool exitThreadMain();
+ virtual void exitThreadMain();
- void set_heartbeat_timeout_seconds(int32_t timeout);
+ void set_heartbeat_timeout_seconds(int32_t timeout, uint8_t session_id);
private:
- struct SessionState;
- typedef std::map<uint8_t, SessionState> SessionMap;
// \brief Heartbeat timeout, should be read from profile
- int32_t heartbeat_timeout_seconds_;
+ int32_t default_heartbeat_timeout_;
// \brief Connection that must be closed when timeout elapsed
Connection *connection_;
- static const int32_t kDefaultCycleTimeout = 100000;
+ //Default HeartBeat cycle timeout (in miliseconds)
+ static const int32_t kDefaultCycleTimeout = 100;
+
+ class SessionState {
+ public:
+ explicit SessionState(int32_t heartbeat_timeout_seconds = 0);
+ void UpdateTimeout(int32_t heartbeat_timeout_seconds);
+ void PrepareToClose();
+ bool IsReadyToClose() const;
+ void KeepAlive();
+ bool HasTimeoutElapsed();
+ private:
+ void RefreshExpiration();
+
+ int32_t heartbeat_timeout_seconds_;
+ TimevalStruct heartbeat_expiration;
+ bool is_heartbeat_sent;
- struct SessionState {
- TimevalStruct heartbeat_expiration;
- bool is_heartbeat_sent;
};
// \brief monitored sessions collection
+ typedef std::map<uint8_t, SessionState> SessionMap;
SessionMap sessions_;
sync_primitives::Lock sessions_list_lock_; // recurcive
sync_primitives::Lock main_thread_lock_;
mutable sync_primitives::Lock heartbeat_timeout_seconds_lock_;
+ sync_primitives::ConditionalVariable heartbeat_monitor_;
volatile bool run_;
void Process();
- void RefreshExpiration(TimevalStruct* expiration) const;
- inline bool HasTimeoutElapsed(const TimevalStruct& expiration) const;
DISALLOW_COPY_AND_ASSIGN(HeartBeatMonitor);
};