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)
107 template <
typename ServiceClass>
111 return dynamic_cast<ServiceClass *
>(
112 getService(
typeid(ServiceClass),
id, implName, details, clients));
117 std::string implName = {},
123 Accelerator *
takeOwnership(std::unique_ptr<Accelerator> accel);
129 virtual void createEngine(
const std::string &engineTypeName, AppIDPath idPath,
138 throw std::runtime_error(
139 "AcceleratorConnection does not own an accelerator");
153 std::string implName,
182 const std::string &backend,
183 const std::string &connection);
193template <
typename TAccelerator>
200#define REGISTER_ACCELERATOR(Name, TAccelerator) \
201 static ::esi::registry::internal::RegisterAccelerator<TAccelerator> \
202 __register_accel____LINE__(Name)
217 addListener(std::initializer_list<ReadChannelPort *> listenPorts,
Abstract class representing a connection to an accelerator.
virtual void disconnect()
Disconnect from the accelerator cleanly.
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< std::string, services::Service * > ServiceTable
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::tuple< const std::type_info *, AppIDPath > ServiceCacheKey
Cache services via a unique_ptr so they get free'd automatically when Accelerator objects get deconst...
std::unique_ptr< AcceleratorServiceThread > serviceThread
std::unique_ptr< Accelerator > ownedAccelerator
Accelerator object owned by this connection.
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.
void stop()
Instruct the service thread to stop running.
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.
AcceleratorServiceThread()
std::unique_ptr< Impl > impl
void addPoll(HWModule &module)
Poll this module.
~AcceleratorServiceThread()
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.
std::unique_ptr< AcceleratorConnection > connect(Context &ctxt, const std::string &backend, const std::string &connection)
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)