FairMQ  1.4.33
C++ Message Queuing Library and Framework
runFairMQDevice.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 #include <fairmq/DeviceRunner.h>
10 #include <boost/program_options.hpp>
11 #include <memory>
12 #include <string>
13 
15 
16 // to be implemented by the user to return a child class of FairMQDevice
17 FairMQDevicePtr getDevice(const fair::mq::ProgOptions& config);
18 
19 // to be implemented by the user to add custom command line options (or just with empty body)
20 void addCustomOptions(boost::program_options::options_description&);
21 
22 int main(int argc, char* argv[])
23 {
24  using namespace fair::mq;
25  using namespace fair::mq::hooks;
26 
27  try {
28  fair::mq::DeviceRunner runner{argc, argv};
29 
30  // runner.AddHook<LoadPlugins>([](DeviceRunner& r){
31  // // for example:
32  // r.fPluginManager->SetSearchPaths({"/lib", "/lib/plugins"});
33  // r.fPluginManager->LoadPlugin("asdf");
34  // });
35 
36  runner.AddHook<SetCustomCmdLineOptions>([](DeviceRunner& r){
37  boost::program_options::options_description customOptions("Custom options");
38  addCustomOptions(customOptions);
39  r.fConfig.AddToCmdLineOptions(customOptions);
40  });
41 
42  // runner.AddHook<ModifyRawCmdLineArgs>([](DeviceRunner& r){
43  // // for example:
44  // r.fRawCmdLineArgs.push_back("--blubb");
45  // });
46 
47  runner.AddHook<InstantiateDevice>([](DeviceRunner& r){
48  r.fDevice = std::unique_ptr<FairMQDevice>{getDevice(r.fConfig)};
49  });
50 
51  return runner.Run();
52 
53  // Run with builtin catch all exception handler, just:
54  // return runner.RunWithExceptionHandlers();
55  } catch (std::exception& e) {
56  LOG(error) << "Uncaught exception reached the top of main: " << e.what();
57  return 1;
58  } catch (...) {
59  LOG(error) << "Uncaught exception reached the top of main.";
60  return 1;
61  }
62 }
fair::mq::ProgOptions
Definition: ProgOptions.h:41
fair::mq::hooks::InstantiateDevice
Definition: DeviceRunner.h:94
fair::mq
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23
fair::mq::hooks::SetCustomCmdLineOptions
Definition: DeviceRunner.h:92
fair::mq::DeviceRunner
Utility class to facilitate a convenient top-level device launch/shutdown.
Definition: DeviceRunner.h:57
FairMQDevice
Definition: FairMQDevice.h:50

privacy