10#include <nlohmann/json.hpp>
12using json = nlohmann::json;
20 MuxedInterruptDistributorFactory::MuxedInterruptDistributorFactory() {
37 std::vector<size_t>
const& subdomainID,
DeviceBackend& backend) {
39 auto const& key = metaDataEntry.first;
42 auto jkey = nlohmann::json::parse(std::string({++key.begin(), key.end()}));
43 auto interruptId = jkey.get<std::vector<size_t>>();
45 if(interruptId == subdomainID) {
46 auto jdescriptor = nlohmann::json::parse(metaDataEntry.second);
47 auto controllerType = jdescriptor.begin().key();
48 auto controllerDescription = jdescriptor.front().dump();
49 return {controllerType, controllerDescription};
52 catch(json::parse_error& e) {
57 std::string subdomainIdString;
58 for(
auto i : subdomainID) {
61 subdomainIdString.pop_back();
64 "No interrupt controller description for SubDomain " + subdomainIdString +
" in MetadataCatalogue");
71 std::string name, description;
72 std::tie(name, description) =
78 return creatorFunctionIter->second(description, std::move(parent));
83 : _backend(parent->getBackend()), _id(parent->getId()), _parent(
std::move(parent)),
84 _asyncDomain(_parent->getDomain()) {}
87 template<
typename DistributorType>
89 std::vector<size_t>
const& qualififedSubDomainId) {
91 assert(!qualififedSubDomainId.empty());
92 auto fullyQualifiedId =
_id;
93 fullyQualifiedId.push_back(qualififedSubDomainId.front());
96 boost::shared_ptr<SubDomain<std::nullptr_t>> subDomain;
97 auto subDomainIter =
_subDomains.find(qualififedSubDomainId.front());
99 subDomain = subDomainIter->second.lock();
103 boost::make_shared<SubDomain<std::nullptr_t>>(
_backend, fullyQualifiedId, shared_from_this(),
_asyncDomain);
104 _subDomains[qualififedSubDomainId.front()] = subDomain;
111 return subDomain->getAccessorManager<DistributorType>(qualififedSubDomainId);
127 auto subDomain = subDomainIter.second.lock();
137 auto subDomain = subDomainIter.second.lock();
139 subDomain->sendException(e);
147 subDomain.
activate(
nullptr, version);
The base class for backends providing IO functionality for the Device class.
virtual MetadataCatalogue getMetadataCatalogue() const =0
Return the device metadata catalogue.
Class for generating and holding version numbers without exposing a numeric representation.
static std::unique_ptr< DummyMuxedInterruptDistributor > create(std::string const &desrciption, boost::shared_ptr< SubDomain< std::nullptr_t > > parent)
static std::unique_ptr< GenericMuxedInterruptDistributor > create(std::string const &description, const boost::shared_ptr< SubDomain< std::nullptr_t > > &parent)
Create parses the json configuration snippet 'description', and calls the constructor.
static MuxedInterruptDistributorFactory & getInstance()
std::map< std::string, std::function< std::unique_ptr< MuxedInterruptDistributor >(std::string, boost::shared_ptr< SubDomain< std::nullptr_t > >)> > _creatorFunctions
Each controller type is registered via name and creator function.
boost::shared_ptr< MuxedInterruptDistributor > createMuxedInterruptDistributor(boost::shared_ptr< SubDomain< std::nullptr_t > > parent)
static std::pair< std::string, std::string > getInterruptControllerNameAndDescriptionFromCatalogue(std::vector< size_t > const &subdomainID, DeviceBackend &backend)
std::vector< size_t > _id
The ID of this controller handler.
MuxedInterruptDistributor(boost::shared_ptr< SubDomain< std::nullptr_t > > parent)
MuxedInterruptDistributor classes must only be constructed inside and held by a DeviceBackend,...
void sendException(const std::exception_ptr &e)
virtual void activate(VersionNumber version)
virtual void activateSubDomain(SubDomain< std::nullptr_t > &subDomain, VersionNumber const &version)
Function to activate a (new) single SubDomain if the MuxedInterruptDistributor is already active.
boost::shared_ptr< AsyncAccessorManager > getAccessorManager(std::vector< size_t > const &qualififedSubDomainId)
Get an AsyncAccessorManager of type DistributorType from the matching SubDomain.
boost::shared_ptr< Domain > _asyncDomain
std::map< size_t, boost::weak_ptr< SubDomain< std::nullptr_t > > > _subDomains
boost::shared_ptr< DeviceBackend > _backend
Send backend-specific asynchronous data to different distributors:
void activate(BackendSpecificDataType, VersionNumber v)
The TriggeredPollDistributor has std::nullptr_t source data type and is polling the data for the Asyn...
Exception thrown when a logic error has occured.
std::string to_string(const std::string &v)