| 82 | } |
| 83 | |
| 84 | ServiceRegistrationBase ServiceRegistry::RegisterService(ModulePrivate* module, |
| 85 | const InterfaceMap& service, |
| 86 | const ServiceProperties& properties) |
| 87 | { |
| 88 | if (service.empty()) |
| 89 | { |
| 90 | throw std::invalid_argument("Can't register empty InterfaceMap as a service"); |
| 91 | } |
| 92 | |
| 93 | // Check if we got a service factory |
| 94 | bool isFactory = service.count("org.cppmicroservices.factory") > 0; |
| 95 | bool isPrototypeFactory = (isFactory ? dynamic_cast<PrototypeServiceFactory*>(reinterpret_cast<ServiceFactory*>(service.find("org.cppmicroservices.factory")->second)) != nullptr : false); |
| 96 | |
| 97 | std::vector<std::string> classes; |
| 98 | // Check if service implements claimed classes and that they exist. |
| 99 | for (InterfaceMap::const_iterator i = service.begin(); |
| 100 | i != service.end(); ++i) |
| 101 | { |
| 102 | if (i->first.empty() || (!isFactory && i->second == nullptr)) |
| 103 | { |
| 104 | throw std::invalid_argument("Can't register as null class"); |
| 105 | } |
| 106 | classes.push_back(i->first); |
| 107 | } |
| 108 | |
| 109 | ServiceRegistrationBase res(module, service, |
| 110 | CreateServiceProperties(properties, classes, isFactory, isPrototypeFactory)); |
| 111 | { |
| 112 | MutexLock lock(mutex); |
| 113 | services.insert(std::make_pair(res, classes)); |
| 114 | serviceRegistrations.push_back(res); |
| 115 | for (std::vector<std::string>::const_iterator i = classes.begin(); |
| 116 | i != classes.end(); ++i) |
| 117 | { |
| 118 | std::vector<ServiceRegistrationBase>& s = classServices[*i]; |
| 119 | std::vector<ServiceRegistrationBase>::iterator ip = |
| 120 | std::lower_bound(s.begin(), s.end(), res); |
| 121 | s.insert(ip, res); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | ServiceReferenceBase r = res.GetReference(std::string()); |
| 126 | ServiceListeners::ServiceListenerEntries listeners; |
| 127 | ServiceEvent registeredEvent(ServiceEvent::REGISTERED, r); |
| 128 | module->coreCtx->listeners.GetMatchingServiceListeners(registeredEvent, listeners); |
| 129 | module->coreCtx->listeners.ServiceChanged(listeners, |
| 130 | registeredEvent); |
| 131 | return res; |
| 132 | } |
| 133 | |
| 134 | void ServiceRegistry::UpdateServiceRegistrationOrder(const ServiceRegistrationBase& sr, |
| 135 | const std::vector<std::string>& classes) |
nothing calls this directly
no test coverage detected