Add timer for connection
authorJunghoon Park <jh9216.park@samsung.com>
Mon, 28 Oct 2019 10:46:16 +0000 (19:46 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 4 Nov 2019 01:25:43 +0000 (10:25 +0900)
- Dbus name for stub app should be appeared within 10s

Change-Id: I11bd7b54afc9df013171c4083d8f2e1555ea7606
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
src/proxy-internal.cc
src/proxy-internal.h

index 04deef8..3546273 100644 (file)
@@ -40,6 +40,10 @@ Proxy::Proxy(bool mock)
 
 Proxy::~Proxy() {
   LOGD("Proxy::~Proxy");
+  if (conn_timer_) {
+    g_source_remove(conn_timer_);
+    conn_timer_ = 0;
+  }
 }
 
 gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
@@ -96,6 +100,10 @@ void Proxy::OnPortRejected(const std::string& appid) {
 void Proxy::OnPortAppeared(const std::string& appid,
                            const std::string& port_name) {
   LOGD("endpoint(%s), port_name(%s)", appid.c_str(), port_name.c_str());
+  if (conn_timer_) {
+    g_source_remove(conn_timer_);
+    conn_timer_ = 0;
+  }
 
   if (listener_ == nullptr)
     return;
@@ -164,9 +172,24 @@ int Proxy::Connect(std::string appid, std::string port_name,
     return RPC_PORT_ERROR_IO_ERROR;
   }
 
+  if (conn_timer_)
+    g_source_remove(conn_timer_);
+  conn_timer_ = g_timeout_add(10 * 1000, DbusNameTimeout, this);
+
   return RPC_PORT_ERROR_NONE;
 }
 
+gboolean Proxy::DbusNameTimeout(gpointer user_data) {
+  Proxy* obj = static_cast<Proxy*>(user_data);
+
+  LOGW("[__DbusNameTimeout__] endpoint(%s)", obj->target_appid_.c_str());
+  if (obj->listener_)
+    obj->listener_->OnRejected(obj->target_appid_);
+
+  obj->conn_timer_ = 0;
+  return G_SOURCE_REMOVE;
+}
+
 Proxy::ProxyPort::ProxyPort(Proxy* parent, int fd, const std::string& id,
     bool receive) : Port(fd, id), parent_(parent) {
   Watch(receive);
index 642be5b..dce40a0 100644 (file)
@@ -80,6 +80,7 @@ class Proxy : public FdBroker::IEventWatcher {
                                        gpointer data);
   static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond,
                                  gpointer data);
+  static gboolean DbusNameTimeout(gpointer user_data);
   void OnPortAppeared(const std::string& appid,
                       const std::string& port_name) override;
   void OnPortVanished(const std::string& appid,
@@ -98,6 +99,7 @@ class Proxy : public FdBroker::IEventWatcher {
   FdBroker fd_broker_;
   std::string target_appid_;
   int fds_[2];
+  guint conn_timer_ = 0;
 };
 
 }  // namespace internal