From d361ecd9895b22b70ae402ac8262aeed59067ef8 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 5 Aug 2020 08:52:30 +0900 Subject: [PATCH] Add asynchronous app com constructor To avoid getting the error from app com creation, app event functions use aul_app_com_create_async() instead of aul_app_com_create(). Adds: - aul_app_com_create_async() Change-Id: Ic96398eae7580c736255b28a7df5d764837d1ed1 Signed-off-by: Hwankyu Jhun --- aul/app_manager/app_event.cc | 4 ++-- include/aul_app_com.h | 7 ++++++- src/app_com.c | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/aul/app_manager/app_event.cc b/aul/app_manager/app_event.cc index b4d99f8..375b70d 100644 --- a/aul/app_manager/app_event.cc +++ b/aul/app_manager/app_event.cc @@ -32,7 +32,7 @@ AppEvent::AppEvent(std::string app_id, AppEvent::IEvent* ev) if (getuid() >= REGULAR_UID_MIN) endpoint += ":" + std::to_string(getuid()); - int ret = aul_app_com_create(endpoint.c_str(), nullptr, OnAppStatusCb, + int ret = aul_app_com_create_async(endpoint.c_str(), nullptr, OnAppStatusCb, this, &handle_); if (ret != AUL_R_OK) { _E("aul_app_com_create(%s) is failed. error(%d)", endpoint.c_str(), ret); @@ -45,7 +45,7 @@ AppEvent::AppEvent(AppEvent::IEvent* ev) : ev_(ev) { if (getuid() >= REGULAR_UID_MIN) endpoint += ":" + std::to_string(getuid()); - int ret = aul_app_com_create(endpoint.c_str(), nullptr, OnAppStatusCb, + int ret = aul_app_com_create_async(endpoint.c_str(), nullptr, OnAppStatusCb, this, &handle_); if (ret != AUL_R_OK) { _E("aul_app_com_create(%s) is failed. error(%d)", endpoint.c_str(), ret); diff --git a/include/aul_app_com.h b/include/aul_app_com.h index 0a01696..2afd864 100644 --- a/include/aul_app_com.h +++ b/include/aul_app_com.h @@ -103,12 +103,17 @@ void aul_app_com_permission_destroy(aul_app_com_permission_h permission); int aul_app_com_permission_set_propagation(aul_app_com_permission_h permission, aul_app_com_propagate_option_e option); int aul_app_com_permission_set_privilege(aul_app_com_permission_h permission, const char *privilege); - int aul_app_com_create(const char *endpoint, aul_app_com_permission_h permission, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection); int aul_app_com_join(const char *endpoint, const char *filter, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection); int aul_app_com_leave(aul_app_com_connection_h connection); int aul_app_com_send(const char *endpoint, bundle *envelope); +int aul_app_com_create_async(const char *endpoint, + aul_app_com_permission_h permission, + app_com_cb callback, + void *user_data, + aul_app_com_connection_h *connection); + #ifdef __cplusplus } #endif diff --git a/src/app_com.c b/src/app_com.c index 7c8c619..90631a4 100644 --- a/src/app_com.c +++ b/src/app_com.c @@ -124,9 +124,12 @@ static aul_app_com_connection_h __add_handler(const char *endpoint, app_com_cb c return h; } -API int aul_app_com_create(const char *endpoint, - aul_app_com_permission_h permission, app_com_cb callback, - void *user_data, aul_app_com_connection_h *connection) +static int __create_app_com(const char *endpoint, + aul_app_com_permission_h permission, + app_com_cb callback, + void *user_data, + bool sync, + aul_app_com_connection_h *connection) { bundle *b; int ret; @@ -162,7 +165,12 @@ API int aul_app_com_create(const char *endpoint, } } - ret = app_send_cmd(AUL_UTIL_PID, APP_COM_CREATE, b); + if (sync) { + ret = app_send_cmd(AUL_UTIL_PID, APP_COM_CREATE, b); + } else { + ret = app_send_cmd_with_noreply(AUL_UTIL_PID, + APP_COM_CREATE, b); + } bundle_free(b); if (ret == 0) @@ -171,6 +179,26 @@ API int aul_app_com_create(const char *endpoint, return ret; } +API int aul_app_com_create(const char *endpoint, + aul_app_com_permission_h permission, + app_com_cb callback, + void *user_data, + aul_app_com_connection_h *connection) +{ + return __create_app_com(endpoint, permission, callback, user_data, + true, connection); +} + +API int aul_app_com_create_async(const char *endpoint, + aul_app_com_permission_h permission, + app_com_cb callback, + void *user_data, + aul_app_com_connection_h *connection) +{ + return __create_app_com(endpoint, permission, callback, user_data, + false, connection); +} + API int aul_app_com_join(const char *endpoint, const char *filter, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection) -- 2.7.4