Пример #1
0
static gboolean
get_all_connections (void)
{
	GError *error = NULL;
	DBusGConnection *bus;
	DBusGProxy *proxy = NULL;
	GPtrArray *paths = NULL;
	int i;
	gboolean sucess = FALSE;

	bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
	if (error || !bus) {
		g_warning ("error: could not connect to dbus");
		goto out;
	}

	proxy = dbus_g_proxy_new_for_name (bus,
	                                   NM_DBUS_SERVICE,
	                                   NM_DBUS_PATH_SETTINGS,
	                                   NM_DBUS_IFACE_SETTINGS);
	if (!proxy) {
		g_warning ("error: failed to create DBus proxy for settings service");
		goto out;
	}

	if (!dbus_g_proxy_call (proxy, "ListConnections", &error,
                                G_TYPE_INVALID,
                                DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, &paths,
                                G_TYPE_INVALID)) {
		/* No connections or settings service may not be running */
		g_clear_error (&error);
		goto out;
	}

	connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);

	for (i = 0; paths && (i < paths->len); i++)
		get_one_connection (bus, g_ptr_array_index (paths, i), connections);

	sucess = TRUE;

out:
	if (bus)
		dbus_g_connection_unref (bus);
	if (proxy)
		g_object_unref (proxy);

	return sucess;
}
Пример #2
0
static void
get_connections_for_service (DBusGConnection *bus,
                             NMConnectionScope scope,
                             GHashTable *table)
{
	GError *error = NULL;
	DBusGProxy *proxy;
	GPtrArray *paths = NULL;
	int i;
	const char *service;

	service = (scope == NM_CONNECTION_SCOPE_SYSTEM) ?
		NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS;

	proxy = dbus_g_proxy_new_for_name (bus,
	                                   service,
	                                   NM_DBUS_PATH_SETTINGS,
	                                   NM_DBUS_IFACE_SETTINGS);
	if (!proxy) {
		g_warning ("error: failed to create DBus proxy for %s", service);
		return;
	}

	if (!dbus_g_proxy_call (proxy, "ListConnections", &error,
                                G_TYPE_INVALID,
                                DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, &paths,
                                G_TYPE_INVALID)) {
		g_warning ("error: failed to read connections from %s:\n    %s",
		           service, error ? error->message : "(unknown)");
		g_clear_error (&error);
		goto out;
	}

	for (i = 0; paths && (i < paths->len); i++)
		get_one_connection (bus, g_ptr_array_index (paths, i), scope, table);

out:
	g_object_unref (proxy);
}