Пример #1
0
/*
 * Dump all devices.
 */
int
dump_all_devices(LibHalContext *hal_ctx)
{
	int i;
	int num_devices;
	char **device_names;
	DBusError error;

	dbus_error_init(&error);

	if (!(device_names =
	libhal_get_all_devices(hal_ctx, &num_devices, &error))) {
		fprintf(stderr, "Empty HAL device list.\n");
		LIBHAL_FREE_DBUS_ERROR(&error);
		return (31);
	}

	for (i = 0; i < num_devices; i++) {
		prt_dev_props(hal_ctx, device_names[i]);
	}

	libhal_free_string_array(device_names);
	dbus_error_free(&error);

	return (0);
}
Пример #2
0
int rsct_usbdev_scan(rsct_usbdev_t **usbdev_list) {
  int rv;

  rv=rsct_usbdev_init();
  if (rv)
    return -1;
  else {
    char **devices;
    int i_devices;
    int rv;

    devices=libhal_get_all_devices(global_hal_context->ctx, &i_devices, &(global_hal_context->dbus_error));
    if (devices==NULL) {
      fprintf(stderr, "RSCT: HAL not running: %s\n", global_hal_context->dbus_error.message);
      return -1;
    }
    if (i_devices<1) {
      fprintf(stderr, "RSCT:  HAL returned an empty device list, this can't be right...\n");
    }

    rv=rsct_usbdev_scan_nonserial(devices, i_devices, usbdev_list);
    if (rv==0)
      rv=rsct_usbdev_scan_serial(devices, i_devices, usbdev_list);

    libhal_free_string_array(devices);
    return rv;
  }

  return 0;
}
Пример #3
0
/* Iterate through all devices currently on the computer. Needed mostly at startup */
void CHALManager::GenerateGDL()
{
  if (m_Context == NULL)
    return;

  char **GDL;
  int i = 0;
  CLog::Log(LOGDEBUG, "HAL: Clearing old global device list, if any");
  m_Volumes.clear();

  CLog::Log(LOGNOTICE, "HAL: Generating global device list");
  GDL = libhal_get_all_devices(g_HalManager.m_Context, &i, &m_Error);

  for (i = 0; GDL[i]; i++)
  {
    AddDevice(GDL[i]);
  }
  CLog::Log(LOGINFO, "HAL: Generated global device list, found %i", i);

  libhal_free_string_array(GDL);
}
Пример #4
0
static void
impl_activate (PeasActivatable *bplugin)
{
	RBMtpPlugin *plugin = RB_MTP_PLUGIN (bplugin);
	GtkUIManager *uimanager = NULL;
	RBRemovableMediaManager *rmm;
	char *file = NULL;
	RBShell *shell;
#if defined(HAVE_GUDEV)
	gboolean rmm_scanned = FALSE;
#else
	int num_mtp_devices;
	LIBMTP_raw_device_t *mtp_devices;
#endif

	g_object_get (plugin, "object", &shell, NULL);

	g_object_get (shell,
		     "ui-manager", &uimanager,
		     "removable-media-manager", &rmm,
		     NULL);

	/* ui */
	rb_media_player_source_init_actions (shell);
	plugin->action_group = gtk_action_group_new ("MTPActions");
	gtk_action_group_set_translation_domain (plugin->action_group,
						 GETTEXT_PACKAGE);
	_rb_action_group_add_display_page_actions (plugin->action_group,
						   G_OBJECT (shell),
						   rb_mtp_plugin_actions,
						   G_N_ELEMENTS (rb_mtp_plugin_actions));
	gtk_ui_manager_insert_action_group (uimanager, plugin->action_group, 0);
	file = rb_find_plugin_data_file (G_OBJECT (bplugin), "mtp-ui.xml");
	plugin->ui_merge_id = gtk_ui_manager_add_ui_from_file (uimanager, file, NULL);
	g_object_unref (uimanager);
	g_object_unref (shell);

	/* device detection */
#if defined(HAVE_GUDEV)
	plugin->create_device_source_id =
		g_signal_connect_object (rmm,
					 "create-source-device",
					 G_CALLBACK (create_source_device_cb),
					 plugin,
					 0);

	/* only scan if we're being loaded after the initial scan has been done */
	g_object_get (rmm, "scanned", &rmm_scanned, NULL);
	if (rmm_scanned)
		rb_removable_media_manager_scan (rmm);
#else
	if (rb_mtp_plugin_setup_dbus_hal_connection (plugin) == FALSE) {
		rb_debug ("not scanning for MTP devices because we couldn't get a HAL context");
		g_object_unref (rmm);
		return;
	}

	rb_profile_start ("scanning for MTP devices");
	LIBMTP_Detect_Raw_Devices (&mtp_devices, &num_mtp_devices);
	if (num_mtp_devices > 0) {
		int num_hal_devices;
		char **hal_devices;
		int i;

		rb_debug ("%d MTP devices found", num_mtp_devices);

		hal_devices = libhal_get_all_devices (plugin->hal_context, &num_hal_devices, NULL);
		for (i = 0; i < num_hal_devices; i++) {
			/* should narrow this down a bit - usb only, for a start */
			rb_mtp_plugin_maybe_add_source (plugin, hal_devices[i], mtp_devices, num_mtp_devices);
		}
		libhal_free_string_array (hal_devices);
	}
	if (mtp_devices != NULL) {
		free (mtp_devices);
	}
	rb_profile_end ("scanning for MTP devices");
#endif

	g_object_unref (rmm);
}
Пример #5
0
// Initialize basic HAL connection
LibHalContext *CHALManager::InitializeHal()
{
  LibHalContext *ctx;
  char **devices;
  int nr;

  if (!InitializeDBus())
    return NULL;

  if (!(ctx = libhal_ctx_new()))
  {
    CLog::Log(LOGERROR, "HAL: failed to create a HAL context!");
    return NULL;
  }

  if (!libhal_ctx_set_dbus_connection(ctx, m_DBusSystemConnection))
    CLog::Log(LOGERROR, "HAL: Failed to connect with dbus");

  libhal_ctx_set_device_added(ctx, DeviceAdded);
  libhal_ctx_set_device_removed(ctx, DeviceRemoved);
  libhal_ctx_set_device_new_capability(ctx, DeviceNewCapability);
  libhal_ctx_set_device_lost_capability(ctx, DeviceLostCapability);
  libhal_ctx_set_device_property_modified(ctx, DevicePropertyModified);
  libhal_ctx_set_device_condition(ctx, DeviceCondition);

  if (!libhal_device_property_watch_all(ctx, &m_Error))
  {
    CLog::Log(LOGERROR, "HAL: Failed to set property watch %s", m_Error.message);
    dbus_error_free(&m_Error);
    libhal_ctx_free(ctx);
    return NULL;
  }

  if (!libhal_ctx_init(ctx, &m_Error))
  {
    CLog::Log(LOGERROR, "HAL: Failed to initialize hal context: %s", m_Error.message);
    dbus_error_free(&m_Error);
    libhal_ctx_free(ctx);
    return NULL;
  }

  /*
 * Do something to ping the HAL daemon - the above functions will
 * succeed even if hald is not running, so long as DBUS is.  But we
 * want to exit silently if hald is not running, to behave on
 * pre-2.6 systems.
 */
  if (!(devices = libhal_get_all_devices(ctx, &nr, &m_Error)))
  {
    CLog::Log(LOGERROR, "HAL: seems that Hal daemon is not running: %s", m_Error.message);
    dbus_error_free(&m_Error);

    libhal_ctx_shutdown(ctx, NULL);
    libhal_ctx_free(ctx);
    return NULL;
  }

  libhal_free_string_array(devices);

  return ctx;
}
Пример #6
0
static int init_hal(void)
{
	LibHalContext *ctx;
	DBusError error;
	DBusConnection *dbus_connection;
	char **devices, **volumes;
	int i, num;

	if (!(ctx = libhal_ctx_new())) {
		fprintf(stderr, "can't initialize\n");
		return -1;
	}

	dbus_error_init(&error);
	dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);

	if (dbus_error_is_set(&error)) {
		fprintf(stderr, "%s\n", error.message);
		dbus_error_free(&error);
		return -1;
	}

	dbus_connection_setup_with_g_main(dbus_connection, NULL);
	libhal_ctx_set_dbus_connection(ctx, dbus_connection);
	libhal_ctx_set_device_property_modified(ctx, hal_property_modified);

	if (!libhal_device_property_watch_all(ctx, &error)) {
		fprintf(stderr, "%s\n", error.message);
		dbus_error_free(&error);
		libhal_ctx_free(ctx);
		return -1;
	}

	if (!libhal_ctx_init(ctx, &error)) {
		fprintf(stderr, "%s\n", error.message);
		dbus_error_free(&error);
		libhal_ctx_free(ctx);
		return -1;
	}

	if (!(devices = libhal_get_all_devices(ctx, &num, &error))) {
		fprintf(stderr, "%s\n", error.message);
		dbus_error_free(&error);
		libhal_ctx_shutdown(ctx, NULL);
		libhal_ctx_free(ctx);
		return -1;
	}

	libhal_free_string_array(devices);

	volumes = libhal_find_device_by_capability(ctx, "volume", &num, &error);
	if (dbus_error_is_set(&error)) {
		printf("can't find volume devices: %s\n", error.message);
		dbus_error_free(&error);
		libhal_ctx_shutdown(ctx, NULL);
		libhal_ctx_free(ctx);
		return -1;
	}

	for (i = 0; i < num; i++) {
		char *udi = volumes[i];

		if (libhal_device_property_exists(ctx, udi, "volume.is_mounted",
			 NULL) && libhal_device_get_property_bool(ctx, udi,
			"volume.is_mounted", NULL))
		{
			hal_property_modified(ctx, udi, "volume.is_mounted",
					      FALSE, FALSE);
			hal_property_modified(ctx, udi, "volume.mount_point",
					      FALSE, FALSE);
		}
	}

	libhal_free_string_array(volumes);

	return 0;
}
Пример #7
0
/*
 * Dump all devices.
 */
int dump_devices(LibHalContext *hal_ctx, char *arg)
{
	int i;
	int num_devices;
	char **device_names;
	DBusError error;
	char *udi = NULL;

	if (arg) {
		if (*arg == '/') {
			udi = arg;
		} else {
#ifdef HAVE_ASPRINTF
			asprintf(&udi, "/org/freedesktop/Hal/devices/%s", arg);
#else
			udi = calloc(1, sizeof ("/org/freedesktop/Hal/devices/%s") + strlen(arg));
			sprintf(udi, "/org/freedesktop/Hal/devices/%s", arg);

#endif
		}
	}

	dbus_error_init(&error);

	if (!udi) {
		if (!(device_names = libhal_get_all_devices(hal_ctx, &num_devices, &error))) {
			fprintf(stderr, "Empty HAL device list.\n");
			LIBHAL_FREE_DBUS_ERROR (&error);
			return 31;
		}
	} else {
		device_names = calloc(2, sizeof *device_names);
		device_names[0] = strdup(udi);
		num_devices = 1;
	}

	for(i = 0; i < num_devices; i++) {
		LibHalPropertySet *props;
		LibHalPropertySetIterator it;
		int type;

		if (!(props = libhal_device_get_all_properties(hal_ctx, device_names[i], &error))) {
			fprintf(stderr, "%s: %s\n", error.name, error.message);
			dbus_error_init(&error);
			continue;
		}

		if (!udi)
			printf("%d: ", i);
		printf("udi = '%s'\n", device_names[i]);

		for(libhal_psi_init(&it, props); libhal_psi_has_more(&it); libhal_psi_next(&it)) {
			type = libhal_psi_get_type(&it);
			switch (type) {
			case LIBHAL_PROPERTY_TYPE_STRING:
				printf("  %s = '%s'  (string)\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_string(&it)
				);
				break;
			case LIBHAL_PROPERTY_TYPE_INT32:
				printf("  %s = %d  (0x%x)  (int)\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_int(&it),
					libhal_psi_get_int(&it)
				);
				break;
			case LIBHAL_PROPERTY_TYPE_UINT64:
				printf("  %s = %lld  (0x%llx)  (uint64)\n",
					libhal_psi_get_key(&it),
					(long long) libhal_psi_get_uint64(&it),
					(long long) libhal_psi_get_uint64(&it)
				);
				break;
			case LIBHAL_PROPERTY_TYPE_DOUBLE:
				printf("  %s = %g  (double)\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_double(&it)
				);
				break;
			case LIBHAL_PROPERTY_TYPE_BOOLEAN:
				printf("  %s = %s  (bool)\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_bool(&it) ? "true" : "false"
				);
				break;
			case LIBHAL_PROPERTY_TYPE_STRLIST:
				{
					char **strlist;

					printf ("  %s = { ", libhal_psi_get_key(&it));
					strlist = libhal_psi_get_strlist(&it);
					while (*strlist) {
						printf("'%s'%s", *strlist, strlist[1] ? ", " : "");
						strlist++;
					}
					printf(" } (string list)\n");
				}
				break;
			default:
				printf("Unknown type %d = 0x%02x\n", type, type);
				break;
			}
		}

		libhal_free_property_set(props);
		printf("\n");
	}

	libhal_free_string_array(device_names);
	dbus_error_free(&error);

	return 0;
}