FairMQ  1.4.33
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 
17 #include <functional>
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 namespace fair::mq
23 {
24 
50 class DeviceRunner
51 {
52  public:
53  DeviceRunner(int argc, char*const* argv, bool printLogo = true);
54 
55  auto Run() -> int;
56  auto RunWithExceptionHandlers() -> int;
57 
58  static bool HandleGeneralOptions(const fair::mq::ProgOptions& config, bool printLogo = true);
59 
60  void SubscribeForConfigChange();
61  void UnsubscribeFromConfigChange();
62 
63  template<typename H>
64  auto AddHook(std::function<void(DeviceRunner&)> hook) -> void
65  {
66  fEvents.Subscribe<H>("runner", hook);
67  }
68  template<typename H>
69  auto RemoveHook() -> void
70  {
71  fEvents.Unsubscribe<H>("runner");
72  }
73 
74  std::vector<std::string> fRawCmdLineArgs;
75  fair::mq::ProgOptions fConfig;
76  std::unique_ptr<FairMQDevice> fDevice;
77  PluginManager fPluginManager;
78  const bool fPrintLogo;
79 
80  private:
81  EventManager fEvents;
82 };
83 
84 namespace hooks {
85 struct LoadPlugins : Event<DeviceRunner&> {};
86 struct SetCustomCmdLineOptions : Event<DeviceRunner&> {};
87 struct ModifyRawCmdLineArgs : Event<DeviceRunner&> {};
88 struct InstantiateDevice : Event<DeviceRunner&> {};
89 } /* namespace hooks */
90 
91 } // namespace fair::mq
92 
93 #endif /* FAIR_MQ_DEVICERUNNER_H */
fair::mq::ProgOptions
Definition: ProgOptions.h:41
fair::mq
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23
fair::mq::DeviceRunner
Utility class to facilitate a convenient top-level device launch/shutdown.
Definition: DeviceRunner.h:57

privacy