TODO: Return proper error/status instead of BOOL?
| 62 | |
| 63 | // TODO: Return proper error/status instead of BOOL? |
| 64 | bool startService(const std::string& id) { |
| 65 | LOGGER.info("Starting {}", id); |
| 66 | auto manifest = findManifestById(id); |
| 67 | if (manifest == nullptr) { |
| 68 | LOGGER.error("manifest not found for service {}", id); |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | auto service_instance = std::make_shared<ServiceInstance>(manifest); |
| 73 | |
| 74 | // Register first, so that a service can retrieve itself during onStart() |
| 75 | instance_mutex.lock(); |
| 76 | service_instance_map[manifest->id] = service_instance; |
| 77 | instance_mutex.unlock(); |
| 78 | |
| 79 | service_instance->setState(State::Starting); |
| 80 | if (service_instance->getService()->onStart(*service_instance)) { |
| 81 | service_instance->setState(State::Started); |
| 82 | } else { |
| 83 | LOGGER.error("Starting {} failed", id); |
| 84 | service_instance->setState(State::Stopped); |
| 85 | instance_mutex.lock(); |
| 86 | service_instance_map.erase(manifest->id); |
| 87 | instance_mutex.unlock(); |
| 88 | } |
| 89 | |
| 90 | LOGGER.info("Started {}", id); |
| 91 | |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | std::shared_ptr<ServiceContext> findServiceContextById(const std::string& id) { |
| 96 | return findServiceInstanceById(id); |
no test coverage detected