FairMQ  1.2.0
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 
14 #include <condition_variable>
15 #include <mutex>
16 #include <string>
17 #include <queue>
18 #include <thread>
19 #include <atomic>
20 
21 namespace fair
22 {
23 namespace mq
24 {
25 namespace plugins
26 {
27 
28 class Control : public Plugin
29 {
30  public:
31  Control(const std::string name, const Plugin::Version version, const std::string maintainer, const std::string homepage, PluginServices* pluginServices);
32 
33  ~Control();
34 
35  private:
36  auto InteractiveMode() -> void;
37  auto PrintInteractiveHelp() -> void;
38  auto StaticMode() -> void;
39  auto WaitForNextState() -> DeviceState;
40  auto SignalHandler(int signal) -> void;
41  auto RunShutdownSequence() -> void;
42  auto RunStartupSequence() -> void;
43  auto EmptyEventQueue() -> void;
44 
45  std::thread fControllerThread;
46  std::thread fSignalHandlerThread;
47  std::queue<DeviceState> fEvents;
48  std::mutex fEventsMutex;
49  std::condition_variable fNewEvent;
50  std::atomic<bool> fDeviceTerminationRequested;
51 }; /* class Control */
52 
53 auto ControlPluginProgramOptions() -> Plugin::ProgOptions;
54 
55 REGISTER_FAIRMQ_PLUGIN(
56  Control, // Class name
57  control, // Plugin name (string, lower case chars only)
58  (Plugin::Version{1,0,1}), // Version
59  "FairRootGroup <fairroot@gsi.de>", // Maintainer
60  "https://github.com/FairRootGroup/FairRoot", // Homepage
61  ControlPluginProgramOptions // Free function which declares custom program options for the plugin
62  // signature: () -> boost::optional<boost::program_options::options_description>
63 )
64 
65 } /* namespace plugins */
66 } /* namespace mq */
67 } /* namespace fair */
68 
69 #endif /* FAIR_MQ_PLUGINS_CONTROL */
Facilitates communication between devices and plugins.
Definition: PluginServices.h:37
Definition: Control.h:28
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:54
Definition: DeviceRunner.h:23
Definition: Version.h:22