activate input event 16/281616/1
authordyamy-lee <dyamy.lee@samsung.com>
Tue, 13 Sep 2022 01:52:56 +0000 (10:52 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 20 Sep 2022 05:09:38 +0000 (14:09 +0900)
mmi_activate_input_event is called by client, and it check saved input event and callback.
If it has matched one, invoke activate input event to stub.

Change-Id: I6866edc74f7453d752b679050a44ce4f55193186

src/mmi-ipc.c
src/mmi-ipc.h
src/mmi.c
src/mmi.h
tests/mmi-main-test.cpp

index c14de7f..651527a 100644 (file)
@@ -180,3 +180,39 @@ int mmi_ipc_register_input_event_result_cb(int input_event_type, rpc_port_proxy_
 
        return MMI_ERROR_NONE;
 }
+
+int mmi_ipc_activate_input_event(int input_event_type)
+{
+       LOGI("Activate about input event type(%d)", input_event_type);
+
+       int ret;
+
+       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;
+       }
+
+       if (mmi_ipc_is_connected() == false) {
+               LOGE("Try to connect again");
+               ret = mmi_ipc_retry_connection(_rpc_h);
+               if (ret != RPC_PORT_ERROR_NONE) {
+                       LOGE("Fail to retry connection(%d)", ret);
+                       return MMI_ERROR_OPERATION_FAILED;
+               }
+       }
+
+       ret = rpc_port_proxy_mmi_invoke_activate_input_event(rpc_h, input_event_type);
+       if (ret != RPC_PORT_ERROR_NONE) {
+               LOGE("Fail to invoke activate input event");
+               return MMI_ERROR_OPERATION_FAILED;
+       }
+
+       return MMI_ERROR_NONE;
+}
index b0fadf9..8d15f77 100644 (file)
@@ -28,6 +28,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);
+int mmi_ipc_activate_input_event(int input_event_type);
 
 rpc_port_proxy_mmi_h mmi_ipc_get_rpc_h(void);
 int mmi_ipc_get_uid(void);
index 08e9796..322381a 100644 (file)
--- a/src/mmi.c
+++ b/src/mmi.c
@@ -18,6 +18,7 @@
 #include "mmi.h"
 #include "mmi-client.h"
 #include "mmi-dbg.h"
+#include "mmi-ipc.h"
 
 MMI_API int mmi_initialize(void)
 {
@@ -53,3 +54,43 @@ MMI_API int mmi_set_result_cb(int input_event_type, mmi_result_cb callback, void
 
        return MMI_ERROR_NONE;
 }
+
+MMI_API int mmi_activate_input_event(int input_event_type)
+{
+       LOGI("Activate input event(%d)", input_event_type);
+
+       int ret;
+       GList* iter = NULL;
+       mmi_result_cb_s *data = NULL;
+       mmi_handle client = mmi_client_get();
+
+       if (g_list_length(client->result_cb_list) > 0) {
+               LOGD("Check length of callback lists = %d", g_list_length(client->result_cb_list));
+
+               iter = g_list_first(client->result_cb_list);
+
+               while (iter != NULL) {
+                       data = iter->data;
+
+                       if (data != NULL) {
+                               int type = data->input_event_type;
+
+                               if (type == input_event_type) {
+                                       ret = mmi_ipc_activate_input_event(input_event_type);
+                                       if(ret != MMI_ERROR_NONE) {
+                                               LOGE("Fail to activate input event(%d)", ret);
+                                               return ret;
+                                       }
+
+                                       LOGD("Activate input event(%d)", type);
+                                       return MMI_ERROR_NONE;
+                               }
+                       }
+
+                       iter = g_list_next(iter);
+               }
+       }
+
+       LOGE("No match callback about input event type(%d)", input_event_type);
+       return MMI_ERROR_INVALID_PARAMETER;
+}
index 56cf354..8c1da0c 100644 (file)
--- a/src/mmi.h
+++ b/src/mmi.h
@@ -56,6 +56,7 @@ extern "C" {
 MMI_API int mmi_initialize(void);
 MMI_API int mmi_deinitialize(void);
 MMI_API int mmi_set_result_cb(int input_event_type, mmi_result_cb callback, void* user_data);
+MMI_API int mmi_activate_input_event(int input_event_type);
 
 #ifdef __cplusplus
 }
index 64ce80e..4170cbf 100644 (file)
@@ -179,3 +179,69 @@ TEST_F(MMIMainTest, MMISetResultCbFailNoRpcHandle)
 
        mmi_deinitialize();
 }
+
+TEST_F(MMIMainTest, MMIActivateInputEventSuccess)
+{
+       int res = mmi_initialize();
+       mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
+
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       res = mmi_set_result_cb(input_event_type, voice_touch_callback, NULL);
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       res = mmi_activate_input_event(input_event_type);
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       mmi_deinitialize();
+}
+
+TEST_F(MMIMainTest, MMIActivateInputEventFailNoEvent)
+{
+       int res = mmi_initialize();
+       mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
+
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       res = mmi_set_result_cb(input_event_type, voice_touch_callback, NULL);
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       res = mmi_activate_input_event(MMI_VOICE_RECOGNITION);
+       EXPECT_EQ(res, MMI_ERROR_INVALID_PARAMETER);
+
+       mmi_deinitialize();
+}
+
+TEST_F(MMIMainTest, MMIActivateInputEventFailNoCallback)
+{
+       int res = mmi_initialize();
+       mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
+
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       res = mmi_activate_input_event(input_event_type);
+       EXPECT_EQ(res, MMI_ERROR_INVALID_PARAMETER);
+
+       mmi_deinitialize();
+}
+
+TEST_F(MMIMainTest, MMIActivateInputEventFailNoRpcHandle)
+{
+       int res = mmi_initialize();
+       mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
+
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       res = mmi_set_result_cb(input_event_type, voice_touch_callback, NULL);
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       mmi_ipc_deinitialize();
+
+       mmi_handle mmi_client = mmi_client_get();
+       mmi_client->rpc_h = NULL;
+
+       res = mmi_activate_input_event(input_event_type);
+       EXPECT_EQ(res, MMI_ERROR_INVALID_PARAMETER);
+
+       mmi_deinitialize();
+}