Use client handle for sending output result 49/282349/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 26 Sep 2022 11:38:08 +0000 (20:38 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Fri, 30 Sep 2022 05:24:55 +0000 (14:24 +0900)
- Requirement:
mmi core wants to control client when mmi manager sends output result to
proper client which set specified event.

- Solution:
This patch fixes parameter of mmi_api_handler_send_result() function
from app id to client handle. Through this change and function of mmi
client module, mmi core can control clients when mmi manager sends
output result to clients which set specified event.

Change-Id: Iee2f0e4c65cc2aeabcec09330264904bfb682052
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
src/mmimgr/mmi-api-handler.c
src/mmimgr/mmi-api-handler.h
src/mmimgr/mmi-core.c

index 792b1fc..baed590 100644 (file)
@@ -233,20 +233,15 @@ 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)
+int mmi_api_handler_send_result(mmi_client *client, int event_type, const char *output_result)
 {
-       if (app_id == NULL) {
-               LOGE("App ID is NULL");
+       if (client == NULL) {
+               LOGE("Client handle 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);
+       const char* app_id = client_manager_get_client_sender(client);
+       rpc_port_stub_mmi_result_cb_h result_cb = client_manager_get_result_cb_handle(client, 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;
index 8e86db0..15629bf 100644 (file)
 #ifndef __MMI_API_HANDLER_H__
 #define __MMI_API_HANDLER_H__
 
-#include "mmi_stub.h"
+
+#include "mmi-client.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+
 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);
+int mmi_api_handler_send_result(mmi_client *client, int event_type, const char *output_result);
 
 #ifdef __cplusplus
 }
index a87c0f2..3e489aa 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <Ecore.h>
 
+#include <glib.h>
+
 #include "mmi-manager.h"
 #include "mmi-manager-dbg.h"
 #include "mmi-api-handler.h"
@@ -43,12 +45,48 @@ enum event_handlers {
        EVENT_HANDLER_MAX
 };
 
+typedef struct {
+       int event_type;
+       const char *json_data;
+} output_result_s;
+
+
 static Ecore_Event_Handler *_event_handlers[EVENT_HANDLER_MAX];
 static mmi_client *g_client = NULL;
 
+
+static void __send_result_to_client(gpointer data, gpointer user_data)
+{
+       mmi_client *client = (mmi_client *)data;
+       output_result_s *output_result = (char *)user_data;
+
+       if (client == NULL || output_result == NULL) {
+               _E("Invalid parameters. Skip this item");
+               return;
+       }
+
+       const char *app_id = client_manager_get_client_sender(client);
+       _D("Send result. app_id(%s), event(%d)", app_id, output_result->event_type);
+
+       int ret = mmi_api_handler_send_result(client, output_result->event_type, output_result->json_data);
+       if (ret != MMI_ERROR_NONE) {
+               _E("Fail to send result. ret(%d/%s)", ret, get_error_message(ret));
+       }
+}
+
 static void __output_result_received_cb(const char *app_id, int type, const char *json_data, void *user_data)
 {
-       int ret = mmi_api_handler_send_resullt(app_id, type, json_data);
+       GList *clients = client_manager_get_clients_listening_event(type);
+       if (clients == NULL) {
+               _E("Fail to get clients which set event type (%d)", type);
+       }
+
+       output_result_s output_result;
+       output_result.event_type = type;
+       output_result.json_data = json_data;
+
+       g_list_foreach(clients, __send_result_to_client, (gpointer)&output_result);
+       g_list_free(clients);
 }
 
 static void __output_modality_received_cb(const char *app_id, int type, void *event, void *user_data)