From bf03989507dc720e71b7d057597282e491b7d1cc Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Thu, 8 Sep 2022 11:32:36 +0900 Subject: [PATCH] change ipc connection as sync and add registering in result cb Changed IPC connection as sync. By sync connection, it can register input event and it's result_cb to mmi service when mmi_set_result_cb is called. Change-Id: I987e0cbb891907c12cbbe8219fd5467676d3e31f --- src/mmi-client.c | 31 ++++++++++++++++++++++++++++++ src/mmi-ipc.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- src/mmi-ipc.h | 1 + src/mmi.c | 4 +--- src/mmi.h | 3 +++ tests/mmi-main-test.cpp | 33 ++++++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 4 deletions(-) diff --git a/src/mmi-client.c b/src/mmi-client.c index eb047e6..6c4088a 100644 --- a/src/mmi-client.c +++ b/src/mmi-client.c @@ -54,6 +54,7 @@ int mmi_client_destroy(void) } mmi_ipc_deinitialize(); + mmi_h->rpc_h = NULL; GList *iter = NULL; mmi_result_cb_s *data = NULL; @@ -81,6 +82,24 @@ int mmi_client_destroy(void) return MMI_ERROR_NONE; } +const char* mmi_client_convert_error_code(int err) +{ + switch (err) { + case MMI_ERROR_NONE: return "MMI_ERROR_NONE"; + case MMI_ERROR_OUT_OF_MEMORY: return "MMI_ERROR_OUT_OF_MEMORY"; + case MMI_ERROR_IO_ERROR: return "MMI_ERROR_IO_ERROR"; + case MMI_ERROR_INVALID_PARAMETER: return "MMI_ERROR_INVALID_PARAMETER"; + case MMI_ERROR_OUT_OF_NETWORK: return "MMI_ERROR_OUT_OF_NETWORK"; + case MMI_ERROR_TIMED_OUT: return "MMI_ERROR_TIMED_OUT"; + case MMI_ERROR_PERMISSION_DENIED: return "MMI_ERROR_PERMISSION_DENIED"; + case MMI_ERROR_NOT_SUPPORTED: return "MMI_ERROR_NOT_SUPPORTED"; + case MMI_ERROR_OPERATION_FAILED: return "MMI_ERROR_OPERATION_FAILED"; + default: + return "Invalid error code"; + } + return NULL; +} + int mmi_client_set_result_cb(int input_event_type, mmi_result_cb callback, void* user_data) { LOGI("Set result cb about input event type(%d) to client", input_event_type); @@ -90,6 +109,11 @@ int mmi_client_set_result_cb(int input_event_type, mmi_result_cb callback, void* return MMI_ERROR_INVALID_PARAMETER; } + if (mmi_h == NULL) { + LOGE("Fail to get client"); + return MMI_ERROR_INVALID_PARAMETER; + } + mmi_result_cb_s* input_result_callback = (mmi_result_cb_s*)calloc(1, sizeof(mmi_result_cb_s)); if (input_result_callback == NULL) { LOGE("[ERROR] Fail to allocate memory"); @@ -100,6 +124,13 @@ int mmi_client_set_result_cb(int input_event_type, mmi_result_cb callback, void* input_result_callback->result_callback = callback; mmi_h->result_cb_list = g_list_append(mmi_h->result_cb_list, input_result_callback); + int ret = mmi_ipc_register_input_event_result_cb(input_event_type, callback); + if (ret != MMI_ERROR_NONE) { + LOGE("Fail to register input event's result callback(%d), reason(%s)", ret, mmi_client_convert_error_code(ret)); + callback(input_event_type, mmi_client_convert_error_code(ret), NULL); + return ret; + } + return MMI_ERROR_NONE; } diff --git a/src/mmi-ipc.c b/src/mmi-ipc.c index c13d036..889c55a 100644 --- a/src/mmi-ipc.c +++ b/src/mmi-ipc.c @@ -17,6 +17,7 @@ #include "mmi-ipc.h" #include "mmi-dbg.h" +#include "mmi-client.h" #include #include @@ -82,13 +83,15 @@ int mmi_ipc_initialize(void) goto err; } - r = rpc_port_proxy_mmi_connect(_rpc_h); + r = rpc_port_proxy_mmi_connect_sync(_rpc_h); if (r != RPC_PORT_ERROR_NONE) { LOGE("Failed to connect to %s ! (error:%d)\n", _stub_appid, r); goto err; } + LOGI("connect mmi ipc"); + return 0; err: if (_rpc_h) @@ -105,9 +108,54 @@ void mmi_ipc_deinitialize(void) if (!_rpc_h) return; + LOGI("disconnect mmi ipc"); + rpc_port_proxy_mmi_destroy(_rpc_h); rpc_port_deregister_proc_info(); _rpc_h = NULL; _connected = 0; } + +int mmi_ipc_register_input_event_result_cb(int input_event_type, rpc_port_proxy_mmi_result_cb_cb callback) +{ + LOGI("Register input event(%d) result cb to MMI Service", input_event_type); + + if (callback == NULL) { + LOGE("Parameter callback is NULL"); + return MMI_ERROR_INVALID_PARAMETER; + } + + mmi_handle client = mmi_client_get(); + if (client == NULL) { + LOGE("Fail to get client"); + return MMI_ERROR_INVALID_PARAMETER; + } + + rpc_port_proxy_mmi_h rpc_h = client->rpc_h; + if (rpc_h == NULL) { + LOGE("Fail to get tidl rpc info"); + return MMI_ERROR_INVALID_PARAMETER; + } + + rpc_port_proxy_mmi_result_cb_h result_cb_h; + int ret = rpc_port_proxy_mmi_result_cb_create(&result_cb_h); + if (ret != RPC_PORT_ERROR_NONE) { + LOGE("Failed to create result callback handle (error:%d)\n", ret); + return MMI_ERROR_OPERATION_FAILED; + } + rpc_port_proxy_mmi_result_cb_set_callback(result_cb_h, callback, NULL); + rpc_port_proxy_mmi_result_cb_set_once(result_cb_h, false); + if (result_cb_h == NULL) { + LOGE("Failed to create event callbacks"); + return MMI_ERROR_OPERATION_FAILED; + } + + ret = rpc_port_proxy_mmi_invoke_register_input_event(rpc_h, input_event_type, result_cb_h); + if (ret != RPC_PORT_ERROR_NONE) { + LOGE("Failed to register event callbacks(%d)\n", ret); + return MMI_ERROR_OPERATION_FAILED; + } + + return MMI_ERROR_NONE; +} diff --git a/src/mmi-ipc.h b/src/mmi-ipc.h index 004c824..b0fadf9 100644 --- a/src/mmi-ipc.h +++ b/src/mmi-ipc.h @@ -27,6 +27,7 @@ extern "C" { int mmi_ipc_initialize(void); void mmi_ipc_deinitialize(void); +int mmi_ipc_register_input_event_result_cb(int input_event_type, rpc_port_proxy_mmi_result_cb_cb callback); rpc_port_proxy_mmi_h mmi_ipc_get_rpc_h(void); int mmi_ipc_get_uid(void); diff --git a/src/mmi.c b/src/mmi.c index 284f6a0..08e9796 100644 --- a/src/mmi.c +++ b/src/mmi.c @@ -45,9 +45,7 @@ MMI_API int mmi_set_result_cb(int input_event_type, mmi_result_cb callback, void { LOGI("Set result cb about input event type(%d)", input_event_type); - int ret; - - ret = mmi_client_set_result_cb(input_event_type, callback, user_data); + int ret = mmi_client_set_result_cb(input_event_type, callback, user_data); if(ret != MMI_ERROR_NONE) { LOGE("Fail to set result cb(%d)", ret); return ret; diff --git a/src/mmi.h b/src/mmi.h index 138f16b..56cf354 100644 --- a/src/mmi.h +++ b/src/mmi.h @@ -28,6 +28,8 @@ typedef enum { MMI_RESULT_SUCCESS } mmi_result_e; +#define TIZEN_ERROR_MMI -0x030F0000 + typedef enum { MMI_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ MMI_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */ @@ -37,6 +39,7 @@ typedef enum { MMI_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the daemon */ MMI_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ MMI_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< MMI NOT supported */ + MMI_ERROR_OPERATION_FAILED = TIZEN_ERROR_MMI | 0x01, /**< Operation failed */ } mmi_error_e; typedef void (*mmi_result_cb)(int input_event_type, const char *result_out, void *user_data); diff --git a/tests/mmi-main-test.cpp b/tests/mmi-main-test.cpp index b73cdd5..64ce80e 100644 --- a/tests/mmi-main-test.cpp +++ b/tests/mmi-main-test.cpp @@ -146,3 +146,36 @@ TEST_F(MMIMainTest, MMIClientDestroyRemoveGList) mmi_client_destroy(); } + +TEST_F(MMIMainTest, MMISetResultCbFailNoClient) +{ + int res = mmi_initialize(); + mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH; + + EXPECT_EQ(res, MMI_ERROR_NONE); + + mmi_client_destroy(); + + res = mmi_set_result_cb(input_event_type, voice_touch_callback, NULL); + EXPECT_EQ(res, MMI_ERROR_INVALID_PARAMETER); + + mmi_deinitialize(); +} + +TEST_F(MMIMainTest, MMISetResultCbFailNoRpcHandle) +{ + int res = mmi_initialize(); + mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH; + + EXPECT_EQ(res, MMI_ERROR_NONE); + + mmi_ipc_deinitialize(); + + mmi_handle mmi_client = mmi_client_get(); + mmi_client->rpc_h = NULL; + + res = mmi_set_result_cb(input_event_type, voice_touch_callback, NULL); + EXPECT_EQ(res, MMI_ERROR_INVALID_PARAMETER); + + mmi_deinitialize(); +} -- 2.7.4