/******************************************************************************** * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence version 3 (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ /* * File: FairMQEventManager.h * Author: winckler * * Created on August 12, 2016, 13:50 PM */ #ifndef FAIRMQEVENTMANAGER_H #define FAIRMQEVENTMANAGER_H #include #include #include #include #include #include #include #include enum class EventId : uint32_t { // Place your new EventManager events here UpdateParam = 0, Custom = 1, }; namespace Events { template struct Traits; template struct Traits { using signal_type = boost::signals2::signal; } ; template struct Traits > { using signal_type = boost::signals2::signal& )>; } ; template <> struct Traits { using signal_type = boost::signals2::signal; } ; template struct Traits { using signal_type = boost::signals2::signal; } ; template struct Traits { using signal_type = boost::signals2::signal; } ; /* template struct Traits2; template <> struct Traits2 { using signal_type = boost::signals2::signal; } ; template struct Traits2 { using signal_type = boost::signals2::signal; } ; template <> struct Traits2 { using signal_type = boost::signals2::signal; } ; // */ } // Events namespace class FairMQEventManager { public: typedef std::pair EventKey; FairMQEventManager() : fEventMap() {} virtual ~FairMQEventManager(){} template void Connect(const std::string& key, F&& func) { GetSlot(key).connect(std::forward(func)); } template void Disonnect(const std::string& key) { GetSlot(key).disconnect(); } template void Emit(const std::string& key, Args&&... args) { GetSlot(key)(std::forward(args)...); } template bool EventKeyFound(const std::string& key) { if (fEventMap.find(std::pair(event,key) ) != fEventMap.end()) return true; else return false; } private: std::map fEventMap; template ::signal_type, typename SlotPtr = boost::shared_ptr > Slot& GetSlot(const std::string& key) { try { EventKey eventKey = std::make_pair(event,key); //static_assert(std::is_same()),SlotPtr>::value, ""); if (fEventMap.find(eventKey) == fEventMap.end()) fEventMap.emplace(eventKey, boost::make_shared()); return *boost::any_cast(fEventMap.at(eventKey)); // auto &&tmp = boost::any_cast(fEventMap.at(eventKey)); // return *tmp; } catch (boost::bad_any_cast const &e) { LOG(ERROR) << "Caught instance of boost::bad_any_cast: " << e.what() << " on event #" << static_cast(event) << " and key" << key; abort(); } } }; #endif /* FAIRMQEVENTMANAGER_H */