#include <stdlib.h>
#include <stdarg.h>
+#include <gio/gio.h>
#include <vconf.h>
-#include <packet.h>
-#include <com-core.h>
-#include <com-core_packet.h>
-
#include "badge.h"
#include "badge_log.h"
#include "badge_error.h"
#include "badge_internal.h"
#include "badge_ipc.h"
-#define BADGE_IPC_TIMEOUT 1.0
-
-#if !defined(VCONFKEY_MASTER_STARTED)
-#define VCONFKEY_MASTER_STARTED "memory/data-provider-master/started"
-#endif
-
-static struct info {
- int server_fd;
- int client_fd;
- const char *socket_file;
- struct {
- int (*request_cb)(const char *appid, const char *name, int type, const char *content, const char *icon, pid_t pid, double period, int allow_duplicate, void *data);
- void *data;
- } server_cb;
- int initialized;
- int is_started_cb_set_svc;
- int is_started_cb_set_task;
-} s_info = {
- .server_fd = -1,
- .client_fd = -1,
- .socket_file = BADGE_ADDR,
- .initialized = 0,
- .is_started_cb_set_svc = 0,
- .is_started_cb_set_task = 0,
-};
+
+#define PROVIDER_BUS_NAME "org.tizen.data_provider_service"
+#define PROVIDER_OBJECT_PATH "/org/tizen/data_provider_service"
+#define PROVIDER_BADGE_INTERFACE_NAME "org.tizen.data_provider_badge_service"
+
+
+#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
+#define DBUS_PATH_DBUS "/org/freedesktop/DBus"
+#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
+
typedef struct _task_list task_list;
struct _task_list {
void (*task_cb) (void *data);
void *data;
};
-
static task_list *g_task_list;
-static int badge_ipc_monitor_register(void);
-static int badge_ipc_monitor_deregister(void);
-static void _do_deferred_task(void);
-static void _master_started_cb_task(keynode_t *node, void *data);
-
-/*!
- * functions to check state of master
- */
-static inline void _set_master_started_cb(vconf_callback_fn cb)
-{
- int ret = -1;
-
- ret = vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, cb, NULL);
- if (ret != 0)
- ERR("failed to notify key(%s) : %d", VCONFKEY_MASTER_STARTED, ret);
-}
-
-static inline void _unset_master_started_cb(vconf_callback_fn cb)
-{
- int ret = -1;
+static GDBusConnection *_gdbus_conn = NULL;
+static int monitor_id = 0;
+static int provider_monitor_id = 0;
+static int is_master_started = 0;
- ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, cb);
- if (ret != 0)
- ERR("failed to notify key(%s) : %d", VCONFKEY_MASTER_STARTED, ret);
-}
+static void _do_deferred_task(void);
int badge_ipc_is_master_ready(void)
{
- int ret = -1, is_master_started = 0;
-
- ret = vconf_get_bool(VCONFKEY_MASTER_STARTED, &is_master_started);
- if (ret == 0 && is_master_started == 1) {
- ERR("the master has been started");
- } else {
+ GVariant *result = NULL;
+ GError *err = NULL;
+ gboolean name_exist;
+
+ result = g_dbus_connection_call_sync(
+ _gdbus_conn,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "NameHasOwner",
+ g_variant_new("(s)", PROVIDER_BUS_NAME),
+ G_VARIANT_TYPE("(b)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
+
+ if (err || (result == NULL)) {
+ if (err) {
+ ERR("No reply. error = %s", err->message);
+ g_error_free(err);
+ }
is_master_started = 0;
- ERR("the master has been stopped");
+ } else {
+ g_variant_get(result, "(b)", &name_exist);
+
+ if (!name_exist) {
+ ERR("Name not exist %s", PROVIDER_BUS_NAME);
+ ERR("the master has been stopped");
+ is_master_started = 0;
+ } else {
+ DBG("the master has been started");
+ is_master_started = 1;
+ }
}
+ if(result)
+ g_variant_unref(result);
+
return is_master_started;
}
void (*badge_add_deferred_task)(void *data),
void *user_data)
{
- task_list *list = NULL;
- task_list *list_new = NULL;
+ task_list *list;
+ task_list *list_new;
list_new = (task_list *) malloc(sizeof(task_list));
if (list_new == NULL)
return BADGE_ERROR_OUT_OF_MEMORY;
- if (s_info.is_started_cb_set_task == 0) {
- _set_master_started_cb(_master_started_cb_task);
- s_info.is_started_cb_set_task = 1;
- }
-
list_new->next = NULL;
list_new->prev = NULL;
int badge_ipc_del_deferred_task(
void (*badge_add_deferred_task)(void *data))
{
- task_list *list_del = NULL;
- task_list *list_prev = NULL;
- task_list *list_next = NULL;
+ task_list *list_del;
+ task_list *list_prev;
+ task_list *list_next;
list_del = g_task_list;
}
free(list_del);
-
- if (g_task_list == NULL) {
- if (s_info.is_started_cb_set_task == 1) {
- _unset_master_started_cb(_master_started_cb_task);
- s_info.is_started_cb_set_task = 0;
- }
- }
-
return BADGE_ERROR_NONE;
}
list_del = list_del->next;
static void _do_deferred_task(void)
{
- task_list *list_do = NULL;
- task_list *list_temp = NULL;
+ task_list *list_do;
+ task_list *list_temp;
if (g_task_list == NULL)
return;
list_do = g_task_list;
g_task_list = NULL;
- if (s_info.is_started_cb_set_task == 1) {
- _unset_master_started_cb(_master_started_cb_task);
- s_info.is_started_cb_set_task = 0;
- }
while (list_do->prev != NULL)
list_do = list_do->prev;
}
}
-static void _master_started_cb_service(keynode_t *node, void *data)
+/*
+ * dbus handler implementation
+ */
+static void _insert_badge_notify(GVariant *parameters)
{
- int ret = BADGE_ERROR_NONE;
-
- if (badge_ipc_is_master_ready()) {
- ERR("try to register a badge service");
- ret = badge_ipc_monitor_deregister();
- if (ret != BADGE_ERROR_NONE)
- ERR("failed to deregister a monitor");
-
- ret = badge_ipc_monitor_register();
- if (ret != BADGE_ERROR_NONE)
- ERR("failed to register a monitor");
-
- } else {
- ERR("try to unregister a badge service");
- ret = badge_ipc_monitor_deregister();
- if (ret != BADGE_ERROR_NONE)
- ERR("failed to deregister a monitor");
+ char *pkgname = NULL;
- }
+ g_variant_get(parameters, "(&s)", &pkgname);
+ badge_changed_cb_call(BADGE_ACTION_CREATE, pkgname, 0);
}
-static void _master_started_cb_task(keynode_t *node, void *data)
+static void _delete_badge_notify(GVariant *parameters)
{
- if (badge_ipc_is_master_ready())
- _do_deferred_task();
+ char *pkgname = NULL;
+
+ g_variant_get(parameters, "(&s)", &pkgname);
+ badge_changed_cb_call(BADGE_ACTION_REMOVE, pkgname, 0);
}
-/*!
- * functions to handler services
- */
-static struct packet *_handler_insert_badge(pid_t pid, int handle, const struct packet *packet)
+static void _set_badge_count_notify(GVariant *parameters)
{
- int ret = 0;
char *pkgname = NULL;
+ int count = 0;
- if (!packet) {
- ERR("a packet is null");
- return NULL;
- }
-
- DBG("");
-
- /* return code, pkgname */
- if (packet_get(packet, "is", &ret, &pkgname) == 2) {
- if (ret == BADGE_ERROR_NONE)
- badge_changed_cb_call(BADGE_ACTION_CREATE, pkgname, 0);
- else
- ERR("failed to insert a new badge:%d", ret);
+ g_variant_get(parameters, "(&si)", &pkgname, &count);
+ badge_changed_cb_call(BADGE_ACTION_UPDATE, pkgname, count);
+}
- } else {
- ERR("failed to get data from a packet");
- }
+static void _set_disp_option_notify(GVariant *parameters)
+{
+ char *pkgname = NULL;
+ int is_display = 0;
- return NULL;
+ g_variant_get(parameters, "(&si)", &pkgname, &is_display);
+ badge_changed_cb_call(BADGE_ACTION_CHANGED_DISPLAY, pkgname, is_display);
}
-static struct packet *_handler_delete_badge(pid_t pid, int handle, const struct packet *packet)
+static void _handle_badge_notify(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
- int ret = 0;
- char *pkgname = NULL;
+ DBG("signal_name: %s", signal_name);
+ if (g_strcmp0(signal_name, "insert_badge_notify") == 0)
+ _insert_badge_notify(parameters);
+ else if (g_strcmp0(signal_name, "delete_badge_notify") == 0)
+ _delete_badge_notify(parameters);
+ else if (g_strcmp0(signal_name, "set_badge_count_notify") == 0)
+ _set_badge_count_notify(parameters);
+ else if (g_strcmp0(signal_name, "set_disp_option_notify") == 0)
+ _set_disp_option_notify(parameters);
+}
- if (!packet) {
- ERR("a packet is null");
- return NULL;
+static int _dbus_init(void)
+{
+ GError *error = NULL;
+
+ if (_gdbus_conn == NULL) {
+ _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (_gdbus_conn == NULL) {
+ if (error != NULL) {
+ ERR("Failed to get dbus [%s]", error->message);
+ g_error_free(error);
+ }
+ return BADGE_ERROR_IO_ERROR;
+ }
+ badge_error_quark();
}
- DBG("");
-
- if (packet_get(packet, "is", &ret, &pkgname) == 2) {
- if (ret == BADGE_ERROR_NONE)
- badge_changed_cb_call(BADGE_ACTION_REMOVE, pkgname, 0);
- else
- ERR("failed to remove a badge:%d", ret);
+ return BADGE_ERROR_NONE;
+}
- } else {
- ERR("failed to get data from a packet");
+static int _dbus_signal_init()
+{
+ int ret = BADGE_ERROR_NONE;
+ int id;
+
+ if (monitor_id == 0) {
+ DBG("get dbus connection success");
+ id = g_dbus_connection_signal_subscribe(_gdbus_conn,
+ PROVIDER_BUS_NAME,
+ PROVIDER_BADGE_INTERFACE_NAME, /* interface */
+ NULL, /* member */
+ PROVIDER_OBJECT_PATH, /* path */
+ NULL, /* arg0 */
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ _handle_badge_notify,
+ NULL,
+ NULL);
+
+ DBG("subscribe id : %d", id);
+ if (id == 0) {
+ ret = BADGE_ERROR_IO_ERROR;
+ ERR("Failed to _register_noti_dbus_interface");
+ } else {
+ monitor_id = id;
+ }
}
- return NULL;
+ return ret;
}
-static struct packet *_handler_set_badge_count(pid_t pid, int handle, const struct packet *packet)
+/*
+ * implement user request
+ */
+static int _send_sync_badge(GVariant *body, GDBusMessage **reply, char *cmd)
{
- int ret = 0;
- char *pkgname = NULL;
- int count = 0;
+ GError *err = NULL;
+ GDBusMessage *msg;
+ int ret = BADGE_ERROR_NONE;
- if (!packet) {
- ERR("a packet is null");
- return NULL;
+ msg = g_dbus_message_new_method_call(
+ PROVIDER_BUS_NAME,
+ PROVIDER_OBJECT_PATH,
+ PROVIDER_BADGE_INTERFACE_NAME,
+ cmd);
+ if (!msg) {
+ ERR("Can't allocate new method call");
+ if (body)
+ g_variant_unref(body);
+ return BADGE_ERROR_OUT_OF_MEMORY;
}
- DBG("");
+ if (body != NULL)
+ g_dbus_message_set_body(msg, body);
- if (packet_get(packet, "isi", &ret, &pkgname, &count) == 3) {
- if (ret == BADGE_ERROR_NONE)
- badge_changed_cb_call(BADGE_ACTION_UPDATE, pkgname, count);
- else
- ERR("failed to update count of badge:%d", ret);
+ *reply = g_dbus_connection_send_message_with_reply_sync(
+ _gdbus_conn,
+ msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL,
+ &err);
- } else {
- ERR("failed to get data from a packet");
+ g_object_unref(msg);
+
+ if (!*reply) {
+ if (err != NULL) {
+ ERR("No reply. cmd = %s, error = %s", cmd, err->message);
+ g_error_free(err);
+ }
+ return BADGE_ERROR_SERVICE_NOT_READY;
+ }
+
+ if (g_dbus_message_to_gerror(*reply, &err)) {
+ ret = err->code;
+ ERR("_send_sync_badge cmd = %s, error %s", cmd, err->message);
+ g_error_free(err);
+ return ret;
}
+ ERR("_send_sync_badge done !!");
+ return BADGE_ERROR_NONE;
- return NULL;
}
-static struct packet *_handler_set_display_option(pid_t pid, int handle, const struct packet *packet)
+static int _send_service_register()
{
- int ret = 0;
- char *pkgname = NULL;
- int is_display = 0;
+ GDBusMessage *reply = NULL;
+ int result;
- if (!packet) {
- ERR("a packet is null");
- return NULL;
- }
+ result = _send_sync_badge(NULL, &reply, "badge_service_register");
- DBG("");
+ if(reply)
+ g_object_unref(reply);
- if (packet_get(packet, "isi", &ret, &pkgname, &is_display) == 3) {
- if (ret == BADGE_ERROR_NONE)
- badge_changed_cb_call(BADGE_ACTION_CHANGED_DISPLAY, pkgname, is_display);
- else
- ERR("failed to update the display option of badge:%d, %d", ret, is_display);
+ DBG("_send_service_register dones");
+ return result;
+}
- } else {
- ERR("failed to get data from a packet");
- }
+static int _ipc_monitor_register(void)
+{
+ DBG("register a service\n");
- return NULL;
+ return _send_service_register();
}
-static int _handler_service_register(pid_t pid, int handle, const struct packet *packet, void *data)
+static void _on_name_appeared(GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
{
- int ret;
-
- DBG("");
+ DBG("name appeared : %s", name);
+ is_master_started = 1;
+ _ipc_monitor_register();
- if (!packet) {
- ERR("Packet is not valid\n");
- ret = BADGE_ERROR_INVALID_PARAMETER;
- } else if (packet_get(packet, "i", &ret) != 1) {
- ERR("Packet is not valid\n");
- ret = BADGE_ERROR_INVALID_PARAMETER;
- } else {
- if (ret == BADGE_ERROR_NONE)
- badge_changed_cb_call(BADGE_ACTION_SERVICE_READY, NULL, 0);
+ _do_deferred_task();
+}
- }
- return ret;
+static void _on_name_vanished(GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ DBG("name vanished : %s", name);
+ is_master_started = 0;
}
-/*!
- * functions to initialize and register a monitor
- */
-static int badge_ipc_monitor_register(void)
+int badge_ipc_monitor_init(void)
{
- int ret;
- struct packet *packet;
- static struct method service_table[] = {
- {
- .cmd = "insert_badge",
- .handler = _handler_insert_badge,
- },
- {
- .cmd = "delete_badge",
- .handler = _handler_delete_badge,
- },
- {
- .cmd = "set_badge_count",
- .handler = _handler_set_badge_count,
- },
- {
- .cmd = "set_disp_option",
- .handler = _handler_set_display_option,
- },
- {
- .cmd = NULL,
- .handler = NULL,
- },
- };
-
- if (s_info.initialized == 1)
- return BADGE_ERROR_NONE;
- else
- s_info.initialized = 1;
-
- ERR("register a service\n");
- com_core_packet_use_thread(1);
-
- s_info.server_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table);
- if (s_info.server_fd < 0) {
- ERR("Failed to make a connection to the master\n");
- return BADGE_ERROR_IO_ERROR;
+ DBG("register a service\n");
+ int ret = BADGE_ERROR_NONE;
+
+ ret = _dbus_init();
+ if (ret != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus %d", ret);
+ return ret;
}
- packet = packet_create("service_register", "");
- if (!packet) {
- ERR("Failed to build a packet\n");
- return BADGE_ERROR_IO_ERROR;
+ ret = _dbus_signal_init();
+ if (ret != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus signal %d", ret);
+ return ret;
}
- ret = com_core_packet_async_send(s_info.server_fd, packet, 1.0, _handler_service_register, NULL);
- DBG("Service register sent: %d\n", ret);
- packet_destroy(packet);
- if (ret != 0) {
- com_core_packet_client_fini(s_info.server_fd);
- s_info.server_fd = BADGE_ERROR_INVALID_PARAMETER;
- ret = BADGE_ERROR_IO_ERROR;
- } else {
- ret = BADGE_ERROR_NONE;
+ ret = _ipc_monitor_register();
+ if (ret != BADGE_ERROR_NONE) {
+ ERR("Can't init ipc_monitor_register %d", ret);
+ return ret;
+ }
+
+ if (provider_monitor_id == 0) {
+ provider_monitor_id = g_bus_watch_name_on_connection(
+ _gdbus_conn,
+ PROVIDER_BUS_NAME,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ _on_name_appeared,
+ _on_name_vanished,
+ NULL,
+ NULL);
+
+ if (provider_monitor_id == 0) {
+ ERR("watch on name fail");
+ g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
+ monitor_id = 0;
+ return BADGE_ERROR_IO_ERROR;
+ }
}
- DBG("Server FD: %d\n", s_info.server_fd);
return ret;
}
-int badge_ipc_monitor_deregister(void)
+int badge_ipc_monitor_fini(void)
{
- if (s_info.initialized == 0)
- return BADGE_ERROR_NONE;
-
- com_core_packet_client_fini(s_info.server_fd);
- s_info.server_fd = BADGE_ERROR_INVALID_PARAMETER;
-
- s_info.initialized = 0;
+ if (provider_monitor_id) {
+ g_bus_unwatch_name(provider_monitor_id);
+ provider_monitor_id = 0;
+ }
+ if (monitor_id) {
+ g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
+ monitor_id = 0;
+ }
return BADGE_ERROR_NONE;
}
-int badge_ipc_monitor_init(void)
+int badge_ipc_request_insert(const char *pkgname, const char *writable_pkg, const char *caller)
{
- int ret = BADGE_ERROR_NONE;
-
- if (badge_ipc_is_master_ready())
- ret = badge_ipc_monitor_register();
+ int result;
+ GDBusMessage *reply = NULL;
+ GVariant *body;
+
+ result = _dbus_init();
+ if (result != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus %d", result);
+ return result;
+ }
- if (s_info.is_started_cb_set_svc == 0) {
- _set_master_started_cb(_master_started_cb_service);
- s_info.is_started_cb_set_svc = 1;
+ body = g_variant_new("(sss)", pkgname, writable_pkg, caller);
+ if (!body) {
+ ERR("Cannot create gvariant. Out of memory.");
+ return BADGE_ERROR_OUT_OF_MEMORY;
}
- return ret;
+ result = _send_sync_badge(body, &reply, "insert_badge");
+
+ if(reply)
+ g_object_unref(reply);
+
+ DBG("badge_ipc_request_insert done [result: %d]", result);
+ return result;
}
-int badge_ipc_monitor_fini(void)
+int badge_ipc_request_delete(const char *pkgname, const char *caller)
{
- int ret = BADGE_ERROR_NONE;
-
- if (s_info.is_started_cb_set_svc == 1) {
- _unset_master_started_cb(_master_started_cb_service);
- s_info.is_started_cb_set_svc = 0;
+ int result;
+ GDBusMessage *reply = NULL;
+ GVariant *body;
+
+ result = _dbus_init();
+ if (result != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus %d", result);
+ return result;
}
+ body = g_variant_new("(ss)", pkgname, caller);
- ret = badge_ipc_monitor_deregister();
+ result = _send_sync_badge(body, &reply, "delete_badge");
- return ret;
-}
+ if(reply)
+ g_object_unref(reply);
+ DBG("badge_ipc_request_delete done [result: %d]", result);
+ return result;
+}
-int badge_ipc_request_insert(const char *pkgname, const char *writable_pkg, const char *caller)
+int badge_ipc_request_set_count(const char *pkgname, const char *caller, int count)
{
- int ret = 0;
- struct packet *packet;
- struct packet *result;
-
- packet = packet_create("insert_badge", "sss", pkgname, writable_pkg, caller);
- result = com_core_packet_oneshot_send(BADGE_ADDR,
- packet,
- BADGE_IPC_TIMEOUT);
- packet_destroy(packet);
-
- if (result != NULL) {
- if (packet_get(result, "i", &ret) != 1) {
- ERR("Failed to get a result packet");
- packet_unref(result);
- return BADGE_ERROR_IO_ERROR;
- }
-
- if (ret != BADGE_ERROR_NONE) {
- packet_unref(result);
- return ret;
- }
- packet_unref(result);
- } else {
- if (badge_ipc_is_master_ready() == 1)
- return BADGE_ERROR_PERMISSION_DENIED;
- else
- return BADGE_ERROR_SERVICE_NOT_READY;
+ int result;
+ GDBusMessage *reply = NULL;
+ GVariant *body;
+
+ result = _dbus_init();
+ if (result != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus %d", result);
+ return result;
}
+ body = g_variant_new("(ssi)", pkgname, caller, count);
- return BADGE_ERROR_NONE;
+ result = _send_sync_badge(body, &reply, "set_badge_count");
+
+ if(reply)
+ g_object_unref(reply);
+
+ DBG("badge_ipc_request_set_count done [result: %d]", result);
+ return result;
}
-int badge_ipc_request_delete(const char *pkgname, const char *caller)
+int badge_ipc_request_get_count(const char *pkgname, unsigned int *count)
{
- int ret = 0;
- struct packet *packet;
- struct packet *result;
-
- packet = packet_create("delete_badge", "ss", pkgname, caller);
- result = com_core_packet_oneshot_send(BADGE_ADDR,
- packet,
- BADGE_IPC_TIMEOUT);
- packet_destroy(packet);
-
- if (result != NULL) {
- if (packet_get(result, "i", &ret) != 1) {
- ERR("Failed to get a result packet");
- packet_unref(result);
- return BADGE_ERROR_IO_ERROR;
- }
+ int result;
+ GDBusMessage *reply = NULL;
+ GVariant *body;
+ GVariant *reply_body;
+ int ret_count;
+
+ result = _dbus_init();
+ if (result != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus %d", result);
+ return result;
+ }
+ body = g_variant_new("(s)", pkgname);
- if (ret != BADGE_ERROR_NONE) {
- packet_unref(result);
- return ret;
- }
- packet_unref(result);
- } else {
- if (badge_ipc_is_master_ready() == 1)
- return BADGE_ERROR_PERMISSION_DENIED;
- else
- return BADGE_ERROR_SERVICE_NOT_READY;
+ result = _send_sync_badge(body, &reply, "get_badge_count");
+ if (result == BADGE_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", &ret_count);
+ *count = ret_count;
}
- return BADGE_ERROR_NONE;
+ if(reply)
+ g_object_unref(reply);
+
+ DBG("badge_ipc_request_get_count done [result: %d]", result);
+ return result;
}
-int badge_ipc_request_set_count(const char *pkgname, const char *caller, int count)
+int badge_ipc_request_set_display(const char *pkgname, const char *caller, unsigned int display_option)
{
- int ret = 0;
- struct packet *packet;
- struct packet *result;
-
- packet = packet_create("set_badge_count", "ssi", pkgname, caller, count);
- result = com_core_packet_oneshot_send(BADGE_ADDR,
- packet,
- BADGE_IPC_TIMEOUT);
- packet_destroy(packet);
-
- if (result != NULL) {
- if (packet_get(result, "i", &ret) != 1) {
- ERR("Failed to get a result packet");
- packet_unref(result);
- return BADGE_ERROR_IO_ERROR;
- }
-
- if (ret != BADGE_ERROR_NONE) {
- packet_unref(result);
- return ret;
- }
- packet_unref(result);
- } else {
- if (badge_ipc_is_master_ready() == 1)
- return BADGE_ERROR_PERMISSION_DENIED;
- else
- return BADGE_ERROR_SERVICE_NOT_READY;
+ int result;
+ GDBusMessage *reply = NULL;
+ GVariant *body;
+
+ result = _dbus_init();
+ if (result != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus %d", result);
+ return result;
}
+ body = g_variant_new("(ssi)", pkgname, caller, display_option);
- return BADGE_ERROR_NONE;
+ result = _send_sync_badge(body, &reply, "set_disp_option");
+ if(reply)
+ g_object_unref(reply);
+
+ DBG("badge_ipc_request_set_display done [result: %d]", result);
+ return result;
}
-int badge_ipc_request_set_display(const char *pkgname, const char *caller, int display_option)
+int badge_ipc_request_get_display(const char *pkgname, unsigned int *is_display)
{
- int ret = 0;
- struct packet *packet;
- struct packet *result;
-
- packet = packet_create("set_disp_option", "ssi", pkgname, caller, display_option);
- result = com_core_packet_oneshot_send(BADGE_ADDR,
- packet,
- BADGE_IPC_TIMEOUT);
- packet_destroy(packet);
-
- if (result != NULL) {
- if (packet_get(result, "i", &ret) != 1) {
- ERR("Failed to get a result packet");
- packet_unref(result);
- return BADGE_ERROR_IO_ERROR;
- }
+ int result ;
+ GDBusMessage *reply = NULL;
+ GVariant *body ;
+ GVariant *reply_body;
+ unsigned int ret_is_display;
+
+ result = _dbus_init();
+ if (result != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus %d", result);
+ return result;
+ }
+ body = g_variant_new("(s)", pkgname);
- if (ret != BADGE_ERROR_NONE) {
- packet_unref(result);
- return ret;
- }
- packet_unref(result);
- } else {
- if (badge_ipc_is_master_ready() == 1)
- return BADGE_ERROR_PERMISSION_DENIED;
- else
- return BADGE_ERROR_SERVICE_NOT_READY;
+ result = _send_sync_badge(body, &reply, "get_disp_option");
+ if (result == BADGE_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", &ret_is_display);
+ *is_display = ret_is_display;
}
- return BADGE_ERROR_NONE;
+ if(reply)
+ g_object_unref(reply);
+
+ DBG("badge_ipc_request_get_display done [result: %d]", result);
+ return result;
}
int badge_ipc_setting_property_set(const char *pkgname, const char *property, const char *value)
{
- int status = 0;
- int ret = 0;
- struct packet *packet;
- struct packet *result;
-
- packet = packet_create("set_noti_property", "sss", pkgname, property, value);
- result = com_core_packet_oneshot_send(BADGE_ADDR,
- packet,
- BADGE_IPC_TIMEOUT);
- packet_destroy(packet);
-
- if (result != NULL) {
- if (packet_get(result, "ii", &status, &ret) != 2) {
- ERR("Failed to get a result packet");
- packet_unref(result);
- return BADGE_ERROR_IO_ERROR;
- }
- packet_unref(result);
- } else {
- ERR("failed to receive answer(delete)");
- return BADGE_ERROR_SERVICE_NOT_READY;
+ int result;
+ GDBusMessage *reply = NULL;
+ GVariant *body;
+
+ result = _dbus_init();
+ if (result != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus %d", result);
+ return result;
}
+ body = g_variant_new("(sss)", pkgname, property, value);
+
+ result = _send_sync_badge(body, &reply, "set_noti_property");
+ if(reply)
+ g_object_unref(reply);
- return status;
+ DBG("badge_ipc_setting_property_set done [result: %d]", result);
+ return result;
}
int badge_ipc_setting_property_get(const char *pkgname, const char *property, char **value)
{
- int status = 0;
- char *ret = NULL;
- struct packet *packet;
- struct packet *result;
-
- packet = packet_create("get_noti_property", "ss", pkgname, property);
- result = com_core_packet_oneshot_send(BADGE_ADDR,
- packet,
- BADGE_IPC_TIMEOUT);
- packet_destroy(packet);
-
- if (result != NULL) {
- if (packet_get(result, "is", &status, &ret) != 2) {
- ERR("Failed to get a result packet");
- packet_unref(result);
- return BADGE_ERROR_IO_ERROR;
- }
- if (status == BADGE_ERROR_NONE && ret != NULL)
- *value = strdup(ret);
+ int result;
+ GDBusMessage *reply = NULL;
+ GVariant *body;
+ GVariant *reply_body;
+ char *ret_val = NULL;
+
+ result = _dbus_init();
+ if (result != BADGE_ERROR_NONE) {
+ ERR("Can't init dbus %d", result);
+ return result;
+ }
+ body = g_variant_new("(ss)", pkgname, property);
- packet_unref(result);
- } else {
- ERR("failed to receive answer(delete)");
- return BADGE_ERROR_SERVICE_NOT_READY;
+ result = _send_sync_badge(body, &reply, "get_noti_property");
+ if (result == BADGE_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(&s)", ret_val);
+
+ if (ret_val != NULL)
+ *value = strdup(ret_val);
+ else
+ result = BADGE_ERROR_IO_ERROR;
}
+ if(reply)
+ g_object_unref(reply);
- return status;
+ DBG("badge_ipc_setting_property_get done [result: %d]", result);
+ return result;
}
+
+