void Activator::ServiceChanged(const ServiceEvent event) { // MutexLocker lock(&m_mutex); if (event.GetType() == ServiceEvent::REGISTERED) { if (!this->ref) { // Get a reference to the service object. this->ref = event.GetServiceReference(); this->axService = this->context->GetService(this->ref); } } // If an Autexousious service was unregistered, see if it // was the one we were using. If so, unget the service // and try to query to get another one. else if (event.GetType() == ServiceEvent::UNREGISTERING) { if (event.GetServiceReference() == this->ref) { // Unget service object and null references. this->context->UngetService(this->ref); this->ref = 0; this->axService = NULL; // Query to see if we can get another service. std::vector<ServiceReference<sl::ax::engine::AutexousiousService> > refs; try { refs = this->context->GetServiceReferences<sl::ax::engine::AutexousiousService>(); } catch (const std::invalid_argument& e) { std::cout << e.what() << std::endl; } if (!refs.empty()) { // Get a reference to the first service object. this->ref = refs.front(); this->axService = this->context->GetService(this->ref); } } } }
void ServiceListeners::GetMatchingServiceListeners(const ServiceEvent& evt, ServiceListenerEntries& set, bool lockProps) { US_UNUSED(Lock(this)); // Filter the original set of listeners ServiceListenerEntries receivers = serviceSet; coreCtx->serviceHooks.FilterServiceEventReceivers(evt, receivers); // Check complicated or empty listener filters for (std::list<ServiceListenerEntry>::const_iterator sse = complicatedListeners.begin(); sse != complicatedListeners.end(); ++sse) { if (receivers.count(*sse) == 0) continue; const LDAPExpr& ldapExpr = sse->GetLDAPExpr(); if (ldapExpr.IsNull() || ldapExpr.Evaluate(evt.GetServiceReference().d->GetProperties(), false)) { set.insert(*sse); } } //US_DEBUG << "Added " << set.size() << " out of " << n // << " listeners with complicated filters"; // Check the cache const std::vector<std::string> c(any_cast<std::vector<std::string> > (evt.GetServiceReference().d->GetProperty(ServiceConstants::OBJECTCLASS(), lockProps))); for (std::vector<std::string>::const_iterator objClass = c.begin(); objClass != c.end(); ++objClass) { AddToSet(set, receivers, OBJECTCLASS_IX, *objClass); } long service_id = any_cast<long>(evt.GetServiceReference().d->GetProperty(ServiceConstants::SERVICE_ID(), lockProps)); std::stringstream ss; ss << service_id; AddToSet(set, receivers, SERVICE_ID_IX, ss.str()); }
void ServiceListeners::GetMatchingServiceListeners(const ServiceEvent& evt, ServiceListenerEntries& set) { // Filter the original set of listeners ServiceListenerEntries receivers = (this->Lock(), serviceSet); // This must not be called with any locks held coreCtx->serviceHooks.FilterServiceEventReceivers(evt, receivers); // Get a copy of the service reference and keep it until we are // done with its properties. auto ref = evt.GetServiceReference(); auto props = ref.d.load()->GetProperties(); { auto l = this->Lock(); US_UNUSED(l); // Check complicated or empty listener filters for (auto& sse : complicatedListeners) { if (receivers.count(sse) == 0) continue; const LDAPExpr& ldapExpr = sse.GetLDAPExpr(); if (ldapExpr.IsNull() || ldapExpr.Evaluate(props, false)) { set.insert(sse); } } // Check the cache const auto c = any_cast<std::vector<std::string>>(props->Value_unlocked(Constants::OBJECTCLASS)); for (auto& objClass : c) { AddToSet_unlocked(set, receivers, OBJECTCLASS_IX, objClass); } long service_id = any_cast<long>(props->Value_unlocked(Constants::SERVICE_ID)); AddToSet_unlocked(set, receivers, SERVICE_ID_IX, cppmicroservices::util::ToString((service_id))); } }