/** * 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); }
/** * cd_sane_client_add: **/ static void cd_sane_client_add (CdMainPrivate *priv, const SANE_Device *sane_device) { gchar *id = NULL; gchar *model = NULL; gchar *vendor = NULL; CdMainDev *dev; GHashTable *properties = NULL; /* ignore noname, no support devices */ if (g_strcmp0 (sane_device->vendor, "Noname") == 0) { g_debug ("CdSaneClient: Ignoring sane device %s", sane_device->name); goto out; } /* convert device_id 'plustek:libusb:004:002' to suitable id */ id = cd_client_get_id_for_sane_device (sane_device); /* see if this device already exists */ dev = cd_main_dev_find_by_id (priv, id); if (dev != NULL) { dev->valid = TRUE; goto out; } /* Make human readable */ model = g_strdup (sane_device->model); g_strdelimit (model, "_", ' '); vendor = g_strdup (sane_device->vendor); g_strdelimit (vendor, "_", ' '); /* create initial device properties */ properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); g_hash_table_insert (properties, (gpointer) CD_DEVICE_PROPERTY_KIND, (gpointer) cd_device_kind_to_string (CD_DEVICE_KIND_SCANNER)); g_hash_table_insert (properties, (gpointer) CD_DEVICE_PROPERTY_MODE, (gpointer) cd_device_mode_to_string (CD_DEVICE_MODE_PHYSICAL)); g_hash_table_insert (properties, (gpointer) CD_DEVICE_PROPERTY_COLORSPACE, (gpointer) cd_colorspace_to_string (CD_COLORSPACE_RGB)); g_hash_table_insert (properties, (gpointer) CD_DEVICE_PROPERTY_VENDOR, (gpointer) vendor); g_hash_table_insert (properties, (gpointer) CD_DEVICE_PROPERTY_MODEL, (gpointer) model); g_hash_table_insert (properties, (gpointer) CD_DEVICE_PROPERTY_SERIAL, (gpointer) sane_device->name); #if 0 g_hash_table_insert (properties, (gpointer) CD_DEVICE_METADATA_OWNER_CMDLINE, (gpointer) priv->argv0); #endif cd_client_create_device (priv->client, id, CD_OBJECT_SCOPE_NORMAL, properties, NULL, cd_main_colord_create_device_cb, NULL); out: if (properties != NULL) g_hash_table_unref (properties); g_free (id); g_free (model); g_free (vendor); }