FairMQ  1.2.1
C++ Message Passing Framework
Monitor.h
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #ifndef FAIR_MQ_SHMEM_MONITOR_H_
9 #define FAIR_MQ_SHMEM_MONITOR_H_
10 
11 #include <boost/interprocess/managed_shared_memory.hpp>
12 
13 #include <thread>
14 #include <chrono>
15 #include <atomic>
16 #include <string>
17 #include <unordered_map>
18 
19 namespace fair
20 {
21 namespace mq
22 {
23 namespace shmem
24 {
25 
26 class Monitor
27 {
28  public:
29  Monitor(const std::string& sessionName, bool selfDestruct, bool interactive, unsigned int timeoutInMS, bool runAsDaemon, bool cleanOnExit);
30 
31  Monitor(const Monitor&) = delete;
32  Monitor operator=(const Monitor&) = delete;
33 
34  void CatchSignals();
35  void Run();
36 
37  virtual ~Monitor();
38 
39  static void Cleanup(const std::string& sessionName);
40  static void RemoveObject(const std::string&);
41  static void RemoveQueue(const std::string&);
42 
43  private:
44  void PrintHeader();
45  void PrintHelp();
46  void PrintQueues();
47  void MonitorHeartbeats();
48  void CheckSegment();
49  void Interactive();
50  void SignalMonitor();
51 
52  bool fSelfDestruct; // will self-destruct after the memory has been closed
53  bool fInteractive; // running in interactive mode
54  bool fSeenOnce; // true is segment has been opened successfully at least once
55  bool fIsDaemon;
56  bool fCleanOnExit;
57  unsigned int fTimeoutInMS;
58  std::string fSessionName;
59  std::string fSegmentName;
60  std::string fManagementSegmentName;
61  std::string fControlQueueName;
62  std::atomic<bool> fTerminating;
63  std::atomic<bool> fHeartbeatTriggered;
64  std::chrono::high_resolution_clock::time_point fLastHeartbeat;
65  std::thread fSignalThread;
66  boost::interprocess::managed_shared_memory fManagementSegment;
67  std::unordered_map<std::string, std::chrono::high_resolution_clock::time_point> fDeviceHeartbeats;
68 };
69 
70 } // namespace shmem
71 } // namespace mq
72 } // namespace fair
73 
74 #endif /* FAIR_MQ_SHMEM_MONITOR_H_ */
Definition: Monitor.h:26
Definition: DeviceRunner.h:23