#include <glib.h>
#include <tizen_core.h>
-#include <chrono>
#include <stdexcept>
#include <utility>
service->OnBaseCreate();
service->state_ = Service::State::Running;
service->NotifyStateChanged();
- service->cond_var_.notify_one();
return false;
}, this, &source);
if (source == nullptr) _E("Failed to add idle job");
}
-void Service::WaitRun() {
- _E("@@ wait run : %s", GetName().c_str());
- std::unique_lock<std::mutex> lock(mutex_);
-
- if (!cond_var_.wait_for (lock, std::chrono::milliseconds(500),
- [this]() { return state_ == State::Running; }))
- _E("@@ wait timeout : %s", GetName().c_str());
-
- _E("@@ wait end : %s", GetName().c_str());
-}
-
void Service::SendMessage(const tizen_base::Bundle& envelope) {
tizen_base::Bundle msg(envelope);
tizen_core_channel_object_h object = nullptr;
constexpr const char kPathUnitedService[] = "/usr/share/united-service/";
constexpr const char kConf[] = "/conf/";
-bool compare_priority(const std::pair<std::string, unsigned int>& pair1,
+bool ComparePriority(const std::pair<std::string, unsigned int>& pair1,
const std::pair<std::string, unsigned int>& pair2) {
return pair1.second > pair2.second;
}
-std::string GetServiceState(tizen_base::Service::State state) {
+std::string ServiceStateToString(tizen_base::Service::State state) {
switch(state) {
case tizen_base::Service::State::Initialized:
return std::string("Initialized");
}
if (!orders_.empty())
- std::sort(orders_.begin(), orders_.end(), compare_priority);
+ std::sort(orders_.begin(), orders_.end(), ComparePriority);
}
int ServiceLoader::Run() {
}
void ServiceLoader::RunService(const std::string& name) {
+ _W("Run service : %s", name.c_str());
+
auto service = GetService(name);
if (service != nullptr && service->IsRunning()) {
_E("Already running. name=%s", name.c_str());
}
void ServiceLoader::RunAllServices() {
- unsigned int previois_prority = 0;
- std::shared_ptr<Service> previous_service = nullptr;
+ _W("RunAllServices : %d", orders_.size());
for (auto& order : orders_) {
- try {
- _E("Run service : %s, priority : %d, pre priority : %d", order.first.c_str(), order.second, previois_prority);
-
- auto info = GetServiceInfo(order.first);
- if (info->GetMode() == "on-demand") {
- _E("%s is on-demand mode. skip to run", order.first.c_str());
- continue;
- }
-
- if (previois_prority == 0)
- previois_prority = order.second;
+ _E("Add order queue service : %s, priority : %d", order.first.c_str(), order.second);
- if (previois_prority == order.second) {
- RunService(order.first);
+ auto info = GetServiceInfo(order.first);
+ if (info->GetMode() == "on-demand") {
+ _E("%s is on-demand mode. skip to run", order.first.c_str());
+ continue;
+ }
- previous_service = GetService(order.first);
- } else {
- if (previous_service != nullptr) {
- previous_service->WaitRun();
- _E("[%s] pre service state is %s", previous_service->GetName().c_str(), GetServiceState(previous_service->GetState()).c_str());
- }
+ order_queue_.push(order.first);
+ }
- RunService(order.first);
+ try {
+ RunService(order_queue_.front());
- previous_service = GetService(order.first);
- }
- } catch (const Exception& e) {
- _E("Error=%s", e.what());
- }
+ order_queue_.pop();
+ } catch (const Exception& e) {
+ _E("Error=%s", e.what());
}
}
void ServiceLoader::ServiceStateChangedCb(const Service* service,
Service::State state) {
- _W("ServiceStateChangedCb %s, state : %s", service->GetName().c_str(), GetServiceState(state).c_str());
+ _W("ServiceStateChangedCb %s, state : %s",
+ service->GetName().c_str(), ServiceStateToString(state).c_str());
+
+ if (state == Service::State::Running) {
+ if (!order_queue_.empty()) {
+ try {
+ RunService(order_queue_.front());
+ order_queue_.pop();
+ } catch (const Exception& e) {
+ _E("Error=%s", e.what());
+ }
+ }
+ }
OnServiceStateChanged(service, state);
if (state == Service::State::Destroyed) {