23 #include "usServiceRegistrationBasePrivate.h"
24 #include "usServiceListenerEntry_p.h"
25 #include "usServiceRegistry_p.h"
28 #include "usModulePrivate.h"
29 #include "usCoreModuleContext_p.h"
35 ServiceRegistrationBase::ServiceRegistrationBase()
47 ServiceRegistrationBase::ServiceRegistrationBase(ServiceRegistrationBasePrivate* registrationPrivate)
48 : d(registrationPrivate)
53 ServiceRegistrationBase::ServiceRegistrationBase(ModulePrivate* module,
const InterfaceMap& service,
54 const ServicePropertiesImpl& props)
55 : d(new ServiceRegistrationBasePrivate(module, service, props))
60 ServiceRegistrationBase::operator bool_type()
const
62 return d != NULL ? &ServiceRegistrationBase::d : NULL;
69 if (d && !d->ref.Deref())
80 if (d && !d->ref.Deref())
86 if (!d)
throw std::logic_error(
"ServiceRegistrationBase object invalid");
87 if (!d->available)
throw std::logic_error(
"Service is unregistered");
90 ref.SetInterfaceId(interfaceId);
96 if (!d)
throw std::logic_error(
"ServiceRegistrationBase object invalid");
98 MutexLock lock(d->eventLock);
101 ServiceListeners::ServiceListenerEntries before;
112 std::vector<std::string> classes;
114 MutexLock lock3(d->propsLock);
118 if (any.
Type() ==
typeid(int)) old_rank =
any_cast<
int>(any);
121 d->module->coreCtx->listeners.GetMatchingServiceListeners(modifiedEndMatchEvent, before,
false);
124 d->properties = ServiceRegistry::CreateServiceProperties(props, classes,
false,
false, sid);
128 if (any.
Type() ==
typeid(int)) new_rank =
any_cast<
int>(any);
132 if (old_rank != new_rank)
134 d->module->coreCtx->services.UpdateServiceRegistrationOrder(*
this, classes);
139 throw std::logic_error(
"Service is unregistered");
143 ServiceListeners::ServiceListenerEntries matchingListeners;
144 d->module->coreCtx->listeners.GetMatchingServiceListeners(modifiedEvent, matchingListeners);
145 d->module->coreCtx->listeners.ServiceChanged(matchingListeners,
149 d->module->coreCtx->listeners.ServiceChanged(before,
150 modifiedEndMatchEvent);
155 if (!d)
throw std::logic_error(
"ServiceRegistrationBase object invalid");
157 if (d->unregistering)
return;
159 MutexLock lock(d->eventLock);
160 if (d->unregistering)
return;
161 d->unregistering =
true;
167 d->module->coreCtx->services.RemoveServiceRegistration(*
this);
172 throw std::logic_error(
"Service is unregistered");
178 ServiceListeners::ServiceListenerEntries listeners;
180 d->module->coreCtx->listeners.GetMatchingServiceListeners(unregisteringEvent, listeners);
181 d->module->coreCtx->listeners.ServiceChanged(
187 MutexLock lock(d->eventLock);
189 MutexLock lock2(d->propsLock);
190 d->available =
false;
191 InterfaceMap::const_iterator factoryIter = d->service.find(
"org.cppmicroservices.factory");
192 if (d->module && factoryIter != d->service.end())
195 ServiceRegistrationBasePrivate::ModuleToServicesMap::const_iterator end = d->prototypeServiceInstances.end();
198 for (ServiceRegistrationBasePrivate::ModuleToServicesMap::const_iterator i = d->prototypeServiceInstances.begin();
201 for (std::list<InterfaceMap>::const_iterator listIter = i->second.begin();
202 listIter != i->second.end(); ++listIter)
210 catch (
const std::exception& )
212 US_WARN <<
"ServiceFactory UngetService implementation threw an exception";
218 ServiceRegistrationBasePrivate::ModuleToServiceMap::const_iterator moduleEnd = d->moduleServiceInstance.end();
219 for (ServiceRegistrationBasePrivate::ModuleToServiceMap::const_iterator i = d->moduleServiceInstance.begin();
225 serviceFactory->
UngetService(i->first, *
this, i->second);
227 catch (
const std::exception& )
229 US_WARN <<
"ServiceFactory UngetService implementation threw an exception";
234 d->dependents.clear();
236 d->prototypeServiceInstances.clear();
237 d->moduleServiceInstance.clear();
242 d->unregistering =
false;
249 if ((!d && !o.d) || !o.d)
return false;
251 return d->reference <(o.d->reference);
256 return d == registration.d;
261 ServiceRegistrationBasePrivate* curr_d = d;
265 if (curr_d && !curr_d->ref.Deref())
ServiceRegistrationBase & operator=(int null)
const std::type_info & Type() const
~ServiceRegistrationBase()
US_Core_EXPORT const std::string & SERVICE_RANKING()
std::map< std::string, void * > InterfaceMap
ValueType * any_cast(Any *operand)
ServiceReferenceBase GetReference(const std::string &interfaceId=std::string()) const
bool operator<(const ServiceRegistrationBase &o) const
US_Core_EXPORT const std::string & OBJECTCLASS()
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
const ValueType & ref_any_cast(const Any &operand)
bool operator==(const ServiceRegistrationBase ®istration) const
virtual void UngetService(Module *module, const ServiceRegistrationBase ®istration, const InterfaceMap &service)=0
void SetProperties(const ServiceProperties &properties)
US_Core_EXPORT const std::string & SERVICE_ID()