FairMQ  1.3.9
C++ Message Passing Framework
Control.h
1 /********************************************************************************
2  * Copyright (C) 2017 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 
9 #ifndef FAIR_MQ_PLUGINS_CONTROL
10 #define FAIR_MQ_PLUGINS_CONTROL
11 
12 #include <fairmq/Plugin.h>
13 #include <fairmq/Version.h>
14 
15 #include <condition_variable>
16 #include <mutex>
17 #include <string>
18 #include <queue>
19 #include <thread>
20 #include <atomic>
21 #include <stdexcept>
22 
23 namespace fair
24 {
25 namespace mq
26 {
27 namespace plugins
28 {
29 
30 class Control : public Plugin
31 {
32  public:
33  Control(const std::string& name, const Plugin::Version version, const std::string& maintainer, const std::string& homepage, PluginServices* pluginServices);
34 
35  ~Control();
36 
37  private:
38  auto InteractiveMode() -> void;
39  static auto PrintInteractiveHelp() -> void;
40  auto StaticMode() -> void;
41  auto WaitForNextState() -> DeviceState;
42  auto SignalHandler() -> void;
43  auto RunShutdownSequence() -> void;
44  auto RunStartupSequence() -> void;
45  auto EmptyEventQueue() -> void;
46 
47  std::thread fControllerThread;
48  std::thread fSignalHandlerThread;
49  std::queue<DeviceState> fEvents;
50  std::mutex fEventsMutex;
51  std::mutex fControllerMutex;
52  std::condition_variable fNewEvent;
53  std::atomic<bool> fDeviceShutdownRequested;
54  std::atomic<bool> fDeviceHasShutdown;
55  std::atomic<bool> fPluginShutdownRequested;
56 
57  struct DeviceErrorState : std::runtime_error { using std::runtime_error::runtime_error; };
58 }; /* class Control */
59 
60 auto ControlPluginProgramOptions() -> Plugin::ProgOptions;
61 
62 REGISTER_FAIRMQ_PLUGIN(
63  Control, // Class name
64  control, // Plugin name (string, lower case chars only)
65  (Plugin::Version{FAIRMQ_VERSION_MAJOR,
66  FAIRMQ_VERSION_MINOR,
67  FAIRMQ_VERSION_PATCH}), // Version
68  "FairRootGroup <fairroot@gsi.de>", // Maintainer
69  "https://github.com/FairRootGroup/FairRoot", // Homepage
70  ControlPluginProgramOptions // Free function which declares custom program options for the
71  // plugin signature: () ->
72  // boost::optional<boost::program_options::options_description>
73 )
74 
75 } /* namespace plugins */
76 } /* namespace mq */
77 } /* namespace fair */
78 
79 #endif /* FAIR_MQ_PLUGINS_CONTROL */
Facilitates communication between devices and plugins.
Definition: PluginServices.h:38
Definition: Control.h:30
Base class for FairMQ plugins.
Definition: Plugin.h:38
DeviceState
See https://github.com/FairRootGroup/FairRoot/blob/dev/fairmq/docs/Device.md#13-state-machine.
Definition: PluginServices.h:60
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23
Definition: Version.h:22

privacy