24 #include "usServiceReferenceBasePrivate.h"
30 class ServiceObjectsBasePrivate
37 ServiceReferenceBase m_reference;
40 std::map<void*, InterfaceMap> m_serviceInstances;
42 std::set<InterfaceMap> m_serviceInterfaceMaps;
44 ServiceObjectsBasePrivate(
ModuleContext* context,
const ServiceReferenceBase& reference)
46 , m_reference(reference)
58 result = m_reference.d->GetPrototypeService(m_context->
GetModule());
62 result = m_reference.d->GetServiceInterfaceMap(m_context->
GetModule());
70 : d(new ServiceObjectsBasePrivate(context, reference))
75 throw std::invalid_argument(
"The service reference is invalid");
88 void* result = im.find(d->m_reference.GetInterfaceId())->second;
92 d->m_serviceInstances.insert(std::make_pair(result, im));
105 result = d->GetServiceInterfaceMap();
109 d->m_serviceInterfaceMaps.insert(result);
121 std::map<void*,InterfaceMap>::iterator serviceIter = d->m_serviceInstances.find(service);
122 if (serviceIter == d->m_serviceInstances.end())
124 throw std::invalid_argument(
"The provided service has not been retrieved via this ServiceObjects instance");
127 if (!d->m_reference.d->UngetPrototypeService(d->m_context->GetModule(), serviceIter->second))
129 US_WARN <<
"Ungetting service unsuccessful";
133 d->m_serviceInstances.erase(serviceIter);
139 if (interfaceMap.empty())
144 std::set<InterfaceMap>::iterator serviceIter = d->m_serviceInterfaceMaps.find(interfaceMap);
145 if (serviceIter == d->m_serviceInterfaceMaps.end())
147 throw std::invalid_argument(
"The provided service has not been retrieved via this ServiceObjects instance");
150 if (!d->m_reference.d->UngetPrototypeService(d->m_context->GetModule(), interfaceMap))
152 US_WARN <<
"Ungetting service unsuccessful";
156 d->m_serviceInterfaceMaps.erase(serviceIter);
162 return d->m_reference;
181 ServiceObjectsBasePrivate* curr_d = d;
185 if (!curr_d->ref.Deref())
void UngetService(void *service)
US_Core_EXPORT const std::string & SCOPE_PROTOTYPE()
std::map< std::string, void * > InterfaceMap
void UngetService(S *service)
US_Core_EXPORT const std::string & SERVICE_SCOPE()
ServiceObjectsBase & operator=(const ServiceObjectsBase &other)
ServiceReferenceBase GetReference() const
void * GetService() const
Module * GetModule() const
ServiceReference< S > GetServiceReference() const
InterfaceMap GetServiceInterfaceMap() const
ServiceObjectsBase(ModuleContext *context, const ServiceReferenceBase &reference)