2 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "mmi-client.h"
22 static mmi_handle mmi_h = NULL;
24 int mmi_client_create(void)
26 mmi_h = (mmi_handle)calloc(1, sizeof(mmi_struct_s));
29 LOGE("Failed to allocate memory for mmi_h !\n");
30 return MMI_ERROR_OUT_OF_MEMORY;
33 if (mmi_ipc_initialize()) {
34 LOGE("Failed to init mmi ipc !\n");
39 return MMI_ERROR_NOT_SUPPORTED;
42 mmi_h->rpc_h = mmi_ipc_get_rpc_h();
43 mmi_h->stub_appid = mmi_ipc_get_stub_appid();
44 mmi_h->result_cb_list = NULL;
46 return MMI_ERROR_NONE;
49 int mmi_client_destroy(void)
52 LOGE("A mmi_h is already NULL");
53 return MMI_ERROR_NONE;
56 mmi_ipc_deinitialize();
59 mmi_result_cb_s *data = NULL;
61 if (g_list_length(mmi_h->result_cb_list) > 0) {
62 iter = g_list_first(mmi_h->result_cb_list);
63 while (iter != NULL) {
66 data->input_event_type = 0;
67 data->result_callback = NULL;
72 iter = g_list_next(iter);
73 mmi_h->result_cb_list = g_list_remove_link(mmi_h->result_cb_list, temp);
81 return MMI_ERROR_NONE;
84 int mmi_client_set_result_cb(int input_event_type, mmi_result_cb callback, void* user_data)
86 LOGI("Set result cb about input event type(%d) to client", input_event_type);
88 if (callback == NULL) {
89 LOGE("Callback is invalid");
90 return MMI_ERROR_INVALID_PARAMETER;
93 mmi_result_cb_s* input_result_callback = (mmi_result_cb_s*)calloc(1, sizeof(mmi_result_cb_s));
94 if (input_result_callback == NULL) {
95 LOGE("[ERROR] Fail to allocate memory");
96 return MMI_ERROR_OUT_OF_MEMORY;
99 input_result_callback->input_event_type = input_event_type;
100 input_result_callback->result_callback = callback;
101 mmi_h->result_cb_list = g_list_append(mmi_h->result_cb_list, input_result_callback);
103 return MMI_ERROR_NONE;
106 mmi_handle mmi_client_get(void)