Example #1
0
ServiceRef::Ptr ServiceRegistry::registerService(const std::string& name, Service::Ptr pService, const Properties& props)
{
	Poco::ScopedLockWithUnlock<FastMutex> lock(_mutex);

	ServiceMap::iterator it = _services.find(name);
	if (it == _services.end())
	{
		ServiceRef::Ptr pServiceRef(new ServiceRef(name, props, pService));
		pServiceRef->properties().set(PROP_NAME, name);
		pServiceRef->properties().set(PROP_TYPE, std::string(pService->type().name()));
		_services[name] = pServiceRef;
		
		lock.unlock();
		
		ServiceEvent registeredEvent(pServiceRef, ServiceEvent::EV_SERVICE_REGISTERED);
		serviceRegistered(this, registeredEvent);
		
		_logger.information(std::string("Service registered: ") + name);
		
		return pServiceRef;
	}
	else throw Poco::ExistsException(name);
}