FairMQ  1.4.14
C++ Message Queuing Library and 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 <stdexcept>
18 #include <unordered_map>
19 
20 namespace fair
21 {
22 namespace mq
23 {
24 namespace shmem
25 {
26 
27 class Monitor
28 {
29  public:
30  Monitor(const std::string& shmId, bool selfDestruct, bool interactive, bool viewOnly, unsigned int timeoutInMS, bool runAsDaemon, bool cleanOnExit);
31 
32  Monitor(const Monitor&) = delete;
33  Monitor operator=(const Monitor&) = delete;
34 
35  virtual ~Monitor();
36 
37  void CatchSignals();
38  void Run();
39 
40  static void Cleanup(const std::string& shmId);
41  static void RemoveObject(const std::string&);
42  static void RemoveFileMapping(const std::string&);
43  static void RemoveQueue(const std::string&);
44  static void RemoveMutex(const std::string&);
45  static void RemoveCondition(const std::string&);
46 
47  struct DaemonPresent : std::runtime_error { using std::runtime_error::runtime_error; };
48 
49  private:
50  void PrintHeader();
51  void PrintHelp();
52  void PrintQueues();
53  void MonitorHeartbeats();
54  void CheckSegment();
55  void Interactive();
56  void SignalMonitor();
57 
58  bool fSelfDestruct; // will self-destruct after the memory has been closed
59  bool fInteractive; // running in interactive mode
60  bool fViewOnly; // view only mode
61  bool fIsDaemon;
62  bool fSeenOnce; // true is segment has been opened successfully at least once
63  bool fCleanOnExit;
64  unsigned int fTimeoutInMS;
65  std::string fShmId;
66  std::string fSegmentName;
67  std::string fManagementSegmentName;
68  std::string fControlQueueName;
69  std::atomic<bool> fTerminating;
70  std::atomic<bool> fHeartbeatTriggered;
71  std::chrono::high_resolution_clock::time_point fLastHeartbeat;
72  std::thread fSignalThread;
73  boost::interprocess::managed_shared_memory fManagementSegment;
74  std::unordered_map<std::string, std::chrono::high_resolution_clock::time_point> fDeviceHeartbeats;
75 };
76 
77 } // namespace shmem
78 } // namespace mq
79 } // namespace fair
80 
81 #endif /* FAIR_MQ_SHMEM_MONITOR_H_ */
Definition: Monitor.h:27
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy