/******************************************************************************** * Copyright (C) 2014 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" * ********************************************************************************/ /* * File: runSamplerRoot.cxx * Author: winckler */ // FairRoot - FairMQ #include "FairMQLogger.h" #include "FairMQProgOptions.h" #include "FairMQDevice.h" #include #include #include #include using namespace std; using FairMQMap = unordered_map>; class MyDevice : public FairMQDevice { public: MyDevice() : fRate(0.5) {} virtual ~MyDevice() {} void SetRate(double r) { fRate = r; } double GetRate() { return fRate; } void Print() { LOG(info) << "[MyDevice] rate = " << fRate; } private: double fRate; }; void MyCallBack(MyDevice& d, double val) { d.SetRate(val); d.Print(); } int main(int argc, char** argv) { try { FairMQProgOptions config; config.GetCmdLineOptions().add_options() ("data-rate", boost::program_options::value()->default_value(0.5), "Data rate"); config.ParseAll(argc, argv, true); // // get FairMQMap // auto map1 = config.GetFairMQMap(); // // update value in variable map, and propagate the update to the FairMQMap // config.SetValue("chans.data.0.address","tcp://localhost:1234"); // // get the updated FairMQMap // auto map2 = config.GetFairMQMap(); // // modify one channel value // map2.at("data").at(0).UpdateSndBufSize(500); // // update the FairMQMap and propagate the change in variable map // config.UpdateChannelMap(map2); MyDevice device; device.SetConfig(config); LOG(info) << "Subscribing: (chans.data.0.address)"; config.Subscribe("test", [&device](const string& key, string value) { if (key == "chans.data.0.address") { LOG(info) << "[callback] Updating device parameter " << key << " = " << value; device.fChannels.at("data").at(0).UpdateAddress(value); } }); LOG(info) << "Subscribing: (chans.data.0.rcvBufSize)"; config.Subscribe("test", [&device](const string& key, int value) { if(key == "chans.data.0.rcvBufSize") { LOG(info) << "[callback] Updating device parameter " << key << " = " << value; device.fChannels.at("data").at(0).UpdateRcvBufSize(value); } }); LOG(info) << "Subscribing: (data-rate)"; config.Subscribe("test", [&device](const string& key, double value) { if (key == "data-rate") { LOG(info) << "[callback] Updating device parameter " << key << " = " << value; device.SetRate(value); } }); LOG(info) << "Starting value updates...\n"; config.SetValue("chans.data.0.address", "tcp://localhost:4321"); LOG(info) << "config: " << config.GetValue("chans.data.0.address"); LOG(info) << "device: " << device.fChannels.at("data").at(0).GetAddress() << endl; config.SetValue("chans.data.0.rcvBufSize", 100); LOG(info) << "config: " << config.GetValue("chans.data.0.rcvBufSize"); LOG(info) << "device: " << device.fChannels.at("data").at(0).GetRcvBufSize() << endl; config.SetValue("data-rate", 0.9); LOG(info) << "config: " << config.GetValue("data-rate"); LOG(info) << "device: " << device.GetRate() << endl; device.Print(); LOG(info) << "nase: " << config.GetValue("nase"); config.Unsubscribe("test"); config.Unsubscribe("test"); config.Unsubscribe("test"); device.ChangeState("END"); } catch (exception& e) { LOG(error) << "Unhandled Exception reached the top of main: " << e.what() << ", application will now exit"; return 1; } return 0; }