21#ifndef ESI_ACCELERATOR_H
22#define ESI_ACCELERATOR_H
39class AcceleratorServiceThread;
66 std::vector<std::unique_ptr<Instance>>
children,
67 std::vector<services::Service *>
services,
68 std::vector<std::unique_ptr<BundlePort>> &
ports)
100 template <
typename ServiceClass>
104 return dynamic_cast<ServiceClass *
>(
105 getService(
typeid(ServiceClass),
id, implName, details, clients));
110 std::string implName = {},
116 Accelerator *
takeOwnership(std::unique_ptr<Accelerator> accel);
122 virtual void createEngine(
const std::string &engineTypeName, AppIDPath idPath,
131 throw std::runtime_error(
132 "AcceleratorConnection does not own an accelerator");
146 std::string implName,
180template <
typename TAccelerator>
187#define REGISTER_ACCELERATOR(Name, TAccelerator) \
188 static ::esi::registry::internal::RegisterAccelerator<TAccelerator> \
189 __register_accel____LINE__(Name)
204 addListener(std::initializer_list<ReadChannelPort *> listenPorts,
Abstract class representing a connection to an accelerator.
std::tuple< std::string, AppIDPath > ServiceCacheKey
Cache services via a unique_ptr so they get free'd automatically when Accelerator objects get deconst...
virtual Service * createService(Service::Type service, AppIDPath idPath, std::string implName, const ServiceImplDetails &details, const HWClientDetails &clients)=0
Called by getServiceImpl exclusively.
services::Service Service
ServiceClass * getService(AppIDPath id={}, std::string implName={}, ServiceImplDetails details={}, HWClientDetails clients={})
Get a typed reference to a particular service type.
Context & getCtxt() const
std::map< AppIDPath, BundleEngineMap > clientEngines
Mapping of clients to their servicing engines.
Context & ctxt
ESI accelerator context.
void registerEngine(AppIDPath idPath, std::unique_ptr< Engine > engine, const HWClientDetails &clients)
If createEngine is overridden, this method should be called to register the engine and all of the cha...
std::map< ServiceCacheKey, std::unique_ptr< Service > > serviceCache
std::unique_ptr< AcceleratorServiceThread > serviceThread
std::unique_ptr< Accelerator > ownedAccelerator
Accelerator object owned by this connection.
virtual void disconnect()
Disconnect from the accelerator cleanly.
std::map< AppIDPath, std::unique_ptr< Engine > > ownedEngines
Collection of owned engines.
Accelerator & getAccelerator()
virtual void createEngine(const std::string &engineTypeName, AppIDPath idPath, const ServiceImplDetails &details, const HWClientDetails &clients)
Create a new engine for channel communication with the accelerator.
virtual const BundleEngineMap & getEngineMapFor(AppIDPath id)
virtual ~AcceleratorConnection()
Logger & getLogger() const
AcceleratorServiceThread * getServiceThread()
Return a pointer to the accelerator 'service' thread (or threads).
Accelerator * takeOwnership(std::unique_ptr< Accelerator > accel)
Assume ownership of an accelerator object.
Background thread which services various requests.
AcceleratorServiceThread()
std::unique_ptr< Impl > impl
void stop()
Instruct the service thread to stop running.
void addPoll(HWModule &module)
Poll this module.
~AcceleratorServiceThread()
void addListener(std::initializer_list< ReadChannelPort * > listenPorts, std::function< void(ReadChannelPort *, MessageData)> callback)
When there's data on any of the listenPorts, call the callback.
Top level accelerator class.
Accelerator(std::optional< ModuleInfo > info, std::vector< std::unique_ptr< Instance > > children, std::vector< services::Service * > services, std::vector< std::unique_ptr< BundlePort > > &ports)
Accelerator(const Accelerator &)=delete
Since engines can support multiple channels BUT not necessarily all of the channels in a bundle,...
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Represents either the top level or an instance of a hardware module.
const std::optional< ModuleInfo > info
const std::vector< std::unique_ptr< BundlePort > > ports
const std::vector< std::unique_ptr< Instance > > children
const std::vector< services::Service * > services
A logical chunk of data representing serialized data.
A ChannelPort which reads data from the accelerator.
Parent class of all APIs modeled as 'services'.
const std::type_info & Type
void registerBackend(const std::string &name, BackendCreate create)
std::function< std::unique_ptr< AcceleratorConnection >(Context &, std::string)> BackendCreate
Backends can register themselves to be connected via a connection string.
constexpr uint64_t MagicNumber
std::map< std::string, std::any > ServiceImplDetails
constexpr uint64_t MagicNumberHi
constexpr uint32_t ExpectedVersionNumber
constexpr uint32_t MetadataOffset
constexpr uint64_t MagicNumberLo
std::vector< HWClientDetail > HWClientDetails
RegisterAccelerator(const char *name)