Create set result cb API in client and test 95/281595/1
authordyamy-lee <dyamy.lee@samsung.com>
Mon, 5 Sep 2022 09:41:07 +0000 (18:41 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 20 Sep 2022 04:52:28 +0000 (13:52 +0900)
This function saves a result callback by each input_event_type in client module.
Also, create input_event_type as enum for readabiltiy.
And, add test code for mmi_client_set_result_cb.

Change-Id: I2a4f27ebe7d1c235a99fc125153d2ed4ef1fed7e

src/mmi-client.c
src/mmi-client.h
src/mmi-common.h
tests/mmi-main-test.cpp

index 6ec1934..bdd0f87 100644 (file)
@@ -48,6 +48,7 @@ int mmi_client_create(void)
        mmi_h->rpc_h = mmi_ipc_get_rpc_h();
        mmi_h->stub_appid = mmi_ipc_get_stub_appid();
        mmi_h->state = mmi_ipc_get_state();
+       mmi_h->result_cb_list = NULL;
 
        return MMI_ERROR_NONE;
 }
@@ -68,5 +69,27 @@ int mmi_client_destroy(void)
 
 int mmi_client_set_result_cb(int input_event_type, result_cb callback, void* user_data)
 {
+       LOGI("Set result cb about input event type(%d) to client", input_event_type);
+
+       if (callback == NULL) {
+               LOGE("Callback is invalid");
+               return MMI_ERROR_INVALID_PARAMETER;
+       }
+
+       result_cb_s* input_result_callback = (result_cb_s*)calloc(1, sizeof(result_cb_s));
+       if (input_result_callback == NULL) {
+               LOGE("[ERROR] Fail to allocate memory");
+               return MMI_ERROR_OUT_OF_MEMORY;
+       }
+
+       input_result_callback->input_event_type = input_event_type;
+       input_result_callback->result_callback = callback;
+       mmi_h->result_cb_list  = g_list_append(mmi_h->result_cb_list, input_result_callback);
+
        return MMI_ERROR_NONE;
 }
+
+mmi_handle mmi_client_get(void)
+{
+       return mmi_h;
+}
index 4ec2669..5f1823a 100644 (file)
@@ -25,6 +25,7 @@
 #define __MMI_CLIENT_H__
 
 #include "mmi-common.h"
+#include <glib.h>
 
 typedef void* mmi_rpc_h;
 
@@ -32,10 +33,17 @@ typedef struct {
        mmi_rpc_h rpc_h;
        const char *stub_appid;
        int state;
+       GList* result_cb_list;
 } mmi_struct_s;
 
 typedef mmi_struct_s* mmi_handle;
 
+typedef struct {
+       int input_event_type;
+       int input_event_state;
+       result_cb result_callback;
+} result_cb_s;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -43,6 +51,7 @@ extern "C" {
 int mmi_client_create(void);
 int mmi_client_destroy(void);
 int mmi_client_set_result_cb(int input_event_type, result_cb callback, void* user_data);
+mmi_handle mmi_client_get(void);
 
 #ifdef __cplusplus
 }
index 3942f3e..00200a1 100644 (file)
@@ -51,4 +51,9 @@ typedef enum {
 
 typedef void (*result_cb)(void *user_data, int input_event_type, const char *result_out);
 
+typedef enum {
+       MMI_VOICE_TOUCH,
+       MMI_VOICE_RECOGNITION,
+} mmi_input_event_type_e;
+
 #endif //__MMI_COMMON_H__
index fe2c0ae..ec312a7 100644 (file)
@@ -61,15 +61,47 @@ TEST_F(MMIMainTest, MmiClientCreateSuccess)
        mmi_client_destroy();
 }
 
-TEST_F(MMIMainTest, MMIClientSetResultCb)
+void voice_touch_callback(void *user_data, int input_event_type, const char *result_out)
+{
+}
+
+TEST_F(MMIMainTest, MMIClientSetResultCbSuccess)
 {
        int res = mmi_init();
-       int input_event_type = 0;
+       mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
 
        EXPECT_EQ(res, MMI_ERROR_NONE);
 
-       res = mmi_client_set_result_cb(input_event_type, NULL, NULL);
+       res = mmi_client_set_result_cb(input_event_type, voice_touch_callback, NULL);
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       mmi_handle mmi_client = mmi_client_get();
+       GList* iter = NULL;
+       result_cb_s *data = NULL;
+
+       iter = g_list_first(mmi_client->result_cb_list);
+       if(NULL != iter) {
+               data = (result_cb_s*)iter->data;
+               EXPECT_NE(data->result_callback, nullptr);
+               EXPECT_EQ(data->result_callback, voice_touch_callback);
+               EXPECT_EQ(data->input_event_type, MMI_VOICE_TOUCH);
+       }
+       else {
+               EXPECT_TRUE(false);
+       }
+
+       mmi_shutdown();
+}
+
+TEST_F(MMIMainTest, MMIClientSetResultCbFail)
+{
+       int res = mmi_init();
+       mmi_input_event_type_e input_event_type = MMI_VOICE_TOUCH;
+
        EXPECT_EQ(res, MMI_ERROR_NONE);
 
+       res = mmi_client_set_result_cb(input_event_type, NULL, NULL);
+       EXPECT_EQ(res, MMI_ERROR_INVALID_PARAMETER);
+
        mmi_shutdown();
 }