Fix wrong implementation
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 19 Mar 2025 12:23:15 +0000 (21:23 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 19 Mar 2025 12:23:15 +0000 (21:23 +0900)
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/dictionary.cc
src/service.cc
src/service.hh
src/service_context.cc
src/service_info.cc
src/service_loader.cc
src/stub_service_loader.cc

index 20420450568489a137470e5afbcde7e23c31d97f..850929c1faffac0ee9673aa24c3d41a24de16623 100644 (file)
 
 #include "dictionary.hh"
 
+#include <utility>
+
+#include "log_private.hh"
+
 namespace tizen_base {
 
 Dictionary::Builder& Dictionary::Builder::SetNumber(dictionary* d) {
@@ -32,6 +36,7 @@ Dictionary::Builder& Dictionary::Builder::SetEntries(dictionary* d) {
   for (unsigned int i = 0; i < d->n; ++i) {
     std::string key = d->key[i] ? d->key[i] : "";
     std::string value = d->val[i] ? d->val[i] : "";
+    _D("key=%s, value=%s", key.c_str(), value.c_str());
     map_[std::move(key)] = std::move(value);
   }
 
index a68f2f50c1a9d94b0ad703f0dc04c3a0447bf746..ba764c965582832c9d2b032b1f80123c161e7a92 100644 (file)
@@ -124,17 +124,20 @@ void Service::Run() {
 void Service::Quit() {
   if (!running_) return;
 
+  std::unique_lock<std::mutex> lock(mutex_);
   tizen_core_source_h source = nullptr;
   tizen_core_add_idle_job(
       core_,
       [](void* user_data) -> bool {
         auto* service = static_cast<Service*>(user_data);
         service->OnDestroy();
+        service->cond_var_.notify_one();
         return false;
       },
       this, &source);
 
   tizen_core_task_quit(task_);
+  cond_var_.wait(lock, [this]() { return state_ == State::Destroyed; });
   running_ = false;
 }
 
index d03cc8f110f8f3f06e68e6b3dc474b6c8690840a..fab5cfd1b6884852faf47a7934e65f457453e75d 100644 (file)
@@ -21,7 +21,9 @@
 #include <tizen_core.h>
 #include <tizen_core_channel.h>
 
+#include <condition_variable>
 #include <memory>
+#include <mutex>
 #include <string>
 
 namespace tizen_base {
@@ -67,6 +69,8 @@ class Service : public std::enable_shared_from_this<Service> {
   tizen_core_channel_receiver_h receiver_ = nullptr;
   tizen_core_source_h source_ = nullptr;
   bool running_ = false;
+  std::mutex mutex_;
+  std::condition_variable cond_var_;
 };
 
 } // namespace tizen_base
index 31ddcdbebdd610adc58da6471c3c87c47fecf89a..8864417ba15ebf52ff04aa9be3282fd9cbc94640 100644 (file)
@@ -63,6 +63,8 @@ bool ServiceContext::Init() {
 void ServiceContext::Shutdown() {
   if (!handle_) return;
 
+  if (service_) service_->Quit();
+
   auto* shutdown_func =
       reinterpret_cast<void (*)(void)>(dlsym(handle_, kUnitedServiceShutdown));
   if (shutdown_func == nullptr) {
index 9b2d8bc7b3cbd52185560e934f3964ec792135b5..0c17c59a1347e54cc35aee273eabc83019d696af 100644 (file)
 
 namespace {
 
-static const std::string kTagUnitedService = "United-Service";
-static const std::string kDescription = kTagUnitedService + ":Description";
-static const std::string kName = kTagUnitedService + ":Name";
-static const std::string kMode = kTagUnitedService + ":Mode";
-static const std::string kType = kTagUnitedService + ":Type";
-static const std::string kPath = kTagUnitedService + ":Path";
+static const std::string kTagUnitedService = "united-service";
+static const std::string kDescription = kTagUnitedService + ":description";
+static const std::string kName = kTagUnitedService + ":name";
+static const std::string kMode = kTagUnitedService + ":mode";
+static const std::string kType = kTagUnitedService + ":type";
+static const std::string kPath = kTagUnitedService + ":path";
 
 }  // namespace
 
@@ -37,10 +37,15 @@ ServiceInfo::ServiceInfo(std::string conf_name,
                          std::shared_ptr<Dictionary> dictionary)
     : conf_name_(std::move(conf_name)) {
   description_ = dictionary->Get(kDescription);
+  _D("Description=%s", description_.c_str());
   name_ = dictionary->Get(kName);
+  _D("Name=%s", name_.c_str());
   mode_ = dictionary->Get(kMode);
+  _D("Mode=%s", mode_.c_str());
   type_ = dictionary->Get(kType);
+  _D("Type=%s", type_.c_str());
   path_ = dictionary->Get(kPath);
+  _D("Path=%s", path_.c_str());
 }
 
 ServiceInfo::~ServiceInfo() {}
index 42692bd1fa5825ab65c250de6dd7e90e17227b89..95f00077963204a0ef9e891ce2cc6085f6f5ee94 100644 (file)
@@ -71,18 +71,8 @@ bool ServiceLoader::Init() {
     _E("tizen_core_add_channel() is failed");
     return false;
   }
-  receiver_ = nullptr;
-
-  try {
-    LoadServices();
-  } catch (const fs::filesystem_error& e) {
-    _E("Exception occurs. error: %s(%d)", e.what(), e.code().value());
-    return false;
-  } catch (const Exception& e) {
-    _E("Exception occurs. error: %s", e.what());
-    return false;
-  }
 
+  receiver_ = nullptr;
   return true;
 }
 
@@ -155,9 +145,21 @@ void ServiceLoader::SendMessage(const tizen_base::Bundle& envelope) {
   }
 }
 
-void ServiceLoader::OnCreate() {}
+void ServiceLoader::OnCreate() {
+  try {
+    LoadServices();
+  } catch (const fs::filesystem_error& e) {
+    _E("Exception occurs. error: %s(%d)", e.what(), e.code().value());
+  } catch (const Exception& e) {
+    _E("Exception occurs. error: %s", e.what());
+  }
+}
 
-void ServiceLoader::OnDestroy() {}
+void ServiceLoader::OnDestroy() {
+  for (auto& context : contexts_) {
+    context->Shutdown();
+  }
+}
 
 void ServiceLoader::OnMessageReceived(const std::string& sender,
                                       const tizen_base::Bundle& envelope) {}
index 1059fa30fc79f62cb7a6418d3233aed533fbbd8a..83e95dc8445e717f59fe9e533bbf7fd10e77b31c 100644 (file)
@@ -51,10 +51,12 @@ class ServiceLoaderExt : public tizen_base::ServiceLoader {
   }
 
   void OnCreate() override {
+    tizen_base::ServiceLoader::OnCreate();
     if (callback_.create) callback_.create(user_data_);
   }
 
   void OnDestroy() override {
+    tizen_base::ServiceLoader::OnDestroy();
     if (callback_.destroy) callback_.destroy(user_data_);
   }