THROW(SERVICE_ERROR_INVALID_CONTEXT);
}
- if (service == nullptr)
+ if (service == nullptr) {
service = std::make_shared<Service>(std::move(info), std::move(listener));
+ if (service == nullptr) {
+ _E("Out of memory. name=%s", name.c_str());
+ THROW(SERVICE_ERROR_OUT_OF_MEMORY);
+ }
+
+ services_[name] = service;
+ }
if (service->IsMonitoring())
service->StopMonitoring();
- if (service == nullptr) {
- _E("Out of memory. name=%s", name.c_str());
- THROW(SERVICE_ERROR_OUT_OF_MEMORY);
- }
-
service->SetStateChangedCb(std::bind(&ServiceLoader::ServiceStateChangedCb,
this, std::placeholders::_1,
std::placeholders::_2));
- services_[name] = service;
service->Run();
}
THROW(SERVICE_ERROR_OUT_OF_MEMORY);
}
- service->SetStateChangedCb(std::bind(&ServiceLoader::ServiceStateChangedCb,
- this, std::placeholders::_1,
- std::placeholders::_2));
services_[name] = service;
service->StartMonitoring(this);
}
_I("%s on-demand launch", name.c_str());
auto& service = it->second;
service->StopMonitoring();
- service->Run();
+ RunService(service->GetName());
}
}
}
}
- OnServiceStateChanged(service, state);
- if (state == Service::State::Destroyed) {
+ _W("Service state changed. name=%s, state=%d", service->GetName().c_str(), static_cast<int>(state));
+ if (state == Service::State::Destroyed)
services_.erase(service->GetName());
- }
+
+ OnServiceStateChanged(service, state);
}
} // namespace tizen_base
void OnMessageReceived(const std::string& sender,
const tizen_base::Bundle& envelope) override {
+ ServiceLoader::OnMessageReceived(sender, envelope);
if (callback_.message)
callback_.message(sender.c_str(), envelope.GetHandle(), user_data_);
}
void OnServiceStateChanged(const tizen_base::Service* service,
- tizen_base::Service::State state) {}
+ tizen_base::Service::State state) {
+ _W("state: %d, mode: %s", static_cast<int>(state), service->GetServiceInfo()->GetMode().c_str());
+ if (state == tizen_base::Service::State::Destroyed &&
+ service->GetServiceInfo()->GetMode() == "on-demand") {
+ _W("monitoring start");
+ context->ListenService(service->GetName());
+ }
+ }
private:
service_loader_lifecycle_callback_s callback_;