FairMQ  1.4.14
C++ Message Queuing Library and Framework
DeviceRunner.h
1 /********************************************************************************
2  * Copyright (C) 2017-2018 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_DEVICERUNNER_H
10 #define FAIR_MQ_DEVICERUNNER_H
11 
12 #include <fairmq/EventManager.h>
13 #include <fairmq/PluginManager.h>
14 #include <fairmq/ProgOptions.h>
15 #include <FairMQDevice.h>
16 #include <FairMQLogger.h>
17 
18 #include <functional>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 namespace fair {
24 namespace mq {
25 
52 {
53  public:
54  DeviceRunner(int argc, char*const* argv, bool printLogo = true);
55 
56  auto Run() -> int;
57  auto RunWithExceptionHandlers() -> int;
58 
59  static bool HandleGeneralOptions(const fair::mq::ProgOptions& config, bool printLogo = true);
60 
61  void SubscribeForConfigChange();
62  void UnsubscribeFromConfigChange();
63 
64  template<typename H>
65  auto AddHook(std::function<void(DeviceRunner&)> hook) -> void
66  {
67  fEvents.Subscribe<H>("runner", hook);
68  }
69  template<typename H>
70  auto RemoveHook() -> void
71  {
72  fEvents.Unsubscribe<H>("runner");
73  }
74 
75  std::vector<std::string> fRawCmdLineArgs;
76  fair::mq::ProgOptions fConfig;
77  std::unique_ptr<FairMQDevice> fDevice;
78  PluginManager fPluginManager;
79  const bool fPrintLogo;
80 
81  private:
82  EventManager fEvents;
83 };
84 
85 namespace hooks {
86 struct LoadPlugins : Event<DeviceRunner&> {};
87 struct SetCustomCmdLineOptions : Event<DeviceRunner&> {};
88 struct ModifyRawCmdLineArgs : Event<DeviceRunner&> {};
89 struct InstantiateDevice : Event<DeviceRunner&> {};
90 } /* namespace hooks */
91 
92 } /* namespace mq */
93 } /* namespace fair */
94 
95 #endif /* FAIR_MQ_DEVICERUNNER_H */
Utility class to facilitate a convenient top-level device launch/shutdown.
Definition: DeviceRunner.h:51
Definition: EventManager.h:31
Definition: DeviceRunner.h:86
Manages event callbacks from different subscribers.
Definition: EventManager.h:51
manages and owns plugin instances
Definition: PluginManager.h:49
Definition: ProgOptions.h:36
Definition: DeviceRunner.h:88
Definition: DeviceRunner.h:89
Definition: DeviceRunner.h:87
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy