return 1;
}
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
+#define DEVICED_BUS "org.tizen.system.deviced"
+#define DEVICED_CORE_PATH "/Org/Tizen/System/DeviceD/Core"
#define BOOTING_DONE_SIGNAL "BootingDone"
#define DEVICED_CORE_INTERFACE "org.tizen.system.deviced.core"
-#define SDBD_BOOT_INFO_FILE "/tmp/sdbd_boot_info"
+#define SDBD_BOOT_INFO_FILE "/tmp/sdbd_boot_info"
-static DBusHandlerResult __sdbd_dbus_signal_filter(DBusConnection *conn,
- DBusMessage *message, void *user_data) {
- D("got dbus message\n");
- const char *interface;
+static GMainLoop *g_mainloop;
- DBusError error;
- dbus_error_init(&error);
-
- interface = dbus_message_get_interface(message);
- if (interface == NULL) {
- D("reject by security issue - no interface\n");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+static void booting_done_signal_subscriber(GDBusConnection *connection,
+ const gchar *sender, const gchar *path, const gchar *interface,
+ const gchar *signal, GVariant *parameters, gpointer user_data)
+{
+ if (g_strcmp0(signal, BOOTING_DONE_SIGNAL) != 0) {
+ D("received signal(%s) does not match the desired signal(%s)\n",
+ signal, BOOTING_DONE_SIGNAL);
+ return;
}
- if (dbus_message_is_signal(message, DEVICED_CORE_INTERFACE,
- BOOTING_DONE_SIGNAL)) {
- booting_done = 1;
- if (access(SDBD_BOOT_INFO_FILE, F_OK) == 0) {
- D("booting is done before\n");
- } else {
- FILE *f = fopen(SDBD_BOOT_INFO_FILE, "w");
- if (f != NULL) {
- fprintf(f, "%d", 1);
- fclose(f);
- }
+ D("received the \"%s\" signal\n", signal);
+
+ booting_done = 1;
+ if (access(SDBD_BOOT_INFO_FILE, F_OK) == 0) {
+ D("booting is already done\n");
+ } else {
+ FILE *info_file = fopen(SDBD_BOOT_INFO_FILE, "w");
+ if (info_file != NULL) {
+ fprintf(info_file, "%d", 1);
+ fclose(info_file);
}
D("booting is done\n");
}
- D("handled dbus message\n");
- return DBUS_HANDLER_RESULT_HANDLED;
+ D("handled the booting done signal\n");
+ g_main_loop_quit(g_mainloop);
}
-static void *bootdone_cb(void *x) {
- int MAX_LOCAL_BUFSZ = 128;
- DBusError error;
- DBusConnection *bus;
- char rule[MAX_LOCAL_BUFSZ];
- GMainLoop *mainloop;
-
-/* g_type_init() is deprecated for glib version 2.35.0 or greater, */
-#if !GLIB_CHECK_VERSION(2,35,0)
- g_type_init();
-#endif
-
- dbus_error_init(&error);
- bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
- if (!bus) {
- D("Failed to connect to the D-BUS daemon: %s", error.message);
- dbus_error_free(&error);
+static void *bootdone_cb(void *args)
+{
+ GError *error = NULL;
+ GDBusConnection *connection = NULL;
+ guint id;
+
+ connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (connection == NULL) {
+ if (error != NULL) {
+ D("failed to connect to the system bus: %s\n", error->message);
+ g_error_free(error);
+ } else {
+ D("failed to connect to the system bus\n");
+ }
return NULL;
}
- dbus_connection_setup_with_g_main(bus, NULL);
- snprintf(rule, MAX_LOCAL_BUFSZ, "type='signal',interface='%s'",
- DEVICED_CORE_INTERFACE);
- /* listening to messages */
- dbus_bus_add_match(bus, rule, &error);
- if (dbus_error_is_set(&error)) {
- D("Fail to rule set: %s", error.message);
- dbus_error_free(&error);
- return NULL;
+ g_mainloop = g_main_loop_new(NULL, false);
+ if (g_mainloop == NULL) {
+ D("failed to create a g_main_loop\n");
+ goto bootdone_out;
}
- if (dbus_connection_add_filter(bus, __sdbd_dbus_signal_filter, NULL, NULL)
- == FALSE)
- return NULL;
+ id = g_dbus_connection_signal_subscribe(connection,
+ DEVICED_BUS, DEVICED_CORE_INTERFACE, BOOTING_DONE_SIGNAL,
+ DEVICED_CORE_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+ booting_done_signal_subscriber, NULL, NULL);
+ if (id == 0) {
+ D("failed to subscribe to the booting done signal\n");
+ goto bootdone_out;
+ }
- D("booting signal initialized\n");
- mainloop = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(mainloop);
+ D("wait for the booting done signal\n");
+ g_main_loop_run(g_mainloop);
- D("dbus loop exited");
- g_main_loop_unref(mainloop);
- dbus_connection_unref(bus);
+ g_dbus_connection_signal_unsubscribe(connection, id);
+
+bootdone_out:
+ if (g_mainloop != NULL) {
+ g_main_loop_unref(g_mainloop);
+ }
+ if (connection != NULL) {
+ g_object_unref(connection);
+ }
+ D("exit the bootdone_cb thread\n");
return NULL;
}
-void register_bootdone_cb() {
- D("registerd bootdone callback\n");
-
+void register_bootdone_cb()
+{
sdb_thread_t t;
if (sdb_thread_create(&t, bootdone_cb, NULL)) {
- D("cannot create service thread\n");
+ D("can not create a service thread to check the booting done\n");
return;
}
+ D("created the bootdone_cb thread\n");
}
static int sdbd_set_groups(const char *name, int gid, struct group_info default_groups[], int default_groups_size) {