void synce_device_dbus_uninit(SynceDevice *self) { SynceDevicePrivate *priv = SYNCE_DEVICE_GET_PRIVATE (self); g_return_if_fail(priv->inited && !(priv->dispose_has_run)); #if !USE_GDBUS GError *error = NULL; DBusGConnection *system_bus = NULL; #endif g_message ("%s: unregistering object path '%s'", G_STRFUNC, priv->obj_path); #if USE_GDBUS g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(priv->interface)); g_object_unref(priv->interface); priv->interface = NULL; #else system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (system_bus == NULL) { g_critical("Failed to connect to system bus: %s", error->message); g_error_free(error); return; } dbus_g_connection_unregister_g_object(system_bus, G_OBJECT(self)); dbus_g_connection_unref(system_bus); #endif return; }
/* Default implementation for close */ static void sw_item_stream_default_close (SwItemStream *item_stream) { SwItemStreamPrivate *priv = GET_PRIVATE (item_stream); SwCore *core; SW_DEBUG (VIEWS, "%s called on %s", G_STRFUNC, priv->object_path); core = sw_core_dup_singleton (); dbus_g_connection_unregister_g_object (sw_core_get_connection (core), G_OBJECT (item_stream)); g_object_unref (core); /* Object is no longer needed */ g_object_unref (item_stream); }
static void w_dbus_unregister_object(WatchdogService * wservice, DBusGProxy *bus_proxy, DBusGConnection *connection) { guint release_result = 0; GError *error = NULL; if(bus_proxy == NULL || !dbus_g_proxy_call(bus_proxy, "ReleaseName", &error, G_TYPE_STRING, WATCHDOG_SERVICE, G_TYPE_INVALID, G_TYPE_UINT, &release_result, G_TYPE_INVALID)){ log_error_message("failed to release '%s' (proxy=%p)\n", WATCHDOG_SERVICE, bus_proxy); if(error) g_error_free(error); } dbus_g_connection_unregister_g_object(connection, wservice); g_object_unref(wservice); return; }
/* activesyncd entry point */ int main (int argc, char** argv) { DBusGConnection* bus = NULL; DBusGProxy* busProxy = NULL; EasSync* EasSyncObj = NULL; EasCommon* EasCommonObj = NULL; EasMail*EasMailObj = NULL; EasTest* EasTestObj = NULL; GMainLoop* loop = NULL; guint result; GError* error = NULL; #if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); #endif dbus_g_thread_init(); #if 0 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL, eas_logger, NULL); #endif g_log_set_default_handler (eas_logger, NULL); signal (SIGABRT, &signalHandler); signal (SIGTERM, &signalHandler); signal (SIGINT, &signalHandler); loop = g_main_loop_new (NULL, FALSE); if (loop == NULL) { g_debug ("Error: Couldn't create GMainLoop"); exit (EXIT_FAILURE); } // Give signalHandler() access to the main loop. g_mainloop = loop; //Creating all the GObjects g_debug ("activesyncd Daemon Started"); g_debug ("Creating eas_sync gobject."); EasSyncObj = eas_sync_new(); if (EasSyncObj == NULL) { g_debug ("Error: Failed to create calendar instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Creating common gobject."); EasCommonObj = g_object_new (EAS_TYPE_COMMON , NULL); if (EasCommonObj == NULL) { g_debug ("Error: Failed to create common instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Creating mail gobject."); EasMailObj = eas_mail_new (); if (EasMailObj == NULL) { g_debug ("Error: Failed to create common instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } EasTestObj = eas_test_new (); if (NULL == EasTestObj) { g_debug ("Failed to make EasTest instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Connecting to the session DBus"); bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (error != NULL) { g_debug ("Error: Connecting to the session DBus (%s)", error->message); g_clear_error (&error); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Registering the well-known name (%s)", EAS_SERVICE_NAME); busProxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (busProxy == NULL) { g_debug ("Error: Failed to get a proxy for D-Bus"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } dbus_g_proxy_set_default_timeout (busProxy, 1000000); /* register the well-known name.*/ g_debug ("D-Bus RequestName RPC "); if (!dbus_g_proxy_call (busProxy, "RequestName", &error, G_TYPE_STRING, EAS_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { g_debug ("Error: D-Bus RequestName RPC failed (%s)", error->message); g_clear_error (&error); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("RequestName returned %d", result); if (result != 1) { g_debug ("Error: Failed to get the primary well-known name"); exit (EXIT_FAILURE); } // Registering sync Gobject dbus_g_connection_register_g_object (bus, EAS_SERVICE_SYNC_OBJECT_PATH, G_OBJECT (EasSyncObj)); // Registering common Gobject dbus_g_connection_register_g_object (bus, EAS_SERVICE_COMMON_OBJECT_PATH, G_OBJECT (EasCommonObj)); // Registering mail Gobject dbus_g_connection_register_g_object (bus, EAS_SERVICE_MAIL_OBJECT_PATH, G_OBJECT (EasMailObj)); dbus_g_connection_register_g_object (bus, EAS_SERVICE_TEST_OBJECT_PATH, G_OBJECT (EasTestObj)); g_debug ("Ready to serve requests"); #ifndef DISABLE_EAS_DAEMON if (daemon (0, 0) != 0) { g_debug ("Failed to daemonize"); } #else g_debug ("Not daemonizing (built with DISABLE_EAS_DAEMON)"); #endif g_main_loop_run (loop); // Clean up g_debug ("Main Cleanup"); g_mainloop = NULL; g_main_loop_unref (loop); // clean up dbus and all its objects if (EasSyncObj) { g_debug ("Unregister and unref EasSyncObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasSyncObj)); g_object_unref(EasSyncObj); } if (EasCommonObj) { g_debug ("Unregister and unref EasCommonObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasCommonObj)); g_object_unref(EasCommonObj); } if (EasMailObj) { g_debug ("Unregister and unref EasMailObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasMailObj)); g_object_unref(EasMailObj); } if (EasTestObj) { g_debug ("Unregister and unref EasTestObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasTestObj)); g_object_unref(EasTestObj); } if (busProxy) { g_debug ("Unref busProxy"); g_object_unref(busProxy); } if(bus) { g_debug ("Flush and unref DBusConnection bus"); dbus_g_connection_flush (bus); dbus_g_connection_unref(bus); } g_debug ("Exiting main()"); return 0; }