/******************************************************************************** * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ #ifndef FAIR_MQ_DEVICERUNNER_H #define FAIR_MQ_DEVICERUNNER_H #include #include #include #include #include #include #include #include #include namespace fair { namespace mq { /** * @class DeviceRunner DeviceRunner.h * @brief Utility class to facilitate a convenient top-level device launch/shutdown. * * Runs a single FairMQ device with config and plugin support. * * For customization user hooks are executed at various steps during device launch/shutdown in the following sequence: * * LoadPlugins * | * v * SetCustomCmdLineOptions * | * v * ModifyRawCmdLineArgs * | * v * InstatiateDevice * * Each hook has access to all members of the DeviceRunner and really only differs by the point in time it is called. * * For an example usage of this class see the fairmq/runFairMQDevice.h header. */ class DeviceRunner { public: DeviceRunner(int argc, char* const argv[]); auto Run() -> int; auto RunWithExceptionHandlers() -> int; template auto AddHook(std::function hook) -> void { fEvents.Subscribe("runner", hook); } template auto RemoveHook() -> void { fEvents.Unsubscribe("runner"); } std::unique_ptr fDevice; std::vector fRawCmdLineArgs; FairMQProgOptions fConfig; PluginManager fPluginManager; private: EventManager fEvents; }; namespace hooks { struct LoadPlugins : Event {}; struct SetCustomCmdLineOptions : Event {}; struct ModifyRawCmdLineArgs : Event {}; struct InstantiateDevice : Event {}; } /* namespace hooks */ } /* namespace mq */ } /* namespace fair */ #endif /* FAIR_MQ_DEVICERUNNER_H */