Skip to content

Source · fairmq/

DeviceRunner.hpublic header

Defines class fair::mq::DeviceRunner.

Described in Configuration and properties, Devices, Plugins and control, custom-controller: control from code, Command-line options, Your first device, Logging.

fairmq/DeviceRunner.h93 lines · C++API: DeviceRunnerGitHub ↗
1/********************************************************************************2 * Copyright (C) 2017-2021 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_H10#define FAIR_MQ_DEVICERUNNER_H11 12#include <fairmq/Device.h>13#include <fairmq/EventManager.h>14#include <fairmq/PluginManager.h>15#include <fairmq/ProgOptions.h>16 17#include <functional>18#include <memory>19#include <string>20#include <vector>21 22namespace fair::mq23{24 25/**26 * @class DeviceRunner DeviceRunner.h <fairmq/DeviceRunner.h>27 * @brief Utility class to facilitate a convenient top-level device launch/shutdown.28 *29 * Runs a single FairMQ device with config and plugin support.30 *31 * For customization user hooks are executed at various steps during device launch/shutdown in the32 * following sequence:33 *34 *         LoadPlugins35 *              |36 *              v37 *   SetCustomCmdLineOptions38 *              |39 *              v40 *    ModifyRawCmdLineArgs41 *              |42 *              v43 *      InstatiateDevice44 *45 * Each hook has access to all members of the DeviceRunner and really only differs by the point in46 * time it is called.47 *48 * For an example usage of this class see the <fairmq/runDevice.h> header.49 */50class DeviceRunner51{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) -> void65    {66        fEvents.Subscribe<H>("runner", hook);67    }68    template<typename H>69    auto RemoveHook() -> void70    {71        fEvents.Unsubscribe<H>("runner");72    }73 74    std::vector<std::string> fRawCmdLineArgs;75    fair::mq::ProgOptions fConfig;76    std::unique_ptr<Device> fDevice;77    PluginManager fPluginManager;78    const bool fPrintLogo;79 80  private:81    EventManager fEvents;82};83 84namespace hooks {85struct LoadPlugins : Event<DeviceRunner&> {};86struct SetCustomCmdLineOptions : Event<DeviceRunner&> {};87struct ModifyRawCmdLineArgs : Event<DeviceRunner&> {};88struct InstantiateDevice : Event<DeviceRunner&> {};89} /* namespace hooks */90 91} // namespace fair::mq92 93#endif /* FAIR_MQ_DEVICERUNNER_H */