| 102 | } |
| 103 | |
| 104 | bool stopService(const std::string& id) { |
| 105 | LOGGER.info("Stopping {}", id); |
| 106 | auto service_instance = findServiceInstanceById(id); |
| 107 | if (service_instance == nullptr) { |
| 108 | LOGGER.warn("Service not running: {}", id); |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | service_instance->setState(State::Stopping); |
| 113 | service_instance->getService()->onStop(*service_instance); |
| 114 | service_instance->setState(State::Stopped); |
| 115 | |
| 116 | instance_mutex.lock(); |
| 117 | service_instance_map.erase(id); |
| 118 | instance_mutex.unlock(); |
| 119 | |
| 120 | if (service_instance.use_count() > 1) { |
| 121 | LOGGER.warn("Possible memory leak: service {} still has {} references", service_instance->getManifest().id, service_instance.use_count() - 1); |
| 122 | } |
| 123 | |
| 124 | LOGGER.info("Stopped {}", id); |
| 125 | |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | State getState(const std::string& id) { |
| 130 | auto service_instance = findServiceInstanceById(id); |
no test coverage detected