FairMQ  1.2.1
C++ Message Passing 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 FairMQProgOptions& 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  {
29  fair::mq::DeviceRunner runner{argc, argv};
30 
31  // runner.AddHook<LoadPlugins>([](DeviceRunner& r){
32  // // for example:
33  // r.fPluginManager->SetSearchPaths({"/lib", "/lib/plugins"});
34  // r.fPluginManager->LoadPlugin("asdf");
35  // });
36 
37  runner.AddHook<SetCustomCmdLineOptions>([](DeviceRunner& r){
38  boost::program_options::options_description customOptions("Custom options");
39  addCustomOptions(customOptions);
40  r.fConfig.AddToCmdLineOptions(customOptions);
41  });
42 
43  // runner.AddHook<ModifyRawCmdLineArgs>([](DeviceRunner& r){
44  // // for example:
45  // r.fRawCmdLineArgs.push_back("--blubb");
46  // });
47 
48  runner.AddHook<InstantiateDevice>([](DeviceRunner& r){
49  r.fDevice = std::shared_ptr<FairMQDevice>{getDevice(r.fConfig)};
50  });
51 
52  return runner.Run();
53 
54  // Run with builtin catch all exception handler, just:
55  // return runner.RunWithExceptionHandlers();
56  }
57  catch (std::exception& e)
58  {
59  LOG(error) << "Unhandled exception reached the top of main: " << e.what() << ", application will now exit";
60  return 1;
61  }
62  catch (...)
63  {
64  LOG(error) << "Non-exception instance being thrown. Please make sure you use std::runtime_exception() instead. Application will now exit.";
65  return 1;
66  }
67 }
Utility class to facilitate a convenient top-level device launch/shutdown.
Definition: DeviceRunner.h:51
Definition: DeviceRunner.h:73
Definition: DeviceRunner.h:25
Definition: FairMQProgOptions.h:41
Definition: DeviceRunner.h:78
Definition: DeviceRunner.h:76
Definition: FairMQDevice.h:44