Implement logic for sending output modality and result 12/281612/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 14 Sep 2022 02:07:25 +0000 (11:07 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Tue, 20 Sep 2022 05:08:43 +0000 (14:08 +0900)
- Requirement:
MMI core module needs to send output result and modality to proper
client app and output modality provider.

- Solution:
This patch adds new logic for sending output result and modality to
client app and output modality provider. For this change, this patch
also fixes interface of output result callback of IU module.

Change-Id: Ib61141ec9c9b6b249f2836f277f81b5a12061eef
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
src/mmimgr/iu/mmi_iu.cpp
src/mmimgr/iu/mmi_iu.h
src/mmimgr/mmi-api-handler.c
src/mmimgr/mmi-api-handler.h
src/mmimgr/mmi-client.c
src/mmimgr/mmi-client.h
src/mmimgr/mmi-core.c
tests/iu/mmi_iu_feed_input_event_unittests.cpp
tests/iu/mmi_iu_feed_intent_unittests.cpp
tests/iu/mmi_iu_noinit_unittests.cpp
tests/iu/mmi_iu_unittests.cpp

index b8d580e..cf9c253 100644 (file)
@@ -65,12 +65,22 @@ static void init()
 
 void __mmi_iu_voice_touch_engine_output_result_cb(const char* app_id, const char* output_result, void *user_data)
 {
-    // TODO: implement
+    if (iu_output_result_received_callback == nullptr) {
+        _E("[MMI IU] Output result callback is not set");
+        return;
+    }
+
+    iu_output_result_received_callback(app_id, MMI_PROVIDER_EVENT_VOICE_TOUCH, output_result, iu_output_result_user_data);
 }
 
 void __mmi_iu_voice_touch_engine_output_modality_cb(const char* app_id, void* output_modality, void *user_data)
 {
-    // TODO: implement
+    if (iu_output_modality_received_callback == nullptr) {
+        _E("[MMI IU] Output result callback is not set");
+        return;
+    }
+
+    iu_output_modality_received_callback(app_id, MMI_PROVIDER_EVENT_VOICE_TOUCH, output_modality, iu_output_modality_user_data);
 }
 
 EXPORT_API int mmi_iu_init()
@@ -120,34 +130,6 @@ EXPORT_API int mmi_iu_set_rule_filepath(const char *filepath)
     return MMI_IU_ERROR_NONE;
 }
 
-static void fire_output_result_callback(const char *app_id, const char *output_intent)
-{
-    if (iu_output_result_received_callback)
-        iu_output_result_received_callback(app_id, output_intent, iu_output_result_user_data);
-    else
-        _D("No output intent receive callback\n");
-}
-
-static void fire_output_result(const char *app_id, const char *json_output_intent)
-{
-    if (g_system_app_id == string(app_id)) {
-        fire_output_result_callback(app_id, json_output_intent);
-        return;
-    }
-
-    if (g_focus_app_id.empty()) {
-        fire_output_result_callback(app_id, json_output_intent);
-        return;
-    }
-
-    if (g_focus_app_id == string(app_id)) {
-        fire_output_result_callback(app_id, json_output_intent);
-        return;
-    }
-
-    _I("different focus app\n");
-}
-
 EXPORT_API int mmi_iu_feed_intent(const char *app_id, const char *json_data)
 {
     if (!app_id || !json_data) {
@@ -181,9 +163,6 @@ EXPORT_API int mmi_iu_feed_input_modality(const char *app_id, int type, void *ev
     }
 
     _I("app state: %d\n", g_app_state);
-
-    fire_output_result(app_id, json_output_result.c_str());
-
     return MMI_IU_ERROR_NONE;
 }
 
index 316f8c1..6ded713 100644 (file)
@@ -47,7 +47,7 @@ extern "C" {
  * @param[in] json_data The output intent data with json format
  * @param[in] user_data The user data passed from the callback function
  */
-typedef void (*mmi_iu_output_result_received_cb)(const char *target_app_id, const char *json_data, void *user_data);
+typedef void (*mmi_iu_output_result_received_cb)(const char *target_app_id, int type, const char *json_data, void *user_data);
 
 typedef void (*mmi_iu_output_modality_received_cb)(const char *target_app_id, int type, void *event, void *user_data);
 
index 2aded0d..792b1fc 100644 (file)
@@ -233,3 +233,31 @@ mmi_api_handler_deinitialize(void)
        _init_done = false;
 }
 
+int mmi_api_handler_send_resullt(const char *app_id, int event_type, const char *output_result)
+{
+       if (app_id == NULL) {
+               LOGE("App ID is NULL");
+               return MMI_ERROR_INVALID_PARAMETER;
+       }
+
+       mmi_client *mclient = client_manager_get_client(app_id);
+       if (mclient == NULL) {
+               LOGE("Failed to get client information from sender(%s)!", app_id);
+               return MMI_ERROR_INVALID_PARAMETER;
+       }
+
+       rpc_port_stub_mmi_result_cb_h result_cb = client_manager_get_result_cb_handle(mclient, event_type);
+       if (result_cb == NULL) {
+               LOGE("Failed to get result callback. App ID(%s), event Type(%d)!", app_id, event_type);
+               return MMI_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = rpc_port_stub_mmi_result_cb_invoke(result_cb, event_type, output_result);
+       if (ret != RPC_PORT_ERROR_NONE) {
+               LOGE("Failed to invoke result callback. App ID(%s), event Type(%d), ret(%d)!", app_id, event_type, ret);
+               return MMI_ERROR_OPERATION_FAILED;
+       }
+
+       LOGI("Send result to client. App ID(%s), event Type(%d)", app_id, event_type);
+       return MMI_ERROR_NONE;
+}
index 81ae12e..8e86db0 100644 (file)
@@ -33,6 +33,8 @@ extern "C" {
 int mmi_api_handler_initialize(void);
 void mmi_api_handler_deinitialize(void);
 
+int mmi_api_handler_send_resullt(const char *app_id, int event_type, const char *output_result);
+
 #ifdef __cplusplus
 }
 #endif
index fc4dcf8..8921ad0 100644 (file)
@@ -210,6 +210,35 @@ client_manager_get_client_pid(mmi_client *client)
        return client->pid;
 }
 
+rpc_port_stub_mmi_result_cb_h client_manager_get_result_cb_handle(mmi_client *client, int input_event_type)
+{
+       LOGI("client_manager_get_result_cb_handle");
+       if (client == NULL) {
+               LOGE("Fail to get client result_cb. client is NULL");
+               return NULL;
+       }
+
+       if (g_list_length(client->result_cb_list) > 0) {
+               LOGE("Fail to get client result_cb. There is no result_cb set");
+               return NULL;
+       }
+
+       GList *iter = g_list_first(client->result_cb_list);
+       while (iter != NULL) {
+               mmi_result_cb_s *data = iter->data;
+               if (data != NULL) {
+                       int type = data->input_event_type;
+
+                       if (type == input_event_type) {
+                               return data->result_cb_h;
+                       }
+               }
+               iter = g_list_next(iter);
+       }
+
+       return NULL;
+}
+
 const char *
 client_manager_get_client_sender(mmi_client *client)
 {
index 0551e6d..bdb243f 100644 (file)
@@ -60,6 +60,7 @@ int client_manager_get_client_uid(mmi_client *client);
 int client_manager_set_client_pid(mmi_client *client, pid_t pid);
 int client_manager_get_client_pid(mmi_client *client);
 const char *client_manager_get_client_sender(mmi_client *client);
+rpc_port_stub_mmi_result_cb_h client_manager_get_result_cb_handle(mmi_client *client, int input_event_type);
 
 void client_manager_init(void);
 void client_manager_shutdown(void);
index 94bbaeb..34a33f8 100644 (file)
@@ -25,8 +25,9 @@
 
 #include "mmi-manager.h"
 #include "mmi-manager-dbg.h"
+#include "mmi-api-handler.h"
 #include "iu/mmi_iu.h"
-
+#include "output_modality/mmi_output_modality.h"
 #include "mmi-core.h"
 
 #define APP_ID "org.tizen.test"
@@ -45,9 +46,9 @@ enum event_handlers {
 static Ecore_Event_Handler *_event_handlers[EVENT_HANDLER_MAX];
 static mmi_client *g_client = NULL;
 
-static void __output_result_received_cb(const char *app_id, const char *json_data, void *user_data)
+static void __output_result_received_cb(const char *app_id, int type, const char *json_data, void *user_data)
 {
-       // TODO: implement
+       int ret = mmi_api_handler_send_resullt(app_id, type, json_data);
 }
 
 static void __output_modality_received_cb(const char *app_id, int type, void *event, void *user_data)
@@ -80,7 +81,11 @@ static void __output_modality_received_cb(const char *app_id, int type, void *ev
                arg.source = gesture_event->source;
        }
        else if (type == MMI_PROVIDER_EVENT_VOICE_TOUCH) {
-               // TODO: implement
+               mmi_output_modality_voice_touch *modality = (mmi_output_modality_voice_touch *)event;
+
+               if (modality != NULL) {
+                       output_modality_voice_touch(*modality);
+               }
        }
 }
 
index 0a33547..286b368 100644 (file)
@@ -47,7 +47,7 @@ static void *g_received_event_data = NULL;
 
 namespace {
 
-static void output_intent_received_cb(const char *app_id, const char *json_data, void *user_data)
+static void output_intent_received_cb(const char *app_id, int type, const char *json_data, void *user_data)
 {
     JsonParser *parser = json_parser_new();
     GError *err_msg = NULL;
index d0af601..b9105f5 100644 (file)
@@ -41,7 +41,7 @@ static string output_action;
 
 namespace {
 
-static void output_intent_received_cb(const char *app_id, const char *json_data, void *user_data)
+static void output_intent_received_cb(const char *app_id, int type, const char *json_data, void *user_data)
 {
     JsonParser *parser = json_parser_new();
     GError *err_msg = NULL;
@@ -90,7 +90,7 @@ class IUClientFeedIntentTest : public testing::Test {
 
             output_action = string("");
 
-            ret = mmi_iu_set_output_intent_received_callback(output_intent_received_cb, NULL);
+            ret = mmi_iu_set_output_result_received_callback(output_intent_received_cb, NULL);
             EXPECT_EQ(ret, MMI_IU_ERROR_NONE);
         }
         virtual void TearDown() {
@@ -685,7 +685,7 @@ TEST_F(IUClientFeedIntentTest, utc_mmi_iu_feed_intent_gesture_flippalm_different
     }
     )";
 
-    int ret = mmi_iu_set_output_intent_received_callback(output_intent_received_cb, NULL);
+    int ret = mmi_iu_set_output_result_received_callback(output_intent_received_cb, NULL);
     EXPECT_EQ(ret, MMI_IU_ERROR_NONE);
 
     ret = mmi_iu_set_focus_app_id(SYSTEM_APP_ID);
index e9983df..a153cfe 100644 (file)
@@ -55,7 +55,7 @@ TEST_F(IUClientNoInitTest, utc_mmi_iu_feed_intent_n)
     EXPECT_EQ(ret, MMI_IU_ERROR_INVALID_PARAMETER);
 }
 
-static void output_intent_received_cb(const char *app_id, const char *json_data, void *user_data)
+static void output_intent_received_cb(const char *app_id, int type, const char *json_data, void *user_data)
 {
 
 }
index 343d93e..c2f310e 100644 (file)
@@ -41,7 +41,7 @@ static string output_action;
 
 namespace {
 
-static void output_intent_received_cb(const char *app_id, const char *json_data, void *user_data)
+static void output_intent_received_cb(const char *app_id, int type, const char *json_data, void *user_data)
 {
 
 }