Use dbus activation for server execution 63/308763/1
authorIlho Kim <ilho159.kim@samsung.com>
Sun, 31 Mar 2024 01:26:48 +0000 (10:26 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Sun, 31 Mar 2024 01:26:48 +0000 (10:26 +0900)
Change-Id: Ia5274b1936d1a5bfc3b52c8f0fb5033b7480e16c
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
client/src/connector.cc
client/src/connector.hh

index 381fe45..af400bd 100644 (file)
@@ -124,7 +124,7 @@ bool Connector::ConnectForAdmin() {
   if (conn_admin_listener_.GetState() == ConnectionState::Connected)
     return true;
 
-  if (!activator_.Connect())
+  if (!activator_.Connect(raw_pc_, "install"))
     return false;
 
   try {
@@ -145,7 +145,7 @@ bool Connector::ConnectForInfo() {
   if (conn_info_listener_.GetState() == ConnectionState::Connected)
     return true;
 
-  if (!activator_.Connect())
+  if (!activator_.Connect(raw_pc_, "getsize"))
     return false;
 
   try {
@@ -166,7 +166,7 @@ bool Connector::ConnectForCache() {
   if (conn_cache_listener_.GetState() == ConnectionState::Connected)
     return true;
 
-  if (!activator_.Connect())
+  if (!activator_.Connect(raw_pc_, "clearcache"))
     return false;
 
   try {
@@ -187,7 +187,7 @@ bool Connector::ConnectForDelayedResult() {
   if (conn_delayed_result_listener_.GetState() == ConnectionState::Connected)
     return true;
 
-  if (!activator_.Connect())
+  if (!activator_.Connect(raw_pc_, "install"))
     return false;
 
   try {
@@ -234,41 +234,57 @@ pkgmgr_client_t* Connector::GetRawPc() {
   return raw_pc_;
 }
 
-bool Connector::Activator::Connect() {
-  if (!Create())
-    return false;
-
-  SetTimeout(60 * 1000);
-
-  int retry_cnt = 3;
-  do {
-    int ret = TryConnect();
-    if (ret == 0) {
-      break;
-    } else if (ret < -1) {
-      _E("Maybe peer not launched or peer dead. path: %s, fd: %d",
-          PACKAGE_MANAGER_SOCKET_PATH, fd_);
-      // If requester is root, don't wait
-      if (getuid() == 0)
-        return false;
-
-      usleep(100 * 1000);
-      --retry_cnt;
-    } else if (ret < 0) {
-      _E("Failed to connect to socket: %s, fd: %d",
-          PACKAGE_MANAGER_SOCKET_PATH, fd_);
-      return false;
-    }
-  } while (retry_cnt > 0);
+bool Connector::Activator::Connect(pkgmgr_client_t* pc, std::string method) {
+       GVariant *result;
+       int ret = PKGMGR_R_ECOMM;
 
-  if (retry_cnt == 0) {
-    _E("Failed to connect with server");
-    return false;
-  }
+       ret = pkgmgr_client_connection_send_request(pc, method.c_str(),
+                       g_variant_new("()"), &result);
+       if (ret != PKGMGR_R_OK) {
+               _E("request failed: %d", ret);
+               return false;
+       }
 
-  return ReceiveReady();
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+  return ret == PKGMGR_R_OK ? true : false;
 }
 
+//bool Connector::Activator::Connect() {
+//  if (!Create())
+//    return false;
+//
+//  SetTimeout(60 * 1000);
+//
+//  int retry_cnt = 3;
+//  do {
+//    int ret = TryConnect();
+//    if (ret == 0) {
+//      break;
+//    } else if (ret < -1) {
+//      _E("Maybe peer not launched or peer dead. path: %s, fd: %d",
+//          PACKAGE_MANAGER_SOCKET_PATH, fd_);
+//      // If requester is root, don't wait
+//      if (getuid() == 0)
+//        return false;
+//
+//      usleep(100 * 1000);
+//      --retry_cnt;
+//    } else if (ret < 0) {
+//      _E("Failed to connect to socket: %s, fd: %d",
+//          PACKAGE_MANAGER_SOCKET_PATH, fd_);
+//      return false;
+//    }
+//  } while (retry_cnt > 0);
+//
+//  if (retry_cnt == 0) {
+//    _E("Failed to connect with server");
+//    return false;
+//  }
+//
+//  return ReceiveReady();
+//}
+
 bool Connector::Activator::Create() {
   if (fd_ != -1)
     return true;
index 29236b3..d8f3499 100644 (file)
@@ -72,7 +72,7 @@ class Connector {
    public:
     Activator() : fd_(-1), addr_{} {}
 
-    bool Connect();
+    bool Connect(pkgmgr_client_t* pc, std::string method);
     bool Create();
     void SetTimeout(int timeout_msec);
     int TryConnect();