2 * Copyright (c) 2019 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.
19 #include "sticker_dbus.h"
24 #define LOG_TAG "STICKER_DBUS"
26 static int is_server_started = 0;
28 static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
30 LOGD("name : %s, name_owner : %s", name, name_owner);
34 static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
36 LOGD("name : %s", name);
40 static int _dbus_init(GDBusConnection **gdbus_connection)
45 if (*gdbus_connection == NULL) {
46 GDBusConnection *conn = NULL;
47 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
50 LOGE("g_bus_get_sync error message = %s", error->message);
53 return STICKER_CLIENT_ERROR_IO_ERROR;
55 *gdbus_connection = conn;
58 LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection));
59 watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
61 G_BUS_NAME_WATCHER_FLAGS_NONE,
66 LOGD("watch_id : %d", watch_id);
68 LOGE("Failed to get identifier");
69 return STICKER_CLIENT_ERROR_IO_ERROR;
72 return STICKER_CLIENT_ERROR_NONE;
75 static void _get_sticker_info_from_gvariant(GVariant *body, sticker_data_h sticker_data)
78 GVariant *value = NULL;
79 GVariantIter *info_iter = NULL;
80 GVariantIter *keyword_iter = NULL;
83 g_variant_get(body, "(a{iv}a(s))", &info_iter, &keyword_iter);
85 if (!info_iter || !keyword_iter) {
86 LOGD("failed to get iter");
90 while (g_variant_iter_loop (info_iter, "{iv}", &key, &value)) {
92 case STICKER_DATA_TYPE_APP_ID:
93 sticker_data->app_id = g_variant_dup_string(value, NULL);
95 case STICKER_DATA_TYPE_URI_TYPE:
96 sticker_data->type = g_variant_get_int32(value);
98 case STICKER_DATA_TYPE_URI:
99 sticker_data->uri = g_variant_dup_string(value, NULL);
101 case STICKER_DATA_TYPE_THUMBNAIL:
102 sticker_data->thumbnail = g_variant_dup_string(value, NULL);
104 case STICKER_DATA_TYPE_DESCRIPTION:
105 sticker_data->description = g_variant_dup_string(value, NULL);
107 case STICKER_DATA_TYPE_GROUP:
108 sticker_data->group = g_variant_dup_string(value, NULL);
110 case STICKER_DATA_TYPE_DATE:
111 sticker_data->date = g_variant_dup_string(value, NULL);
113 case STICKER_DATA_TYPE_DISP_TYPE:
114 sticker_data->disp_type = g_variant_get_int32(value);
121 while (g_variant_iter_loop (keyword_iter, "(s)", &keyword)) {
122 sticker_data->keyword = g_list_append(sticker_data->keyword, strdup((const char *)keyword));
126 g_variant_unref(value);
128 g_variant_iter_free(info_iter);
129 g_variant_iter_free(keyword_iter);
132 static void _free_sticker_data(sticker_data_h sticker_data)
134 if (sticker_data->app_id) {
135 free(sticker_data->app_id);
136 sticker_data->app_id = NULL;
139 if (sticker_data->uri) {
140 free(sticker_data->uri);
141 sticker_data->uri = NULL;
144 if (sticker_data->thumbnail) {
145 free(sticker_data->thumbnail);
146 sticker_data->thumbnail = NULL;
149 if (sticker_data->keyword) {
150 g_list_free_full(sticker_data->keyword, free);
151 sticker_data->keyword = NULL;
154 if (sticker_data->group) {
155 free(sticker_data->group);
156 sticker_data->group = NULL;
159 if (sticker_data->description) {
160 free(sticker_data->description);
161 sticker_data->description = NULL;
164 if (sticker_data->date) {
165 free(sticker_data->date);
166 sticker_data->date = NULL;
173 static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVariant *body)
176 g_variant_get(body, "(i)", &ret);
179 provider_handle->insert_finished_cb(STICKER_ERROR_NONE, provider_handle->insert_finished_cb_user_data);
181 provider_handle->insert_finished_cb(STICKER_ERROR_OPERATION_FAILED, provider_handle->insert_finished_cb_user_data);
186 static void _handle_sticker_consumer_cb(GDBusConnection *connection,
187 const gchar *sender_name,
188 const gchar *object_path,
189 const gchar *interface_name,
190 const gchar *signal_name,
191 GVariant *parameters,
194 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
195 sticker_consumer_h consumer_handle = (sticker_consumer_h)user_data;
197 if (consumer_handle == NULL) {
198 LOGE("consumer handle is not available");
202 if (parameters == NULL) {
203 LOGE("failed to get sticker info");
207 #if 0 // Receive the sticker information by asynchronous communication.
208 if (g_strcmp0(signal_name, "send_group_list") == 0) {
209 if (consumer_handle->group_foreach_cb != NULL)
210 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
212 } else if (g_strcmp0(signal_name, "send_keyword_list") == 0) {
213 if (consumer_handle->keyword_foreach_cb != NULL)
214 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
218 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
221 LOGE("failed to allocate memory");
225 _get_sticker_info_from_gvariant(parameters, sticker_data);
227 if (g_strcmp0(signal_name, "send_all_sticker_info") == 0) {
228 if (consumer_handle->data_foreach_cb != NULL)
229 consumer_handle->data_foreach_cb(sticker_data, consumer_handle->data_foreach_cb_user_data);
231 LOGW("No registered callback function");
232 } else if (g_strcmp0(signal_name, "send_sticker_info_by_keyword") == 0) {
233 if (consumer_handle->data_foreach_by_keyword_cb != NULL)
234 consumer_handle->data_foreach_by_keyword_cb(sticker_data, consumer_handle->data_foreach_by_keyword_cb_user_data);
236 LOGW("No registered callback function");
237 } else if (g_strcmp0(signal_name, "send_sticker_info_by_group") == 0) {
238 if (consumer_handle->data_foreach_by_group_cb != NULL)
239 consumer_handle->data_foreach_by_group_cb(sticker_data, consumer_handle->data_foreach_by_group_cb_user_data);
241 LOGW("No registered callback function");
242 } else if (g_strcmp0(signal_name, "send_sticker_info_by_type") == 0) {
243 if (consumer_handle->data_foreach_by_type_cb != NULL)
244 consumer_handle->data_foreach_by_type_cb(sticker_data, consumer_handle->data_foreach_by_type_cb_user_data);
246 LOGW("No registered callback function");
249 _free_sticker_data(sticker_data);
254 static void _handle_sticker_provider_cb(GDBusConnection *connection,
255 const gchar *sender_name,
256 const gchar *object_path,
257 const gchar *interface_name,
258 const gchar *signal_name,
259 GVariant *parameters,
262 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
263 sticker_provider_h provider_handle = (sticker_provider_h)user_data;
265 if (provider_handle == NULL) {
266 LOGE("provider handle is not available");
270 if (parameters == NULL) {
271 LOGE("failed to get sticker info");
275 if (g_strcmp0(signal_name, "send_insert_result") == 0) {
276 if (provider_handle->insert_finished_cb != NULL)
277 _call_insert_finished_cb(provider_handle, parameters);
280 #if 0 // Receive the sticker information by asynchronous communication.
281 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
284 LOGE("failed to allocate memory");
288 _get_sticker_info_from_gvariant(parameters, sticker_data);
290 if (g_strcmp0(signal_name, "send_sticker_info_by_appid") == 0) {
291 if (provider_handle->data_foreach_cb != NULL)
292 provider_handle->data_foreach_cb(sticker_data, provider_handle->data_foreach_cb_user_data);
294 LOGW("No registered callback function");
297 _free_sticker_data(sticker_data);
301 static int _dbus_signal_init(GDBusConnection *gdbus_connection, int *monitor_id, CLIENT_LIB lib, void *data)
303 int ret = STICKER_CLIENT_ERROR_NONE;
304 if (*monitor_id == 0) {
306 if (lib == STICKER_CLIENT_LIB_CONSUMER)
307 id = g_dbus_connection_signal_subscribe(gdbus_connection,
309 STICKER_CONSUMER_INTERFACE_NAME,
313 G_DBUS_SIGNAL_FLAGS_NONE,
314 _handle_sticker_consumer_cb,
317 else if (lib == STICKER_CLIENT_LIB_PROVIDER)
318 id = g_dbus_connection_signal_subscribe(gdbus_connection,
320 STICKER_PROVIDER_INTERFACE_NAME,
324 G_DBUS_SIGNAL_FLAGS_NONE,
325 _handle_sticker_provider_cb,
330 ret = STICKER_CLIENT_ERROR_IO_ERROR;
331 LOGE("g_dbus_connection_signal_subscribe() failed");
340 static GDBusMessage *_get_gbus_message(GVariant *body, const char *cmd)
342 GDBusMessage *message = NULL;
343 message = g_dbus_message_new_method_call(
346 STICKER_INTERFACE_NAME,
350 LOGE("Failed to create a new gdbus message");
352 g_variant_unref(body);
357 g_dbus_message_set_body(message, body);
362 static int _send_gdbus_sync_message(GDBusConnection *gdbus_connection, GDBusMessage *msg, GDBusMessage **reply, const char *cmd)
364 int ret = STICKER_CLIENT_ERROR_NONE;
367 *reply = g_dbus_connection_send_message_with_reply_sync(
370 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
377 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
379 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
380 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
381 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
387 if (g_dbus_message_to_gerror(*reply, &err)) {
388 LOGE("error message = %s, code = %d", err->message, err->code);
389 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
390 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
397 LOGD("Send a message to server(cmd : %s)", cmd);
398 return STICKER_CLIENT_ERROR_NONE;
401 static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body, GDBusMessage **reply, char *cmd)
403 int ret = STICKER_CLIENT_ERROR_NONE;
404 GDBusMessage *msg = NULL;
406 msg = _get_gbus_message(body, cmd);
408 return STICKER_CLIENT_ERROR_IO_ERROR;
410 ret = _send_gdbus_sync_message(gdbus_connection, msg, reply, cmd);
418 static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd)
420 int ret = STICKER_CLIENT_ERROR_NONE;
421 GDBusMessage *msg = NULL;
424 msg = _get_gbus_message(body, cmd);
426 return STICKER_CLIENT_ERROR_IO_ERROR;
428 g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
434 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
435 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
437 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
438 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
447 static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id)
450 GDBusMessage *reply = NULL;
451 GVariant *reply_body = NULL;
453 ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "sticker_service_register");
455 if (ret != STICKER_CLIENT_ERROR_NONE) {
456 LOGE("_send_sync_message() failed : %d", ret);
460 reply_body = g_dbus_message_get_body(reply);
461 g_variant_get(reply_body, "(i)", server_watcher_id);
464 g_object_unref(reply);
466 is_server_started = 1;
470 static void _on_name_appeared(GDBusConnection *connection,
472 const gchar *name_owner,
475 if (is_server_started == 0) {
476 int *watcher_id = (int *)user_data;
477 _monitor_register(connection, watcher_id);
482 static void _on_name_vanished(GDBusConnection *connection,
486 is_server_started = 0;
490 int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
491 int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data)
495 ret = _dbus_init(gdbus_connection);
496 if (ret != STICKER_CLIENT_ERROR_NONE) {
497 LOGE("_dbus_init() failed : %d", ret);
501 ret = _dbus_signal_init(*gdbus_connection, monitor_id, lib, data);
502 if (ret != STICKER_CLIENT_ERROR_NONE) {
503 LOGE("_dbus_signal_init() failed : %d", ret);
507 ret = _monitor_register(*gdbus_connection, server_watcher_id);
508 if (ret != STICKER_CLIENT_ERROR_NONE) {
509 LOGE("_monitor_register() failed : %d", ret);
513 if (*server_monitor_id == 0) {
514 *server_monitor_id = g_bus_watch_name_on_connection(
517 G_BUS_NAME_WATCHER_FLAGS_NONE,
522 if (*server_monitor_id == 0) {
523 g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
525 LOGE("Failed to get identifier");
526 return STICKER_CLIENT_ERROR_IO_ERROR;
530 return STICKER_CLIENT_ERROR_NONE;
533 int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id)
537 if (server_watcher_id) {
538 ret = _send_async_message(gdbus_connection, g_variant_new("(i)", *server_watcher_id), "sticker_service_unregister");
539 if (ret != STICKER_CLIENT_ERROR_NONE) {
540 LOGE("Failed to unregister sticker service");
544 *server_watcher_id = 0;
547 if (*server_monitor_id) {
548 g_bus_unwatch_name(*server_monitor_id);
549 *server_monitor_id = 0;
553 g_dbus_connection_signal_unsubscribe(gdbus_connection, *monitor_id);
557 return STICKER_CLIENT_ERROR_NONE;
560 static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
563 LOGE("keyword doesn't exist");
567 g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
570 int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
574 GDBusMessage *reply = NULL;
575 GVariant *reply_body = NULL;
576 GVariantBuilder *info_builder;
577 GVariantBuilder *keyword_builder;
579 if (!sticker_data->app_id || (sticker_data->type < 1) || !sticker_data->uri || !sticker_data->group || !sticker_data->keyword)
580 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
582 info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
583 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_data->app_id));
584 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_data->type));
585 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_data->uri));
586 if (sticker_data->thumbnail)
587 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_data->thumbnail));
588 if (sticker_data->description)
589 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description));
590 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group));
591 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type));
593 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
594 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
596 ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
597 if (ret != STICKER_CLIENT_ERROR_NONE) {
598 LOGW("Failed to save sticker info");
602 reply_body = g_dbus_message_get_body(reply);
603 g_variant_get(reply_body, "(i)", &ret_id);
604 sticker_data->sticker_info_id = ret_id;
606 LOGD("ret_id : %d", ret_id);
608 g_variant_builder_unref(info_builder);
609 g_variant_builder_unref(keyword_builder);
612 g_variant_unref(reply_body);
615 g_object_unref(reply);
620 int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
624 ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
625 if (ret != STICKER_CLIENT_ERROR_NONE)
626 LOGE("failed to send json path");
631 int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id)
634 GDBusMessage *reply = NULL;
636 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
637 if (ret != STICKER_CLIENT_ERROR_NONE)
638 LOGE("failed to delete sticker info");
641 g_object_unref(reply);
646 int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
649 GDBusMessage *reply = NULL;
650 GVariant *reply_body = NULL;
651 sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
654 LOGE("failed to allocate memory");
655 return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
658 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
659 if (ret == STICKER_CLIENT_ERROR_NONE) {
660 reply_body = g_dbus_message_get_body(reply);
661 _get_sticker_info_from_gvariant(reply_body, origin_data);
663 LOGW("failed to get sticker info");
666 g_object_unref(reply);
670 if (sticker_data->uri && strcmp(sticker_data->uri, origin_data->uri) != 0) {
671 LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, sticker_data->uri);
672 ret = _send_sync_message(gdbus_connection, g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri), &reply, "update_sticker_uri");
673 if (ret != STICKER_CLIENT_ERROR_NONE) {
674 LOGE("failed to update sticker uri");
679 if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
680 LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
681 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
682 if (ret != STICKER_CLIENT_ERROR_NONE) {
683 LOGE("failed to update sticker type");
688 if (sticker_data->thumbnail && strcmp(sticker_data->thumbnail, origin_data->thumbnail) != 0) {
689 LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, sticker_data->thumbnail);
690 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
691 if (ret != STICKER_CLIENT_ERROR_NONE) {
692 LOGE("failed to update sticker thumbnail");
697 if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
698 LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
699 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
700 if (ret != STICKER_CLIENT_ERROR_NONE) {
701 LOGE("failed to update sticker description");
706 if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
707 LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group);
708 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group");
709 if (ret != STICKER_CLIENT_ERROR_NONE) {
710 LOGE("failed to update sticker group");
715 if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) {
716 LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type);
717 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type");
718 if (ret != STICKER_CLIENT_ERROR_NONE) {
719 LOGE("failed to update sticker display type");
724 if (sticker_data->keyword) {
725 GVariantBuilder *keyword_builder;
726 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
727 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
728 ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
729 if (ret != STICKER_CLIENT_ERROR_NONE)
730 LOGE("failed to update sticker keyword");
731 g_variant_builder_unref(keyword_builder);
735 _free_sticker_data(origin_data);
738 g_variant_unref(reply_body);
741 g_object_unref(reply);
746 int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, int record_id)
749 GDBusMessage *reply = NULL;
750 GVariant *reply_body = NULL;
752 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info");
753 if (ret == STICKER_CLIENT_ERROR_NONE) {
754 reply_body = g_dbus_message_get_body(reply);
755 sticker_data->sticker_info_id = record_id;
756 _get_sticker_info_from_gvariant(reply_body, sticker_data);
759 g_variant_unref(reply_body);
763 g_object_unref(reply);
768 int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list)
771 GDBusMessage *reply = NULL;
772 GVariantIter *iter = NULL;
773 GVariant *reply_body = NULL;
776 if (group_list == NULL) {
777 LOGE("group_list is invalid");
778 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
781 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_list");
782 if (ret == STICKER_CLIENT_ERROR_NONE) {
783 reply_body = g_dbus_message_get_body(reply);
784 g_variant_get(reply_body, "(a(s))", &iter);
787 LOGD("failed to get iter");
788 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
791 while (g_variant_iter_loop (iter, "(s)", &group)) {
792 *group_list = g_list_append(*group_list, strdup((const char *)group));
795 g_variant_iter_free(iter);
799 g_variant_unref(reply_body);
802 g_object_unref(reply);
807 int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list)
810 GDBusMessage *reply = NULL;
811 GVariantIter *iter = NULL;
812 GVariant *reply_body = NULL;
813 char *keyword = NULL;
815 if (keyword_list == NULL) {
816 LOGE("keyword_list is invalid");
817 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
820 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_keyword_list");
821 if (ret == STICKER_CLIENT_ERROR_NONE) {
822 reply_body = g_dbus_message_get_body(reply);
823 g_variant_get(reply_body, "(a(s))", &iter);
826 LOGD("failed to get iter");
827 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
830 while (g_variant_iter_loop (iter, "(s)", &keyword)) {
831 *keyword_list = g_list_append(*keyword_list, strdup((const char *)keyword));
834 g_variant_iter_free(iter);
838 g_variant_unref(reply_body);
841 g_object_unref(reply);
846 int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char *app_id, int *count)
849 GDBusMessage *reply = NULL;
850 GVariant *reply_body = NULL;
852 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
853 if (ret == STICKER_CLIENT_ERROR_NONE) {
854 reply_body = g_dbus_message_get_body(reply);
855 g_variant_get(reply_body, "(i)", count);
859 g_variant_unref(reply_body);
862 g_object_unref(reply);
867 int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
870 GDBusMessage *reply = NULL;
871 GVariant *reply_body = NULL;
873 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_all_sticker_info");
874 if (ret == STICKER_CLIENT_ERROR_NONE) {
875 reply_body = g_dbus_message_get_body(reply);
876 g_variant_get(reply_body, "(a(i))", &(*id_iter));
880 g_variant_unref(reply_body);
883 g_object_unref(reply);
888 int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
891 GDBusMessage *reply = NULL;
892 GVariant *reply_body = NULL;
894 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid");
895 if (ret == STICKER_CLIENT_ERROR_NONE) {
896 reply_body = g_dbus_message_get_body(reply);
897 g_variant_get(reply_body, "(a(i))", &(*id_iter));
901 g_variant_unref(reply_body);
904 g_object_unref(reply);
909 int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_uri_type_e type, int offset, int count, GVariantIter **id_iter)
912 GDBusMessage *reply = NULL;
913 GVariant *reply_body = NULL;
915 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_type");
916 if (ret == STICKER_CLIENT_ERROR_NONE) {
917 reply_body = g_dbus_message_get_body(reply);
918 g_variant_get(reply_body, "(a(i))", &(*id_iter));
922 g_variant_unref(reply_body);
925 g_object_unref(reply);
930 int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, const char *app_id, const char *group, int offset, int count, GVariantIter **id_iter)
933 GDBusMessage *reply = NULL;
934 GVariant *reply_body = NULL;
936 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, group, offset, count), &reply, "get_sticker_info_by_group");
937 if (ret == STICKER_CLIENT_ERROR_NONE) {
938 reply_body = g_dbus_message_get_body(reply);
939 g_variant_get(reply_body, "(a(i))", &(*id_iter));
943 g_variant_unref(reply_body);
946 g_object_unref(reply);
951 int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, const char *app_id, const char *keyword, int offset, int count, GVariantIter **id_iter)
954 GDBusMessage *reply = NULL;
955 GVariant *reply_body = NULL;
957 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, keyword, offset, count), &reply, "get_sticker_info_by_keyword");
958 if (ret == STICKER_CLIENT_ERROR_NONE) {
959 reply_body = g_dbus_message_get_body(reply);
960 g_variant_get(reply_body, "(a(i))", &(*id_iter));
964 g_variant_unref(reply_body);
967 g_object_unref(reply);
972 int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, int offset, int count, GVariantIter **id_iter)
975 GDBusMessage *reply = NULL;
976 GVariant *reply_body = NULL;
978 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type");
979 if (ret == STICKER_CLIENT_ERROR_NONE) {
980 reply_body = g_dbus_message_get_body(reply);
981 g_variant_get(reply_body, "(a(i))", &(*id_iter));
985 g_variant_unref(reply_body);
988 g_object_unref(reply);
993 int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, GList **group_list)
996 GDBusMessage *reply = NULL;
997 GVariantIter *iter = NULL;
998 GVariant *reply_body = NULL;
1001 if (group_list == NULL) {
1002 LOGE("group_list is invalid");
1003 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
1006 ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
1007 if (ret == STICKER_CLIENT_ERROR_NONE) {
1008 reply_body = g_dbus_message_get_body(reply);
1009 g_variant_get(reply_body, "(a(s))", &iter);
1012 LOGD("failed to get iter");
1013 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
1016 while (g_variant_iter_loop (iter, "(s)", &group)) {
1017 *group_list = g_list_append(*group_list, strdup((const char *)group));
1020 g_variant_iter_free(iter);
1024 g_variant_unref(reply_body);
1027 g_object_unref(reply);