2 * Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 #include "mmifw-ipc.h"
26 #include "mmifw-dbg.h"
30 int MMI_EVENT_CONNECTION;
32 int MMI_EVENT_STATE_CHANGE;
33 int MMI_EVENT_WAKE_UP;
35 int MMI_EVENT_GESTURE;
38 int MMI_EVENT_FEEDBACK;
40 static int _mmi_init_count = 0;
41 Eina_List *listener_list = NULL;
46 if (++_mmi_init_count != 1)
47 return _mmi_init_count;
52 mmi_event_listener *listener = NULL;
56 EINA_LIST_FOREACH(listener_list, l, listener)
57 ecore_event_handler_del(listener);
59 listener_list = eina_list_free(listener_list);
63 MMI_EVENT_CONNECTION = ecore_event_type_new();
64 MMI_EVENT_FOCUS = ecore_event_type_new();
65 MMI_EVENT_STATE_CHANGE = ecore_event_type_new();
66 MMI_EVENT_WAKE_UP = ecore_event_type_new();
67 MMI_EVENT_KEY = ecore_event_type_new();
68 MMI_EVENT_GESTURE = ecore_event_type_new();
69 MMI_EVENT_VOICE = ecore_event_type_new();
70 MMI_EVENT_ACTION = ecore_event_type_new();
71 MMI_EVENT_FEEDBACK = ecore_event_type_new();
73 return _mmi_init_count;
76 return --_mmi_init_count;
82 if (_mmi_init_count <= 0)
84 ERR("Init count must be greater than 0.");
90 MMI_EVENT_CONNECTION = -1;
92 MMI_EVENT_STATE_CHANGE = -1;
93 MMI_EVENT_WAKE_UP = -1;
95 MMI_EVENT_GESTURE = -1;
97 MMI_EVENT_ACTION = -1;
98 MMI_EVENT_FEEDBACK = -1;
101 mmi_event_listener *listener = NULL;
105 EINA_LIST_FOREACH(listener_list, l, listener)
106 ecore_event_handler_del(listener);
108 listener_list = eina_list_free(listener_list);
109 listener_list = NULL;
112 ecore_main_loop_quit();
113 return _mmi_init_count;
117 mmi_instance_create(const char *app_id)
121 h = (mmi_handle)calloc(1, sizeof(mmi_struct));
125 ERR("Failed to allocate memory for mmi_handle !\n");
129 if (mmi_ipc_init(app_id))
131 ERR("Failed to init mmifw ipc !\n");
135 h->rpc_h = mmi_ipc_get_rpc_h();
136 h->app_id = mmi_ipc_get_appid();
137 h->stub_appid = mmi_ipc_get_stub_appid();
138 h->uid = mmi_ipc_get_uid();
139 h->state = mmi_ipc_get_state();
148 MMIFW_API mmi_event_listener *
149 mmi_event_add_listener(mmi_handle h, int ev_type, mmi_event_handler_cb func, const void *data)
151 mmi_event_listener *listener;
155 listener = ecore_event_handler_add(ev_type, func, data);
156 listener_list = eina_list_append(listener_list, listener);
161 mmi_request_send_get_focus(mmi_handle h)
163 mmi_result res = MMI_RESULT_SUCCESS;
167 ERR("Given mmi_handle is invalid !\n");
168 return MMI_RESULT_FAIL;
171 if (mmi_ipc_is_connected())
172 rpc_port_proxy_mmifw_invoke_get_focus(h->rpc_h);
175 ERR("Not connected yet !\n");
176 res = MMI_RESULT_FAIL;
179 LOGI("Get_focus request has been sent !\n");
185 mmi_state_get_current_state(mmi_handle h)
187 mmi_state state = MMI_STATE_NONE;
191 ERR("Given mmi_handle is invalid !\n");
200 mmi_request_send_set_state(mmi_handle h, mmi_state state)
202 mmi_result res = MMI_RESULT_SUCCESS;
206 ERR("Given mmi_handle is invalid !\n");
207 return MMI_RESULT_FAIL;
210 if (state == h->state)
212 ERR("Given state equals to the current state. Ignored !\n");
216 rpc_port_proxy_mmifw_invoke_set_state(h->rpc_h, state);
221 mmi_event_remove_listener(mmi_handle h, mmi_event_listener *listener)
226 listener_list = eina_list_remove(listener_list, listener);
228 ecore_event_handler_del(listener);
232 mmi_event_remove_all_listeners(mmi_handle h)
235 mmi_event_listener *listener = NULL;
239 EINA_LIST_FOREACH(listener_list, l, listener)
240 ecore_event_handler_del(listener);
242 listener_list = eina_list_free(listener_list);
243 listener_list = NULL;
247 mmi_instance_destroy(mmi_handle h)