change ipc connection as sync and add registering in result cb 14/281614/1
authordyamy-lee <dyamy.lee@samsung.com>
Thu, 8 Sep 2022 02:32:36 +0000 (11:32 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 20 Sep 2022 05:09:36 +0000 (14:09 +0900)
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
src/mmi-ipc.c
src/mmi-ipc.h
src/mmi.c
src/mmi.h
tests/mmi-main-test.cpp

index eb047e65936907f8cb1046bd7c853fab0c1ba708..6c4088a303aafa9b4da341e4278b605b961d012b 100644 (file)
@@ -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;
 }
 
index c13d0365886a0f98f004c9b08b58c80ca98fa962..889c55a84830536c5bfb8e35677e54205606aab4 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "mmi-ipc.h"
 #include "mmi-dbg.h"
+#include "mmi-client.h"
 
 #include <tzplatform_config.h>
 #include <unistd.h>
@@ -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;
+}
index 004c8242b519168d623f67b0bcded542909d4664..b0fadf9984b6fafb16037ab52eff09f57ac040c8 100644 (file)
@@ -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);
index 284f6a05e662eceec91a111b1bb44f4969da8407..08e9796b20cd718dc11ececeb712f31f3bbf1655 100644 (file)
--- 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;
index 138f16b3e9ed2391f87dfd158530643306259e03..56cf35497401d29907048e43eafbcb0af796136f 100644 (file)
--- 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);
index b73cdd50ee24212faaf84f6a59a92b652cb7821c..64ce80ebc31aca0bea44c540bee5fcaf93b93ea1 100644 (file)
@@ -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();
+}