Change length of copy when snprintf is called
[platform/core/api/gesture.git] / client / gesture_client_dbus.c
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <dlog.h>
18 #include <aul.h>
19
20 #include "gesture_client_dbus.h"
21
22 #ifdef LOG_TAG
23 #undef LOG_TAG
24 #endif
25 #define LOG_TAG "GESTURE_CLIENT_DBUS"
26
27 static int is_server_started = 0;
28
29 static hand_gesture_handtype_e g_hand_type = HAND_GESTURE_LEFT_HAND;
30 static hand_gesture_workmode_e g_work_mode = HAND_GESTURE_WORK_MODE_ONE_WAY;
31 static hand_gesture_option_e g_option = HAND_GESTURE_OPTION_DEFAULT;
32 static int g_sensitivity = 1;
33
34 static char *g_engine_app_id;
35 static char *g_engine_name;
36
37
38 static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
39 {
40         LOGD("name : %s, name_owner : %s", name, name_owner);
41 }
42
43 static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
44 {
45         LOGD("name : %s", name);
46 }
47
48 static int _dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_id)
49 {
50         GError *error = NULL;
51
52         if (*gdbus_connection == NULL) {
53                 GDBusConnection *conn = NULL;
54                 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
55                 if (conn == NULL) {
56                         if (error != NULL) {
57                                 LOGE("g_bus_get_sync error message = %s", error->message);
58                                 g_error_free(error);
59                         }
60                         return HAND_GESTURE_ERROR_OPERATION_FAILED;
61                 }
62                 *gdbus_connection = conn;
63         }
64
65         LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection));
66         if (*server_watcher_id == 0) {
67                 *server_watcher_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
68                         GESTURE_DBUS_NAME,
69                         G_BUS_NAME_WATCHER_FLAGS_NONE,
70                         _server_appeared_cb,
71                         _server_vanished_cb,
72                         NULL, NULL);
73         }
74
75         LOGD("server_watcher_id : %d", *server_watcher_id);
76         if (*server_watcher_id == 0) {
77                 LOGE("Failed to get identifier");
78                 return HAND_GESTURE_ERROR_OPERATION_FAILED;
79         }
80
81         return HAND_GESTURE_ERROR_NONE;
82 }
83
84
85 static void _handle_gesture_cb(GDBusConnection *connection,
86                                         const gchar *sender_name,
87                                         const gchar *object_path,
88                                         const gchar *interface_name,
89                                         const gchar *signal_name,
90                                         GVariant *parameters,
91                                         gpointer user_data)
92 {
93         LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
94         hand_gesture_h _handle = (hand_gesture_h)user_data;
95
96         if (_handle == NULL) {
97                 LOGE("handle is not available");
98                 return;
99         }
100
101         if (parameters == NULL) {
102                 LOGE("failed to get gesture info");
103                 return;
104         }
105
106         if (g_strcmp0(signal_name, GESTURE_CLIENT_SIGNAL_GET_RESULT) == 0) {
107                 LOGD("[GESTURE_CLIENT_SIGNAL_GET_RESULT] called");
108                 int event;
109                 int gesture_type;
110                 int ltype;
111                 int levent;
112                 int lcount;
113                 g_variant_get(parameters, "(iiiii)", &event, &gesture_type, &ltype, &levent, &lcount);
114 #if 0
115                 char *printmsg = g_variant_print(parameters, true);
116                 LOGD("start parameter print : %s", printmsg);
117                 g_free(printmsg);
118                 LOGD("[event = %d] [gesture_type = %d] [ltype = %d] [levent = %d] [lcount = %d]", event, gesture_type, ltype, levent, lcount);
119 #endif
120                 if (_handle->recog_cb) {
121                         LOGD("[CLIENT DBUS] Send recognition result. gesture_type(%d)", gesture_type);
122                         _handle->recog_cb(_handle, gesture_type, 0, HAND_GESTURE_ERROR_NONE, _handle->recog_user_data);
123                 }
124         }
125         else if (g_strcmp0(signal_name, GESTURE_CLIENT_SIGNAL_GET_ERROR) == 0) {
126                 int error;
127                 char* err_msg = NULL;
128                 g_variant_get(parameters, "(is)", &error, err_msg);
129                 LOGD("[CLIENT DBUS] error(%d)", error);
130
131                 if (_handle->error_cb) {
132                         LOGD("[CLIENT DBUS] Send error");
133                         _handle->error_cb(_handle, (hand_gesture_error_e)error, err_msg, _handle->error_user_data);
134                 } else {
135                         LOGW("[CLIENT DBUS] There is no error callback");
136                 }
137         }
138         else if (g_strcmp0(signal_name, GESTURE_CLIENT_SIGNAL_GET_MOTION_STATUS) == 0) {
139
140         }
141         else if (g_strcmp0(signal_name, GESTURE_CLIENT_SIGNAL_GET_ENGINE_INFO) == 0) {
142                 g_variant_get(parameters, "(ss)", &g_engine_app_id, &g_engine_name);
143 #if 1
144                 char *printmsg = g_variant_print(parameters, true);
145                 LOGD("[engineInfo]start parameter print : %s", printmsg);
146                 g_free(printmsg);
147                 LOGE("[engineInfo][g_engine_app_id = %s] [g_engine_name = %s]", g_engine_app_id, g_engine_name);
148 #endif
149
150         }
151 }
152
153 static int _dbus_signal_init(GDBusConnection *gdbus_connection, int *monitor_id, CLIENT_LIB lib, void *data)
154 {
155         int ret = HAND_GESTURE_ERROR_NONE;
156         if (*monitor_id == 0) {
157                 int id = 0;
158                 if (lib == GESTURE_CLIENT_LIB_GESTURE) {
159                         id = g_dbus_connection_signal_subscribe(gdbus_connection,
160                                                         GESTURE_DBUS_NAME,
161                                                         GESTURE_CLIENT_INTERFACE_NAME,
162                                                         NULL,
163                                                         GESTURE_OBJECT_PATH,
164                                                         NULL,
165                                                         G_DBUS_SIGNAL_FLAGS_NONE,
166                                                         _handle_gesture_cb,
167                                                         data,
168                                                         NULL);
169                 } else if (lib == GESTURE_CLIENT_LIB_ENGINE) {
170                         LOGD("Fail to come for ENGINE lib");
171                 } else {
172                         LOGD("Fail to Not CLIENT lib");
173                 }
174
175                 LOGD("id : %d", id);
176                 if (id == 0) {
177                         ret = HAND_GESTURE_ERROR_OPERATION_FAILED;
178                         LOGE("g_dbus_connection_signal_subscribe() failed");
179                 } else {
180                         *monitor_id = id;
181                 }
182         }
183
184         return ret;
185 }
186
187 static GDBusMessage *gdbus_make_message(GVariant *body, const char *cmd)
188 {
189         LOGD("gdbus_make_message : cmd = %s", cmd);
190         GDBusMessage *message = NULL;
191         message = g_dbus_message_new_method_call(
192         GESTURE_DBUS_NAME,
193         GESTURE_OBJECT_PATH,
194         GESTURE_INTERFACE_NAME,
195         cmd);
196
197         if (!message) {
198                 LOGE("Failed to create a new gdbus message");
199                 if (body)
200                         g_variant_unref(body);
201                 return NULL;
202         }
203
204         if (body != NULL)
205                 g_dbus_message_set_body(message, body);
206
207         return message;
208 }
209
210 static int _send_message_with_sync(GDBusConnection *gdbus_connection, GDBusMessage *msg, GDBusMessage **reply, const char *cmd)
211 {
212         LOGD("_send_message_with_sync : cmd = %s", cmd);
213         int ret = HAND_GESTURE_ERROR_NONE;
214         GError *err = NULL;
215
216         gchar *printmsg = g_dbus_message_print (msg, 1);
217         LOGD("[sync] before send to server, print : %s", printmsg);
218         g_free(printmsg);
219
220         *reply = g_dbus_connection_send_message_with_reply_sync(
221                                         gdbus_connection,
222                                         msg,
223                                         G_DBUS_SEND_MESSAGE_FLAGS_NONE,
224                                         -1,
225                                         NULL,
226                                         NULL,
227                                         &err);
228
229         if (!*reply) {
230                 ret = HAND_GESTURE_ERROR_OPERATION_FAILED;
231                 if (err != NULL) {
232                         LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
233                         if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
234                                 ret = HAND_GESTURE_ERROR_PERMISSION_DENIED;
235                         g_error_free(err);
236                 }
237                 return ret;
238         }
239
240         if (g_dbus_message_to_gerror(*reply, &err)) {
241                 LOGE("error message = %s, code = %d", err->message, err->code);
242                 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
243                         ret = HAND_GESTURE_ERROR_PERMISSION_DENIED;
244                 else
245                         ret = err->code;
246                 g_error_free(err);
247                 return ret;
248         }
249 #if 0
250         printmsg = g_dbus_message_print (*reply, 1);
251         LOGD("[sync] reply from server, print : %s", printmsg);
252         g_free(printmsg);
253
254         GVariant *result = NULL;
255         result = g_dbus_message_get_body(*reply);
256         if (result != NULL) {
257                 printmsg = g_variant_print(result, true);
258                 LOGD("Result msg print : %s", printmsg);
259                 g_free(printmsg);
260         }
261 #endif
262         return HAND_GESTURE_ERROR_NONE;
263 }
264
265 static int gdbus_send_message_with_sync(GDBusConnection *gdbus_connection, GVariant *body, GDBusMessage **reply, char *cmd)
266 {
267         LOGD("gdbus_send_message_with_sync start : cmd = %s", cmd);
268
269         int ret = HAND_GESTURE_ERROR_NONE;
270         GDBusMessage *msg = NULL;
271
272         msg = gdbus_make_message(body, cmd);
273         if (msg == NULL)
274                 return HAND_GESTURE_ERROR_OPERATION_FAILED;
275
276         ret = _send_message_with_sync(gdbus_connection, msg, reply, cmd);
277
278         if (msg)
279                 g_object_unref(msg);
280
281         return ret;
282 }
283
284 static void _async_cb(GDBusConnection *connection, GAsyncResult *res, gpointer user_data)
285 {
286         LOGD("_async_cb start");
287         GDBusMessage *reply = NULL;
288         GError *err = NULL;
289 //      hand_gesture_data_h gesturedata = (hand_gesture_data_h)user_data;
290
291         reply = g_dbus_connection_send_message_with_reply_finish(connection, res, &err);
292         if (reply) {
293                 if (g_dbus_message_to_gerror(reply, &err)) {
294                         LOGE("error message = %s, code = %d", err->message, err->code);
295                         g_error_free(err);
296                         return;
297                 }
298 #if 0
299                 GVariant *result = g_dbus_message_get_body(reply);
300                 gchar *printmsg = g_variant_print (result, true);
301                 LOGD("[async] _async_cb, print : %s", printmsg);
302                 g_free(printmsg);
303 #endif
304
305         } else {
306                 LOGE("There is no reply");
307                 return;
308         }
309
310         if (reply)
311                 g_object_unref(reply);
312
313         return;
314 }
315
316 static int gdbus_send_message_with_async(GDBusConnection *gdbus_connection, GVariant *body, char *cmd, hand_gesture_data_h gesture_data)
317 {
318         LOGD("gdbus_send_message_with_async start : cmd = %s", cmd);
319         int ret = HAND_GESTURE_ERROR_NONE;
320         GDBusMessage *msg = NULL;
321
322         msg = gdbus_make_message(body, cmd);
323         if (msg == NULL)
324                 return HAND_GESTURE_ERROR_OPERATION_FAILED;
325
326         g_dbus_connection_send_message_with_reply(
327                 gdbus_connection,
328                 msg,
329                 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
330                 -1,
331                 NULL,
332                 NULL,
333                 (GAsyncReadyCallback)_async_cb,
334                 gesture_data);
335
336         if (msg)
337                 g_object_unref(msg);
338
339         return ret;
340 }
341
342 static int _monitor_register(GDBusConnection *gdbus_connection, const char *uid, const char *smack_label)
343 {
344         int ret;
345         GDBusMessage *reply = NULL;
346         GVariant *client_body = NULL;
347
348         char appid[1024] = {0, };
349         int pid = getpid();
350         ret = aul_app_get_appid_bypid(pid, appid, sizeof(appid));
351         if (ret != 0) {
352                 LOGE("aul_app_get_appid_bypid() failed : %d", ret);
353         }
354
355         LOGI("[INFO] appid(%s), pid(%d), uid(%s), smack_label(%s)", appid, pid, uid, smack_label);
356
357         client_body = g_variant_new("(iisiss)", 11, GESTURE_CLIENT_LIB_GESTURE, appid, pid, uid, smack_label);
358
359         ret = gdbus_send_message_with_sync(gdbus_connection, client_body, &reply, GESTURE_MSG_SERVICE_REGISTER);
360         if (reply)
361                 g_object_unref(reply);
362
363         if (client_body)
364                 g_variant_unref(client_body);
365
366         if (ret != HAND_GESTURE_ERROR_NONE) {
367                 LOGE("gdbus_send_message_with_sync() failed : %d", ret);
368                 return ret;
369         }
370
371         is_server_started = 1;
372         return ret;
373 }
374
375 static void _on_name_appeared(GDBusConnection *connection,
376                 const gchar     *name,
377                 const gchar     *name_owner,
378                 gpointer         user_data)
379 {
380         struct hand_gesture_s *_struct = user_data;
381
382         if (is_server_started == 0) {
383                 LOGI("uid(%s), smack_label(%s)", _struct->uid, _struct->smack_label);
384                 _monitor_register(connection, _struct->uid, _struct->smack_label);
385         }
386 }
387
388 static void _on_name_vanished(GDBusConnection *connection,
389                 const gchar     *name,
390                 gpointer         user_data)
391 {
392         is_server_started = 0;
393 }
394
395 int gesture_client_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_id,
396                                 int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, const char *uid, const char *smack_label, void *data)
397 {
398         LOGD("gesture_client_dbus_init start");
399
400         int ret;
401
402         ret = _dbus_init(gdbus_connection, server_watcher_id);
403         if (ret != HAND_GESTURE_ERROR_NONE) {
404                 LOGE("_dbus_init() failed : %d", ret);
405                 return ret;
406         }
407
408         ret = _dbus_signal_init(*gdbus_connection, monitor_id, lib, data);
409         if (ret != HAND_GESTURE_ERROR_NONE) {
410                 LOGE("_dbus_signal_init() failed : %d", ret);
411                 return ret;
412         }
413
414         ret = _monitor_register(*gdbus_connection, uid, smack_label);
415         if (ret != HAND_GESTURE_ERROR_NONE) {
416                 LOGE("_monitor_register() failed : %d", ret);
417                 return ret;
418         }
419
420         if (*server_monitor_id == 0) {
421                 *server_monitor_id = g_bus_watch_name_on_connection(
422                                 *gdbus_connection,
423                                 GESTURE_DBUS_NAME,
424                                 G_BUS_NAME_WATCHER_FLAGS_NONE,
425                                 _on_name_appeared,
426                                 _on_name_vanished,
427                                 data,
428                                 NULL);
429                 if (*server_monitor_id == 0) {
430                         g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
431                         *monitor_id = 0;
432                         LOGE("Failed to get identifier");
433                         return HAND_GESTURE_ERROR_OPERATION_FAILED;
434                 }
435         }
436
437         return HAND_GESTURE_ERROR_NONE;
438 }
439
440 int gesture_client_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_monitor_id, int *monitor_id)
441 {
442         if (*server_monitor_id) {
443                 g_bus_unwatch_name(*server_monitor_id);
444                 *server_monitor_id = 0;
445         }
446
447         if (*monitor_id) {
448                 g_dbus_connection_signal_unsubscribe(gdbus_connection, *monitor_id);
449                 *monitor_id = 0;
450         }
451
452         return HAND_GESTURE_ERROR_NONE;
453 }
454
455 int gesture_client_dbus_initialize_engine(GDBusConnection *gdbus_connection)
456 {
457         int ret;
458         GDBusMessage *reply = NULL;
459         GVariant *body = NULL;
460
461         body = g_variant_new("()");
462         ret = gdbus_send_message_with_sync(gdbus_connection, body, &reply, GESTURE_CLIENT_MSG_INITIALIZE_ENGINE);
463         if (ret != HAND_GESTURE_ERROR_NONE)
464                 LOGE("failed to initialize");
465
466         if (body)
467                 g_variant_unref(body);
468
469         if (reply)
470                 g_object_unref(reply);
471
472         return ret;
473
474 }
475
476 int gesture_client_dbus_deinitialize_engine(GDBusConnection *gdbus_connection)
477 {
478         int ret;
479         GDBusMessage *reply = NULL;
480         GVariant *body = NULL;
481
482         body = g_variant_new("()");
483         ret = gdbus_send_message_with_sync(gdbus_connection, body, &reply, GESTURE_CLIENT_MSG_DEINITIALIZE_ENGINE);
484         if (ret != HAND_GESTURE_ERROR_NONE)
485                 LOGE("failed to deinitialize");
486
487         if (body)
488                 g_variant_unref(body);
489
490         if (reply)
491                 g_object_unref(reply);
492
493         return ret;
494
495 }
496
497 int gesture_client_dbus_set_handtype(GDBusConnection *gdbus_connection, hand_gesture_handtype_e hand_type)
498 {
499         int ret = HAND_GESTURE_ERROR_NONE;
500         if (hand_type > HAND_GESTURE_RIGHT_HAND || hand_type < HAND_GESTURE_NO_SELECTED_HAND) {
501                 LOGE("Invalid Parmeter");
502                 return HAND_GESTURE_ERROR_INVALID_PARAMETER;
503         }
504         g_hand_type = hand_type;
505
506         return ret;
507 }
508
509 int gesture_client_dbus_set_workmode(GDBusConnection *gdbus_connection, hand_gesture_workmode_e work_mode)
510 {
511         int ret = HAND_GESTURE_ERROR_NONE;
512         if (work_mode > HAND_GESTURE_WORK_MODE_UNDEFINED || work_mode < HAND_GESTURE_WORK_MODE_ONE_WAY) {
513                 LOGE("Invalid Parmeter");
514                 return HAND_GESTURE_ERROR_INVALID_PARAMETER;
515         }
516         g_work_mode = work_mode;
517
518         return ret;
519 }
520
521 int gesture_client_dbus_set_option(GDBusConnection *gdbus_connection, hand_gesture_option_e option)
522 {
523         int ret = HAND_GESTURE_ERROR_NONE;
524         if (option > HAND_GESTURE_OPTION_ALWAYS_ON || option < HAND_GESTURE_OPTION_DEFAULT) {
525                 LOGE("Invalid Parmeter");
526                 return HAND_GESTURE_ERROR_INVALID_PARAMETER;
527         }
528         g_option = option;
529
530         return ret;
531 }
532
533 int gesture_client_dbus_set_sensitivity(GDBusConnection *gdbus_connection, int sensitivity)
534 {
535         int ret = HAND_GESTURE_ERROR_NONE;
536         g_sensitivity = sensitivity;
537
538         return ret;
539 }
540
541 int gesture_client_dbus_start_recognition(GDBusConnection *gdbus_connection, hand_gesture_type_e gesture_type, hand_gesture_data_h gesture_data, hand_gesture_recognition_cb callback)
542 {
543         LOGD("gesture_client_dbus_start_recognition start");
544         LOGD("client busname: %s", g_dbus_connection_get_unique_name(gdbus_connection));
545
546         GVariant *body = NULL;
547         body = g_variant_new("(iiiii)", gesture_type, g_hand_type, g_work_mode, g_option, g_sensitivity);
548
549         gdbus_send_message_with_async(gdbus_connection, body, GESTURE_CLIENT_MSG_START_RECOGNITION, gesture_data);
550
551         if (body)
552                 g_variant_unref(body);
553
554         return HAND_GESTURE_ERROR_NONE;
555 }
556
557 int gesture_client_dbus_stop_recognition(GDBusConnection *gdbus_connection)
558 {
559         int ret;
560         GDBusMessage *reply = NULL;
561         GVariant *body = NULL;
562
563         body = g_variant_new("()");
564         ret = gdbus_send_message_with_sync(gdbus_connection, body, &reply, GESTURE_CLIENT_MSG_STOP_RECOGNITION);
565         if (ret != HAND_GESTURE_ERROR_NONE)
566                 LOGE("failed to stop gesture");
567
568         if (body)
569                 g_variant_unref(body);
570
571         if (reply)
572                 g_object_unref(reply);
573
574         return ret;
575
576 }
577
578 int gesture_client_dbus_foreach_result_time(GDBusConnection *gdbus_connection)
579 {
580         int ret;
581         GDBusMessage *reply = NULL;
582         GVariant *body = NULL;
583
584         body = g_variant_new("()");
585         ret = gdbus_send_message_with_sync(gdbus_connection, body, &reply, GESTURE_CLIENT_MSG_FOREACH_RESULT_TIME);
586         if (ret != HAND_GESTURE_ERROR_NONE)
587                 LOGE("failed to foreach_result_time");
588
589         if (body)
590                 g_variant_unref(body);
591
592         if (reply)
593                 g_object_unref(reply);
594
595         return ret;
596
597 }
598
599 int gesture_client_dbus_foreach_supported_type(GDBusConnection *gdbus_connection)
600 {
601         int ret;
602         GDBusMessage *reply = NULL;
603         GVariant *body = NULL;
604
605         body = g_variant_new("()");
606         ret = gdbus_send_message_with_sync(gdbus_connection, body, &reply, GESTURE_CLIENT_MSG_FOREACH_SUPPORTED_TYPE);
607         if (ret != HAND_GESTURE_ERROR_NONE)
608                 LOGE("failed to foreach_supported_type");
609
610         if (body)
611                 g_variant_unref(body);
612
613         if (reply)
614                 g_object_unref(reply);
615
616         return ret;
617
618 }
619
620 int gesture_client_dbus_is_support_gesture_type(GDBusConnection *gdbus_connection, hand_gesture_type_e gesture, bool* supported)
621 {
622         int ret;
623         GDBusMessage *reply = NULL;
624         GVariant *body = NULL;
625
626         body = g_variant_new("(i)", gesture);
627         ret = gdbus_send_message_with_sync(gdbus_connection, body, &reply, GESTURE_CLIENT_MSG_IS_SUPPORT_GESTURE_TYPE);
628         if (ret != HAND_GESTURE_ERROR_NONE || NULL == reply) {
629                 LOGE("failed to is_supported_gesture_type");
630         } else {
631                 LOGD("Check reply from server");
632                 GVariant *reply_body = g_dbus_message_get_body(reply);
633                 if (NULL == reply_body) {
634                         LOGE("There is no return value");
635                         ret = HAND_GESTURE_ERROR_OPERATION_FAILED;
636                 } else {
637                         g_variant_get(reply_body, "(b)", supported);
638                         LOGD("supported(%d)", *supported);
639                 }
640         }
641
642         if (body)
643                 g_variant_unref(body);
644
645         if (reply)
646                 g_object_unref(reply);
647
648         return ret;
649
650 }
651
652 int gesture_client_dbus_get_engine_info(GDBusConnection *gdbus_connection, char** engine_app_id, char** engine_name)
653 {
654         int ret;
655         GDBusMessage *reply = NULL;
656         GVariant *body = NULL;
657
658         body = g_variant_new("()");
659         ret = gdbus_send_message_with_sync(gdbus_connection, body, &reply, GESTURE_CLIENT_MSG_ENGINE_GET_INFO);
660         if (ret != HAND_GESTURE_ERROR_NONE)
661                 LOGE("Fail to send message");
662
663         GVariant *reply_body = g_dbus_message_get_body(reply);
664         if (NULL == reply_body) {
665                 LOGE("There is no return value");
666                 ret = HAND_GESTURE_ERROR_OPERATION_FAILED;
667         } else {
668                 g_variant_get(reply_body, "(ss)", engine_app_id, engine_name);
669                 if (NULL == engine_app_id || NULL == engine_name) {
670                         LOGE("Fail to get engine info");
671                         ret = HAND_GESTURE_ERROR_OPERATION_FAILED;
672                 } else {
673                         if (NULL != g_engine_app_id) {
674                                 free(g_engine_app_id);
675                         }
676
677                         if (NULL != g_engine_name) {
678                                 free(g_engine_name);
679                         }
680
681                         g_engine_app_id = *engine_app_id;
682                         g_engine_name = *engine_name;
683                         LOGD("APP ID(%s), Name(%s)", *engine_app_id, *engine_name);
684                 }
685         }
686
687         if (body)
688                 g_variant_unref(body);
689
690         if (reply)
691                 g_object_unref(reply);
692
693         return ret;
694 }
695