11#ifndef O2_FRAMEWORK_SERVICEREGISTRY_H_
12#define O2_FRAMEWORK_SERVICEREGISTRY_H_
50template <
typename T,
typename LOCKING = NoLocking>
65template <
typename,
typename =
void>
71struct ServiceKindExtractor<T,
std::void_t<decltype(T::service_kind)>> : std::is_same<decltype(T::service_kind), enum ServiceKind> {
153 return {streamId, 0};
175 return {streamId, dataProcessorId};
185 static_assert(
MAX_SERVICES_MASK < 0x7FFFFFFF,
"MAX_SERVICES_MASK must be smaller than 0x7FFFFFFF");
193 void throwError(
const char*
name, int64_t hash, int64_t streamId, int64_t dataprocessorId)
const;
196 using hash_type =
decltype(TypeIdHelpers::uniqueId<void>());
265 template <
class I,
class C, enum ServiceKind K = ServiceKind::Serial>
266 requires std::is_base_of_v<I, C>
277 template <
class I,
class C, enum ServiceKind K = ServiceKind::Serial>
278 requires std::is_base_of_v<I, C>
284 constexpr ServiceTypeHash typeHash{TypeIdHelpers::uniqueId<I const>()};
285 this->
registerService(typeHash,
reinterpret_cast<void*
>(
const_cast<C*
>(service)), K, salt,
typeid(C).
name());
289 template <
typename T>
290 requires(std::is_const_v<T> ==
false)
304 template <
typename T>
310 if constexpr (std::is_const_v<T>) {
311 return *
reinterpret_cast<T const*
>(
ptr);
313 return *
reinterpret_cast<T*
>(
ptr);
#define O2_BUILTIN_UNREACHABLE
#define O2_BUILTIN_LIKELY(x)
#define O2_DPL_ACQUIRE(...)
#define O2_DPL_RELEASE(...)
#define O2_DPL_CAPABILITY(x)
service_ptr(service_ptr< T, LOCKING > const &)=delete
service_ptr(T *ptr, LOCKING policy)
service_ptr & operator=(service_ptr< T, LOCKING > const &)=delete
GLuint const GLchar * name
GLint GLint GLsizei GLint GLenum GLenum type
Defining PrimaryVertex explicitly as messageable.
ServiceKind
The kind of service we are asking for.
constexpr ServiceKind service_kind_v
Defining DataPointCompositeObject explicitly as copiable.
Running state information of a given device.
ServiceKind kind
Kind of service.
void * instance
Type erased pointer to a service.
unsigned int hash
Unique hash associated to the type of service.
std::string name
Mnemonic name to use for the service.
void postRenderGUICallbacks()
std::atomic< int > lockCounter
std::array< std::atomic< Key >, MAX_SERVICES+MAX_DISTANCE > mServicesKey
void unlock(Salt salt) const O2_DPL_RELEASE(mMutex)
static constexpr Salt GLOBAL_CONTEXT_SALT
std::vector< ServiceSpec > mSpecs
static Salt streamSalt(short streamId, short dataProcessorId)
std::array< void *, MAX_SERVICES+MAX_DISTANCE > mServicesValue
void registerService(C const *service, Salt salt=ServiceRegistry::globalDeviceSalt())
decltype(TypeIdHelpers::uniqueId< void >()) hash_type
static constexpr int32_t MAX_DISTANCE
The maximum distance a entry can be from the optimal slot.
static constexpr int32_t valueFromSalt(Salt salt)
void lateBindStreamServices(DeviceState &state, fair::mq::ProgOptions &options, ServiceRegistry::Salt salt)
void declareService(ServiceSpec const &spec, DeviceState &state, fair::mq::ProgOptions &options, ServiceRegistry::Salt salt=ServiceRegistry::globalDeviceSalt())
void registerService(ServiceHandle handle, Salt salt=ServiceRegistry::globalDeviceSalt())
Register a service given an handle.
static Salt globalStreamSalt(short streamId)
void registerService(ServiceTypeHash typeHash, void *service, ServiceKind kind, Salt salt, char const *name=nullptr, ServiceRegistry::SpecIndex specIndex=SpecIndex{-1}) const
int getPos(ServiceTypeHash typeHash, Salt salt) const
ServiceRegistry & operator=(ServiceRegistry const &other)
void preExitCallbacks()
Invoke callbacks on exit.
bool active(Salt salt) const
Check if service of type T is currently active.
constexpr Index indexFromInstance(InstanceId id) const
static constexpr uint32_t MAX_SERVICES
The number of slots in the hashmap.
void bindService(ServiceRegistry::Salt salt, ServiceSpec const &spec, void *service) const
static constexpr uint64_t valueFromKey(Key key)
void throwError(const char *name, int64_t hash, int64_t streamId, int64_t dataprocessorId) const
To hide exception throwing from QC.
std::array< Meta, MAX_SERVICES+MAX_DISTANCE > mServicesMeta
static Salt globalDeviceSalt()
void * get(ServiceTypeHash typeHash, Salt salt, ServiceKind kind, char const *name=nullptr) const
std::vector< ServicePostRenderGUIHandle > mPostRenderGUIHandles
Callbacks to be executed after the main GUI has been drawn.
void lock(Salt salt) const O2_DPL_ACQUIRE(mMutex)
std::array< std::atomic< bool >, MAX_SERVICES+MAX_DISTANCE > mServicesBooked
static Salt dataProcessorSalt(short dataProcessorId)
static constexpr uint32_t MAX_SERVICES_MASK
The mask to use to calculate the initial slot id.
std::recursive_mutex mMutex
constexpr InstanceId instanceFromTypeSalt(ServiceTypeHash type, Salt salt) const
void registerService(C *service, Salt salt=ServiceRegistry::globalDeviceSalt())
VectorOfTObjectPtrs other