Skip to content

Source · fairmq/

runDevice.hpublic header

Described in Devices, 1-1: sampler and sink, dds: run with DDS, Your first device.

fairmq/runDevice.h59 lines · C++GitHub ↗
1/********************************************************************************2 * Copyright (C) 2017-2022 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 13// to be implemented by the user to return a child class of fair::mq::Device14std::unique_ptr<fair::mq::Device> getDevice(fair::mq::ProgOptions& config);15 16// to be implemented by the user to add custom command line options (or just with empty body)17void addCustomOptions(boost::program_options::options_description&);18 19int main(int argc, char* argv[])20{21    using namespace fair::mq;22    using namespace fair::mq::hooks;23 24    try {25        DeviceRunner runner(argc, argv);26 27        // runner.AddHook<LoadPlugins>([](DeviceRunner& r){28        //     // for example:29        //     r.fPluginManager->SetSearchPaths({"/lib", "/lib/plugins"});30        //     r.fPluginManager->LoadPlugin("asdf");31        // });32 33        runner.AddHook<SetCustomCmdLineOptions>([](DeviceRunner& r){34            boost::program_options::options_description customOptions("Custom options");35            addCustomOptions(customOptions);36            r.fConfig.AddToCmdLineOptions(customOptions);37        });38 39        // runner.AddHook<ModifyRawCmdLineArgs>([](DeviceRunner& r){40        //     // for example:41        //     r.fRawCmdLineArgs.push_back("--blubb");42        // });43 44        runner.AddHook<InstantiateDevice>([](DeviceRunner& r){45            r.fDevice = getDevice(r.fConfig);46        });47 48        return runner.Run();49 50        // Run with builtin catch all exception handler, just:51        // return runner.RunWithExceptionHandlers();52    } catch (std::exception& e) {53        LOG(error) << "Uncaught exception reached the top of main: " << e.what();54        return 1;55    } catch (...) {56        LOG(error) << "Uncaught exception reached the top of main.";57        return 1;58    }59}