Source · fairmq/plugins/config/
Config.cxxsource
Described in Configuration and properties, 1-n-1: sampler, processors and sink, Configure channels, JSON configuration, Command-line options, Tune and debug.
1/********************************************************************************2 * Copyright (C) 2017-2023 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 "Config.h"10 11#include <fairmq/JSONParser.h>12#include <fairmq/SuboptParser.h>13 14#include <cstddef> // for std::size_t15#include <vector>16 17using namespace std;18 19namespace fair::mq::plugins20{21 22Config::Config(const string& name, Plugin::Version version, const string& maintainer, const string& homepage, PluginServices* pluginServices)23 : Plugin(name, version, maintainer, homepage, pluginServices)24{25 SubscribeToDeviceStateChange([&](DeviceState newState) {26 if (newState == DeviceState::InitializingDevice) {27 string idForParser;28 29 if (PropertyExists("config-key")) {30 idForParser = GetProperty<string>("config-key");31 } else if (PropertyExists("id")) {32 idForParser = GetProperty<string>("id");33 }34 35 if (!idForParser.empty()) {36 try {37 if (PropertyExists("mq-config")) {38 LOG(debug) << "mq-config: Using default JSON parser";39 SetProperties(JSONParser(GetProperty<string>("mq-config"), idForParser));40 } else if (PropertyExists("channel-config")) {41 LOG(debug) << "channel-config: Parsing channel configuration";42 SetProperties(SuboptParser(GetProperty<vector<string>>("channel-config"), idForParser));43 } else {44 LOG(info) << "fair::mq::plugins::Config: no channels configuration provided via --mq-config or --channel-config";45 }46 } catch (exception& e) {47 LOG(error) << e.what();48 }49 } else {50 LOG(warn) << "No device ID or config-key provided for the configuration parser.";51 }52 }53 });54}55 56Plugin::ProgOptions ConfigPluginProgramOptions()57{58 namespace po = boost::program_options;59 auto pluginOptions = po::options_description{"FairMQ device options"};60 pluginOptions.add_options()61 ("id", po::value<string >()->default_value(""), "Device ID.")62 ("io-threads", po::value<int >()->default_value(1), "Number of I/O threads.")63 ("transport", po::value<string >()->default_value("zeromq"), "Transport ('zeromq'/'shmem').")64 ("network-interface", po::value<string >()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).")65 ("init-timeout", po::value<int >()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).")66 ("print-channels", po::value<bool >()->implicit_value(true), "Print registered channel endpoints in a machine-readable format (<channel name>:<min num subchannels>:<max num subchannels>)")67 ("shm-segment-size", po::value<size_t >()->default_value(2ULL << 30), "Shared memory: size of the shared memory segment (in bytes).")68 ("shm-allocation", po::value<string >()->default_value("rbtree_best_fit"), "Shared memory allocation algorithm: rbtree_best_fit/simple_seq_fit.")69 ("shm-segment-id", po::value<uint16_t >()->default_value(0), "EXPERIMENTAL: Shared memory segment id for message creation.")70 ("shmid", po::value<uint64_t >(), "EXPERIMENTAL: Fixed shmid to use instead of deriving it from the session name.")71 ("shm-mlock-segment", po::value<bool >()->default_value(false), "Shared memory: mlock the shared memory segment after initialization (opened or created).")72 ("shm-mlock-segment-on-creation", po::value<bool >()->default_value(false), "Shared memory: mlock the shared memory segment only once when created.")73 ("shm-zero-segment", po::value<bool >()->default_value(false), "Shared memory: zero the shared memory segment memory after initialization (opened or created).")74 ("shm-zero-segment-on-creation", po::value<bool >()->default_value(false), "Shared memory: zero the shared memory segment memory only once when created.")75 ("shm-throw-bad-alloc", po::value<bool >()->default_value(true), "Shared memory: throw fair::mq::MessageBadAlloc if cannot allocate a message (retry if false).")76 ("shm-metadata-msg-size", po::value<std::size_t >()->default_value(0), "Shared memory: size of the zmq metadata message (values smaller than minimum are clamped to the minimum).")77 ("bad-alloc-max-attempts", po::value<int >(), "Maximum number of allocation attempts before throwing fair::mq::MessageBadAlloc. -1 is infinite. There is always at least one attempt, so 0 has safe effect as 1.")78 ("bad-alloc-attempt-interval", po::value<int >()->default_value(50), "Interval between attempts if cannot allocate a message (in ms).")79 ("shm-monitor", po::value<bool >()->default_value(false), "Shared memory: run monitor daemon.")80 ("shm-no-cleanup", po::value<bool >()->default_value(false), "Shared memory: do not cleanup the memory when last device leaves.")81 ("rate", po::value<float >()->default_value(0.), "Rate for conditional run loop (Hz).")82 ("session", po::value<string >()->default_value("default"), "Session name.")83 ("config-key", po::value<string >(), "Use provided value instead of device id for fetching the configuration from JSON file.")84 ("mq-config", po::value<string >(), "JSON input as file.")85 ("channel-config", po::value<vector<string>>()->multitoken()->composing(), "Configuration of single or multiple channel(s) by comma separated key=value list");86 return pluginOptions;87}88 89Config::~Config()90{91 UnsubscribeFromDeviceStateChange();92}93 94} // namespace fair::mq::plugins