Apply feedbacks
authorChanggyu Choi <changyu.choi@samsung.com>
Wed, 14 May 2025 09:02:09 +0000 (18:02 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Wed, 14 May 2025 09:02:19 +0000 (18:02 +0900)
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
15 files changed:
src/activation_method/dbus_monitor.cc
src/activation_method/dbus_monitor.hh
src/activation_method/fd_monitor.cc
src/activation_method/fd_monitor.hh
src/activation_method/path_info.cc
src/activation_method/path_monitor.cc
src/activation_method/path_monitor.hh
src/activation_method/socket_info.cc
src/activation_method/socket_info.hh
src/event_listener.hh
src/service.cc
src/service.hh
src/service_info.cc
src/service_loader.cc
src/service_loader.hh

index afe94e4c456be94874cbddbd4d9b7c708b1cbf13..09a990308389c64173118b672523f07b3126d4de 100644 (file)
@@ -9,7 +9,7 @@ namespace tizen_base {
 
 DBusMonitor::DBusMonitor(std::string name,
                          std::string bus_name,
-                         IEventListener* listener)
+                         IActivationEventListener* listener)
     : name_(std::move(name)),
       bus_name_(std::move(bus_name)),
       listener_(listener) {
@@ -52,7 +52,7 @@ void DBusMonitor::NameAppearedCb(GDBusConnection* connection,
   _I("name appeared : %s", name);
   auto* self = static_cast<DBusMonitor*>(user_data);
   if (self->bus_name_ == name) {
-    self->listener_->OnEvent(self->name_);
+    self->listener_->OnActivationEvent(self->name_);
   }
 }
 
index 35d02b1d5aa2b9e900be5f8e895ceb48b5734fcc..b500c7ba1e2d7a2016f51044de27f93d903cf136 100644 (file)
@@ -28,7 +28,7 @@ namespace tizen_base {
 
 class DBusMonitor {
  public:
-  DBusMonitor(std::string name, std::string bus_name, IEventListener* listener);
+  DBusMonitor(std::string name, std::string bus_name, IActivationEventListener* listener);
   ~DBusMonitor();
 
   static void BusAcquiredCb(GDBusConnection* connection,
@@ -46,7 +46,7 @@ class DBusMonitor {
   std::string name_;
   std::string bus_name_;
   gint own_id_ = 0;
-  IEventListener* listener_;
+  IActivationEventListener* listener_;
 };
 
 };  // namespace tizen_base
index 01ba28509d0b93866be6ea79335d7184e2a8c4fe..c9b0dc4f0caa4cd4c84c95fcab9219c055c41194 100644 (file)
 #include "../log_private.hh"
 namespace tizen_base {
 
-FdMonitor::FdMonitor(std::string name, int fd, IEventListener* listener)
+FdMonitor::FdMonitor(std::string name, int fd, IActivationEventListener* listener)
     : name_(std::move(name)), listener_(listener) {}
 
 FdMonitor::FdMonitor(std::string name,
                      std::string path,
-                     IEventListener* listener)
+                     IActivationEventListener* listener)
     : name_(std::move(name)), listener_(listener) {
   int n = sd_listen_fds(0);
   if (n < 0) {
@@ -80,7 +80,7 @@ gboolean FdMonitor::UnixFdSourceFunc(gint fd,
   }
 
   _I("Receive event from fd(%d) name(%s)", fd, self->name_.c_str());
-  self->listener_->OnEvent(self->name_);
+  self->listener_->OnActivationEvent(self->name_);
   self->unix_fd_source_id_ = 0;
   return G_SOURCE_REMOVE;
 }
index 59c6e1c70282791de91d93c00438a4784313f7ee..9cc8f2dbea05d85ac698bca4645d7941fb12a597 100644 (file)
@@ -28,15 +28,15 @@ namespace tizen_base {
 
 class FdMonitor {
  public:
-  FdMonitor(std::string, int fd, IEventListener* listener);
-  FdMonitor(std::string name, std::string path, IEventListener* listener);
+  FdMonitor(std::string, int fd, IActivationEventListener* listener);
+  FdMonitor(std::string name, std::string path, IActivationEventListener* listener);
   ~FdMonitor();
   static gboolean UnixFdSourceFunc(gint fd, GIOCondition cond, gpointer data);
 
  private:
   guint unix_fd_source_id_ = 0;
   std::string name_;
-  IEventListener* listener_ = nullptr;
+  IActivationEventListener* listener_ = nullptr;
 };
 
 };
index 19a715511248b64ba2694a70a5181214e94870fd..e2a673357feec4f5e18ebaa5d37c8405fa042387 100644 (file)
@@ -14,7 +14,7 @@ PathInfo::Mode StringToMode(const std::string& str) {
   if (str == "deleted")
     return PathInfo::Mode::Deleted;
 
-  std::runtime_error("Invalid path activation mode: " + str);
+  throw std::runtime_error("Invalid path activation mode: " + str);
 }
 
 }  // namespace
index 2a9457ff3260e669a240c6c4a343e9d670b960bd..de8072def81ea36c792aac035add9463387a4e0d 100644 (file)
@@ -25,12 +25,11 @@ GFileMonitorEvent ConvertType(PathInfo::Mode mode) {
 PathMonitor::PathMonitor(std::string name,
                          std::string path,
                          PathInfo::Mode mode,
-                         IEventListener* listener)
+                         IActivationEventListener* listener)
     : name_(std::move(name)), mode_(mode), listener_(listener) {
   fs::path full_path = fs::path(path);
   std::error_code error;
 
-  listener_ = listener;
   dir_path_ = full_path.parent_path();
   target_name_ = full_path.filename().string();
   dir_ = g_file_new_for_path(dir_path_.c_str());
@@ -45,11 +44,15 @@ PathMonitor::PathMonitor(std::string name,
 
   g_signal_connect(monitor_, "changed", G_CALLBACK(OnFileChanged), this);
   if (mode_ == PathInfo::Mode::Created && fs::exists(full_path, error)) {
-    if (monitor_)
+    if (monitor_) {
       g_object_unref(monitor_);
+      monitor_ = nullptr;
+    }
 
-    if (dir_)
+    if (dir_) {
       g_object_unref(dir_);
+      dir_ = nullptr;
+    }
 
     NotifyEvent();
   }
@@ -73,7 +76,6 @@ gboolean PathMonitor::OnFileChanged(GFileMonitor* monitor,
   gchar* basename = g_file_get_basename(file);
   GFileMonitorEvent target_event = ConvertType(self->mode_);
 
-  _W("[%s] %d", basename, event_type);
   if (event_type == target_event && strcmp(basename, file_name.c_str()) == 0) {
     self->NotifyEvent();
     return G_SOURCE_REMOVE;
@@ -87,7 +89,7 @@ void PathMonitor::NotifyEvent() {
       +[](gpointer data) -> gboolean {
         auto* self = static_cast<PathMonitor*>(data);
         if (self->listener_)
-          self->listener_->OnEvent(self->name_);
+          self->listener_->OnActivationEvent(self->name_);
         return G_SOURCE_REMOVE;
       },
       this);
index 037738925a5c6bad1800e93cd36a659f1e8b2b52..108cfc96966faf46ffbf9add962c13685de9886b 100644 (file)
@@ -35,7 +35,7 @@ class PathMonitor {
   PathMonitor(std::string name,
               std::string path,
               PathInfo::Mode mode,
-              IEventListener* listener);
+              IActivationEventListener* listener);
 
   ~PathMonitor();
 
@@ -54,7 +54,7 @@ class PathMonitor {
   fs::path dir_path_;
   std::string target_name_;
   PathInfo::Mode mode_;
-  IEventListener* listener_;
+  IActivationEventListener* listener_;
 };
 
 };  // namespace tizen_base
index 54b3de86719f21b1fdc07542cf5b41cbdf9129b9..8a6fbc5d1cee3b934379e2611d8f9398d3b8fd40 100644 (file)
@@ -4,15 +4,11 @@
 
 namespace tizen_base {
 
-SocketInfo::SocketInfo(std::string path, int mode)
-    : path_(std::move(path)), mode_(mode) {}
+SocketInfo::SocketInfo(std::string path)
+    : path_(std::move(path)) {}
 
 const std::string& SocketInfo::GetPath() const {
   return path_;
 }
 
-int SocketInfo::GetMode() const {
-  return mode_;
-}
-
 }  // namespace tizen_base
index 3b26a698dc1fb147f0c354e4981cf29636e74c5f..de0dcfcf869844652900179870918e347261f5d0 100644 (file)
@@ -23,13 +23,11 @@ namespace tizen_base {
 
 class SocketInfo {
  public:
-  SocketInfo(std::string path, int mode);
+  SocketInfo(std::string path);
   const std::string& GetPath() const;
-  int GetMode() const;
 
  private:
   std::string path_;
-  int mode_;
 };
 
 }  // namespace tizen_base
index 1b4ed635dbfc5c92bcdad1ceb0065d2fd08a628d..bc31cb9b483b746c4ee9aeb3f1d9f586d0b12bd6 100644 (file)
@@ -21,9 +21,9 @@
 
 namespace tizen_base {
 
-class IEventListener {
+class IActivationEventListener {
  public:
-  virtual void OnEvent(const std::string& name) = 0;
+  virtual void OnActivationEvent(const std::string& name) = 0;
 };
 
 }  // namespace tizen_base
index e05a4f2efa857c34dc519dfc67e80d342b542282..5576ee5714979f8672049485ddc652cac9e5b2a8 100644 (file)
@@ -251,7 +251,7 @@ bool Service::IsMonitoring() const {
   return monitoring_;
 }
 
-void Service::StartMonitoring(IEventListener* listener) {
+void Service::StartMonitoring(IActivationEventListener* listener) {
   if (monitoring_) {
     _W("Already monitoring");
     return;
index f1ec9636c0ed994968f61a947e231d04ad957c36..c28ec4bb7a5abcc200fb70f2d05fe40b0ee6bce1 100644 (file)
@@ -73,7 +73,7 @@ class Service : public std::enable_shared_from_this<Service> {
   void SetStateChangedCb(StateChangedCb cb);
 
   bool IsMonitoring() const;
-  void StartMonitoring(IEventListener* listener);
+  void StartMonitoring(IActivationEventListener* listener);
   void StopMonitoring();
 
  private:
index cf97ca0cd1dcfa00eeba2c44038ed2613ae4ae71..566343f1cbffa7a9e7a0350e805faa1567b85bf7 100644 (file)
@@ -86,7 +86,7 @@ ServiceInfo::ServiceInfo(std::string conf_name,
             "No socket activation method defined in configuration file: " +
             conf_name_);
 
-      socket_info_ = std::make_shared<SocketInfo>(std::move(socket), 0);
+      socket_info_ = std::make_shared<SocketInfo>(std::move(socket));
     } else if (type_ == "path") {
       std::string path = dictionary->Get(kPathActivation);
       if (path.empty())
index 5601b817f592a116bdca953bbffd4737ca83ef2a..3c54ad3cf89916185458ebf0b6644f6ed67e1dd3 100755 (executable)
@@ -398,7 +398,7 @@ void ServiceLoader::OnMessageReceived(const std::string& sender,
 void ServiceLoader::OnServiceStateChanged(const Service* service,
                                           Service::State state) {}
 
-void ServiceLoader::OnEvent(const std::string& name) {
+void ServiceLoader::OnActivationEvent(const std::string& name) {
   auto it = services_.find(name);
 
   if (it != services_.end()) {
index 5f826cda0695b2fd5c51e87fe71b4b4da28bb582..d018c82d24ede6d49ba5b1d06ae19050b711b66b 100644 (file)
@@ -38,7 +38,7 @@
 
 namespace tizen_base {
 
-class ServiceLoader : public IEventListener {
+class ServiceLoader : public IActivationEventListener {
  public:
   ServiceLoader(int argc, char** argv, std::string name);
   ~ServiceLoader();
@@ -62,7 +62,7 @@ class ServiceLoader : public IEventListener {
   virtual void OnServiceStateChanged(const Service* service,
                                      Service::State state);
 
-  void OnEvent(const std::string& name) override;
+  void OnActivationEvent(const std::string& name) override;
 
  private:
   std::shared_ptr<Service> GetService(const std::string& name);