static void gupnp_connman_manager_constructed (GObject *object) { GUPnPConnmanManager *manager; GObjectClass *object_class; manager = GUPNP_CONNMAN_MANAGER (object); manager->priv->cancellable = g_cancellable_new (); manager->priv->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); init_connman_manager (manager); schedule_loopback_context_creation (manager); /* Call super */ object_class = G_OBJECT_CLASS (gupnp_connman_manager_parent_class); if (object_class->constructed != NULL) { object_class->constructed (object); } }
static void gupnp_network_manager_constructed (GObject *object) { GUPnPNetworkManager *manager; GUPnPNetworkManagerPrivate *priv; GObjectClass *object_class; manager = GUPNP_NETWORK_MANAGER (object); priv = manager->priv; priv->cancellable = g_cancellable_new (); priv->nm_devices = NULL; priv->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); init_network_manager (manager); schedule_loopback_context_creation (manager); /* Call super */ object_class = G_OBJECT_CLASS (gupnp_network_manager_parent_class); if (object_class->constructed != NULL) { object_class->constructed (object); } }
static void purge_temp (CcPrivacyPanel *self) { GDBusConnection *bus; gboolean result; GtkWidget *dialog; dialog = WID ("trash_dialog"); result = run_warning (GTK_WINDOW (dialog), _("Delete all the temporary files?"), _("All the temporary files will be permanently deleted."), _("_Purge Temporary Files")); if (!result) return; bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); g_dbus_connection_call (bus, "org.gnome.SettingsDaemon", "/org/gnome/SettingsDaemon/Housekeeping", "org.gnome.SettingsDaemon.Housekeeping", "RemoveTempFiles", NULL, NULL, 0, -1, NULL, NULL, NULL); g_object_unref (bus); }
static void empty_trash (CcPrivacyPanel *self) { GDBusConnection *bus; gboolean result; GtkWidget *dialog; dialog = WID ("trash_dialog"); result = run_warning (GTK_WINDOW (dialog), _("Empty all items from Trash?"), _("All items in the Trash will be permanently deleted."), _("_Empty Trash")); if (!result) return; bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); g_dbus_connection_call (bus, "org.gnome.SettingsDaemon", "/org/gnome/SettingsDaemon/Housekeeping", "org.gnome.SettingsDaemon.Housekeeping", "EmptyTrash", NULL, NULL, 0, -1, NULL, NULL, NULL); g_object_unref (bus); }
gboolean account_init (GDBusConnection *bus, GError **error) { GDBusInterfaceSkeleton *helper; g_autofree char *object_path = NULL; system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error); if (system_bus == NULL) return FALSE; helper = G_DBUS_INTERFACE_SKELETON (xdp_impl_account_skeleton_new ()); g_signal_connect (helper, "handle-get-user-information", G_CALLBACK (handle_get_user_information), NULL); if (!g_dbus_interface_skeleton_export (helper, bus, DESKTOP_PORTAL_OBJECT_PATH, error)) return FALSE; object_path = g_strdup_printf ("/org/freedesktop/Accounts/User%d", getuid ()); user = org_freedesktop_accounts_user_proxy_new_sync (system_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, "org.freedesktop.Accounts", object_path, NULL, error); if (user == NULL) return FALSE; g_debug ("providing %s", g_dbus_interface_skeleton_get_info (helper)->name); return TRUE; }
static void cinnamon_dbus_init (gboolean replace) { GDBusConnection *session; GDBusProxy *bus; GError *error = NULL; guint32 request_name_flags; guint32 request_name_result; session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (error) { g_printerr ("Failed to connect to session bus: %s", error->message); exit (1); } bus = g_dbus_proxy_new_sync (session, G_DBUS_PROXY_FLAGS_NONE, NULL, /* interface info */ "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", NULL, /* cancellable */ &error); request_name_flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; if (replace) request_name_flags |= DBUS_NAME_FLAG_REPLACE_EXISTING; cinnamon_dbus_acquire_name (bus, request_name_flags, &request_name_result, CINNAMON_DBUS_SERVICE, TRUE); if (!(request_name_result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER || request_name_result == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER)) { g_printerr (CINNAMON_DBUS_SERVICE " already exists on bus and --replace not specified\n"); exit (1); } /* * We always specify REPLACE_EXISTING to ensure we kill off * the existing service if it was running. */ request_name_flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; cinnamon_dbus_acquire_names (bus, request_name_flags, /* Also grab org.gnome.Panel to replace any existing panel process */ "org.gnome.Panel", TRUE, /* ...and the org.gnome.Magnifier service. */ MAGNIFIER_DBUS_SERVICE, FALSE, /* ...and the org.freedesktop.Notifications service. */ "org.freedesktop.Notifications", FALSE, NULL); /* ...and the on-screen keyboard service */ cinnamon_dbus_acquire_name (bus, DBUS_NAME_FLAG_REPLACE_EXISTING, &request_name_result, "org.gnome.Caribou.Keyboard", FALSE); g_object_unref (bus); g_object_unref (session); }
static gboolean gimp_unique_dbus_open (const gchar **filenames, gboolean as_new) { #ifndef GIMP_CONSOLE_COMPILATION /* for the DBus service names */ #include "gui/gimpdbusservice.h" GDBusConnection *connection; GError *error = NULL; connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (connection) { gboolean success = TRUE; if (filenames) { const gchar *method = as_new ? "OpenAsNew" : "Open"; gchar *cwd = g_get_current_dir (); gint i; for (i = 0; filenames[i] && success; i++) { GFile *file; file = g_file_new_for_commandline_arg_and_cwd (filenames[i], cwd); if (file) { GVariant *result; gchar *uri = g_file_get_uri (file); result = g_dbus_connection_call_sync (connection, GIMP_DBUS_SERVICE_NAME, GIMP_DBUS_SERVICE_PATH, GIMP_DBUS_INTERFACE_NAME, method, g_variant_new ("(s)", uri), NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, NULL); g_free (uri); if (result) g_variant_unref (result); else success = FALSE; g_object_unref (file); } else { g_printerr ("conversion to uri failed for '%s'\n", filenames[i]); } } g_free (cwd); } else { GVariant *result; result = g_dbus_connection_call_sync (connection, GIMP_DBUS_SERVICE_NAME, GIMP_DBUS_SERVICE_PATH, GIMP_DBUS_INTERFACE_NAME, "Activate", NULL, NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, NULL); if (result) g_variant_unref (result); else success = FALSE; } g_object_unref (connection); return success; } else { g_printerr ("%s\n", error->message); g_clear_error (&error); } #endif return FALSE; }
static void test_getservers_uccs (void) { DbusTestService * service = dbus_test_service_new(NULL); /* RLS */ DbusTestProcess * rls = dbus_test_process_new(REMOTE_LOGON_SERVICE); dbus_test_process_append_param(rls, "--config-file=" UCCS_CONFIG_FILE); dbus_test_service_add_task(service, DBUS_TEST_TASK(rls)); /* Dummy */ DbusTestTask * dummy = dbus_test_task_new(); dbus_test_task_set_wait_for(dummy, "org.ArcticaProject.RemoteLogon"); dbus_test_service_add_task(service, dummy); /* Get RLS up and running and us on that bus */ dbus_test_service_start_tasks(service); GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_dbus_connection_set_exit_on_close(session, FALSE); GVariant * retval = g_dbus_connection_call_sync(session, "org.ArcticaProject.RemoteLogon", "/org/ArcticaProject/RemoteLogon", "org.ArcticaProject.RemoteLogon", "GetServers", NULL, /* params */ G_VARIANT_TYPE("(a(sssba(sbva{sv})a(si)))"), /* ret type */ G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); g_assert(retval != NULL); g_assert(g_variant_n_children(retval) == 1); GVariant * array = g_variant_get_child_value(retval, 0); g_assert(g_variant_n_children(array) == 1); g_assert(g_variant_is_of_type(array, G_VARIANT_TYPE_ARRAY)); GVariant * tuple = g_variant_get_child_value(array, 0); if (TRUE) { /* type check */ GVariant * type = g_variant_get_child_value(tuple, 0); g_assert(g_variant_is_of_type(type, G_VARIANT_TYPE_STRING)); g_assert(g_strcmp0(g_variant_get_string(type, NULL), "uccs") == 0); g_variant_unref(type); } if (TRUE) { /* name check */ GVariant * name = g_variant_get_child_value(tuple, 1); g_assert(g_variant_is_of_type(name, G_VARIANT_TYPE_STRING)); g_assert(g_strcmp0(g_variant_get_string(name, NULL), "Test Server Name") == 0); g_variant_unref(name); } if (TRUE) { /* uri check */ GVariant * uri = g_variant_get_child_value(tuple, 2); g_assert(g_variant_is_of_type(uri, G_VARIANT_TYPE_STRING)); g_assert(g_strcmp0(g_variant_get_string(uri, NULL), "https://uccs.test.mycompany.com/") == 0); g_variant_unref(uri); } g_variant_unref(tuple); g_variant_unref(array); g_variant_unref(retval); g_object_unref(session); g_object_unref(rls); g_object_unref(service); return; }
/** * gcm_utils_install_package: **/ gboolean gcm_utils_install_package (const gchar *package_name, GtkWindow *window) { GDBusConnection *connection; GVariant *args = NULL; GVariant *response = NULL; GVariantBuilder *builder = NULL; GError *error = NULL; gboolean ret = FALSE; guint32 xid = 0; gchar **packages = NULL; g_return_val_if_fail (package_name != NULL, FALSE); #ifndef HAVE_PACKAGEKIT g_warning ("cannot install %s: this package was not compiled with --enable-packagekit", package_name); goto out; #endif /* get xid of this window */ if (window != NULL) xid = gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET(window))); /* we're expecting an array of packages */ packages = g_strsplit (package_name, "|", 1); /* get a session bus connection */ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (connection == NULL) { /* TRANSLATORS: no DBus session bus */ g_print ("%s %s\n", _("Failed to connect to session bus:"), error->message); g_error_free (error); goto out; } /* create arguments */ builder = g_variant_builder_new (G_VARIANT_TYPE ("(uass)")); g_variant_builder_add_value (builder, g_variant_new_uint32 (xid)); g_variant_builder_add_value (builder, g_variant_new_strv ((const gchar * const *)packages, -1)); g_variant_builder_add_value (builder, g_variant_new_string ("hide-confirm-search,hide-finished")); args = g_variant_builder_end (builder); /* execute sync method */ response = g_dbus_connection_call_sync (connection, PK_DBUS_SERVICE, PK_DBUS_PATH, PK_DBUS_INTERFACE_MODIFY, "InstallPackageNames", args, NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &error); if (response == NULL) { /* TRANSLATORS: the DBus method failed */ g_warning ("%s %s\n", _("The request failed:"), error->message); g_error_free (error); goto out; } /* success */ ret = TRUE; out: if (builder != NULL) g_variant_builder_unref (builder); if (args != NULL) g_variant_unref (args); if (response != NULL) g_variant_unref (response); g_strfreev (packages); return ret; }
static gboolean tracker_controller_dbus_start (TrackerController *controller, GError **error) { TrackerControllerPrivate *priv; GError *err = NULL; GDBusInterfaceVTable interface_vtable = { handle_method_call, NULL, NULL }; priv = controller->priv; priv->connection = tracker_sparql_connection_get (NULL, &err); if (!priv->connection) { g_propagate_error (error, err); return FALSE; } priv->d_connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &err); if (!priv->d_connection) { g_propagate_error (error, err); return FALSE; } priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &err); if (!priv->introspection_data) { g_propagate_error (error, err); return FALSE; } g_message ("Registering D-Bus object..."); g_message (" Path:'" TRACKER_WRITEBACK_PATH "'"); g_message (" Object Type:'%s'", G_OBJECT_TYPE_NAME (controller)); priv->registration_id = g_dbus_connection_register_object (priv->d_connection, TRACKER_WRITEBACK_PATH, priv->introspection_data->interfaces[0], &interface_vtable, controller, NULL, &err); if (err) { g_critical ("Could not register the D-Bus object "TRACKER_WRITEBACK_PATH", %s", err ? err->message : "no error given."); g_propagate_error (error, err); return FALSE; } priv->bus_name_id = g_bus_own_name_on_connection (priv->d_connection, TRACKER_WRITEBACK_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE, bus_name_acquired_cb, bus_name_vanished_cb, controller, NULL); if (err) { g_critical ("Could not own the D-Bus name "TRACKER_WRITEBACK_SERVICE", %s", err ? err->message : "no error given."); g_propagate_error (error, err); return FALSE; } return TRUE; }
static void install_packages (InstallerData *idata) { GDBusConnection *connection; GError *error = NULL; connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (connection != NULL) { GdkWindow *window; GDBusProxy *proxy; window = gtk_widget_get_window (GTK_WIDGET (idata->window)); if (window != NULL) { GdkCursor *cursor; GdkDisplay *display; display = gtk_widget_get_display (GTK_WIDGET (idata)); cursor = gdk_cursor_new_for_display (display, GDK_WATCH); gdk_window_set_cursor (window, cursor); g_object_unref (cursor); } proxy = g_dbus_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.PackageKit", "/org/freedesktop/PackageKit", "org.freedesktop.PackageKit.Modify", NULL, &error); if (proxy != NULL) { guint xid; char **names; char **real_names; if (window != NULL) xid = GDK_WINDOW_XID (window); else xid = 0; names = g_strsplit (idata->packages, ",", -1); real_names = get_packages_real_names (names); g_dbus_proxy_call (proxy, "InstallPackageNames", g_variant_new ("(u^ass)", xid, names, "hide-confirm-search,hide-finished,hide-warning"), G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, packagekit_install_package_names_ready_cb, idata); g_strfreev (real_names); g_strfreev (names); } } if (error != NULL) { char *message; message = g_strdup_printf ("%s\n%s", _("There was an internal error trying to search for applications:"), error->message); package_installer_terminated (idata, FR_PROC_ERROR_GENERIC, message); g_clear_error (&error); } }
static gboolean miner_manager_initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { TrackerMinerManager *manager; GError *inner_error = NULL; TrackerMinerManagerPrivate *priv; GList *m; manager = TRACKER_MINER_MANAGER (initable); priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager); priv->connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &inner_error); if (!priv->connection) { g_propagate_error (error, inner_error); return FALSE; } initialize_miners_data (manager); for (m = priv->miners; m; m = m->next) { GDBusProxy *proxy; MinerData *data; data = m->data; data->connection = g_object_ref (priv->connection); data->manager = G_OBJECT (manager); g_object_weak_ref (data->manager, data_manager_weak_notify, data); proxy = g_dbus_proxy_new_sync (priv->connection, (priv->auto_start ? G_DBUS_PROXY_FLAGS_NONE : G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START), NULL, data->dbus_name, data->dbus_path, TRACKER_MINER_DBUS_INTERFACE, NULL, &inner_error); /* This error shouldn't be considered fatal */ if (inner_error) { g_critical ("Could not create proxy on the D-Bus session bus, %s", inner_error ? inner_error->message : "no error given."); g_clear_error (&inner_error); continue; } data->progress_signal = g_dbus_connection_signal_subscribe (priv->connection, data->dbus_name, TRACKER_MINER_DBUS_INTERFACE, "Progress", data->dbus_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, miner_progress_changed, data, NULL); data->paused_signal = g_dbus_connection_signal_subscribe (priv->connection, data->dbus_name, TRACKER_MINER_DBUS_INTERFACE, "Paused", data->dbus_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, miner_paused, data, NULL); data->resumed_signal = g_dbus_connection_signal_subscribe (priv->connection, data->dbus_name, TRACKER_MINER_DBUS_INTERFACE, "Resumed", data->dbus_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, miner_resumed, data, NULL); g_hash_table_insert (priv->miner_proxies, proxy, g_strdup (data->dbus_name)); data->watch_name_id = g_bus_watch_name (TRACKER_IPC_BUS, data->dbus_name, G_BUS_NAME_WATCHER_FLAGS_NONE, miner_appears, miner_disappears, data, NULL); } return TRUE; }
int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load_data, lua_State *L) { double start_wtime = dt_get_wtime(); #ifndef __WIN32__ if(getuid() == 0 || geteuid() == 0) printf( "WARNING: either your user id or the effective user id are 0. are you running darktable as root?\n"); #endif #if defined(__SSE__) // make everything go a lot faster. _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); #endif dt_set_signal_handlers(); #include "is_supported_platform.h" int sse2_supported = 0; #ifdef HAVE_BUILTIN_CPU_SUPPORTS // NOTE: _may_i_use_cpu_feature() looks better, but only avaliable in ICC __builtin_cpu_init(); sse2_supported = __builtin_cpu_supports("sse2"); #else sse2_supported = dt_detect_cpu_features() & CPU_FLAG_SSE2; #endif if(!sse2_supported) { fprintf(stderr, "[dt_init] SSE2 instruction set is unavailable.\n"); fprintf(stderr, "[dt_init] expect a LOT of functionality to be broken. you have been warned.\n"); } #ifdef M_MMAP_THRESHOLD mallopt(M_MMAP_THRESHOLD, 128 * 1024); /* use mmap() for large allocations */ #endif // make sure that stack/frame limits are good (musl) dt_set_rlimits(); // we have to have our share dir in XDG_DATA_DIRS, // otherwise GTK+ won't find our logo for the about screen (and maybe other things) { const gchar *xdg_data_dirs = g_getenv("XDG_DATA_DIRS"); gchar *new_xdg_data_dirs = NULL; gboolean set_env = TRUE; if(xdg_data_dirs != NULL && *xdg_data_dirs != '\0') { // check if DARKTABLE_SHAREDIR is already in there gboolean found = FALSE; gchar **tokens = g_strsplit(xdg_data_dirs, G_SEARCHPATH_SEPARATOR_S, 0); // xdg_data_dirs is neither NULL nor empty => tokens != NULL for(char **iter = tokens; *iter != NULL; iter++) if(!strcmp(DARKTABLE_SHAREDIR, *iter)) { found = TRUE; break; } g_strfreev(tokens); if(found) set_env = FALSE; else new_xdg_data_dirs = g_strjoin(G_SEARCHPATH_SEPARATOR_S, DARKTABLE_SHAREDIR, xdg_data_dirs, NULL); } else { #ifndef _WIN32 // see http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html for a reason to use those as a // default if(!g_strcmp0(DARKTABLE_SHAREDIR, "/usr/local/share") || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/local/share/") || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/share") || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/share/")) new_xdg_data_dirs = g_strdup("/usr/local/share/" G_SEARCHPATH_SEPARATOR_S "/usr/share/"); else new_xdg_data_dirs = g_strdup_printf("%s" G_SEARCHPATH_SEPARATOR_S "/usr/local/share/" G_SEARCHPATH_SEPARATOR_S "/usr/share/", DARKTABLE_SHAREDIR); #else set_env = FALSE; #endif } if(set_env) g_setenv("XDG_DATA_DIRS", new_xdg_data_dirs, 1); g_free(new_xdg_data_dirs); } setlocale(LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, DARKTABLE_LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); // init all pointers to 0: memset(&darktable, 0, sizeof(darktable_t)); darktable.start_wtime = start_wtime; darktable.progname = argv[0]; // FIXME: move there into dt_database_t dt_pthread_mutex_init(&(darktable.db_insert), NULL); dt_pthread_mutex_init(&(darktable.plugin_threadsafe), NULL); dt_pthread_mutex_init(&(darktable.capabilities_threadsafe), NULL); darktable.control = (dt_control_t *)calloc(1, sizeof(dt_control_t)); // database char *dbfilename_from_command = NULL; char *noiseprofiles_from_command = NULL; char *datadir_from_command = NULL; char *moduledir_from_command = NULL; char *tmpdir_from_command = NULL; char *configdir_from_command = NULL; char *cachedir_from_command = NULL; #ifdef HAVE_OPENCL gboolean exclude_opencl = FALSE; gboolean print_statistics = strcmp(argv[0], "darktable-cltest"); #endif #ifdef USE_LUA char *lua_command = NULL; #endif darktable.num_openmp_threads = 1; #ifdef _OPENMP darktable.num_openmp_threads = omp_get_num_procs(); #endif darktable.unmuted = 0; GSList *config_override = NULL; for(int k = 1; k < argc; k++) { if(argv[k][0] == '-') { if(!strcmp(argv[k], "--help")) { return usage(argv[0]); } if(!strcmp(argv[k], "-h")) { return usage(argv[0]); } else if(!strcmp(argv[k], "--version")) { #ifdef USE_LUA const char *lua_api_version = strcmp(LUA_API_VERSION_SUFFIX, "") ? STR(LUA_API_VERSION_MAJOR) "." STR(LUA_API_VERSION_MINOR) "." STR(LUA_API_VERSION_PATCH) "-" LUA_API_VERSION_SUFFIX : STR(LUA_API_VERSION_MAJOR) "." STR(LUA_API_VERSION_MINOR) "." STR(LUA_API_VERSION_PATCH); #endif printf("this is %s\ncopyright (c) 2009-%s johannes hanika\n" PACKAGE_BUGREPORT "\n\ncompile options:\n" " bit depth is %s\n" #ifdef _DEBUG " debug build\n" #else " normal build\n" #endif #if defined(__SSE2__) && defined(__SSE__) " SSE2 optimized codepath enabled\n" #else " SSE2 optimized codepath disabled\n" #endif #ifdef _OPENMP " OpenMP support enabled\n" #else " OpenMP support disabled\n" #endif #ifdef HAVE_OPENCL " OpenCL support enabled\n" #else " OpenCL support disabled\n" #endif #ifdef USE_LUA " Lua support enabled, API version %s\n" #else " Lua support disabled\n" #endif #ifdef USE_COLORDGTK " Colord support enabled\n" #else " Colord support disabled\n" #endif #ifdef HAVE_GPHOTO2 " gPhoto2 support enabled\n" #else " gPhoto2 support disabled\n" #endif #ifdef HAVE_GRAPHICSMAGICK " GraphicsMagick support enabled\n" #else " GraphicsMagick support disabled\n" #endif #ifdef HAVE_OPENEXR " OpenEXR support enabled\n" #else " OpenEXR support disabled\n" #endif , darktable_package_string, darktable_last_commit_year, (sizeof(void *) == 8 ? "64 bit" : sizeof(void *) == 4 ? "32 bit" : "unknown") #if USE_LUA , lua_api_version #endif ); return 1; } else if(!strcmp(argv[k], "--library") && argc > k + 1) { dbfilename_from_command = argv[++k]; argv[k-1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--datadir") && argc > k + 1) { datadir_from_command = argv[++k]; argv[k-1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--moduledir") && argc > k + 1) { moduledir_from_command = argv[++k]; argv[k-1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--tmpdir") && argc > k + 1) { tmpdir_from_command = argv[++k]; argv[k-1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--configdir") && argc > k + 1) { configdir_from_command = argv[++k]; argv[k-1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--cachedir") && argc > k + 1) { cachedir_from_command = argv[++k]; argv[k-1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--localedir") && argc > k + 1) { bindtextdomain(GETTEXT_PACKAGE, argv[++k]); argv[k-1] = NULL; argv[k] = NULL; } else if(argv[k][1] == 'd' && argc > k + 1) { if(!strcmp(argv[k + 1], "all")) darktable.unmuted = 0xffffffff; // enable all debug information else if(!strcmp(argv[k + 1], "cache")) darktable.unmuted |= DT_DEBUG_CACHE; // enable debugging for lib/film/cache module else if(!strcmp(argv[k + 1], "control")) darktable.unmuted |= DT_DEBUG_CONTROL; // enable debugging for scheduler module else if(!strcmp(argv[k + 1], "dev")) darktable.unmuted |= DT_DEBUG_DEV; // develop module else if(!strcmp(argv[k + 1], "input")) darktable.unmuted |= DT_DEBUG_INPUT; // input devices else if(!strcmp(argv[k + 1], "camctl")) darktable.unmuted |= DT_DEBUG_CAMCTL; // camera control module else if(!strcmp(argv[k + 1], "perf")) darktable.unmuted |= DT_DEBUG_PERF; // performance measurements else if(!strcmp(argv[k + 1], "pwstorage")) darktable.unmuted |= DT_DEBUG_PWSTORAGE; // pwstorage module else if(!strcmp(argv[k + 1], "opencl")) darktable.unmuted |= DT_DEBUG_OPENCL; // gpu accel via opencl else if(!strcmp(argv[k + 1], "sql")) darktable.unmuted |= DT_DEBUG_SQL; // SQLite3 queries else if(!strcmp(argv[k + 1], "memory")) darktable.unmuted |= DT_DEBUG_MEMORY; // some stats on mem usage now and then. else if(!strcmp(argv[k + 1], "lighttable")) darktable.unmuted |= DT_DEBUG_LIGHTTABLE; // lighttable related stuff. else if(!strcmp(argv[k + 1], "nan")) darktable.unmuted |= DT_DEBUG_NAN; // check for NANs when processing the pipe. else if(!strcmp(argv[k + 1], "masks")) darktable.unmuted |= DT_DEBUG_MASKS; // masks related stuff. else if(!strcmp(argv[k + 1], "lua")) darktable.unmuted |= DT_DEBUG_LUA; // lua errors are reported on console else if(!strcmp(argv[k + 1], "print")) darktable.unmuted |= DT_DEBUG_PRINT; // print errors are reported on console else if(!strcmp(argv[k + 1], "camsupport")) darktable.unmuted |= DT_DEBUG_CAMERA_SUPPORT; // camera support warnings are reported on console else return usage(argv[0]); k++; argv[k-1] = NULL; argv[k] = NULL; } else if(argv[k][1] == 't' && argc > k + 1) { darktable.num_openmp_threads = CLAMP(atol(argv[k + 1]), 1, 100); printf("[dt_init] using %d threads for openmp parallel sections\n", darktable.num_openmp_threads); k++; argv[k-1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--conf") && argc > k + 1) { gchar *keyval = g_strdup(argv[++k]), *c = keyval; argv[k-1] = NULL; argv[k] = NULL; gchar *end = keyval + strlen(keyval); while(*c != '=' && c < end) c++; if(*c == '=' && *(c + 1) != '\0') { *c++ = '\0'; dt_conf_string_entry_t *entry = (dt_conf_string_entry_t *)g_malloc(sizeof(dt_conf_string_entry_t)); entry->key = g_strdup(keyval); entry->value = g_strdup(c); config_override = g_slist_append(config_override, entry); } g_free(keyval); } else if(!strcmp(argv[k], "--noiseprofiles") && argc > k + 1) { noiseprofiles_from_command = argv[++k]; argv[k-1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--luacmd") && argc > k + 1) { #ifdef USE_LUA lua_command = argv[++k]; #else ++k; #endif argv[k-1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--disable-opencl")) { #ifdef HAVE_OPENCL exclude_opencl = TRUE; #endif argv[k] = NULL; } else if(!strcmp(argv[k], "--")) { // "--" confuses the argument parser of glib/gtk. remove it. argv[k] = NULL; break; } else return usage(argv[0]); // fail on unrecognized options } } // remove the NULLs to not confuse gtk_init() later. for(int i = 1; i < argc; i++) { int k; for(k = i; k < argc; k++) if(argv[k] != NULL) break; if(k > i) { k -= i; for(int j = i + k; j < argc; j++) { argv[j-k] = argv[j]; argv[j] = NULL; } argc -= k; } } if(darktable.unmuted & DT_DEBUG_MEMORY) { fprintf(stderr, "[memory] at startup\n"); dt_print_mem_usage(); } if(init_gui) { // I doubt that connecting to dbus for darktable-cli makes sense darktable.dbus = dt_dbus_init(); // make sure that we have no stale global progress bar visible. thus it's run as early is possible dt_control_progress_init(darktable.control); } #ifdef _OPENMP omp_set_num_threads(darktable.num_openmp_threads); #endif dt_loc_init_datadir(datadir_from_command); dt_loc_init_plugindir(moduledir_from_command); if(dt_loc_init_tmp_dir(tmpdir_from_command)) { fprintf(stderr, "error: invalid temporary directory: %s\n", darktable.tmpdir); return usage(argv[0]); } dt_loc_init_user_config_dir(configdir_from_command); dt_loc_init_user_cache_dir(cachedir_from_command); #ifdef USE_LUA dt_lua_init_early(L); #endif // thread-safe init: dt_exif_init(); char datadir[PATH_MAX] = { 0 }; dt_loc_get_user_config_dir(datadir, sizeof(datadir)); char darktablerc[PATH_MAX] = { 0 }; snprintf(darktablerc, sizeof(darktablerc), "%s/darktablerc", datadir); // initialize the config backend. this needs to be done first... darktable.conf = (dt_conf_t *)calloc(1, sizeof(dt_conf_t)); dt_conf_init(darktable.conf, darktablerc, config_override); g_slist_free_full(config_override, g_free); // set the interface language const gchar *lang = dt_conf_get_string("ui_last/gui_language"); #if defined(_WIN32) // get the default locale if no language preference was specified in the config file if(lang == NULL || lang[0] == '\0') { const wchar_t *wcLocaleName = NULL; wcLocaleName = dtwin_get_locale(); if(wcLocaleName != NULL) { gchar *langLocale; langLocale = g_utf16_to_utf8(wcLocaleName, -1, NULL, NULL, NULL); if(langLocale != NULL) { g_free((gchar *)lang); lang = g_strdup(langLocale); } } } #endif // defined (_WIN32) if(lang != NULL && lang[0] != '\0') { g_setenv("LANGUAGE", lang, 1); if(setlocale(LC_ALL, lang) != NULL) gtk_disable_setlocale(); setlocale(LC_MESSAGES, lang); g_setenv("LANG", lang, 1); } g_free((gchar *)lang); // we need this REALLY early so that error messages can be shown, however after gtk_disable_setlocale if(init_gui) { #ifdef GDK_WINDOWING_WAYLAND // There are currently bad interactions with Wayland (drop-downs // are very narrow, scroll events lost). Until this is fixed, give // priority to the XWayland backend for Wayland users. gdk_set_allowed_backends("x11,*"); #endif gtk_init(&argc, &argv); } // detect cpu features and decide which codepaths to enable dt_codepaths_init(); // get the list of color profiles darktable.color_profiles = dt_colorspaces_init(); // initialize the database darktable.db = dt_database_init(dbfilename_from_command, load_data); if(darktable.db == NULL) { printf("ERROR : cannot open database\n"); return 1; } else if(!dt_database_get_lock_acquired(darktable.db)) { gboolean image_loaded_elsewhere = FALSE; #ifndef MAC_INTEGRATION // send the images to the other instance via dbus fprintf(stderr, "trying to open the images in the running instance\n"); GDBusConnection *connection = NULL; for(int i = 1; i < argc; i++) { // make the filename absolute ... if(argv[i] == NULL || *argv[i] == '\0') continue; gchar *filename = dt_util_normalize_path(argv[i]); if(filename == NULL) continue; if(!connection) connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); // ... and send it to the running instance of darktable image_loaded_elsewhere = g_dbus_connection_call_sync(connection, "org.darktable.service", "/darktable", "org.darktable.service.Remote", "Open", g_variant_new("(s)", filename), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL) != NULL; g_free(filename); } if(connection) g_object_unref(connection); #endif if(!image_loaded_elsewhere) dt_database_show_error(darktable.db); return 1; } // Initialize the signal system darktable.signals = dt_control_signal_init(); // Make sure that the database and xmp files are in sync // We need conf and db to be up and running for that which is the case here. // FIXME: is this also useful in non-gui mode? GList *changed_xmp_files = NULL; if(init_gui && dt_conf_get_bool("run_crawler_on_start")) { changed_xmp_files = dt_control_crawler_run(); } if(init_gui) { dt_control_init(darktable.control); } else { if(dbfilename_from_command && !strcmp(dbfilename_from_command, ":memory:")) dt_gui_presets_init(); // init preset db schema. darktable.control->running = 0; darktable.control->accelerators = NULL; dt_pthread_mutex_init(&darktable.control->run_mutex, NULL); } // initialize collection query darktable.collection = dt_collection_new(NULL); /* initialize selection */ darktable.selection = dt_selection_new(); /* capabilities set to NULL */ darktable.capabilities = NULL; // Initialize the password storage engine darktable.pwstorage = dt_pwstorage_new(); darktable.guides = dt_guides_init(); #ifdef HAVE_GRAPHICSMAGICK /* GraphicsMagick init */ InitializeMagick(darktable.progname); // *SIGH* dt_set_signal_handlers(); #endif darktable.opencl = (dt_opencl_t *)calloc(1, sizeof(dt_opencl_t)); #ifdef HAVE_OPENCL dt_opencl_init(darktable.opencl, exclude_opencl, print_statistics); #endif darktable.points = (dt_points_t *)calloc(1, sizeof(dt_points_t)); dt_points_init(darktable.points, dt_get_num_threads()); darktable.noiseprofile_parser = dt_noiseprofile_init(noiseprofiles_from_command); // must come before mipmap_cache, because that one will need to access // image dimensions stored in here: darktable.image_cache = (dt_image_cache_t *)calloc(1, sizeof(dt_image_cache_t)); dt_image_cache_init(darktable.image_cache); darktable.mipmap_cache = (dt_mipmap_cache_t *)calloc(1, sizeof(dt_mipmap_cache_t)); dt_mipmap_cache_init(darktable.mipmap_cache); // The GUI must be initialized before the views, because the init() // functions of the views depend on darktable.control->accels_* to register // their keyboard accelerators if(init_gui) { darktable.gui = (dt_gui_gtk_t *)calloc(1, sizeof(dt_gui_gtk_t)); if(dt_gui_gtk_init(darktable.gui)) return 1; dt_bauhaus_init(); } else darktable.gui = NULL; darktable.view_manager = (dt_view_manager_t *)calloc(1, sizeof(dt_view_manager_t)); dt_view_manager_init(darktable.view_manager); // check whether we were able to load darkroom view. if we failed, we'll crash everywhere later on. if(!darktable.develop) return 1; darktable.imageio = (dt_imageio_t *)calloc(1, sizeof(dt_imageio_t)); dt_imageio_init(darktable.imageio); // load the darkroom mode plugins once: dt_iop_load_modules_so(); if(init_gui) { #ifdef HAVE_GPHOTO2 // Initialize the camera control. // this is done late so that the gui can react to the signal sent but before switching to lighttable! darktable.camctl = dt_camctl_new(); #endif darktable.lib = (dt_lib_t *)calloc(1, sizeof(dt_lib_t)); dt_lib_init(darktable.lib); dt_gui_gtk_load_config(); // init the gui part of views dt_view_manager_gui_init(darktable.view_manager); // Loading the keybindings char keyfile[PATH_MAX] = { 0 }; // First dump the default keymapping snprintf(keyfile, sizeof(keyfile), "%s/keyboardrc_default", datadir); gtk_accel_map_save(keyfile); // Removing extraneous semi-colons from the default keymap strip_semicolons_from_keymap(keyfile); // Then load any modified keys if available snprintf(keyfile, sizeof(keyfile), "%s/keyboardrc", datadir); if(g_file_test(keyfile, G_FILE_TEST_EXISTS)) gtk_accel_map_load(keyfile); else gtk_accel_map_save(keyfile); // Save the default keymap if none is present // initialize undo struct darktable.undo = dt_undo_init(); } if(darktable.unmuted & DT_DEBUG_MEMORY) { fprintf(stderr, "[memory] after successful startup\n"); dt_print_mem_usage(); } dt_image_local_copy_synch(); /* init lua last, since it's user made stuff it must be in the real environment */ #ifdef USE_LUA dt_lua_init(darktable.lua_state.state, lua_command); #endif if(init_gui) { const char *mode = "lighttable"; // april 1st: you have to earn using dt first! or know that you can switch views with keyboard shortcuts time_t now; time(&now); struct tm lt; localtime_r(&now, <); if(lt.tm_mon == 3 && lt.tm_mday == 1) mode = "knight"; // we have to call dt_ctl_switch_mode_to() here already to not run into a lua deadlock. // having another call later is ok dt_ctl_switch_mode_to(mode); #ifndef MAC_INTEGRATION // load image(s) specified on cmdline. // this has to happen after lua is initialized as image import can run lua code // If only one image is listed, attempt to load it in darkroom int last_id = 0; gboolean only_single_images = TRUE; int loaded_images = 0; for(int i = 1; i < argc; i++) { gboolean single_image = FALSE; if(argv[i] == NULL || *argv[i] == '\0') continue; int new_id = dt_load_from_string(argv[i], FALSE, &single_image); if(new_id > 0) { last_id = new_id; loaded_images++; if(!single_image) only_single_images = FALSE; } } if(loaded_images == 1 && only_single_images) { dt_control_set_mouse_over_id(last_id); dt_ctl_switch_mode_to("darkroom"); } #endif } // last but not least construct the popup that asks the user about images whose xmp files are newer than the // db entry if(init_gui && changed_xmp_files) { dt_control_crawler_show_image_list(changed_xmp_files); } dt_print(DT_DEBUG_CONTROL, "[init] startup took %f seconds\n", dt_get_wtime() - start_wtime); return 0; }
static DBusHandlerResult dbus_filter_function (DBusConnection *connection, DBusMessage *message, void *user_data) { if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") && !tp_strdiff (dbus_message_get_path (message), DBUS_PATH_LOCAL)) { /* MC initialization sets exit on disconnect - turn it off again, so we * get a graceful exit instead (to keep gcov happy) */ dbus_connection_set_exit_on_disconnect (connection, FALSE); g_message ("Got disconnected from the session bus"); mcd_mission_abort ((McdMission *) mcd); } else if (dbus_message_is_method_call (message, "org.freedesktop.Telepathy.MissionControl5.RegressionTests", "Abort")) { DBusMessage *reply; g_idle_add (delayed_abort, NULL); reply = dbus_message_new_method_return (message); if (reply == NULL || !dbus_connection_send (connection, reply, NULL)) g_error ("Out of memory"); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else if (dbus_message_is_method_call (message, "org.freedesktop.Telepathy.MissionControl5.RegressionTests", "BillyIdle")) { /* Used to drive a souped-up version of sync_dbus(), where we need to * ensure that all idles have fired, on top of the D-Bus queue being * drained. */ DBusMessage *reply = dbus_message_new_method_return (message); GVariant *variant; GDBusConnection *system_bus; if (reply == NULL) g_error ("Out of memory"); /* Sync GDBus, too, to make sure we have received any pending * FakeNetworkMonitor messages. */ system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); g_assert (system_bus != NULL); variant = g_dbus_connection_call_sync (system_bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); g_assert (variant != NULL); g_variant_unref (variant); g_object_unref (system_bus); g_idle_add_full (G_PRIORITY_LOW, billy_idle, reply, (GDestroyNotify) dbus_message_unref); return DBUS_HANDLER_RESULT_HANDLED; } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
int main (int argc, char **argv) { GError *error = NULL; GDBusConnection *gdbus = NULL; GDBusConnection *gdbus_system = NULL; DBusConnection *connection = NULL; int ret = 1; GMainLoop *teardown_loop; guint linger_time = 5; g_type_init (); g_set_application_name ("Mission Control regression tests"); mcd_debug_init (); tp_debug_set_flags (g_getenv ("MC_TP_DEBUG")); /* Not all warnings are fatal due to MC spamming warnings (fd.o #23486), * but GLib and GObject warnings are pretty serious */ g_log_set_fatal_mask ("GLib", G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); g_log_set_fatal_mask ("GLib-GObject", G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); gdbus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); g_assert_no_error (error); g_assert (gdbus != NULL); g_dbus_connection_set_exit_on_close (gdbus, FALSE); gdbus_system = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); g_assert_no_error (error); g_assert (gdbus_system != NULL); g_dbus_connection_set_exit_on_close (gdbus_system, FALSE); bus_daemon = tp_dbus_daemon_dup (&error); g_assert_no_error (error); g_assert (bus_daemon != NULL); /* It appears that dbus-glib registers a filter that wrongly returns * DBUS_HANDLER_RESULT_HANDLED for signals, so for *our* filter to have any * effect, we need to install it as soon as possible */ connection = dbus_g_connection_get_connection ( tp_proxy_get_dbus_connection (bus_daemon)); dbus_connection_add_filter (connection, dbus_filter_function, NULL, NULL); mcd = mcd_service_new (); /* Listen for suicide notification */ g_signal_connect_after (mcd, "abort", G_CALLBACK (on_abort), NULL); /* connect */ mcd_mission_connect (MCD_MISSION (mcd)); dbus_connection_set_exit_on_disconnect (connection, FALSE); mcd_service_run (MCD_OBJECT (mcd)); ret = 0; teardown_loop = g_main_loop_new (NULL, FALSE); if (g_getenv ("MC_LINGER_TIME") != NULL) { linger_time = g_ascii_strtoull (g_getenv ("MC_LINGER_TIME"), NULL, 10); } /* Keep running in the background until it's all over. This means valgrind * and refdbg can get complete information. */ g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, linger_time, the_end, teardown_loop, (GDestroyNotify) g_main_loop_unref); g_main_loop_run (teardown_loop); if (connection != NULL) { dbus_connection_flush (connection); } tp_clear_object (&gdbus); tp_clear_object (&gdbus_system); tp_clear_object (&bus_daemon); dbus_shutdown (); g_message ("Exiting with %d", ret); return ret; }
gboolean builder_host_spawnv (GFile *dir, char **output, GError **error, const gchar * const *argv) { guint32 client_pid; GVariantBuilder *fd_builder = g_variant_builder_new (G_VARIANT_TYPE("a{uh}")); GVariantBuilder *env_builder = g_variant_builder_new (G_VARIANT_TYPE("a{ss}")); g_autoptr(GUnixFDList) fd_list = g_unix_fd_list_new (); gint stdout_handle, stdin_handle, stderr_handle; g_autoptr(GDBusConnection) connection = NULL; g_autoptr(GVariant) ret = NULL; g_autoptr(GMainLoop) loop = NULL; g_auto(GStrv) env_vars = NULL; guint subscription; HostCommandCallData data = { NULL }; guint sigterm_id = 0, sigint_id = 0; g_autofree gchar *commandline = NULL; g_autoptr(GOutputStream) out = NULL; int pipefd[2]; int i; commandline = flatpak_quote_argv ((const char **) argv); g_debug ("Running '%s' on host", commandline); connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error); if (connection == NULL) return FALSE; loop = g_main_loop_new (NULL, FALSE); data.connection = connection; data.loop = loop; data.refs = 1; subscription = g_dbus_connection_signal_subscribe (connection, NULL, "org.freedesktop.Flatpak.Development", "HostCommandExited", "/org/freedesktop/Flatpak/Development", NULL, G_DBUS_SIGNAL_FLAGS_NONE, host_command_exited_cb, &data, NULL); stdin_handle = g_unix_fd_list_append (fd_list, 0, error); if (stdin_handle == -1) return FALSE; if (output) { g_autoptr(GInputStream) in = NULL; if (pipe2 (pipefd, O_CLOEXEC) != 0) { glnx_set_error_from_errno (error); return FALSE; } data.refs++; in = g_unix_input_stream_new (pipefd[0], TRUE); out = g_memory_output_stream_new_resizable (); g_output_stream_splice_async (out, in, G_OUTPUT_STREAM_SPLICE_NONE, 0, NULL, output_spliced_cb, &data); stdout_handle = g_unix_fd_list_append (fd_list, pipefd[1], error); close (pipefd[1]); if (stdout_handle == -1) return FALSE; } else { stdout_handle = g_unix_fd_list_append (fd_list, 1, error); if (stdout_handle == -1) return FALSE; } stderr_handle = g_unix_fd_list_append (fd_list, 2, error); if (stderr_handle == -1) return FALSE; g_variant_builder_add (fd_builder, "{uh}", 0, stdin_handle); g_variant_builder_add (fd_builder, "{uh}", 1, stdout_handle); g_variant_builder_add (fd_builder, "{uh}", 2, stderr_handle); env_vars = g_listenv (); for (i = 0; env_vars[i] != NULL; i++) { const char *env_var = env_vars[i]; g_variant_builder_add (env_builder, "{ss}", env_var, g_getenv (env_var)); } sigterm_id = g_unix_signal_add (SIGTERM, sigterm_handler, &data); sigint_id = g_unix_signal_add (SIGINT, sigint_handler, &data); ret = g_dbus_connection_call_with_unix_fd_list_sync (connection, "org.freedesktop.Flatpak", "/org/freedesktop/Flatpak/Development", "org.freedesktop.Flatpak.Development", "HostCommand", g_variant_new ("(^ay^aay@a{uh}@a{ss}u)", dir ? flatpak_file_get_path_cached (dir) : "", argv, g_variant_builder_end (fd_builder), g_variant_builder_end (env_builder), FLATPAK_HOST_COMMAND_FLAGS_CLEAR_ENV), G_VARIANT_TYPE ("(u)"), G_DBUS_CALL_FLAGS_NONE, -1, fd_list, NULL, NULL, error); if (ret == NULL) return FALSE; g_variant_get (ret, "(u)", &client_pid); data.client_pid = client_pid; g_main_loop_run (loop); g_source_remove (sigterm_id); g_source_remove (sigint_id); g_dbus_connection_signal_unsubscribe (connection, subscription); if (!g_spawn_check_exit_status (data.exit_status, error)) return FALSE; if (out) { if (data.splice_error) { g_propagate_error (error, data.splice_error); return FALSE; } /* Null terminate */ g_output_stream_write (out, "\0", 1, NULL, NULL); g_output_stream_close (out, NULL, NULL); *output = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (out)); } return TRUE; }
int main (int argc, char *argv[]) { GMainLoop *loop; GDBusConnection *conn; gboolean replace; gboolean show_version; GError *error; guint name_owner_id; GBusNameOwnerFlags flags; GOptionContext *context; const GOptionEntry options[] = { { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, N_("Replace old daemon."), NULL }, { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version."), NULL}, { NULL } }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); g_set_application_name (_("GVFS Metadata Daemon")); context = g_option_context_new (""); g_option_context_set_summary (context, _("Metadata daemon for GVFS")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); replace = FALSE; show_version = FALSE; name_owner_id = 0; error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { /* Translators: the first %s is the application name, */ /* the second %s is the error message */ g_printerr (_("%s: %s"), g_get_application_name(), error->message); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); g_error_free (error); g_option_context_free (context); return 1; } g_option_context_free (context); if (show_version) { g_print(PACKAGE_STRING "\n"); return 0; } error = NULL; conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (!conn) { g_printerr ("Failed to connect to the D-BUS daemon: %s (%s, %d)\n", error->message, g_quark_to_string (error->domain), error->code); g_error_free (error); return 1; } tree_infos = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)tree_info_free); loop = g_main_loop_new (NULL, FALSE); g_dbus_connection_set_exit_on_close (conn, FALSE); g_signal_connect (conn, "closed", G_CALLBACK (on_connection_closed), loop); flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; if (replace) flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; skeleton = gvfs_metadata_skeleton_new (); g_signal_connect (skeleton, "handle-set", G_CALLBACK (handle_set), skeleton); g_signal_connect (skeleton, "handle-remove", G_CALLBACK (handle_remove), skeleton); g_signal_connect (skeleton, "handle-move", G_CALLBACK (handle_move), skeleton); g_signal_connect (skeleton, "handle-get-tree-from-device", G_CALLBACK (handle_get_tree_from_device), skeleton); error = NULL; if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton), conn, G_VFS_DBUS_METADATA_PATH, &error)) { g_printerr ("Error exporting metadata daemon: %s (%s, %d)\n", error->message, g_quark_to_string (error->domain), error->code); g_error_free (error); g_object_unref (conn); g_main_loop_unref (loop); return 1; } name_owner_id = g_bus_own_name_on_connection (conn, G_VFS_DBUS_METADATA_NAME, flags, NULL, on_name_lost, loop, NULL); g_main_loop_run (loop); if (skeleton) g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (skeleton)); if (name_owner_id != 0) g_bus_unown_name (name_owner_id); if (conn) g_object_unref (conn); if (loop != NULL) g_main_loop_unref (loop); return 0; }
int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *box; GtkWidget *button; GtkWidget *tv; GtkWidget *buttons; MenuHolder *holder; GMenuModel *model; GActionGroup *group; GDBusConnection *bus; GError *error = NULL; gboolean do_export = FALSE; gboolean do_import = FALSE; GOptionEntry entries[] = { { "export", 0, 0, G_OPTION_ARG_NONE, &do_export, "Export actions and menus over D-Bus", NULL }, { "import", 0, 0, G_OPTION_ARG_NONE, &do_import, "Use exported actions and menus", NULL }, { NULL, } }; gtk_init_with_args (&argc, &argv, NULL, entries, NULL, NULL); if (do_export && do_import) { g_error ("can't have it both ways\n"); exit (1); } window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "delete-event", G_CALLBACK(on_delete_event), NULL); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_add (GTK_CONTAINER (window), box); bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); if (do_import) { g_print ("Getting menus from the bus...\n"); model = (GMenuModel*)g_dbus_menu_model_get (bus, BUS_NAME, OBJ_PATH); g_print ("Getting actions from the bus...\n"); group = (GActionGroup*)g_dbus_action_group_get (bus, BUS_NAME, OBJ_PATH); } else { group = get_group (); model = get_model (); tv = create_action_treeview (group); gtk_container_add (GTK_CONTAINER (box), tv); buttons = create_add_remove_buttons (group, model, tv); gtk_container_add (GTK_CONTAINER (box), buttons); } if (do_export) { g_print ("Exporting menus on the bus...\n"); if (!g_dbus_connection_export_menu_model (bus, OBJ_PATH, model, &error)) { g_warning ("Menu export failed: %s", error->message); exit (1); } g_print ("Exporting actions on the bus...\n"); if (!g_dbus_connection_export_action_group (bus, OBJ_PATH, group, &error)) { g_warning ("Action export failed: %s", error->message); exit (1); } g_bus_own_name_on_connection (bus, BUS_NAME, 0, NULL, NULL, NULL, NULL); } else { holder = menu_holder_new (model, group); button = gtk_button_new_with_label ("Click here"); g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), holder); gtk_container_add (GTK_CONTAINER (box), button); } gtk_widget_show_all (window); gtk_main (); return 0; }
int dt_init(int argc, char *argv[], const int init_gui,lua_State *L) { #ifndef __WIN32__ if(getuid() == 0 || geteuid() == 0) printf("WARNING: either your user id or the effective user id are 0. are you running darktable as root?\n"); #endif // make everything go a lot faster. _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); #if !defined __APPLE__ && !defined __WIN32__ _dt_sigsegv_old_handler = signal(SIGSEGV,&_dt_sigsegv_handler); #endif #ifndef __GNUC_PREREQ // on OSX, gcc-4.6 and clang chokes if this is not here. #if defined __GNUC__ && defined __GNUC_MINOR__ # define __GNUC_PREREQ(maj, min) \ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) #else # define __GNUC_PREREQ(maj, min) 0 #endif #endif #ifndef __has_builtin // http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros #define __has_builtin(x) false #endif #ifndef __SSE3__ #error "Unfortunately we depend on SSE3 instructions at this time." #error "Please contribute a backport patch (or buy a newer processor)." #else #if (__GNUC_PREREQ(4,8) || __has_builtin(__builtin_cpu_supports)) //FIXME: check will work only in GCC 4.8+ !!! implement manual cpuid check !!! //NOTE: _may_i_use_cpu_feature() looks better, but only avaliable in ICC if (!__builtin_cpu_supports("sse3")) { fprintf(stderr, "[dt_init] unfortunately we depend on SSE3 instructions at this time.\n"); fprintf(stderr, "[dt_init] please contribute a backport patch (or buy a newer processor).\n"); return 1; } #else //FIXME: no way to check for SSE3 in runtime, implement manual cpuid check !!! #endif #endif #ifdef M_MMAP_THRESHOLD mallopt(M_MMAP_THRESHOLD,128*1024) ; /* use mmap() for large allocations */ #endif // we have to have our share dir in XDG_DATA_DIRS, // otherwise GTK+ won't find our logo for the about screen (and maybe other things) { const gchar *xdg_data_dirs = g_getenv("XDG_DATA_DIRS"); gchar *new_xdg_data_dirs = NULL; gboolean set_env = TRUE; if(xdg_data_dirs != NULL && *xdg_data_dirs != '\0') { // check if DARKTABLE_SHAREDIR is already in there gboolean found = FALSE; gchar **tokens = g_strsplit(xdg_data_dirs, ":", 0); // xdg_data_dirs is neither NULL nor empty => tokens != NULL for(char **iter = tokens; *iter != NULL; iter++) if(!strcmp(DARKTABLE_SHAREDIR, *iter)) { found = TRUE; break; } g_strfreev(tokens); if(found) set_env = FALSE; else new_xdg_data_dirs = g_strjoin(":", DARKTABLE_SHAREDIR, xdg_data_dirs, NULL); } else { // see http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html for a reason to use those as a default if(!g_strcmp0(DARKTABLE_SHAREDIR, "/usr/local/share") || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/local/share/") || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/share") || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/share/")) new_xdg_data_dirs = g_strdup("/usr/local/share/:/usr/share/"); else new_xdg_data_dirs = g_strdup_printf("%s:/usr/local/share/:/usr/share/", DARKTABLE_SHAREDIR); } if(set_env) g_setenv("XDG_DATA_DIRS", new_xdg_data_dirs, 1); g_free(new_xdg_data_dirs); } setlocale(LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, DARKTABLE_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); // init all pointers to 0: memset(&darktable, 0, sizeof(darktable_t)); darktable.progname = argv[0]; // database gchar *dbfilename_from_command = NULL; char *datadir_from_command = NULL; char *moduledir_from_command = NULL; char *tmpdir_from_command = NULL; char *configdir_from_command = NULL; char *cachedir_from_command = NULL; #ifdef USE_LUA char *lua_command = NULL; #endif darktable.num_openmp_threads = 1; #ifdef _OPENMP darktable.num_openmp_threads = omp_get_num_procs(); #endif darktable.unmuted = 0; GSList *images_to_load = NULL, *config_override = NULL; for(int k=1; k<argc; k++) { if(argv[k][0] == '-') { if(!strcmp(argv[k], "--help")) { return usage(argv[0]); } if(!strcmp(argv[k], "-h")) { return usage(argv[0]); } else if(!strcmp(argv[k], "--version")) { printf("this is "PACKAGE_STRING"\ncopyright (c) 2009-2014 johannes hanika\n"PACKAGE_BUGREPORT"\n" #ifdef _OPENMP "OpenMP support enabled\n" #else "OpenMP support disabled\n" #endif ); return 1; } else if(!strcmp(argv[k], "--library")) { dbfilename_from_command = argv[++k]; } else if(!strcmp(argv[k], "--datadir")) { datadir_from_command = argv[++k]; } else if(!strcmp(argv[k], "--moduledir")) { moduledir_from_command = argv[++k]; } else if(!strcmp(argv[k], "--tmpdir")) { tmpdir_from_command = argv[++k]; } else if(!strcmp(argv[k], "--configdir")) { configdir_from_command = argv[++k]; } else if(!strcmp(argv[k], "--cachedir")) { cachedir_from_command = argv[++k]; } else if(!strcmp(argv[k], "--localedir")) { bindtextdomain (GETTEXT_PACKAGE, argv[++k]); } else if(argv[k][1] == 'd' && argc > k+1) { if(!strcmp(argv[k+1], "all")) darktable.unmuted = 0xffffffff; // enable all debug information else if(!strcmp(argv[k+1], "cache")) darktable.unmuted |= DT_DEBUG_CACHE; // enable debugging for lib/film/cache module else if(!strcmp(argv[k+1], "control")) darktable.unmuted |= DT_DEBUG_CONTROL; // enable debugging for scheduler module else if(!strcmp(argv[k+1], "dev")) darktable.unmuted |= DT_DEBUG_DEV; // develop module else if(!strcmp(argv[k+1], "fswatch")) darktable.unmuted |= DT_DEBUG_FSWATCH; // fswatch module else if(!strcmp(argv[k+1], "input")) darktable.unmuted |= DT_DEBUG_INPUT; // input devices else if(!strcmp(argv[k+1], "camctl")) darktable.unmuted |= DT_DEBUG_CAMCTL; // camera control module else if(!strcmp(argv[k+1], "perf")) darktable.unmuted |= DT_DEBUG_PERF; // performance measurements else if(!strcmp(argv[k+1], "pwstorage")) darktable.unmuted |= DT_DEBUG_PWSTORAGE; // pwstorage module else if(!strcmp(argv[k+1], "opencl")) darktable.unmuted |= DT_DEBUG_OPENCL; // gpu accel via opencl else if(!strcmp(argv[k+1], "sql")) darktable.unmuted |= DT_DEBUG_SQL; // SQLite3 queries else if(!strcmp(argv[k+1], "memory")) darktable.unmuted |= DT_DEBUG_MEMORY; // some stats on mem usage now and then. else if(!strcmp(argv[k+1], "lighttable")) darktable.unmuted |= DT_DEBUG_LIGHTTABLE; // lighttable related stuff. else if(!strcmp(argv[k+1], "nan")) darktable.unmuted |= DT_DEBUG_NAN; // check for NANs when processing the pipe. else if(!strcmp(argv[k+1], "masks")) darktable.unmuted |= DT_DEBUG_MASKS; // masks related stuff. else if(!strcmp(argv[k+1], "lua")) darktable.unmuted |= DT_DEBUG_LUA; // lua errors are reported on console else return usage(argv[0]); k ++; } else if(argv[k][1] == 't' && argc > k+1) { darktable.num_openmp_threads = CLAMP(atol(argv[k+1]), 1, 100); printf("[dt_init] using %d threads for openmp parallel sections\n", darktable.num_openmp_threads); k ++; } else if(!strcmp(argv[k], "--conf")) { gchar *keyval = g_strdup(argv[++k]), *c = keyval; gchar *end = keyval + strlen(keyval); while(*c != '=' && c < end) c++; if(*c == '=' && *(c+1) != '\0') { *c++ = '\0'; dt_conf_string_entry_t *entry = (dt_conf_string_entry_t*)g_malloc(sizeof(dt_conf_string_entry_t)); entry->key = g_strdup(keyval); entry->value = g_strdup(c); config_override = g_slist_append(config_override, entry); } g_free(keyval); } else if(!strcmp(argv[k], "--luacmd")) { #ifdef USE_LUA lua_command = argv[++k]; #else ++k; #endif } } #ifndef MAC_INTEGRATION else { images_to_load = g_slist_append(images_to_load, argv[k]); } #endif } if(darktable.unmuted & DT_DEBUG_MEMORY) { fprintf(stderr, "[memory] at startup\n"); dt_print_mem_usage(); } #ifdef _OPENMP omp_set_num_threads(darktable.num_openmp_threads); #endif dt_loc_init_datadir(datadir_from_command); dt_loc_init_plugindir(moduledir_from_command); if(dt_loc_init_tmp_dir(tmpdir_from_command)) { printf(_("ERROR : invalid temporary directory : %s\n"),darktable.tmpdir); return usage(argv[0]); } dt_loc_init_user_config_dir(configdir_from_command); dt_loc_init_user_cache_dir(cachedir_from_command); #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif // does not work, as gtk is not inited yet. // even if it were, it's a super bad idea to invoke gtk stuff from // a signal handler. /* check cput caps */ // dt_check_cpu(argc,argv); #ifdef HAVE_GEGL char geglpath[PATH_MAX]; char datadir[PATH_MAX]; dt_loc_get_datadir(datadir, sizeof(datadir)); snprintf(geglpath, sizeof(geglpath), "%s/gegl:/usr/lib/gegl-0.0", datadir); (void)setenv("GEGL_PATH", geglpath, 1); gegl_init(&argc, &argv); #endif #ifdef USE_LUA dt_lua_init_early(L); #endif // thread-safe init: dt_exif_init(); char datadir[PATH_MAX]; dt_loc_get_user_config_dir (datadir, sizeof(datadir)); char filename[PATH_MAX]; snprintf(filename, sizeof(filename), "%s/darktablerc", datadir); // initialize the config backend. this needs to be done first... darktable.conf = (dt_conf_t *)calloc(1, sizeof(dt_conf_t)); dt_conf_init(darktable.conf, filename, config_override); g_slist_free_full(config_override, g_free); // set the interface language const gchar* lang = dt_conf_get_string("ui_last/gui_language"); // we may not g_free 'lang' since it is owned by setlocale afterwards if(lang != NULL && lang[0] != '\0') { if(setlocale(LC_ALL, lang) != NULL) gtk_disable_setlocale(); } // initialize the database darktable.db = dt_database_init(dbfilename_from_command); if(darktable.db == NULL) { printf("ERROR : cannot open database\n"); return 1; } else if(!dt_database_get_lock_acquired(darktable.db)) { // send the images to the other instance via dbus if(images_to_load) { GSList *p = images_to_load; // get a connection! GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SESSION,NULL, NULL); while (p != NULL) { // make the filename absolute ... gchar *filename = dt_make_path_absolute((gchar*)p->data); if(filename == NULL) continue; // ... and send it to the running instance of darktable g_dbus_connection_call_sync(connection, "org.darktable.service", "/darktable", "org.darktable.service.Remote", "Open", g_variant_new ("(s)", filename), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); p = g_slist_next(p); g_free(filename); } g_slist_free(images_to_load); g_object_unref(connection); } return 1; } // Initialize the signal system darktable.signals = dt_control_signal_init(); // Make sure that the database and xmp files are in sync before starting the fswatch. // We need conf and db to be up and running for that which is the case here. // FIXME: is this also useful in non-gui mode? GList *changed_xmp_files = NULL; if(init_gui && dt_conf_get_bool("run_crawler_on_start")) { changed_xmp_files = dt_control_crawler_run(); } // Initialize the filesystem watcher darktable.fswatch=dt_fswatch_new(); #ifdef HAVE_GPHOTO2 // Initialize the camera control darktable.camctl=dt_camctl_new(); #endif // get max lighttable thumbnail size: darktable.thumbnail_width = CLAMPS(dt_conf_get_int("plugins/lighttable/thumbnail_width"), 200, 3000); darktable.thumbnail_height = CLAMPS(dt_conf_get_int("plugins/lighttable/thumbnail_height"), 200, 3000); // and make sure it can be mip-mapped all the way from mip4 to mip0 darktable.thumbnail_width /= 16; darktable.thumbnail_width *= 16; darktable.thumbnail_height /= 16; darktable.thumbnail_height *= 16; // Initialize the password storage engine darktable.pwstorage=dt_pwstorage_new(); // FIXME: move there into dt_database_t dt_pthread_mutex_init(&(darktable.db_insert), NULL); dt_pthread_mutex_init(&(darktable.plugin_threadsafe), NULL); dt_pthread_mutex_init(&(darktable.capabilities_threadsafe), NULL); darktable.control = (dt_control_t *)calloc(1, sizeof(dt_control_t)); if(init_gui) { dt_control_init(darktable.control); } else { if(dbfilename_from_command && !strcmp(dbfilename_from_command, ":memory:")) dt_gui_presets_init(); // init preset db schema. darktable.control->running = 0; darktable.control->accelerators = NULL; dt_pthread_mutex_init(&darktable.control->run_mutex, NULL); } // initialize collection query darktable.collection_listeners = NULL; darktable.collection = dt_collection_new(NULL); /* initialize selection */ darktable.selection = dt_selection_new(); /* capabilities set to NULL */ darktable.capabilities = NULL; #ifdef HAVE_GRAPHICSMAGICK /* GraphicsMagick init */ InitializeMagick(darktable.progname); #endif darktable.opencl = (dt_opencl_t *)calloc(1, sizeof(dt_opencl_t)); #ifdef HAVE_OPENCL dt_opencl_init(darktable.opencl, argc, argv); #endif darktable.blendop = (dt_blendop_t *)calloc(1, sizeof(dt_blendop_t)); dt_develop_blend_init(darktable.blendop); darktable.points = (dt_points_t *)calloc(1, sizeof(dt_points_t)); dt_points_init(darktable.points, dt_get_num_threads()); // must come before mipmap_cache, because that one will need to access // image dimensions stored in here: darktable.image_cache = (dt_image_cache_t *)calloc(1, sizeof(dt_image_cache_t)); dt_image_cache_init(darktable.image_cache); darktable.mipmap_cache = (dt_mipmap_cache_t *)calloc(1, sizeof(dt_mipmap_cache_t)); dt_mipmap_cache_init(darktable.mipmap_cache); // The GUI must be initialized before the views, because the init() // functions of the views depend on darktable.control->accels_* to register // their keyboard accelerators if(init_gui) { darktable.gui = (dt_gui_gtk_t *)calloc(1, sizeof(dt_gui_gtk_t)); if(dt_gui_gtk_init(darktable.gui, argc, argv)) return 1; dt_bauhaus_init(); } else darktable.gui = NULL; darktable.view_manager = (dt_view_manager_t *)calloc(1, sizeof(dt_view_manager_t)); dt_view_manager_init(darktable.view_manager); darktable.imageio = (dt_imageio_t *)calloc(1, sizeof(dt_imageio_t)); dt_imageio_init(darktable.imageio); // load the darkroom mode plugins once: dt_iop_load_modules_so(); if(init_gui) { darktable.lib = (dt_lib_t *)calloc(1, sizeof(dt_lib_t)); dt_lib_init(darktable.lib); dt_control_load_config(darktable.control); } if(init_gui) { // Loading the keybindings char keyfile[PATH_MAX]; // First dump the default keymapping snprintf(keyfile, sizeof(keyfile), "%s/keyboardrc_default", datadir); gtk_accel_map_save(keyfile); // Removing extraneous semi-colons from the default keymap strip_semicolons_from_keymap(keyfile); // Then load any modified keys if available snprintf(keyfile, sizeof(keyfile), "%s/keyboardrc", datadir); if(g_file_test(keyfile, G_FILE_TEST_EXISTS)) gtk_accel_map_load(keyfile); else gtk_accel_map_save(keyfile); // Save the default keymap if none is present // I doubt that connecting to dbus for darktable-cli makes sense darktable.dbus = dt_dbus_init(); // initialize undo struct darktable.undo = dt_undo_init(); // load image(s) specified on cmdline int id = 0; if(images_to_load) { // If only one image is listed, attempt to load it in darkroom gboolean load_in_dr = (g_slist_next(images_to_load) == NULL); GSList *p = images_to_load; while (p != NULL) { // don't put these function calls into MAX(), the macro will evaluate // it twice (and happily deadlock, in this particular case) int newid = dt_load_from_string((gchar*)p->data, load_in_dr); id = MAX(id, newid); p = g_slist_next(p); } if (!load_in_dr || id == 0) dt_ctl_switch_mode_to(DT_LIBRARY); g_slist_free(images_to_load); } else dt_ctl_switch_mode_to(DT_LIBRARY); } if(darktable.unmuted & DT_DEBUG_MEMORY) { fprintf(stderr, "[memory] after successful startup\n"); dt_print_mem_usage(); } dt_image_local_copy_synch(); /* init lua last, since it's user made stuff it must be in the real environment */ #ifdef USE_LUA dt_lua_init(darktable.lua_state.state,lua_command); #endif // last but not least construct the popup that asks the user about images whose xmp files are newer than the db entry if(init_gui && changed_xmp_files) { dt_control_crawler_show_image_list(changed_xmp_files); } return 0; }
static void impl_activate(PeasActivatable *activatable) { XmrMprisPlugin *plugin; GError *error = NULL; GDBusInterfaceInfo *ifaceinfo; plugin = XMR_MPRIS_PLUGIN(activatable); g_object_get(plugin, "object", &plugin->window, NULL); g_object_get(plugin->window, "player", &plugin->player, NULL); g_signal_connect(plugin->window, "track-changed", G_CALLBACK(track_changed), plugin); g_signal_connect(plugin->player, "tick", G_CALLBACK(player_tick), plugin); plugin->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { xmr_debug("Unable to connect to D-Bus session bus: %s", error->message); return ; } /* parse introspection data */ plugin->node_info = g_dbus_node_info_new_for_xml(mpris_introspection_xml, &error); if (error != NULL) { xmr_debug("Unable to read MPRIS interface specificiation: %s", error->message); return; } /* register root interface */ ifaceinfo = g_dbus_node_info_lookup_interface (plugin->node_info, MPRIS_ROOT_INTERFACE); plugin->root_id = g_dbus_connection_register_object(plugin->connection, MPRIS_OBJECT_NAME, ifaceinfo, &root_vtable, plugin, NULL, &error); if (error != NULL) { xmr_debug("unable to register MPRIS root interface: %s", error->message); g_error_free (error); } /* register player interface */ ifaceinfo = g_dbus_node_info_lookup_interface(plugin->node_info, MPRIS_PLAYER_INTERFACE); plugin->player_id = g_dbus_connection_register_object(plugin->connection, MPRIS_OBJECT_NAME, ifaceinfo, &player_vtable, plugin, NULL, &error); if (error != NULL) { xmr_debug("Unable to register MPRIS player interface: %s", error->message); g_error_free (error); } plugin->name_own_id = g_bus_own_name(G_BUS_TYPE_SESSION, MPRIS_BUS_NAME_PREFIX ".xmradio", G_BUS_NAME_OWNER_FLAGS_NONE, NULL, (GBusNameAcquiredCallback) name_acquired_cb, (GBusNameLostCallback) name_lost_cb, g_object_ref(plugin), g_object_unref); }
int main (int argc, char **argv) { GDBusConnection *bus; GError *error = NULL; XfpmPowerManager *proxy; GOptionContext *octx; gboolean run = FALSE; gboolean quit = FALSE; gboolean config = FALSE; gboolean version = FALSE; gboolean reload = FALSE; gboolean no_daemon = FALSE; gboolean debug = FALSE; gboolean dump = FALSE; gchar *client_id = NULL; GOptionEntry option_entries[] = { { "run",'r', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &run, NULL, NULL }, { "no-daemon",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &no_daemon, N_("Do not daemonize"), NULL }, { "debug",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &debug, N_("Enable debugging"), NULL }, { "dump",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &dump, N_("Dump all information"), NULL }, { "restart", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &reload, N_("Restart the running instance of Xfce power manager"), NULL}, { "customize", 'c', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &config, N_("Show the configuration dialog"), NULL }, { "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &quit, N_("Quit any running xfce power manager"), NULL }, { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version, N_("Version information"), NULL }, { "sm-client-id", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &client_id, NULL, NULL }, { NULL, }, }; /* Parse the options */ octx = g_option_context_new(""); g_option_context_set_ignore_unknown_options(octx, TRUE); g_option_context_add_main_entries(octx, option_entries, NULL); g_option_context_add_group(octx, xfce_sm_client_get_option_group(argc, argv)); /* We can't add the following command because it will invoke gtk_init before we have a chance to fork. g_option_context_add_group(octx, gtk_get_option_group(TRUE)); */ if(!g_option_context_parse(octx, &argc, &argv, &error)) { g_printerr(_("Failed to parse arguments: %s\n"), error->message); g_option_context_free(octx); g_error_free(error); return EXIT_FAILURE; } g_option_context_free(octx); if ( version ) show_version (); /* Fork if needed */ if ( dump == FALSE && debug == FALSE && no_daemon == FALSE && daemon(0,0) ) { g_critical ("Could not daemonize"); } /* Initialize */ xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8"); g_set_application_name (PACKAGE_NAME); if (!gtk_init_check (&argc, &argv)) { if (G_LIKELY (error)) { g_printerr ("%s: %s.\n", G_LOG_DOMAIN, error->message); g_printerr (_("Type '%s --help' for usage."), G_LOG_DOMAIN); g_printerr ("\n"); g_error_free (error); } else { g_error ("Unable to open display."); } return EXIT_FAILURE; } xfpm_debug_init (debug); bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if ( error ) { xfce_dialog_show_error (NULL, error, "%s", _("Unable to get connection to the message bus session")); g_error ("%s: \n", error->message); } if ( quit ) { if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") ) { g_print (_("Xfce power manager is not running")); g_print ("\n"); return EXIT_SUCCESS; } else { proxy = xfpm_power_manager_proxy_new_sync (bus, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, "org.xfce.PowerManager", "/org/xfce/PowerManager", NULL, NULL); if ( !proxy ) { g_critical ("Failed to get proxy"); g_object_unref(bus); return EXIT_FAILURE; } xfpm_power_manager_call_quit_sync (proxy, NULL, &error); g_object_unref (proxy); if ( error) { g_critical ("Failed to send quit message %s:\n", error->message); g_error_free (error); } } return EXIT_SUCCESS; } if ( config ) { g_spawn_command_line_async ("xfce4-power-manager-settings", &error); if ( error ) { g_critical ("Failed to execute xfce4-power-manager-settings: %s", error->message); g_error_free (error); return EXIT_FAILURE; } return EXIT_SUCCESS; } if ( reload ) { if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") && !xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement")) { g_print ("Xfce power manager is not running\n"); xfpm_start (bus, client_id, dump); } proxy = xfpm_power_manager_proxy_new_sync (bus, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, "org.xfce.PowerManager", "/org/xfce/PowerManager", NULL, NULL); if ( !proxy ) { g_critical ("Failed to get proxy"); g_object_unref (bus); return EXIT_FAILURE; } if ( !xfpm_power_manager_call_restart_sync (proxy, NULL, NULL) ) { g_critical ("Unable to send reload message"); g_object_unref (proxy); g_object_unref (bus); return EXIT_SUCCESS; } return EXIT_SUCCESS; } if (dump) { if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager")) { xfpm_dump_remote (bus); return EXIT_SUCCESS; } } if (xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement") ) { g_print ("%s: %s\n", _("Xfce Power Manager"), _("Another power manager is already running")); } else if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager")) { g_print (_("Xfce power manager is already running")); g_print ("\n"); return EXIT_SUCCESS; } else { xfpm_start (bus, client_id, dump); } return EXIT_SUCCESS; }
static void is_udisks_plugin_activate(PeasActivatable *activatable) { IsUdisksPlugin *self = IS_UDISKS_PLUGIN(activatable); IsUdisksPluginPrivate *priv = self->priv; GDBusProxy *proxy; GError *error = NULL; GVariant *container, *paths; GVariantIter iter; gchar *path; priv->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (!priv->connection) { is_warning("udisks", "Failed to open connection to system dbus: %s", error->message); g_error_free(error); goto out; } /* This is the proxy which is only used once during the enumeration of * the device object paths */ proxy = g_dbus_proxy_new_sync(priv->connection, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL, UDISKS_BUS_NAME, UDISKS_OBJECT_PATH, UDISKS_INTERFACE_NAME, NULL, &error); if (!proxy) { is_warning("udisks", "Error getting proxy to udisks on system bus: %s", error->message); g_error_free(error); goto out; } /* The object paths of the disks are enumerated and placed in an array * of object paths */ container = g_dbus_proxy_call_sync(proxy, "EnumerateDevices", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (!container) { is_warning("udisks", "Failed to enumerate disk devices: %s", error->message); g_error_free(error); g_object_unref(proxy); goto out; } paths = g_variant_get_child_value(container, 0); g_variant_unref(container); g_variant_iter_init(&iter, paths); while (g_variant_iter_loop(&iter, "o", &path)) { /* This proxy is used to get the required data in order to build * up the list of sensors */ GDBusProxy *sensor_proxy; GVariant *model, *smart_available; IsSensor *sensor; gchar *name, *sensor_path; sensor_proxy = g_dbus_proxy_new_sync(priv->connection, G_DBUS_PROXY_FLAGS_NONE, NULL, UDISKS_BUS_NAME, path, UDISKS_DEVICE_INTERFACE_NAME, NULL, &error); if (!sensor_proxy) { is_debug("udisks", "error getting sensor proxy for disk %s: %s", path, error->message); g_clear_error(&error); g_object_unref(sensor_proxy); continue; } smart_available = g_dbus_proxy_get_cached_property(sensor_proxy, "DriveAtaSmartIsAvailable"); if (!smart_available) { is_debug("udisks", "error getting smart status for disk %s", path); g_object_unref(sensor_proxy); continue; } if (!g_variant_get_boolean(smart_available)) { is_debug("udisks", "drive %s does not support SMART monitoring, ignoring...", path); g_variant_unref(smart_available); g_object_unref(sensor_proxy); continue; } g_variant_unref(smart_available); model = g_dbus_proxy_get_cached_property(sensor_proxy, "DriveModel"); if (!model) { is_debug("udisks", "error getting drive model for disk %s", path); g_clear_error(&error); g_object_unref(sensor_proxy); continue; } name = g_path_get_basename(path); sensor_path = g_strdup_printf("udisks/%s", name); sensor = is_temperature_sensor_new(sensor_path); is_sensor_set_label(sensor, g_variant_get_string(model, NULL)); is_sensor_set_digits(sensor, 0); is_sensor_set_icon(sensor, IS_STOCK_DISK); /* only update every minute to avoid waking disk too much */ is_sensor_set_update_interval(sensor, 60); g_signal_connect(sensor, "update-value", G_CALLBACK(update_sensor_value), self); is_manager_add_sensor(is_application_get_manager(priv->application), sensor); g_free(sensor_path); g_free(name); g_object_unref(sensor); g_object_unref(sensor_proxy); } g_variant_unref(paths); g_object_unref(proxy); out: return; }
/** * autolink_dbusclient_init - Linux app management * * @pdbusclient : autolink_dbusclient_st * @busname : dbus bus name, for example "org.autolink.AppMngService" * @signame : signal name, for example "AppMngSignal",Must be camel format * * returns: * */ extern gint32 autolink_dbusclient_init(autolink_dbusclient_ptr pdbusclient, const char *busname, const char *objpath) { int ret; gboolean bRet = TRUE; GError *pConnError = NULL; GError *pProxyError = NULL; pthread_t tid_client; if (pdbusclient == NULL || busname == NULL || objpath == NULL) return ERR_PARAMENT; if (pdbusclient->tid_client != 0) return ERR_CONDITION; g_type_init(); /** initial for usage of "g" types */ mainloop = g_main_loop_new (NULL, FALSE); /** create main loop, but do not start it.*/ do{ bRet = TRUE; /** First step: get a connection */ pConnection = g_bus_get_sync (AUTOLINK_GDBUS_BUS, NULL, &pConnError); if (NULL == pConnError){ /** Second step: try to get a connection to the given bus.*/ pProxy = gdbus_mcuinfo_proxy_new_sync (pConnection, G_DBUS_PROXY_FLAGS_NONE, busname, //AUTOLINK_GDBUS_BUS_NAME, objpath, //AUTOLINK_GDBUS_BUS_OBJECT_PATH, NULL, &pProxyError); if (0 == pProxy) { ERR_LOG ("autolink_dbusclient_init: Failed to create proxy. Reason: %s.\n", pProxyError->message); g_error_free (pProxyError); pConnError = NULL; bRet = FALSE; } } else{ ERR_LOG ("autolink_dbusclient_init: Failed to connect to dbus. Reason: %s.\n", pConnError->message); g_error_free (pConnError); pConnError = NULL; bRet = FALSE; } usleep (200*1000); }while(FALSE == bRet); if (TRUE == bRet) { /** Third step: Attach to dbus signals */ register_client_sighandler (pProxy); } /* create dbus client thread */ ret = pthread_create (&tid_client,NULL,&dbus_client_thread,(void *)mainloop); INFO_LOG ("create dbus client pthread %s.\n",(ret)?"fail":"success"); if (ret != 0) return ERR_THREAD; pdbusclient->mainloop = mainloop; pdbusclient->tid_client = tid_client; pdbusclient->pProxy = pProxy; return ERR_OK; }
GDBusConnection * _g_dbus_connection_get_sync (const char *dbus_id, GCancellable *cancellable, GError **error) { GDBusConnection *bus; ThreadLocalConnections *local; GError *local_error; GDBusConnection *connection; gchar *address1; GVfsDBusDaemon *daemon_proxy; gboolean res; if (g_cancellable_set_error_if_cancelled (cancellable, error)) return NULL; local = g_private_get (&local_connections); if (local == NULL) { local = g_new0 (ThreadLocalConnections, 1); local->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_object_unref); g_private_set (&local_connections, local); } if (dbus_id == NULL) { /* Session bus */ if (local->session_bus) { if (! g_dbus_connection_is_closed (local->session_bus)) return local->session_bus; /* Session bus was disconnected, re-connect */ g_object_unref (local->session_bus); local->session_bus = NULL; } } else { /* Mount daemon connection */ connection = g_hash_table_lookup (local->connections, dbus_id); if (connection != NULL) { if (g_dbus_connection_is_closed (connection)) { /* The mount for this connection died, we invalidate * the caches, and then caller needs to retry. */ invalidate_local_connection (dbus_id, error); return NULL; } return connection; } } if (local->session_bus == NULL) { bus = g_bus_get_sync (G_BUS_TYPE_SESSION, cancellable, error); if (bus == NULL) return NULL; local->session_bus = bus; if (dbus_id == NULL) return bus; /* We actually wanted the session bus, so done */ } daemon_proxy = gvfs_dbus_daemon_proxy_new_sync (local->session_bus, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, dbus_id, G_VFS_DBUS_DAEMON_PATH, cancellable, error); if (daemon_proxy == NULL) return NULL; address1 = NULL; res = gvfs_dbus_daemon_call_get_connection_sync (daemon_proxy, &address1, NULL, cancellable, error); g_object_unref (daemon_proxy); if (!res) { g_free (address1); return NULL; } local_error = NULL; connection = g_dbus_connection_new_for_address_sync (address1, G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, NULL, /* GDBusAuthObserver */ cancellable, &local_error); g_free (address1); if (!connection) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error while getting peer-to-peer dbus connection: %s", local_error->message); g_error_free (local_error); return NULL; } vfs_connection_setup (connection, FALSE); g_hash_table_insert (local->connections, g_strdup (dbus_id), connection); return connection; }
static gint enable_ssh_service () { GDBusConnection *connection; GError *error = NULL; GVariant *temp_variant; connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (!connection) { g_critical ("Error connecting to D-Bus system bus: %s", error->message); g_clear_error (&error); return 1; } temp_variant = g_dbus_connection_call_sync (connection, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartUnit", g_variant_new ("(ss)", SSHD_SERVICE, "replace"), (GVariantType *) "(o)", G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (!temp_variant) { g_critical ("Error starting " SSHD_SERVICE ": %s", error->message); g_clear_error (&error); return 1; } g_variant_unref (temp_variant); temp_variant = g_dbus_connection_call_sync (connection, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "EnableUnitFiles", g_variant_new ("(^asbb)", service_list, FALSE, FALSE), (GVariantType *) "(ba(sss))", G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (!temp_variant) { g_critical ("Error enabling " SSHD_SERVICE ": %s", error->message); g_clear_error (&error); return 1; } g_variant_unref (temp_variant); return 0; }
int main (int argc, char **argv) { guint owner_id; GBytes *introspection_bytes; g_autoptr(GError) error = NULL; g_autofree char *path = NULL; GDBusConnection *session_bus; GOptionContext *context; setlocale (LC_ALL, ""); /* Avoid even loading gvfs to avoid accidental confusion */ g_setenv ("GIO_USE_VFS", "local", TRUE); context = g_option_context_new ("- document portal"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s\n", error->message); return 1; } if (opt_daemon) { pid_t pid; ssize_t read_res; daemon_event_fd = eventfd (0, EFD_CLOEXEC); pid = fork (); if (pid != 0) { guint64 counter; read_res = read (daemon_event_fd, &counter, sizeof (counter)); if (read_res != 8) exit (1); exit (counter - 1); } } if (opt_verbose) g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, message_handler, NULL); g_set_prgname (argv[0]); loop = g_main_loop_new (NULL, FALSE); path = g_build_filename (g_get_user_data_dir (), "xdg-app/db", TABLE_NAME, NULL); db = xdg_app_db_new (path, FALSE, &error); if (db == NULL) { g_printerr ("Failed to load db: %s\n", error->message); do_exit (2); } session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (session_bus == NULL) { g_printerr ("No session bus: %s\n", error->message); do_exit (3); } permission_store = xdg_app_permission_store_proxy_new_sync (session_bus,G_DBUS_PROXY_FLAGS_NONE, "org.freedesktop.XdgApp", "/org/freedesktop/XdgApp/PermissionStore", NULL, &error); if (permission_store == NULL) { g_print ("No permission store: %s\n", error->message); do_exit (4); } /* We want do do our custom post-mainloop exit */ g_dbus_connection_set_exit_on_close (session_bus, FALSE); g_signal_connect (session_bus, "closed", G_CALLBACK (session_bus_closed), NULL); if (set_one_signal_handler(SIGHUP, exit_handler, 0) == -1 || set_one_signal_handler(SIGINT, exit_handler, 0) == -1 || set_one_signal_handler(SIGTERM, exit_handler, 0) == -1 || set_one_signal_handler(SIGPIPE, SIG_IGN, 0) == -1) { do_exit (5); } introspection_bytes = g_resources_lookup_data ("/org/freedesktop/portal/Documents/org.freedesktop.portal.Documents.xml", 0, NULL); g_assert (introspection_bytes != NULL); introspection_data = g_dbus_node_info_new_for_xml (g_bytes_get_data (introspection_bytes, NULL), NULL); owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.freedesktop.portal.Documents", G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0), on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); g_main_loop_run (loop); xdp_fuse_exit (); g_bus_unown_name (owner_id); g_dbus_node_info_unref (introspection_data); do_exit (final_exit_status); return 0; }
static void dun_start (NmaBtDevice *self) { NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); gboolean have_mm = FALSE, have_mm1 = TRUE; g_message ("%s: starting DUN device discovery...", __func__); _set_status (self, _("Detecting phone configuration...")); /* ModemManager stuff */ priv->mm_proxy = dbus_g_proxy_new_for_name (priv->bus, MM_SERVICE, MM_PATH, MM_INTERFACE); g_assert (priv->mm_proxy); have_mm = _name_has_owner (priv->bus, MM_SERVICE); dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, G_TYPE_BOXED, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->mm_proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->mm_proxy, "DeviceAdded", G_CALLBACK (modem_added), self, NULL); dbus_g_proxy_add_signal (priv->mm_proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->mm_proxy, "DeviceRemoved", G_CALLBACK (modem_removed), self, NULL); #if WITH_MODEM_MANAGER_1 /* ModemManager1 stuff */ { priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); if (priv->dbus_connection) { priv->modem_manager_1 = mm_manager_new_sync (priv->dbus_connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, NULL, NULL); if (priv->modem_manager_1) { g_signal_connect (priv->modem_manager_1, "object-added", G_CALLBACK (modem_object_added), self); g_signal_connect (priv->modem_manager_1, "object-removed", G_CALLBACK (modem_object_removed), self); } } have_mm1 = !!priv->modem_manager_1; } #endif /* Ensure at least one of ModemManager or ModemManager1 are around */ if (!have_mm && !have_mm1) { dun_error (self, __func__, NULL, _("ModemManager is not running")); return; } /* Bluez */ priv->dun_proxy = dbus_g_proxy_new_for_name (priv->bus, BLUEZ_SERVICE, priv->object_path, BLUEZ_SERIAL_INTERFACE); g_assert (priv->dun_proxy); priv->dun_timeout_id = g_timeout_add_seconds (45, dun_timeout_cb, self); g_message ("%s: calling Connect...", __func__); /* Watch for BT device property changes */ dbus_g_object_register_marshaller (_nma_marshal_VOID__STRING_BOXED, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->dun_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->dun_proxy, "PropertyChanged", G_CALLBACK (dun_property_changed), self, NULL); /* Request a connection to the device and get the port */ dbus_g_proxy_begin_call_with_timeout (priv->dun_proxy, "Connect", dun_connect_cb, self, NULL, 20000, G_TYPE_STRING, "dun", G_TYPE_INVALID); g_message ("%s: waiting for Connect success...", __func__); }
static void services_constructed (GObject *_object) { Services *services = SERVICES (_object); GDBusConnection *connection; services->systemd = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, 0, NULL, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", NULL, NULL); connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); if (connection) { g_dbus_connection_signal_subscribe (connection, "org.freedesktop.systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged", "/org/freedesktop/systemd1", NULL, G_DBUS_SIGNAL_FLAGS_NONE, on_unit_files_changed_signal, services, NULL); g_dbus_connection_signal_subscribe (connection, "org.freedesktop.systemd1", "org.freedesktop.DBus.Properties", "PropertiesChanged", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, on_systemd_properties_changed, services, NULL); g_dbus_connection_signal_subscribe (connection, "org.freedesktop.systemd1", "org.freedesktop.systemd1.Manager", "UnitNew", "/org/freedesktop/systemd1", NULL, G_DBUS_SIGNAL_FLAGS_NONE, on_unit_new_signal, services, NULL); g_dbus_connection_signal_subscribe (connection, "org.freedesktop.systemd1", "org.freedesktop.systemd1.Manager", "UnitRemoved", "/org/freedesktop/systemd1", NULL, G_DBUS_SIGNAL_FLAGS_NONE, on_unit_removed_signal, services, NULL); } if (services->systemd) g_dbus_proxy_call (services->systemd, "Subscribe", NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, on_subscribe_done, NULL); services->delayed_unit_news = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_delayed_unit_new); if (G_OBJECT_CLASS (services_parent_class)->constructed != NULL) G_OBJECT_CLASS (services_parent_class)->constructed (_object); }
static void _setup_agent_and_adapters(GTlmNfc* self) { GError *error = NULL; /* Introspection data for the agent object we are exporting */ const gchar introspection_xml[] = "<node>" " <interface name='org.neard.NDEFAgent'>" " <method name='GetNDEF'>" " <arg type='a{sv}' name='values' direction='in'/>" " </method>" " <method name='Release'>" " </method>" " </interface>" "</node>"; const GDBusInterfaceVTable interface_vtable = { _handle_agent_method_call, _handle_agent_get_property, _handle_agent_set_property }; self->system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (self->system_bus == NULL) { g_debug ("Error getting a system bus: %s", error->message); g_error_free (error); return; } GDBusNodeInfo *introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); self->agent_registration_id = g_dbus_connection_register_object (self->system_bus, "/org/tlmnfc/agent", introspection_data->interfaces[0], &interface_vtable, self, NULL, &error); if (self->agent_registration_id <= 0) { g_debug ("Error registering an agent object: %s", error->message); g_dbus_node_info_unref (introspection_data); g_error_free (error); return; } g_dbus_node_info_unref (introspection_data); GVariant* agent_register_response = g_dbus_connection_call_sync (self->system_bus, "org.neard", "/org/neard", "org.neard.AgentManager", "RegisterNDEFAgent", g_variant_new("(os)", "/org/tlmnfc/agent", "application/gtlm-nfc"), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (agent_register_response == NULL) { g_debug ("Error registering an agent with neard: %s", error->message); g_error_free (error); return; } g_variant_unref(agent_register_response); self->neard_manager = g_dbus_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, "org.neard", "/", NULL, NULL, NULL, NULL, &error); if (self->neard_manager == NULL) { g_debug ("Error creating neard object manager: %s", error->message); g_error_free (error); return ; } // subscribe to interface added/removed signals g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), "interface-added", G_CALLBACK (_on_interface_added), self); g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), "interface-removed", G_CALLBACK (_on_interface_removed), self); g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), "object-added", G_CALLBACK (_on_object_added), self); g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), "object-removed", G_CALLBACK (_on_object_removed), self); g_signal_connect (G_DBUS_OBJECT_MANAGER(self->neard_manager), "interface-proxy-properties-changed", G_CALLBACK (_on_property_changed), self); _setup_nfc_adapters(self); return; }
void GetPowerStatus_Linux(PowerStatus& result) { std::vector<std::string> devicePaths; GDBusProxy *proxy; GDBusConnection *conn; GError *error = nullptr; char *s; guint32 u; guint64 x; gboolean b; gdouble d; GVariant *variant; GVariantIter *iter; conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error); if (conn == nullptr) { LOG_FAIL(U"❌ PowerStatus: Failed to get d-bus connection."); return; } proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, nullptr, NAME_UPower, OBJECT_UPower, INTERFACE_UPower, nullptr, &error); if (proxy == nullptr) { LOG_FAIL(U"❌ PowerStatus: Failed to get d-bus proxy."); return; } variant = g_dbus_proxy_get_cached_property(proxy, "DaemonVersion"); if (variant == nullptr) { LOG_FAIL(U"❌ PowerStatus: Failed to get UPower properties."); return; } g_variant_get(variant, "s", &s); g_variant_unref(variant); LOG_INFO(U"ℹ️ PowerStatus: UPower daemon version {}"_fmt(s)); variant = g_dbus_proxy_call_sync(proxy, "EnumerateDevices", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error); if (variant == nullptr) { LOG_FAIL(U"❌ PowerStatus: Failed to enumerate power supply devices."); return; } g_variant_get(variant, "(ao)", &iter); while (g_variant_iter_loop(iter, "o", &s)) { devicePaths.push_back(s); } g_variant_iter_free(iter); g_variant_unref(variant); g_object_unref(proxy); result.battery = BatteryStatus::NoBattery; for (const auto &dev : devicePaths) { proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, nullptr, NAME_UPower, dev.c_str(), INTERFACE_UPower_Device, nullptr, &error); if (!get_property_and_output_log(proxy, "Type", "u", &u)) continue; if (u == 1) { //line power if (get_property_and_output_log(proxy, "Online", "b", &b)) { result.ac = b ? ACLineStatus::Online : ACLineStatus::Offline; } } else if (u == 2) { //battery if (get_property_and_output_log(proxy, "Percentage", "d", &d)) { result.batteryLifePercent = static_cast<int32>(d); result.battery = d <= 5 ? BatteryStatus::Critical : d <= 33 ? BatteryStatus::Low : d <= 66 ? BatteryStatus::Middle : BatteryStatus::High; } if (get_property_and_output_log(proxy, "State", "u", &u)) { if (u == 1) { //charging result.charging = true; if (get_property_and_output_log(proxy, "TimeToFull", "x", &x)) { if (x != 0) result.batteryTimeToFullChargeSec = static_cast<int32>(x); } } else if (u == 2) { //discharging if (get_property_and_output_log(proxy, "TimeToEmpty", "x", &x)) { if (x != 0) result.batteryLifeTimeSec = static_cast<int32>(x); } } } } } g_object_unref(conn); }