Add main thread service
authorChanggyu Choi <changyu.choi@samsung.com>
Sun, 27 Apr 2025 09:04:12 +0000 (18:04 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Wed, 14 May 2025 11:36:57 +0000 (20:36 +0900)
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
include/service_loader.h
src/service.cc
src/service_info.cc
src/service_info.hh
src/service_loader.cc
src/service_loader.hh

index 55040b8ea5ade3052498507c23bbcc0de72586cd..bac592a9947bcbf9c317fbffa831b1f62ec0c03f 100644 (file)
@@ -21,6 +21,8 @@
 #include <service_types.h>
 #include <tizen_error.h>
 
+#include <service.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -240,6 +242,8 @@ int service_loader_load_service(const char *name);
 
 int service_loader_unload_service(const char *name);
 
+int service_loader_get_service(const char* name, service_h *service);
+
 #ifdef __cplusplus
 }
 #endif
index 5576ee5714979f8672049485ddc652cac9e5b2a8..39d3c6c3b636d2128426359d0702855aabd4a103 100644 (file)
@@ -64,7 +64,12 @@ Service::~Service() {
 
 bool Service::Init() {
   tizen_core_init();
-  int ret = tizen_core_task_create(GetName().c_str(), true, &task_);
+  int ret = false;
+  if (info_->UseMainThread())
+    ret = tizen_core_task_create("main", false, &task_);
+  else
+    ret = tizen_core_task_create(GetName().c_str(), true, &task_);
+
   if (ret != TIZEN_CORE_ERROR_NONE) {
     _E("tizen_core_task_create() is failed. name=%s", GetName().c_str());
     return false;
index 566343f1cbffa7a9e7a0350e805faa1567b85bf7..0c3d4bfb4c474520c402dac082df904670ad10fb 100644 (file)
@@ -39,6 +39,8 @@ static const std::string kVconfActivation = kActivationMethod + ":vconf";
 
 static const int kMinPriority = 1;
 static const int kMaxPriority = 99;
+static const std::string kUseMainThread =
+    kTagUnitedService + ":use-main-thread";
 
 }  // namespace
 
@@ -57,6 +59,9 @@ ServiceInfo::ServiceInfo(std::string conf_name,
   _D("Type=%s", type_.c_str());
   path_ = dictionary->Get(kPath);
   _D("Path=%s", path_.c_str());
+  std::string use_main_thread = dictionary->Get(kUseMainThread);
+  if (use_main_thread == "true")
+    use_main_thread_ = true;
 
   assembly_ = std::make_shared<ServiceAssembly>(path_);
 
@@ -141,6 +146,10 @@ const std::string& ServiceInfo::GetPath() const {
   return path_;
 }
 
+bool ServiceInfo::UseMainThread() const {
+  return use_main_thread_;
+}
+
 const unsigned int ServiceInfo::GetPriority() const { return priority_; }
 
 std::shared_ptr<ServiceAssembly> ServiceInfo::GetAssembly() const {
index c95e436c057de42095bc13f165760e4ba7da6e8d..0a00fd0f43f7f51b8796fa4720914ef343f9c0bb 100644 (file)
@@ -42,6 +42,7 @@ class ServiceInfo {
   const std::string& GetType() const;
   const std::string& GetPath() const;
   const unsigned int GetPriority() const;
+  bool UseMainThread() const;
   std::shared_ptr<ServiceAssembly> GetAssembly() const;
 
   std::shared_ptr<DBusInfo> GetDbusInfo() const;
@@ -50,6 +51,7 @@ class ServiceInfo {
   // std::shared_ptr<VconfInfo> GetVconfInfo() const;
 
  private:
+  bool use_main_thread_ = true;
   std::string conf_name_;
   std::string name_;
   std::string description_;
index 3c54ad3cf89916185458ebf0b6644f6ed67e1dd3..aa181e4928edc821d52fd4032e75dca09599225b 100755 (executable)
@@ -299,6 +299,10 @@ void ServiceLoader::QuitService(const std::string& name) {
     THROW(SERVICE_ERROR_INVALID_CONTEXT);
   }
 
+  if (service->GetServiceInfo()->UseMainThread()) {
+    _E("Cannot quit main thread service. name=%s", service->GetName().c_str());
+    THROW(SERVICE_ERROR_INVALID_CONTEXT);
+  }
   service->Quit();
 }
 
index d018c82d24ede6d49ba5b1d06ae19050b711b66b..d98d1b7fbed5c55865851f4ff9b27ce5fb4fce26 100644 (file)
@@ -54,6 +54,7 @@ class ServiceLoader : public IActivationEventListener {
   void ListenService(const std::string& name);
   void LoadService(const std::string& name);
   void UnloadService(const std::string& name);
+  std::shared_ptr<Service> GetService(const std::string& name);
 
   virtual void OnCreate();
   virtual void OnDestroy();
@@ -65,7 +66,6 @@ class ServiceLoader : public IActivationEventListener {
   void OnActivationEvent(const std::string& name) override;
 
  private:
-  std::shared_ptr<Service> GetService(const std::string& name);
   std::shared_ptr<ServiceInfo> GetServiceInfo(const std::string& name);
   void ServiceStateChangedCb(const Service* service, Service::State state);