FairMQ  1.3.9
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  static void RemoveMutex(const std::string&);
43 
44  private:
45  void PrintHeader();
46  void PrintHelp();
47  void PrintQueues();
48  void MonitorHeartbeats();
49  void CheckSegment();
50  void Interactive();
51  void SignalMonitor();
52 
53  bool fSelfDestruct; // will self-destruct after the memory has been closed
54  bool fInteractive; // running in interactive mode
55  bool fSeenOnce; // true is segment has been opened successfully at least once
56  bool fIsDaemon;
57  bool fCleanOnExit;
58  unsigned int fTimeoutInMS;
59  std::string fShmId;
60  std::string fSegmentName;
61  std::string fManagementSegmentName;
62  std::string fControlQueueName;
63  std::atomic<bool> fTerminating;
64  std::atomic<bool> fHeartbeatTriggered;
65  std::chrono::high_resolution_clock::time_point fLastHeartbeat;
66  std::thread fSignalThread;
67  boost::interprocess::managed_shared_memory fManagementSegment;
68  std::unordered_map<std::string, std::chrono::high_resolution_clock::time_point> fDeviceHeartbeats;
69 };
70 
71 } // namespace shmem
72 } // namespace mq
73 } // namespace fair
74 
75 #endif /* FAIR_MQ_SHMEM_MONITOR_H_ */
Definition: Monitor.h:26
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy