Beispiel #1
0
GMountSpec *
g_mount_spec_from_dbus (GVariant *value)
{
  GMountSpec *spec;
  const gchar *key;
  const gchar *mount_prefix;
  GVariantIter *iter_mount_spec_items;
  GVariant *v;

  mount_prefix = NULL;
  g_variant_get (value, "(^&aya{sv})",
                 &mount_prefix,
                 &iter_mount_spec_items);
  
  spec = g_mount_spec_new (NULL);
  g_free (spec->mount_prefix);
  spec->mount_prefix = NULL;
  if (mount_prefix && mount_prefix[0])
    spec->mount_prefix = g_strdup (mount_prefix);

  while (g_variant_iter_loop (iter_mount_spec_items, "{&sv}", &key, &v))
    {
      add_item (spec, key, g_variant_dup_bytestring (v, NULL));
    }

  g_variant_iter_free (iter_mount_spec_items);

  /* Sort on key */
  g_array_sort (spec->items, item_compare);
  
  return spec;
}
static void
grok_platform_data (GApplicationCommandLine *cmdline)
{
    GVariantIter iter;
    const gchar *key;
    GVariant *value;

    g_variant_iter_init (&iter, cmdline->priv->platform_data);

    while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
        if (strcmp (key, "cwd") == 0)
        {
            if (!cmdline->priv->cwd)
                cmdline->priv->cwd = g_variant_dup_bytestring (value, NULL);
        }

        else if (strcmp (key, "environ") == 0)
        {
            if (!cmdline->priv->environ)
                cmdline->priv->environ =
                    g_variant_dup_bytestring_array (value, NULL);
        }
}
Beispiel #3
0
static char*
get_atk_bridge_path (void)
{
  GSettings *atspi_settings = NULL;
  GVariant *variant = NULL;
  char *value = NULL;
  const char * const *schemas = NULL;
  gboolean found = FALSE;
  int i = 0;

  schemas = g_settings_list_schemas ();

  for (i = 0; schemas [i]; i++)
    {
      if (!strcmp (schemas[i], AT_SPI_SCHEMA))
        {
          found = TRUE;
          break;
        }
    }

  if (!found)
    {
      g_warning ("Accessibility: %s schema not found. Are you sure that at-spi or"
                 " at-spi2 is installed on your system?", AT_SPI_SCHEMA);
      return NULL;
    }

  atspi_settings = g_settings_new (AT_SPI_SCHEMA);
  variant = g_settings_get_value (atspi_settings, ATK_BRIDGE_LOCATION_KEY);
  value = g_variant_dup_bytestring (variant, NULL);
  g_variant_unref (variant);
  g_object_unref (atspi_settings);

  return value;
}
Beispiel #4
0
struct UD2_enumerations* enum_objects() {
	g_type_init();

	struct UD2_enumerations* enumerations = g_new(struct UD2_enumerations, 1);
	GList* UD2_drives = NULL;
	GList* UD2_blocks = NULL;

	GDBusProxy* UD2_Proxy = NULL;
	GError* error=NULL;
	
	UD2_Proxy = g_dbus_proxy_new_for_bus_sync(	G_BUS_TYPE_SYSTEM,
							G_DBUS_PROXY_FLAGS_NONE,
							NULL,
							UD2_DBUS_NAME,
							UD2_PATH,
							DBUS_MANAGER_IFACE,
							NULL,
							&error);

	if (!UD2_Proxy) {
		g_printerr("%s\n", error->message);
		g_error_free(error);
	}

	/* Use the GetManagedObjects method from the ObjectManager interface to
	 * enumerate UD2 objects
	 */
	GVariant* UD2_Objects = g_dbus_proxy_call_sync(	UD2_Proxy,
							(gchar*) "GetManagedObjects",
							NULL,
							G_DBUS_CALL_FLAGS_NONE,
							-1,
							NULL,
							&error);

	if (!UD2_Objects) {
		g_printerr("%s\n", error->message);
		g_error_free(error);
	}

	/* 
	As per http://dbus.freedesktop.org/doc/dbus-specification.html
	the return type for method GetManagedObjects is
	DICT<OBJPATH,DICT<STRING,DICT<STRING,VARIANT>>> or (a{oa{sa{sv}}}) in
	DBus parlance.
	*/
	g_assert_cmpstr("(a{oa{sa{sv}}})", ==, g_variant_get_type_string(UD2_Objects));
	/* The tuple contains only one dictionary */
	g_assert_cmpint(1, ==, g_variant_n_children(UD2_Objects));
	/* Re-parent UD2_Objects to the sole element in the tuple */
	UD2_Objects = g_variant_get_child_value(UD2_Objects, 0);


	GVariantIter* dict_iter = g_variant_iter_new(UD2_Objects);
	GVariant* kv_pair;
	while(kv_pair = g_variant_iter_next_value(dict_iter)) {

		gchar* dbus_object_path;
		GVariant* interface_dict;
		g_variant_get(kv_pair, "{o*}", &dbus_object_path, &interface_dict);

		if (0 == g_strcmp0("/org/freedesktop/UDisks2/Manager", dbus_object_path))
			goto next_object;

		/* Store the object's properties in a hash table */
		GHashTable* UD2_object_properties = g_hash_table_new(g_str_hash, g_str_equal);
		g_hash_table_insert(UD2_object_properties, "object_path", g_strdup(dbus_object_path));

		/* Parse the object's DBus interfaces */
		GVariantIter* interface_iterator = g_variant_iter_new(interface_dict);
		GVariant* interface_kv_pair;
		while(interface_kv_pair = g_variant_iter_next_value(interface_iterator)) {
			gchar* UD2_interface;
			GVariant* properties_dict;
			g_variant_get(interface_kv_pair, "{s*}", &UD2_interface, &properties_dict);


			/* Is this a UD2 drive? */
			if (0 == g_strcmp0(UD2_DRIVE_IFACE, UD2_interface)) {
				GVariant* ejectable = g_variant_lookup_value(
				    properties_dict,
				    "Ejectable",
				    NULL);
				g_hash_table_insert(UD2_object_properties,
				    (gchar*) "ejectable",
				    GINT_TO_POINTER(g_variant_get_boolean(ejectable)));
				g_variant_unref(ejectable);

				GVariant* optical = g_variant_lookup_value(
				    properties_dict,
				    "Optical",
				    NULL);
				g_hash_table_insert(UD2_object_properties,
				    (gchar*) "optical",
				    GINT_TO_POINTER(g_variant_get_boolean(optical)));
				g_variant_unref(optical);

				UD2_drives = g_list_append(UD2_drives, UD2_object_properties);
			}

			/* Is this a block device? */
			if (0 == g_strcmp0(UD2_BLOCK_IFACE, UD2_interface)) {
				GVariant* preferred_path = g_variant_lookup_value(
				    properties_dict,
				    "PreferredDevice",
				    NULL);
				g_hash_table_insert(UD2_object_properties,
				    (gchar*) "dev_path",
				    g_variant_dup_bytestring(preferred_path, NULL));
				g_variant_unref(preferred_path);

				/* In addition to the preferred path, there may
 				 * be any number of human-readable symlinks under
				 * /dev
				 */
				GVariant* symlinks = g_variant_lookup_value(properties_dict, "Symlinks", NULL);
				//g_print("Symlinks has %d elements\n", g_variant_n_children(symlinks));

				GVariantIter* symlink_iterator = g_variant_iter_new(symlinks);
				GVariant* symlink;
				GList* symlink_list = NULL;
				while(symlink = g_variant_iter_next_value(symlink_iterator)) {
					symlink_list = g_list_append(symlink_list, (gpointer) g_variant_dup_bytestring(symlink, NULL));
					g_variant_unref(symlink);
				}
				g_variant_iter_free(symlink_iterator);
				g_variant_unref(symlinks);

				g_hash_table_insert(UD2_object_properties, (gchar*) "symlinks", symlink_list);

				UD2_blocks = g_list_append(UD2_blocks, UD2_object_properties);
			}

			/* TODO How shall we handle partition tables? */
			if (0 == g_strcmp0(UD2_PTABLE_IFACE, UD2_interface)) {
				g_hash_table_insert(UD2_object_properties,
				    (gchar*) "has_partition_table",
				    GINT_TO_POINTER((gboolean) TRUE));
			}

			/* Does this block device have a filesystem? */
			if (0 == g_strcmp0(UD2_FS_IFACE, UD2_interface)) {
				g_hash_table_insert(UD2_object_properties,
				    (gchar*) "has_filesystem",
				    GINT_TO_POINTER((gboolean) TRUE));

				/* Is the FS mounted? We don't really care where */
				GVariant* mountpoints = g_variant_lookup_value(
				    properties_dict,
				    "MountPoints",
				    NULL);
				if (0 < g_variant_n_children(mountpoints)) {
					g_hash_table_insert(UD2_object_properties,
					    (gchar*) "mounted",
					    GINT_TO_POINTER((gboolean) TRUE));
				} else {
					g_hash_table_insert(UD2_object_properties,
					    (gchar*) "mounted",
					    GINT_TO_POINTER((gboolean) FALSE));
				}
				g_variant_unref(mountpoints);
			}

			g_free(UD2_interface);
			g_variant_unref(interface_kv_pair);
		}
		g_variant_iter_free(interface_iterator);

next_object:
		g_variant_unref(interface_dict);
		g_free(dbus_object_path);
		g_variant_unref(kv_pair);
	}
	g_variant_iter_free(dict_iter);

	/* Populate the UD2_enumerations struct */
	enumerations->drives = UD2_drives;
	enumerations->block_devices = UD2_blocks;

	g_variant_unref(UD2_Objects);
	g_object_unref(UD2_Proxy);

	return enumerations;
}