From dcac87686af6c737b8a3d3fa6173cdc09b05bf98 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 9 Sep 2021 20:03:41 +0900 Subject: [PATCH] iu: Add bridge code between mmi-manager and iu Change-Id: I4ae67aebd57c6cd5392bbf09e293229883c93f95 Signed-off-by: Jihoon Kim --- src/iu/data/default_rule.json | 12 ++ src/iu/intent_understanding_engine.cpp | 26 ++-- src/iu/intent_understanding_engine.h | 2 +- src/iu/mmi_iu.cpp | 5 +- src/meson.build | 2 + src/mmi-common.h | 3 +- src/mmi-iu-bridge.c | 243 +++++++++++++++++++++++++++++++++ src/mmi-iu-bridge.h | 38 ++++++ src/mmi-manager.c | 4 + 9 files changed, 319 insertions(+), 16 deletions(-) create mode 100644 src/mmi-iu-bridge.c create mode 100644 src/mmi-iu-bridge.h diff --git a/src/iu/data/default_rule.json b/src/iu/data/default_rule.json index ba8d522..880d286 100644 --- a/src/iu/data/default_rule.json +++ b/src/iu/data/default_rule.json @@ -283,6 +283,18 @@ "Action" : "PressBackButton" } ], + "MMIStatus": "Initiation", + "OutputIntent": { + "Action" : "Cancel" + } + }, + { + "InputIntents" : [ + { + "Modality" : "KeyInput", + "Action" : "PressBackButton" + } + ], "MMIStatus": "Feedback", "OutputIntent": { "Action" : "Cancel" diff --git a/src/iu/intent_understanding_engine.cpp b/src/iu/intent_understanding_engine.cpp index 9228156..ddfc62c 100644 --- a/src/iu/intent_understanding_engine.cpp +++ b/src/iu/intent_understanding_engine.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "mmi_iu_log.h" @@ -36,14 +35,14 @@ using namespace std; -static unordered_map key_action_map - = { { MMI_EVENT_KEYEVENT_MIC, "Mic" }, - { XKB_KEY_Up, "Up" }, - { XKB_KEY_Down, "Down" }, - { XKB_KEY_Left, "Left" }, - { XKB_KEY_Right, "Right" }, - { XKB_KEY_Return, "OK" }, - { XKB_KEY_XF86Back, "Back" }, +static unordered_map key_action_map + = { { "UP", "Up" }, + { "DOWN", "Down" }, + { "LEFT", "Left" }, + { "RIGHT", "Right" }, + { "RETURN", "OK" }, + { "XF86Back", "Back" }, + { "I69", "Back" }, }; static unordered_map voice_action_map @@ -319,12 +318,15 @@ cleanup: return ret; } -string IntentUnderstandingEngine::convert_key_event(int type, int keycode) +string IntentUnderstandingEngine::convert_key_event(int type, char *keyname) { string action; string button_name; - button_name = key_action_map[keycode]; + if (!keyname) + return string(""); + + button_name = key_action_map[string(keyname)]; if (!button_name.empty()) { action = "Press" + button_name + "Button"; } @@ -364,7 +366,7 @@ bool IntentUnderstandingEngine::set_input_event(int type, void *event) if (type == MMI_PROVIDER_EVENT_KEY) { modality_type = "KeyInput"; key_event = (mmi_provider_event_key *)event; - action = convert_key_event(type, key_event->keycode); + action = convert_key_event(type, key_event->keyname); } else if (type == MMI_PROVIDER_EVENT_VOICE) { modality_type = "Voice"; diff --git a/src/iu/intent_understanding_engine.h b/src/iu/intent_understanding_engine.h index 0675607..f1d4799 100644 --- a/src/iu/intent_understanding_engine.h +++ b/src/iu/intent_understanding_engine.h @@ -60,7 +60,7 @@ private: bool parse_json_data(JsonParser *parser); - string convert_key_event(int type, int keycode); + string convert_key_event(int type, char *keyname); string convert_voice_event(int type); string convert_gesture_event(int type); string convert_vision_event(int type); diff --git a/src/iu/mmi_iu.cpp b/src/iu/mmi_iu.cpp index 09d9804..03ebc16 100644 --- a/src/iu/mmi_iu.cpp +++ b/src/iu/mmi_iu.cpp @@ -22,7 +22,6 @@ */ #include -#include #include #include #include @@ -182,8 +181,10 @@ EXPORT_API int mmi_iu_feed_input_event(const char *app_id, int type, void *event } if (iu_engine) - if (!iu_engine->set_input_event(type, event)) + if (!iu_engine->set_input_event(type, event)) { + LOGE("Failed to set input event"); return MMI_IU_ERROR_OPERATION_FAILED; + } _I("app state: %d\n", g_app_state); diff --git a/src/meson.build b/src/meson.build index 71fca79..1325c18 100644 --- a/src/meson.build +++ b/src/meson.build @@ -17,6 +17,8 @@ mmi_manager_srcs = [ 'mmi-fusion.h', 'mmi-fusion-iface.h', 'mmi-manager-dbg.h', + 'mmi-iu-bridge.c', + 'mmi-iu-bridge.h', 'interface/mmifw_stub.h', 'interface/mmifw_stub.c', 'iu/input_intent.cpp', diff --git a/src/mmi-common.h b/src/mmi-common.h index d046e1d..cd336bf 100644 --- a/src/mmi-common.h +++ b/src/mmi-common.h @@ -91,7 +91,8 @@ typedef enum mmi_event_action_type MMI_EVENT_ACTION_TYPE_STOP, MMI_EVENT_ACTION_TYPE_EXECUTE, MMI_EVENT_ACTION_TYPE_LAUNCH, - MMI_EVENT_ACTION_TYPE_REVOKE + MMI_EVENT_ACTION_TYPE_REVOKE, + MMI_EVENT_ACTION_TYPE_CANCEL } mmi_event_action_type; typedef enum mmi_event_feedback_type diff --git a/src/mmi-iu-bridge.c b/src/mmi-iu-bridge.c new file mode 100644 index 0000000..3f5fb9a --- /dev/null +++ b/src/mmi-iu-bridge.c @@ -0,0 +1,243 @@ +/* +* Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include +#include + +#include "mmi-manager.h" +#include "iu/mmi_iu_log.h" +#include "iu/mmi_iu.h" + +#define APP_ID "org.tizen.test" + +enum event_handlers { + EVENT_HANDLER_FOCUS_CHANGE, + EVENT_HANDLER_STATE_CHANGE, + EVENT_HANDLER_KEY, + EVENT_HANDLER_GESTURE, + EVENT_HANDLER_VOICE, + EVENT_HANDLER_VISION, + EVENT_HANDLER_MAX +}; + +static Ecore_Event_Handler *_event_handlers[EVENT_HANDLER_MAX]; +static mmi_client *g_client = NULL; + +static void output_intent_received_cb(const char *app_id, const char *json_data, void *user_data) +{ + JsonParser *parser = json_parser_new(); + GError *err_msg = NULL; + JsonNode *root = NULL; + JsonObject *root_obj = NULL; + const gchar *action = NULL; + + action_event_arg arg; + arg.timestamp = ecore_time_get(); + char* arr[1] = { "Action" }; + arg.cmd = NULL; + arg.args = arr; + arg.nargs = 1; + arg.source = NULL; + + json_parser_load_from_data(parser, (char *)json_data, -1, &err_msg); + if (err_msg) { + LOGE("failed to load json file. error message: %s\n", err_msg->message); + goto cleanup; + } + + root = json_parser_get_root(parser); + if (root == NULL) { + LOGE("failed to get root\n"); + goto cleanup; + } + + root_obj = json_node_get_object(root); + if (root_obj == NULL) { + LOGE("failed to get object\n"); + goto cleanup; + } + + action = json_object_get_string_member(root_obj, "Action"); + LOGD("Action: %s\n", action); + + if (strcmp(action, "WakeUp") == 0) { + wakeup_event_arg arg; + arg.type = MMI_EVENT_WAKEUP_TYPE_WAKEUP; + arg.source = NULL; + arg.timestamp = ecore_time_get(); + + client_manager_send_wakeup_event(g_client, &arg); + } + else if (strcmp(action, "Execute") == 0) { + arg.type = MMI_EVENT_ACTION_TYPE_EXECUTE; + client_manager_send_action_event(g_client, &arg); + } + else if (strcmp(action, "Play") == 0) { + arg.type = MMI_EVENT_ACTION_TYPE_PLAY; + client_manager_send_action_event(g_client, &arg); + } + else if (strcmp(action, "Cancel") == 0) { + arg.type = MMI_EVENT_ACTION_TYPE_CANCEL; + client_manager_send_action_event(g_client, &arg); + } + else if (strcmp(action, "Pause") == 0) { + arg.type = MMI_EVENT_ACTION_TYPE_PAUSE; + client_manager_send_action_event(g_client, &arg); + } + else if (strcmp(action, "Stop") == 0) { + arg.type = MMI_EVENT_ACTION_TYPE_STOP; + client_manager_send_action_event(g_client, &arg); + } + +cleanup: + if (err_msg) + g_error_free(err_msg); + + if (parser) + g_object_unref(parser); +} + +static Eina_Bool +_focus_change_cb(void *data EINA_UNUSED, int type, void *event) +{ + mmi_manager_event_focus_change *ev = (mmi_manager_event_focus_change *)event; + + LOGI("[focus change] cur focus : %p, new focus : %p", ev->cur_focus, ev->new_focus); + + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_state_change_cb(void *data EINA_UNUSED, int type, void *event) +{ + mmi_manager_event_state_change *ev = (mmi_manager_event_state_change *)event; + g_client = ev->client; + + LOGI("state : %d", ev->to_state); + mmi_iu_set_app_state(ev->to_state); + + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_key_event_cb(void *data EINA_UNUSED, int type, void *event) +{ + mmi_provider_event_key *ev = (mmi_provider_event_key *)event; + + LOGI("[key event] code : %d, name : %s, type : %d, timestamp : %d, source: %s", ev->keycode, ev->keyname, ev->type, ev->timestamp, ev->source); + + if (ev->key_down) { + mmi_iu_feed_input_event(APP_ID, MMI_PROVIDER_EVENT_KEY, ev); + } + + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_gesture_event_cb(void *data EINA_UNUSED, int type, void *event) +{ + mmi_provider_event_gesture *ev = (mmi_provider_event_gesture *)event; + + LOGI("[gesture event] type : %d, timestamp : %d", ev->type, ev->timestamp); + + mmi_iu_feed_input_event(APP_ID, MMI_PROVIDER_EVENT_GESTURE, ev); + + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_voice_event_cb(void *data EINA_UNUSED, int type, void *event) +{ + mmi_provider_event_voice *ev = (mmi_provider_event_voice *)event; + + LOGI("[voice event] type : %d, timestamp : %d", ev->type, ev->timestamp); + + mmi_iu_feed_input_event(APP_ID, MMI_PROVIDER_EVENT_VOICE, ev); + + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_vision_event_cb(void *data EINA_UNUSED, int type, void *event) +{ + mmi_provider_event_vision *ev = (mmi_provider_event_vision *)event; + + mmi_iu_feed_input_event(APP_ID, MMI_PROVIDER_EVENT_KEY, ev); + + return ECORE_CALLBACK_PASS_ON; +} + +static void +init_event_handler() +{ + _event_handlers[EVENT_HANDLER_FOCUS_CHANGE] = ecore_event_handler_add(MMI_MANAGER_EVENT_FOCUS_CHANGE, + _focus_change_cb, NULL); + _event_handlers[EVENT_HANDLER_STATE_CHANGE] = ecore_event_handler_add(MMI_MANAGER_EVENT_STATE_CHANGE, + _state_change_cb, NULL); + + _event_handlers[EVENT_HANDLER_KEY] = ecore_event_handler_add(MMI_PROVIDER_EVENT_KEY, + _key_event_cb, NULL); + _event_handlers[EVENT_HANDLER_GESTURE] = ecore_event_handler_add(MMI_PROVIDER_EVENT_GESTURE, + _gesture_event_cb, NULL); + _event_handlers[EVENT_HANDLER_VOICE] = ecore_event_handler_add(MMI_PROVIDER_EVENT_VOICE, + _voice_event_cb, NULL); + _event_handlers[EVENT_HANDLER_VISION] = ecore_event_handler_add(MMI_PROVIDER_EVENT_VISION, + _vision_event_cb, NULL); +} + +static void +shutdown_event_handler() +{ + for (int i=0; i #include @@ -301,7 +302,9 @@ mmi_manager_init() client_manager_init(); mmi_api_handler_init(); + mmi_iu_bridge_init(); _event_handler_init(); + _init_done = true; } @@ -324,6 +327,7 @@ mmi_manager_shutdown() return; _event_handler_shutdown(); + mmi_iu_bridge_shutdown(); mmi_api_handler_shutdown(); client_manager_shutdown(); -- 2.7.4