Modify sending ping request 58/308658/4
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 28 Mar 2024 10:41:44 +0000 (19:41 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Thu, 28 Mar 2024 11:07:56 +0000 (11:07 +0000)
This patch changes the ping request to asynchronous.

Change-Id: Ia37d49b9e6f2f74434e510bbad1147e699f554f5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_launchpad.cc
src/lib/amd_launchpad.h
src/lib/amd_login_monitor.c
src/lib/amd_request.cc
src/lib/amd_request.h

index cf0378a4b967b32115dd91a7d469c67582ea93cd..6a88973dda79d79e035f88950ec3d4773aea56ec 100644 (file)
@@ -146,19 +146,18 @@ class Launchpad : public ClientChannel::IEvent {
     return inst;
   }
 
-  int Launch(unsigned int id, bundle* request, uid_t uid,
+  int SendRequest(unsigned int id, int cmd, bundle* request, uid_t uid,
       launchpad_result_cb cb, void* data) {
     try {
-      auto client_channel = std::make_shared<ClientChannel>(uid, id, cb, data,
-          this);
+      auto client_channel =
+          std::make_shared<ClientChannel>(uid, id, cb, data, this);
       std::string endpoint = GetEndpoint(uid, LAUNCHPAD_PROCESS_POOL_SOCK);
       client_channel->Connect(endpoint);
       client_channel->SetSendBufferSize(AUL_SOCK_MAXBUFF);
       client_channel->SetReceiveBufferSize(AUL_SOCK_MAXBUFF);
       client_channel->SetReceiveTimeout(5000);
 
-      tizen_base::Parcel parcel = CreateParcel(PAD_CMD_LAUNCH, AUL_SOCK_ASYNC,
-          request);
+      tizen_base::Parcel parcel = CreateParcel(cmd, AUL_SOCK_ASYNC, request);
       int ret = client_channel->Send(parcel.GetData(), parcel.GetDataSize());
       if (ret != 0) {
         _E("Send() is failed. error(%d)", ret);
@@ -174,6 +173,11 @@ class Launchpad : public ClientChannel::IEvent {
     return 0;
   }
 
+  int Launch(unsigned int id, bundle* request, uid_t uid,
+      launchpad_result_cb cb, void* data) {
+    return SendRequest(id, PAD_CMD_LAUNCH, request, uid, cb, data);
+  }
+
   static std::string GetEndpoint(uid_t uid, const std::string& name) {
     return "/run/aul/daemons/" + std::to_string(uid) + "/" + name;
   }
@@ -232,3 +236,11 @@ int _launchpad_send_hint(uid_t uid, int hint) {
   tizen_base::Bundle b;
   return SendAndReceive(b.GetHandle(), uid, hint);
 }
+
+int _launchpad_send_request_with_result_cb(unsigned int id, int cmd,
+                                           bundle* request, uid_t uid,
+                                           launchpad_result_cb callback,
+                                           void* user_data) {
+  return Launchpad::GetInst().SendRequest(id, cmd, request, uid, callback,
+                                          user_data);
+}
index ce0f70e00e85712b51df4767bfead0dc3164a4d1..0f3aa8a7ee63a01e607dab9bb990734363d81ae2 100644 (file)
@@ -29,10 +29,13 @@ typedef void (*launchpad_result_cb)(unsigned int id, int result,
                void* user_data);
 
 int _launchpad_launch_with_result_cb(unsigned int id, bundle *request,
-               uid_t uid, launchpad_result_cb callback, voiduser_data);
+               uid_t uid, launchpad_result_cb callback, void *user_data);
 
 int _launchpad_send_hint(uid_t uid, int hint);
 
+int _launchpad_send_request_with_result_cb(unsigned int id, int cmd,
+               bundle *request, uid_t uid, launchpad_result_cb callback, void *user_data);
+
 #ifdef __cplusplus
 }
 #endif
index ce69f94007229a87af3f3229d7ccbcba5b6d6637..1864fe66394b642e439685f9a1651763f64765dc 100644 (file)
@@ -37,6 +37,7 @@
 #include "amd_config.h"
 #include "amd_cynara.h"
 #include "amd_launch.h"
+#include "amd_launchpad.h"
 #include "amd_login_monitor.h"
 #include "amd_noti.h"
 #include "amd_request.h"
@@ -129,7 +130,6 @@ static logout_handler logout_table[] = {
        }
 };
 
-static int __connect_to_launchpad(uid_t uid);
 static void __user_login(struct user_s *user);
 static struct user_s *__find_user(uid_t uid);
 
@@ -529,14 +529,55 @@ static void __add_login_timer(struct user_s *user)
                        __login_timeout_handler, user);
 }
 
+static void __launchpad_ping_result_cb(unsigned int id, int result,
+               void *user_data)
+{
+       uid_t uid = GPOINTER_TO_UINT(user_data);
+       struct user_s *user;
+
+       __set_launchpad_pid(uid, result);
+       _W("[PAD_CMD_PING] uid: %u, result: %d", uid, result);
+
+       user = __find_user(uid);
+       if (user) {
+               user->state = UID_STATE_ONLINE;
+         __user_login(user);
+       }
+}
+
+static void __send_ping_to_launchpad(uid_t uid)
+{
+       int ret;
+       bundle *b;
+       char path[PATH_MAX];
+
+       snprintf(path, sizeof(path), "%s/%d/%s",
+                       PATH_AUL_DAEMONS, uid, LAUNCHPAD_PROCESS_POOL_SOCK);
+       if (access(path, F_OK) != 0) {
+               _D("%s doesn't exist", path);
+               return;
+       }
+
+       b = bundle_create();
+       if (b == NULL) {
+               _E("out of memory");
+               return;
+       }
+
+       ret = _launchpad_send_request_with_result_cb(_request_generate_id(),
+                       PAD_CMD_PING, b, uid, __launchpad_ping_result_cb,
+                       GUINT_TO_POINTER(uid));
+       bundle_free(b);
+       if (ret < 0)
+               _E("Failed to send ping request. uid(%u), error(%d)", uid, ret);
+}
+
 static void __user_login(struct user_s *user)
 {
        unsigned int i;
 
        if (user->state == UID_STATE_OPENING) {
-               if (__connect_to_launchpad(user->uid) == 0)
-                       user->state = UID_STATE_ONLINE;
-
+               __send_ping_to_launchpad(user->uid);
                __add_login_timer(user);
        }
 
@@ -653,38 +694,6 @@ int _login_monitor_get_uids(uid_t **uids)
        return r;
 }
 
-static int __connect_to_launchpad(uid_t uid)
-{
-       int r;
-       bundle *b;
-       char path[PATH_MAX];
-
-       snprintf(path, sizeof(path), "%s/%d/%s",
-                       PATH_AUL_DAEMONS, uid, LAUNCHPAD_PROCESS_POOL_SOCK);
-       if (access(path, F_OK) != 0) {
-               _D("%s doesn't exist", path);
-               return -1;
-       }
-
-       b = bundle_create();
-       if (b == NULL) {
-               _E("out of memory");
-               return -1;
-       }
-
-       r = _send_cmd_to_launchpad(LAUNCHPAD_PROCESS_POOL_SOCK,
-                       uid, PAD_CMD_PING, b);
-       bundle_free(b);
-       if (r < 0) {
-               _E("Failed to connect launchpad - uid(%d), result(%d)", uid, r);
-               return -1;
-       }
-
-       __set_launchpad_pid(uid, r);
-
-       return 0;
-}
-
 static void __check_user_state(void)
 {
        uid_t *uids = NULL;
index 15e3201096983902d7720166d1d94fb73cc27ad3..c56b40e15976a97ca9ecc1c03fb99494ab4f167c 100644 (file)
@@ -245,3 +245,7 @@ void _request_fini(void) {
   _D("request fini");
   amd::RequestManager::GetInst().Fini();
 }
+
+unsigned int _request_generate_id(void) {
+  return amd::Request::GenerateRequestID();
+}
index c2548cb3a804f70fa1d8ab9c227c3a75744f6ef8..5bb524633a26cfb480d91342087bb39884b2d7d9 100644 (file)
@@ -96,6 +96,8 @@ const char *_request_get_request_type(request_h req);
 
 unsigned int _request_get_timeout(request_h req);
 
+unsigned int _request_generate_id(void);
+
 #ifdef __cplusplus
 }
 #endif