MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / startService

Function startService

Tactility/Source/service/ServiceRegistration.cpp:64–93  ·  view source on GitHub ↗

TODO: Return proper error/status instead of BOOL?

Source from the content-addressed store, hash-verified

62
63// TODO: Return proper error/status instead of BOOL?
64bool 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
95std::shared_ptr<ServiceContext> findServiceContextById(const std::string& id) {
96 return findServiceInstanceById(id);

Callers 2

addServiceFunction · 0.85
attachDevicesFunction · 0.85

Calls 8

findManifestByIdFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80
getServiceMethod · 0.80
lockMethod · 0.45
unlockMethod · 0.45
setStateMethod · 0.45
onStartMethod · 0.45

Tested by

no test coverage detected