/******************************************************************************** * 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_PLUGINS_DDS #define FAIR_MQ_PLUGINS_DDS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace fair { namespace mq { namespace plugins { struct DDSConfig { DDSConfig() : fSubChannelAddresses() , fDDSValues() {} // container of sub channel addresses std::vector fSubChannelAddresses; // dds values for the channel std::unordered_map fDDSValues; }; struct IofN { IofN(int i, int n) : fI(i) , fN(n) , fEntries() {} unsigned int fI; unsigned int fN; std::vector fEntries; }; class DDS : public Plugin { public: DDS(const std::string& name, const Plugin::Version version, const std::string& maintainer, const std::string& homepage, PluginServices* pluginServices); ~DDS(); private: auto HandleControl() -> void; auto FillChannelContainers() -> void; auto SubscribeForConnectingChannels() -> void; auto PublishBoundChannels() -> void; auto SubscribeForCustomCommands() -> void; auto HeartbeatSender() -> void; dds::intercom_api::CIntercomService fService; dds::intercom_api::CCustomCmd fDDSCustomCmd; dds::intercom_api::CKeyValue fDDSKeyValue; uint64_t fDDSTaskId; std::unordered_map> fBindingChans; std::unordered_map fConnectingChans; std::unordered_map fI; std::unordered_map fIofN; std::mutex fStopMutex; std::condition_variable fStopCondition; const std::set fTransitions; std::thread fControllerThread; DeviceState fCurrentState, fLastState; fair::mq::StateQueue fStateQueue; std::atomic fDeviceTerminationRequested; std::atomic fServiceStarted; std::set fHeartbeatSubscribers; std::mutex fHeartbeatSubscriberMutex; std::set fStateChangeSubscribers; std::mutex fStateChangeSubscriberMutex; std::thread fHeartbeatThread; std::chrono::milliseconds fHeartbeatInterval; }; Plugin::ProgOptions DDSProgramOptions() { boost::program_options::options_description options{"DDS Plugin"}; options.add_options() ("dds-i", boost::program_options::value>()->multitoken()->composing(), "Task index for chosing connection target (single channel n to m). When all values come via same update.") ("dds-i-n", boost::program_options::value>()->multitoken()->composing(), "Task index for chosing connection target (one out of n values to take). When values come as independent updates."); return options; } REGISTER_FAIRMQ_PLUGIN( DDS, // Class name dds, // Plugin name (string, lower case chars only) (Plugin::Version{FAIRMQ_VERSION_MAJOR, FAIRMQ_VERSION_MINOR, FAIRMQ_VERSION_PATCH}), // Version "FairRootGroup ", // Maintainer "https://github.com/FairRootGroup/FairMQ", // Homepage DDSProgramOptions // custom program options for the plugin ) } /* namespace plugins */ } /* namespace mq */ } /* namespace fair */ #endif /* FAIR_MQ_PLUGINS_DDS */