示例#1
0
/**
 * cd_plugin_add:
 **/
static void
cd_plugin_add (CdPlugin *plugin, GUdevDevice *udev_device)
{
	const gchar *devclass;
	const gchar *seat;
	_cleanup_free_ gchar *id = NULL;
	_cleanup_free_ gchar *model = NULL;
	_cleanup_free_ gchar *vendor = NULL;
	_cleanup_object_unref_ CdDevice *device = NULL;

	/* is a scanner? */
	if (!g_udev_device_has_property (udev_device, "libsane_matched"))
		return;

	/* skip hubs */
	devclass = g_udev_device_get_sysfs_attr (udev_device, "bDeviceClass");
	if (devclass == NULL || g_strcmp0 (devclass, "09") == 0)
		return;

	/* replace underscores with spaces */
	model = g_strdup (g_udev_device_get_property (udev_device,
						      "ID_MODEL"));
	if (model != NULL) {
		g_strdelimit (model, "_\r\n", ' ');
		g_strchomp (model);
	}
	vendor = g_strdup (g_udev_device_get_property (udev_device,
						       "ID_VENDOR"));
	if (vendor != NULL) {
		g_strdelimit (vendor, "_\r\n", ' ');
		g_strchomp (vendor);
	}

	/* generate ID */
	id = cd_plugin_get_scanner_id_for_udev_device (udev_device);

	/* assume device belongs to "seat0" if not tagged */
	seat = g_udev_device_get_property (udev_device, "ID_SEAT");
	if (seat == NULL)
		seat = "seat0";

	/* create new device */
	device = cd_device_new ();
	cd_device_set_id (device, id);
	cd_device_set_property_internal (device,
					 "Kind",
					 "scanner",
					 FALSE,
					 NULL);
	if (model != NULL) {
		cd_device_set_property_internal (device,
						 "Model",
						 model,
						 FALSE,
						 NULL);
	}
	if (vendor != NULL) {
		cd_device_set_property_internal (device,
						 "Vendor",
						 vendor,
						 FALSE,
						 NULL);
	}
	cd_device_set_property_internal (device,
					 "Colorspace",
					 "rgb",
					 FALSE,
					 NULL);
	cd_device_set_property_internal (device,
					 "Serial",
					 g_udev_device_get_sysfs_path (udev_device),
					 FALSE,
					 NULL);
	cd_device_set_property_internal (device,
					 "Seat",
					 seat,
					 FALSE,
					 NULL);

	/* keep track so we can remove with the same device */
	g_hash_table_insert (plugin->priv->devices,
			     g_strdup (g_udev_device_get_sysfs_path (udev_device)),
			     g_object_ref (device));

	g_debug ("CdPlugin: emit add: %s", id);
	cd_plugin_device_added (plugin, device);
}
示例#2
0
/**
 * cd_plugin_add:
 **/
static void
cd_plugin_add (CdPlugin *plugin, GUdevDevice *udev_device)
{
	const gchar *seat;
	g_autofree gchar *id = NULL;
	g_autofree gchar *model = NULL;
	g_autofree gchar *vendor = NULL;
	g_autoptr(CdDevice) device = NULL;

	/* is a proper camera and not a webcam */
	if (!g_udev_device_has_property (udev_device, "ID_GPHOTO2"))
		return;

	/* is a scanner? */
	if (!g_udev_device_has_property (udev_device, "COLORD_DEVICE"))
		return;

	/* replace underscores with spaces */
	model = g_strdup (g_udev_device_get_property (udev_device,
						      "ID_MODEL"));
	if (model != NULL) {
		g_strdelimit (model, "_\r\n", ' ');
		g_strchomp (model);
	}
	vendor = g_strdup (g_udev_device_get_property (udev_device,
						       "ID_VENDOR"));
	if (vendor != NULL) {
		g_strdelimit (vendor, "_\r\n", ' ');
		g_strchomp (vendor);
	}

	/* generate ID */
	id = cd_plugin_get_camera_id_for_udev_device (udev_device);

	/* assume device belongs to "seat0" if not tagged */
	seat = g_udev_device_get_property (udev_device, "ID_SEAT");
	if (seat == NULL)
		seat = "seat0";

	/* create new device */
	device = cd_device_new ();
	cd_device_set_id (device, id);
	cd_device_set_property_internal (device,
					 CD_DEVICE_PROPERTY_KIND,
					 cd_device_kind_to_string (CD_DEVICE_KIND_CAMERA),
					 FALSE,
					 NULL);
	if (model != NULL) {
		cd_device_set_property_internal (device,
						 CD_DEVICE_PROPERTY_MODEL,
						 model,
						 FALSE,
						 NULL);
	}
	if (vendor != NULL) {
		cd_device_set_property_internal (device,
						 CD_DEVICE_PROPERTY_VENDOR,
						 vendor,
						 FALSE,
						 NULL);
	}
	cd_device_set_property_internal (device,
					 CD_DEVICE_PROPERTY_COLORSPACE,
					 "rgb",
					 FALSE,
					 NULL);
	cd_device_set_property_internal (device,
					 CD_DEVICE_PROPERTY_SERIAL,
					 g_udev_device_get_sysfs_path (udev_device),
					 FALSE,
					 NULL);
	cd_device_set_property_internal (device,
					 CD_DEVICE_PROPERTY_SEAT,
					 seat,
					 FALSE,
					 NULL);
	if (cd_plugin_is_device_embedded (udev_device)) {
		cd_device_set_property_internal (device,
						 CD_DEVICE_PROPERTY_EMBEDDED,
						 NULL,
						 FALSE,
						 NULL);
	}

	/* keep track so we can remove with the same device */
	g_hash_table_insert (plugin->priv->devices,
			     g_strdup (g_udev_device_get_sysfs_path (udev_device)),
			     g_object_ref (device));

	g_debug ("CdPlugin: emit add: %s", id);
	cd_plugin_device_added (plugin, device);
}