/******************************************************************************** * Copyright (C) 2017-2018 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" * ********************************************************************************/ #include "Config.h" #include #include #include using namespace std; namespace fair { namespace mq { namespace plugins { Config::Config(const string& name, const Plugin::Version version, const string& maintainer, const string& homepage, PluginServices* pluginServices) : Plugin(name, version, maintainer, homepage, pluginServices) { SubscribeToDeviceStateChange([&](DeviceState newState) { if (newState == DeviceState::InitializingDevice) { string idForParser; if (PropertyExists("config-key")) { idForParser = GetProperty("config-key"); } else if (PropertyExists("id")) { idForParser = GetProperty("id"); } if (idForParser != "") { try { if (PropertyExists("mq-config")) { LOG(debug) << "mq-config: Using default JSON parser"; SetProperties(JSONParser(GetProperty("mq-config"), idForParser)); } else if (PropertyExists("channel-config")) { LOG(debug) << "channel-config: Parsing channel configuration"; SetProperties(SuboptParser(GetProperty>("channel-config"), idForParser)); } else { LOG(warn) << "fair::mq::plugins::Config: no channels configuration provided via --mq-config or --channel-config"; } } catch (exception& e) { LOG(error) << e.what(); } } else { LOG(warn) << "No device ID or config-key provided for the configuration parser."; } } }); } Plugin::ProgOptions ConfigPluginProgramOptions() { namespace po = boost::program_options; auto pluginOptions = po::options_description{"FairMQ device options"}; pluginOptions.add_options() ("id", po::value()->default_value(""), "Device ID.") ("io-threads", po::value()->default_value(1), "Number of I/O threads.") ("transport", po::value()->default_value("zeromq"), "Transport ('zeromq'/'shmem').") ("network-interface", po::value()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).") ("init-timeout", po::value()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).") ("max-run-time", po::value()->default_value(0), "Maximum runtime for the Running state handler, after which state will change to Ready (in seconds, 0 for no limit).") ("print-channels", po::value()->implicit_value(true), "Print registered channel endpoints in a machine-readable format (::)") ("shm-segment-size", po::value()->default_value(2ULL << 30), "Shared memory: size of the shared memory segment (in bytes).") ("shm-throw-bad-alloc", po::value()->default_value(true), "Throw a fair::mq::MessageBadAlloc if cannot allocate a message (retry if false).") ("shm-monitor", po::value()->default_value(true), "Shared memory: run monitor daemon.") ("ofi-size-hint", po::value()->default_value(0), "EXPERIMENTAL: OFI size hint for the allocator.") ("rate", po::value()->default_value(0.), "Rate for conditional run loop (Hz).") ("session", po::value()->default_value("default"), "Session name.") ("config-key", po::value(), "Use provided value instead of device id for fetching the configuration from JSON file.") ("mq-config", po::value(), "JSON input as file.") ("channel-config", po::value>()->multitoken()->composing(), "Configuration of single or multiple channel(s) by comma separated key=value list"); return pluginOptions; } Config::~Config() { UnsubscribeFromDeviceStateChange(); } } /* namespace plugins */ } /* namespace mq */ } /* namespace fair */