This patch changes the ping request to asynchronous.
Change-Id: Ia37d49b9e6f2f74434e510bbad1147e699f554f5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
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);
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;
}
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);
+}
void* user_data);
int _launchpad_launch_with_result_cb(unsigned int id, bundle *request,
- uid_t uid, launchpad_result_cb callback, void* user_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
#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"
}
};
-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);
__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);
}
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;
_D("request fini");
amd::RequestManager::GetInst().Fini();
}
+
+unsigned int _request_generate_id(void) {
+ return amd::Request::GenerateRequestID();
+}
unsigned int _request_get_timeout(request_h req);
+unsigned int _request_generate_id(void);
+
#ifdef __cplusplus
}
#endif