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 #define STICKER_DIRECTORY "/opt/usr/share/sticker-data"
28 static int is_server_started = 0;
29 static CLIENT_LIB last_req_lib = STICKER_CLIENT_LIB_NONE;
31 static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
33 LOGD("name : %s, name_owner : %s", name, name_owner);
37 static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
39 LOGD("name : %s", name);
43 static int _dbus_init(GDBusConnection **gdbus_connection)
48 if (*gdbus_connection == NULL) {
49 GDBusConnection *conn = NULL;
50 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
54 LOGE("g_bus_get_sync error message = %s", error->message);
58 return STICKER_CLIENT_ERROR_IO_ERROR;
60 *gdbus_connection = conn;
63 LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection));
64 watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
66 G_BUS_NAME_WATCHER_FLAGS_NONE,
71 LOGD("watch_id : %d", watch_id);
73 LOGE("Failed to get identifier"); //LCOV_EXCL_LINE
74 return STICKER_CLIENT_ERROR_IO_ERROR;
77 return STICKER_CLIENT_ERROR_NONE;
80 static void _get_sticker_info_from_gvariant(GVariantIter *info_iter, GVariantIter *keyword_iter, sticker_data_h sticker_data)
83 GVariant *value = NULL;
86 if (!info_iter || !keyword_iter) {
87 LOGW("failed to get iter");
91 while (g_variant_iter_loop (info_iter, "{iv}", &key, &value)) {
93 case STICKER_DATA_TYPE_INFO_ID:
94 sticker_data->sticker_info_id = g_variant_get_int32(value);
96 case STICKER_DATA_TYPE_APP_ID:
97 sticker_data->app_id = g_variant_dup_string(value, NULL);
99 case STICKER_DATA_TYPE_URI_TYPE:
100 sticker_data->type = g_variant_get_int32(value);
102 case STICKER_DATA_TYPE_URI:
103 sticker_data->uri = g_variant_dup_string(value, NULL);
105 case STICKER_DATA_TYPE_THUMBNAIL:
106 sticker_data->thumbnail = g_variant_dup_string(value, NULL);
108 case STICKER_DATA_TYPE_DESCRIPTION:
109 sticker_data->description = g_variant_dup_string(value, NULL);
111 case STICKER_DATA_TYPE_GROUP:
112 sticker_data->group = g_variant_dup_string(value, NULL);
114 case STICKER_DATA_TYPE_DATE:
115 sticker_data->date = g_variant_dup_string(value, NULL);
117 case STICKER_DATA_TYPE_DISP_TYPE:
118 sticker_data->disp_type = g_variant_get_int32(value);
125 while (g_variant_iter_loop (keyword_iter, "(s)", &keyword)) {
126 sticker_data->keyword = g_list_append(sticker_data->keyword, strdup((const char *)keyword));
130 g_variant_unref(value);
132 g_variant_iter_free(info_iter);
133 g_variant_iter_free(keyword_iter);
136 static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVariant *body)
139 g_variant_get(body, "(i)", &ret);
142 provider_handle->insert_finished_cb(STICKER_ERROR_NONE, provider_handle->insert_finished_cb_user_data);
144 provider_handle->insert_finished_cb(STICKER_ERROR_OPERATION_FAILED, provider_handle->insert_finished_cb_user_data);
149 static void _handle_sticker_consumer_cb(GDBusConnection *connection,
150 const gchar *sender_name,
151 const gchar *object_path,
152 const gchar *interface_name,
153 const gchar *signal_name,
154 GVariant *parameters,
157 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
159 sticker_consumer_h consumer_handle = (sticker_consumer_h)user_data;
161 if (consumer_handle == NULL) {
162 LOGE("consumer handle is not available");
166 if (parameters == NULL) {
167 LOGE("failed to get sticker info");
171 if (g_strcmp0(signal_name, "send_sticker_changed_event") == 0) {
172 if (consumer_handle->event_cb != NULL) {
173 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
176 GVariantIter *info_iter = NULL;
177 GVariantIter *keyword_iter = NULL;
179 g_variant_get(parameters, "(ia{iv}a(s))", &event_type, &info_iter, &keyword_iter);
180 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
181 consumer_handle->event_cb((sticker_consumer_event_type_e)event_type, sticker_data, consumer_handle->event_cb_user_data);
182 sticker_data_destroy(sticker_data);
189 static void _handle_sticker_provider_cb(GDBusConnection *connection,
190 const gchar *sender_name,
191 const gchar *object_path,
192 const gchar *interface_name,
193 const gchar *signal_name,
194 GVariant *parameters,
197 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
198 sticker_provider_h provider_handle = (sticker_provider_h)user_data;
200 if (provider_handle == NULL) {
201 LOGE("provider handle is not available");
205 if (parameters == NULL) {
206 LOGE("failed to get sticker info");
210 if (g_strcmp0(signal_name, "send_insert_result") == 0) {
211 if (provider_handle->insert_finished_cb != NULL)
212 _call_insert_finished_cb(provider_handle, parameters);
216 static int _dbus_signal_init(GDBusConnection *gdbus_connection, int *monitor_id, CLIENT_LIB lib, void *data)
218 int ret = STICKER_CLIENT_ERROR_NONE;
219 if (*monitor_id == 0) {
221 if (lib == STICKER_CLIENT_LIB_CONSUMER)
222 id = g_dbus_connection_signal_subscribe(gdbus_connection,
224 STICKER_CONSUMER_INTERFACE_NAME,
228 G_DBUS_SIGNAL_FLAGS_NONE,
229 _handle_sticker_consumer_cb,
232 else if (lib == STICKER_CLIENT_LIB_PROVIDER)
233 id = g_dbus_connection_signal_subscribe(gdbus_connection,
235 STICKER_PROVIDER_INTERFACE_NAME,
239 G_DBUS_SIGNAL_FLAGS_NONE,
240 _handle_sticker_provider_cb,
246 ret = STICKER_CLIENT_ERROR_IO_ERROR;
247 LOGE("g_dbus_connection_signal_subscribe() failed");
257 static GDBusMessage *_get_gdbus_message(GVariant *body, const char *cmd)
259 GDBusMessage *message = NULL;
260 message = g_dbus_message_new_method_call(
263 STICKER_INTERFACE_NAME,
268 LOGE("Failed to create a new gdbus message");
270 g_variant_unref(body);
276 g_dbus_message_set_body(message, body);
281 static int _send_gdbus_sync_message(GDBusConnection *gdbus_connection, GDBusMessage *msg, GDBusMessage **reply, const char *cmd)
283 int ret = STICKER_CLIENT_ERROR_NONE;
286 *reply = g_dbus_connection_send_message_with_reply_sync(
289 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
297 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
299 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
300 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
301 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
308 if (g_dbus_message_to_gerror(*reply, &err)) {
310 LOGE("error message = %s, code = %d", err->message, err->code);
311 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
312 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
320 LOGD("Send a message to server(cmd : %s)", cmd);
321 return STICKER_CLIENT_ERROR_NONE;
324 static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body, GDBusMessage **reply, char *cmd)
326 int ret = STICKER_CLIENT_ERROR_NONE;
327 GDBusMessage *msg = NULL;
329 msg = _get_gdbus_message(body, cmd);
331 return STICKER_CLIENT_ERROR_IO_ERROR;
333 ret = _send_gdbus_sync_message(gdbus_connection, msg, reply, cmd);
341 static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd)
343 int ret = STICKER_CLIENT_ERROR_NONE;
344 GDBusMessage *msg = NULL;
347 msg = _get_gdbus_message(body, cmd);
349 return STICKER_CLIENT_ERROR_IO_ERROR;
351 g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
358 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
359 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
361 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
362 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
372 static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id, CLIENT_LIB lib)
375 GDBusMessage *reply = NULL;
376 GVariant *reply_body = NULL;
378 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", (int)lib), &reply, "sticker_service_register");
379 if (ret != STICKER_CLIENT_ERROR_NONE) {
380 LOGE("_send_sync_message() failed : %d", ret);
384 reply_body = g_dbus_message_get_body(reply);
385 g_variant_get(reply_body, "(i)", server_watcher_id);
388 g_object_unref(reply);
390 is_server_started = 1;
394 static void _on_name_appeared(GDBusConnection *connection,
396 const gchar *name_owner,
399 if (is_server_started == 0) {
400 int *watcher_id = (int *)user_data;
401 _monitor_register(connection, watcher_id, last_req_lib);
406 static void _on_name_vanished(GDBusConnection *connection,
410 is_server_started = 0;
414 int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
415 int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data)
420 ret = _dbus_init(gdbus_connection);
421 if (ret != STICKER_CLIENT_ERROR_NONE) {
423 LOGE("_dbus_init() failed : %d", ret);
428 ret = _dbus_signal_init(*gdbus_connection, monitor_id, lib, data);
429 if (ret != STICKER_CLIENT_ERROR_NONE) {
431 LOGE("_dbus_signal_init() failed : %d", ret);
436 ret = _monitor_register(*gdbus_connection, server_watcher_id, lib);
437 if (ret != STICKER_CLIENT_ERROR_NONE) {
439 LOGE("_monitor_register() failed : %d", ret);
444 if (*server_monitor_id == 0) {
445 *server_monitor_id = g_bus_watch_name_on_connection(
448 G_BUS_NAME_WATCHER_FLAGS_NONE,
453 if (*server_monitor_id == 0) {
455 g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
457 LOGE("Failed to get identifier");
458 return STICKER_CLIENT_ERROR_IO_ERROR;
463 return STICKER_CLIENT_ERROR_NONE;
466 int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib)
470 if (server_watcher_id) {
471 ret = _send_async_message(gdbus_connection, g_variant_new("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister");
472 if (ret != STICKER_CLIENT_ERROR_NONE) {
473 LOGE("Failed to unregister sticker service");
477 *server_watcher_id = 0;
480 if (*server_monitor_id) {
481 g_bus_unwatch_name(*server_monitor_id);
482 *server_monitor_id = 0;
486 g_dbus_connection_signal_unsubscribe(gdbus_connection, *monitor_id);
490 return STICKER_CLIENT_ERROR_NONE;
493 static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
496 LOGE("keyword doesn't exist");
500 g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
503 int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
507 GDBusMessage *reply = NULL;
508 GVariant *reply_body = NULL;
509 GVariantBuilder *info_builder;
510 GVariantBuilder *keyword_builder;
512 if (!sticker_data->app_id || (sticker_data->type < 1) || !sticker_data->uri || !sticker_data->group || !sticker_data->keyword)
513 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
515 info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
516 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_data->app_id));
517 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_data->type));
518 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_data->uri));
519 if (sticker_data->thumbnail)
520 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_data->thumbnail));
521 if (sticker_data->description)
522 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description));
523 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group));
524 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type));
526 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
527 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
529 ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
530 if (ret != STICKER_CLIENT_ERROR_NONE) {
531 LOGW("Failed to save sticker info");
535 reply_body = g_dbus_message_get_body(reply);
536 g_variant_get(reply_body, "(i)", &ret_id);
537 sticker_data->sticker_info_id = ret_id;
539 LOGD("ret_id : %d", ret_id);
541 g_variant_builder_unref(info_builder);
542 g_variant_builder_unref(keyword_builder);
545 g_variant_unref(reply_body);
548 g_object_unref(reply);
553 int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
557 ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
558 if (ret != STICKER_CLIENT_ERROR_NONE)
559 LOGE("failed to send json path");
564 int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id)
567 GDBusMessage *reply = NULL;
569 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
570 if (ret != STICKER_CLIENT_ERROR_NONE)
571 LOGE("failed to delete sticker info");
574 g_object_unref(reply);
579 int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri)
582 GDBusMessage *reply = NULL;
584 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "delete_sticker_info_by_uri");
585 if (ret != STICKER_CLIENT_ERROR_NONE)
586 LOGE("failed to delete sticker info");
589 g_object_unref(reply);
594 int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
597 bool is_updated = false;
598 GDBusMessage *reply = NULL;
599 GVariant *reply_body = NULL;
600 sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
603 LOGE("failed to allocate memory");
604 return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
607 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
608 if (ret == STICKER_CLIENT_ERROR_NONE) {
609 reply_body = g_dbus_message_get_body(reply);
610 GVariantIter *info_iter = NULL;
611 GVariantIter *keyword_iter = NULL;
613 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
614 _get_sticker_info_from_gvariant(info_iter, keyword_iter, origin_data);
616 LOGW("failed to get sticker info");
619 g_object_unref(reply);
623 if (sticker_data->uri) {
625 char *conv_path = NULL;
626 if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
627 len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
628 conv_path = (char *)calloc(len, sizeof(char));
630 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
632 conv_path = strdup(sticker_data->uri);
634 if (conv_path && (strcmp(conv_path, origin_data->uri) != 0)) {
635 LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
637 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
638 if (ret == STICKER_CLIENT_ERROR_NONE) {
639 reply_body = g_dbus_message_get_body(reply);
640 g_variant_get(reply_body, "(i)", &is_exist);
643 LOGE("file already exists");
644 ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
649 LOGE("failed to check file exists");
654 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");
655 if (ret != STICKER_CLIENT_ERROR_NONE) {
656 LOGE("failed to update sticker uri");
665 if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
666 LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
667 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
668 if (ret != STICKER_CLIENT_ERROR_NONE) {
669 LOGE("failed to update sticker type");
675 if (sticker_data->thumbnail) {
676 int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
677 char *conv_path = (char *)calloc(len, sizeof(char));
679 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
680 if (strcmp(conv_path, origin_data->thumbnail) != 0)
682 LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
683 ret = _send_sync_message(gdbus_connection, g_variant_new("(iss)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
684 if (ret != STICKER_CLIENT_ERROR_NONE)
686 LOGE("failed to update sticker thumbnail");
696 if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
697 LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
698 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
699 if (ret != STICKER_CLIENT_ERROR_NONE) {
700 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");
716 if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) {
717 LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type);
718 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type");
719 if (ret != STICKER_CLIENT_ERROR_NONE) {
720 LOGE("failed to update sticker display type");
726 if (sticker_data->keyword) {
727 GVariantBuilder *keyword_builder;
728 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
729 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
730 ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
731 if (ret != STICKER_CLIENT_ERROR_NONE)
732 LOGE("failed to update sticker keyword");
735 g_variant_builder_unref(keyword_builder);
739 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event");
742 sticker_data_destroy(origin_data);
745 g_variant_unref(reply_body);
748 g_object_unref(reply);
753 int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, int record_id)
756 GDBusMessage *reply = NULL;
757 GVariant *reply_body = NULL;
758 GVariantIter *info_iter = NULL;
759 GVariantIter *keyword_iter = NULL;
761 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info");
762 if (ret == STICKER_CLIENT_ERROR_NONE) {
763 reply_body = g_dbus_message_get_body(reply);
764 sticker_data->sticker_info_id = record_id;
766 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
767 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
770 g_variant_unref(reply_body);
774 g_object_unref(reply);
779 int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list)
782 GDBusMessage *reply = NULL;
783 GVariantIter *iter = NULL;
784 GVariant *reply_body = NULL;
787 if (group_list == NULL) {
788 LOGE("group_list is invalid");
789 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
792 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_list");
793 if (ret == STICKER_CLIENT_ERROR_NONE) {
794 reply_body = g_dbus_message_get_body(reply);
795 g_variant_get(reply_body, "(a(s))", &iter);
798 LOGD("failed to get iter");
799 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
802 while (g_variant_iter_loop (iter, "(s)", &group)) {
803 *group_list = g_list_append(*group_list, strdup((const char *)group));
806 g_variant_iter_free(iter);
810 g_variant_unref(reply_body);
813 g_object_unref(reply);
818 int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list)
821 GDBusMessage *reply = NULL;
822 GVariantIter *iter = NULL;
823 GVariant *reply_body = NULL;
824 char *keyword = NULL;
826 if (keyword_list == NULL) {
827 LOGE("keyword_list is invalid");
828 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
831 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_keyword_list");
832 if (ret == STICKER_CLIENT_ERROR_NONE) {
833 reply_body = g_dbus_message_get_body(reply);
834 g_variant_get(reply_body, "(a(s))", &iter);
837 LOGD("failed to get iter");
838 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
841 while (g_variant_iter_loop (iter, "(s)", &keyword)) {
842 *keyword_list = g_list_append(*keyword_list, strdup((const char *)keyword));
845 g_variant_iter_free(iter);
849 g_variant_unref(reply_body);
852 g_object_unref(reply);
857 int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char *app_id, int *count)
860 GDBusMessage *reply = NULL;
861 GVariant *reply_body = NULL;
863 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
864 if (ret == STICKER_CLIENT_ERROR_NONE) {
865 reply_body = g_dbus_message_get_body(reply);
866 g_variant_get(reply_body, "(i)", count);
870 g_variant_unref(reply_body);
873 g_object_unref(reply);
878 int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
881 GDBusMessage *reply = NULL;
882 GVariant *reply_body = NULL;
884 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_all_sticker_info");
885 if (ret == STICKER_CLIENT_ERROR_NONE) {
886 reply_body = g_dbus_message_get_body(reply);
887 g_variant_get(reply_body, "(a(i))", id_iter);
891 g_variant_unref(reply_body);
894 g_object_unref(reply);
899 int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
902 GDBusMessage *reply = NULL;
903 GVariant *reply_body = NULL;
905 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid");
906 if (ret == STICKER_CLIENT_ERROR_NONE) {
907 reply_body = g_dbus_message_get_body(reply);
908 g_variant_get(reply_body, "(a(i))", id_iter);
912 g_variant_unref(reply_body);
915 g_object_unref(reply);
920 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)
923 GDBusMessage *reply = NULL;
924 GVariant *reply_body = NULL;
926 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_type");
927 if (ret == STICKER_CLIENT_ERROR_NONE) {
928 reply_body = g_dbus_message_get_body(reply);
929 g_variant_get(reply_body, "(a(i))", id_iter);
933 g_variant_unref(reply_body);
936 g_object_unref(reply);
941 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)
944 GDBusMessage *reply = NULL;
945 GVariant *reply_body = NULL;
947 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, group, offset, count), &reply, "get_sticker_info_by_group");
948 if (ret == STICKER_CLIENT_ERROR_NONE) {
949 reply_body = g_dbus_message_get_body(reply);
950 g_variant_get(reply_body, "(a(i))", id_iter);
954 g_variant_unref(reply_body);
957 g_object_unref(reply);
962 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)
965 GDBusMessage *reply = NULL;
966 GVariant *reply_body = NULL;
968 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, keyword, offset, count), &reply, "get_sticker_info_by_keyword");
969 if (ret == STICKER_CLIENT_ERROR_NONE) {
970 reply_body = g_dbus_message_get_body(reply);
971 g_variant_get(reply_body, "(a(i))", id_iter);
975 g_variant_unref(reply_body);
978 g_object_unref(reply);
983 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)
986 GDBusMessage *reply = NULL;
987 GVariant *reply_body = NULL;
989 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type");
990 if (ret == STICKER_CLIENT_ERROR_NONE) {
991 reply_body = g_dbus_message_get_body(reply);
992 g_variant_get(reply_body, "(a(i))", id_iter);
996 g_variant_unref(reply_body);
999 g_object_unref(reply);
1004 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)
1007 GDBusMessage *reply = NULL;
1008 GVariantIter *iter = NULL;
1009 GVariant *reply_body = NULL;
1012 if (group_list == NULL) {
1013 LOGE("group_list is invalid");
1014 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
1017 ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
1018 if (ret == STICKER_CLIENT_ERROR_NONE) {
1019 reply_body = g_dbus_message_get_body(reply);
1020 g_variant_get(reply_body, "(a(s))", &iter);
1023 LOGD("failed to get iter");
1024 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
1027 while (g_variant_iter_loop (iter, "(s)", &group)) {
1028 *group_list = g_list_append(*group_list, strdup((const char *)group));
1031 g_variant_iter_free(iter);
1035 g_variant_unref(reply_body);
1038 g_object_unref(reply);
1043 int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result)
1046 GDBusMessage *reply = NULL;
1047 GVariant *reply_body = NULL;
1049 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "check_file_exists");
1050 if (ret == STICKER_CLIENT_ERROR_NONE) {
1051 reply_body = g_dbus_message_get_body(reply);
1052 g_variant_get(reply_body, "(i)", result);
1056 g_variant_unref(reply_body);
1059 g_object_unref(reply);
1064 int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id)
1067 GDBusMessage *reply = NULL;
1069 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "insert_recent_sticker_info");
1070 if (ret != STICKER_CLIENT_ERROR_NONE)
1071 LOGE("failed to insert recent sticker info");
1074 g_object_unref(reply);
1079 int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter)
1082 GDBusMessage *reply = NULL;
1083 GVariant *reply_body = NULL;
1085 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_sticker_info");
1086 if (ret == STICKER_CLIENT_ERROR_NONE) {
1087 reply_body = g_dbus_message_get_body(reply);
1088 g_variant_get(reply_body, "(a(i))", id_iter);
1092 g_variant_unref(reply_body);
1095 g_object_unref(reply);
1100 int sticker_dbus_get_sticker_info_by_uri(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, const char *uri)
1103 GDBusMessage *reply = NULL;
1104 GVariant *reply_body = NULL;
1105 GVariantIter *info_iter = NULL;
1106 GVariantIter *keyword_iter = NULL;
1108 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "get_sticker_info_by_uri");
1109 if (ret == STICKER_CLIENT_ERROR_NONE) {
1110 reply_body = g_dbus_message_get_body(reply);
1111 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
1112 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
1115 g_variant_unref(reply_body);
1119 g_object_unref(reply);
1124 int sticker_dbus_check_group_exists(GDBusConnection *gdbus_connection, const char *app_id, const char *group, int *result)
1127 GDBusMessage *reply = NULL;
1128 GVariant *reply_body = NULL;
1130 ret = _send_sync_message(gdbus_connection, g_variant_new("(ss)", app_id, group), &reply, "check_group_exists");
1131 if (ret == STICKER_CLIENT_ERROR_NONE) {
1132 reply_body = g_dbus_message_get_body(reply);
1133 g_variant_get(reply_body, "(i)", result);
1137 g_variant_unref(reply_body);
1140 g_object_unref(reply);
1145 int sticker_dbus_set_group_image(GDBusConnection *gdbus_connection, const char *app_id, const char *group, sticker_data_uri_type_e type, const char *uri)
1148 GDBusMessage *reply = NULL;
1150 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssis)", app_id, group, (int)type, uri), &reply, "set_group_image");
1151 if (ret != STICKER_CLIENT_ERROR_NONE)
1152 LOGE("failed to set group image");
1155 g_object_unref(reply);
1160 int sticker_dbus_get_group_image_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_image_list)
1163 GDBusMessage *reply = NULL;
1164 GVariantIter *iter = NULL;
1165 GVariant *reply_body = NULL;
1170 if (group_image_list == NULL) {
1171 LOGE("group_image_list is invalid");
1172 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
1175 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_image_list");
1176 if (ret == STICKER_CLIENT_ERROR_NONE) {
1177 reply_body = g_dbus_message_get_body(reply);
1178 g_variant_get(reply_body, "(a(sis))", &iter);
1181 LOGD("failed to get iter");
1182 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
1185 while (g_variant_iter_loop (iter, "(sis)", &group, &type, &uri)) {
1186 sticker_group_image_s *group_image = NULL;
1187 group_image = g_try_new0(sticker_group_image_s, 1);
1190 group_image->group = strdup(group);
1194 group_image->uri_type = (sticker_data_uri_type_e)type;
1196 group_image->uri = strdup(uri);
1201 *group_image_list = g_list_append(*group_image_list, group_image);
1205 g_variant_iter_free(iter);
1209 g_variant_unref(reply_body);
1212 g_object_unref(reply);