/**
 * iio_fixup_sampling_frequency: Fixup devices *sampling_frequency attributes
 * @dev: the IIO device to fix the sampling frequencies for
 *
 * Make sure devices with *sampling_frequency attributes are sampling at
 * 10Hz or more. This fixes 2 problems:
 * 1) Some buffered devices default their sampling_frequency to 0Hz and then
 * never produce any readings.
 * 2) Some polled devices default to 1Hz and wait for a fresh sample before
 * returning from sysfs *_raw reads, blocking all of iio-sensor-proxy for
 * multiple seconds
 **/
gboolean
iio_fixup_sampling_frequency (GUdevDevice *dev)
{
	GDir *dir;
	const char *device_dir;
	const char *name;
	GError *error = NULL;
	double sample_freq;

	device_dir = g_udev_device_get_sysfs_path (dev);
	dir = g_dir_open (g_udev_device_get_sysfs_path (dev), 0, &error);
	if (!dir) {
		g_warning ("Failed to open directory '%s': %s", device_dir, error->message);
		g_error_free (error);
		return FALSE;
	}

	while ((name = g_dir_read_name (dir))) {
		if (g_str_has_suffix (name, "sampling_frequency") == FALSE)
			continue;

		sample_freq = g_udev_device_get_sysfs_attr_as_double (dev, name);
		if (sample_freq >= IIO_MIN_SAMPLING_FREQUENCY)
			continue; /* Continue with pre-set sample freq. */

		/* Sample freq too low, set it to 10Hz */
		if (write_sysfs_int (name, device_dir, IIO_MIN_SAMPLING_FREQUENCY) < 0)
			g_warning ("Could not fix sample-freq for %s/%s", device_dir, name);
	}
	g_dir_close (dir);
	return TRUE;
}
static char *
get_trigger_name (GUdevDevice *device)
{
	GList *devices, *l;
	GUdevClient *client;
	gboolean has_trigger = FALSE;
	char *trigger_name;
	const gchar * const subsystems[] = { "iio", NULL };

	client = g_udev_client_new (subsystems);
	devices = g_udev_client_query_by_subsystem (client, "iio");

	/* Find the associated trigger */
	trigger_name = g_strdup_printf ("als-dev%s", g_udev_device_get_number (device));
	for (l = devices; l != NULL; l = l->next) {
		GUdevDevice *dev = l->data;

		if (g_strcmp0 (trigger_name, g_udev_device_get_sysfs_attr (dev, "name")) == 0) {
			g_debug ("Found associated trigger at %s", g_udev_device_get_sysfs_path (dev));
			has_trigger = TRUE;
			break;
		}
	}

	g_list_free_full (devices, g_object_unref);
	g_clear_object (&client);

	if (has_trigger)
		return trigger_name;

	g_warning ("Could not find trigger name associated with %s",
		   g_udev_device_get_sysfs_path (device));
	g_free (trigger_name);
	return NULL;
}
Exemple #3
0
static gboolean
dummy_loop_object_process_uevent (StoragedModuleObject  *module_object,
                                  const gchar           *action,
                                  StoragedLinuxDevice   *device)
{
  DummyLoopObject *object;
  GList *link;

  g_return_val_if_fail (DUMMY_IS_LOOP_OBJECT (module_object), FALSE);
  g_return_val_if_fail (device == NULL || STORAGED_IS_LINUX_DEVICE (device), FALSE);

  if (! dummy_loop_object_should_include_device (device))
    return FALSE;

  object = DUMMY_LOOP_OBJECT (module_object);

  link = NULL;
  if (device != NULL)
    link = find_link_for_sysfs_path (object, g_udev_device_get_sysfs_path (device->udev_device));
  if (g_strcmp0 (action, "remove") == 0)
    {
      if (link != NULL)
        {
          g_object_unref (STORAGED_LINUX_DEVICE (link->data));
          object->devices = g_list_delete_link (object->devices, link);
        }
      else
        {
          storaged_warning ("Object doesn't have device with sysfs path %s on remove event",
                            g_udev_device_get_sysfs_path (device->udev_device));
        }
    }
  else
    {
      if (link != NULL)
        {
          g_object_unref (STORAGED_LINUX_DEVICE (link->data));
          link->data = g_object_ref (device);
        }
      else
        {
          if (device != NULL)
            {
              object->devices = g_list_append (object->devices, g_object_ref (device));
              g_object_notify (G_OBJECT (object), "device");
            }
        }
    }

  update_iface (STORAGED_OBJECT (object), action, linux_loop_check, linux_loop_connect, linux_loop_update,
                DUMMY_TYPE_LINUX_LOOP, &object->iface_loop);

  return TRUE;
}
/**
 * enable_sensors: enable all the sensors in a device
 * @device_dir: the IIO device directory in sysfs
 * @
 **/
static gboolean
enable_sensors (GUdevDevice *dev,
                int          enable)
{
	GDir *dir;
	char *device_dir;
	const char *name;
	gboolean ret = FALSE;
	GError *error = NULL;

	device_dir = g_build_filename (g_udev_device_get_sysfs_path (dev), "scan_elements", NULL);
	dir = g_dir_open (device_dir, 0, &error);
	if (!dir) {
		g_warning ("Failed to open directory '%s': %s", device_dir, error->message);
		g_free (device_dir);
		g_error_free (error);
		return FALSE;
	}

	while ((name = g_dir_read_name (dir))) {
		char *path;

		if (g_str_has_suffix (name, "_en") == FALSE)
			continue;

		/* Already enabled? */
		path = g_strdup_printf ("scan_elements/%s", name);
		if (g_udev_device_get_sysfs_attr_as_boolean (dev, path)) {
			g_debug ("Already enabled sensor %s/%s", device_dir, name);
			ret = TRUE;
			g_free (path);
			continue;
		}
		g_free (path);

		/* Enable */
		if (write_sysfs_int (name, device_dir, enable) < 0) {
			g_warning ("Could not enable sensor %s/%s", device_dir, name);
			continue;
		}

		ret = TRUE;
		g_debug ("Enabled sensor %s/%s", device_dir, name);
	}
	g_dir_close (dir);
	g_free (device_dir);

	if (!ret) {
		g_warning ("Failed to enable any sensors for device '%s'",
			   g_udev_device_get_sysfs_path (dev));
	}

	return ret;
}
/**
 * udisks_linux_drive_object_uevent:
 * @object: A #UDisksLinuxDriveObject.
 * @action: Uevent action or %NULL
 * @device: A #UDisksLinuxDevice device object or %NULL if the device hasn't changed.
 *
 * Updates all information on interfaces on @drive.
 */
void
udisks_linux_drive_object_uevent (UDisksLinuxDriveObject *object,
                                  const gchar            *action,
                                  UDisksLinuxDevice      *device)
{
  GList *link;
  gboolean conf_changed;

  g_return_if_fail (UDISKS_IS_LINUX_DRIVE_OBJECT (object));
  g_return_if_fail (device == NULL || UDISKS_IS_LINUX_DEVICE (device));

  link = NULL;
  if (device != NULL)
    link = find_link_for_sysfs_path (object, g_udev_device_get_sysfs_path (device->udev_device));
  if (g_strcmp0 (action, "remove") == 0)
    {
      if (link != NULL)
        {
          g_object_unref (UDISKS_LINUX_DEVICE (link->data));
          object->devices = g_list_delete_link (object->devices, link);
        }
      else
        {
          udisks_warning ("Drive doesn't have device with sysfs path %s on remove event",
                          g_udev_device_get_sysfs_path (device->udev_device));
        }
    }
  else
    {
      if (link != NULL)
        {
          g_object_unref (UDISKS_LINUX_DEVICE (link->data));
          link->data = g_object_ref (device);
        }
      else
        {
          if (device != NULL)
            object->devices = g_list_append (object->devices, g_object_ref (device));
        }
    }

  conf_changed = FALSE;
  conf_changed |= update_iface (object, action, drive_check, drive_connect, drive_update,
                                UDISKS_TYPE_LINUX_DRIVE, &object->iface_drive);
  conf_changed |= update_iface (object, action, drive_ata_check, drive_ata_connect, drive_ata_update,
                                UDISKS_TYPE_LINUX_DRIVE_ATA, &object->iface_drive_ata);

  if (conf_changed)
    apply_configuration (object);
}
Exemple #6
0
static void
uevent_cb (GUdevClient *client, const char *action, GUdevDevice *device, RBRemovableMediaManager *mgr)
{
	RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (mgr);
	GUdevDeviceNumber devnum;
	devnum = g_udev_device_get_device_number (device);
	rb_debug ("%s event for %s (%x)", action, g_udev_device_get_sysfs_path (device), devnum);

	if (g_str_equal (action, "add")) {
		RBSource *source = NULL;

		/* probably need to filter out devices related to things we've already seen.. */
		if (g_hash_table_lookup (priv->device_mapping, GINT_TO_POINTER (devnum)) != NULL) {
			rb_debug ("already have a source for this device");
			return;
		}

		g_signal_emit (mgr, rb_removable_media_manager_signals[CREATE_SOURCE_DEVICE], 0, device, &source);
		if (source != NULL) {
			rb_debug ("created a source for this device");
			g_hash_table_insert (priv->device_mapping, GINT_TO_POINTER (devnum), source);
			rb_removable_media_manager_append_media_source (mgr, source);
		}
	} else if (g_str_equal (action, "remove")) {
		RBSource *source;

		source = g_hash_table_lookup (priv->device_mapping, GINT_TO_POINTER (devnum));
		if (source) {
			rb_debug ("removing the source created for this device");
			rb_source_delete_thyself (source);
		}
	}
}
static GSource *
watch_attr (UDisksLinuxDevice *device,
            const gchar       *attr,
            GSourceFunc        callback,
            gpointer           user_data)
{
  GError *error = NULL;
  gchar *path = NULL;
  GIOChannel *channel = NULL;
  GSource *ret = NULL;;

  g_return_val_if_fail (UDISKS_IS_LINUX_DEVICE (device), NULL);

  path = g_strdup_printf ("%s/%s", g_udev_device_get_sysfs_path (device->udev_device), attr);
  channel = g_io_channel_new_file (path, "r", &error);
  if (channel != NULL)
    {
      ret = g_io_create_watch (channel, G_IO_ERR);
      g_source_set_callback (ret, callback, user_data, NULL);
      g_source_attach (ret, g_main_context_get_thread_default ());
      g_source_unref (ret);
      g_io_channel_unref (channel); /* the keeps a reference to this object */
    }
  else
    {
      udisks_warning ("Error creating watch for file %s: %s (%s, %d)",
                      path, error->message, g_quark_to_string (error->domain), error->code);
      g_clear_error (&error);
    }
  g_free (path);

  return ret;
}
static gboolean
udev_uevent_cb (GUdevClient *udev,
		const gchar *action,
		GUdevDevice *device,
		gpointer     user_data)
{
	FuPlugin *plugin = FU_PLUGIN(user_data);

	if (action == NULL)
		return TRUE;

	g_debug ("uevent for %s: %s", g_udev_device_get_sysfs_path (device), action);

	/* intel-wmi-thunderbolt has been loaded/unloaded */
	if (g_str_equal (action, "change")) {
		fu_plugin_thunderbolt_power_get_path (plugin);
		if (fu_plugin_thunderbolt_power_supported (plugin)) {
			fu_plugin_set_enabled (plugin, TRUE);
			fu_plugin_request_recoldplug (plugin);
		} else {
			fu_plugin_set_enabled (plugin, FALSE);
		}
	}

	return TRUE;
}
static gboolean
disk_is_partitioned_by_kernel (GUdevDevice *device)
{
    gboolean ret = FALSE;
    GDir *dir = NULL;
    const gchar *name;
    const gchar *device_name;

    g_return_val_if_fail (g_strcmp0 (g_udev_device_get_devtype (device), "disk") == 0, FALSE);

    dir = g_dir_open (g_udev_device_get_sysfs_path (device), 0 /* flags */, NULL /* GError */);
    if (dir == NULL)
        goto out;

    device_name = g_udev_device_get_name (device);
    while ((name = g_dir_read_name (dir)) != NULL)
    {
        /* TODO: could check that it's a block device - for now, just
         * checking the name suffices
         */
        if (g_str_has_prefix (name, device_name))
        {
            ret = TRUE;
            goto out;
        }
    }

out:
    if (dir != NULL)
        g_dir_close (dir);
    return ret;
}
Exemple #10
0
static void
udev_device_added (SettingsPluginIfupdown *self, GUdevDevice *device)
{
	SettingsPluginIfupdownPrivate *priv = SETTINGS_PLUGIN_IFUPDOWN_GET_PRIVATE (self);
	const char *iface, *path;
	NMIfupdownConnection *exported;

	iface = g_udev_device_get_name (device);
	path = g_udev_device_get_sysfs_path (device);
	if (!iface || !path)
		return;

	nm_log_info (LOGD_SETTINGS, "devices added (path: %s, iface: %s)", path, iface);

	/* if we have a configured connection for this particular iface
	 * we want to either unmanage the device or lock it
	 */
	exported = g_hash_table_lookup (priv->connections, iface);
	if (!exported && !g_hash_table_lookup (priv->eni_ifaces, iface)) {
		nm_log_info (LOGD_SETTINGS, "device added (path: %s, iface: %s): no ifupdown configuration found.",
		             path, iface);
		return;
	}

	g_hash_table_insert (priv->kernel_ifaces, g_strdup (iface), g_object_ref (device));

	if (exported)
		bind_device_to_connection (self, device, exported);

	if (ALWAYS_UNMANAGE || priv->unmanage_well_known)
		g_signal_emit_by_name (G_OBJECT (self), NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED);
}
Exemple #11
0
/**
 * cd_plugin_uevent_cb:
 **/
static void
cd_plugin_uevent_cb (GUdevClient *udev_client,
		     const gchar *action,
		     GUdevDevice *udev_device,
		     CdPlugin *plugin)
{
	const gchar *sysfs_path;
	CdDevice *device;

	/* remove */
	if (g_strcmp0 (action, "remove") == 0) {

		/* is this a scanner device we added */
		sysfs_path = g_udev_device_get_sysfs_path (udev_device);
		device = g_hash_table_lookup (plugin->priv->devices, sysfs_path);
		if (device == NULL)
			return;

		g_debug ("CdPlugin: remove %s", sysfs_path);
		cd_plugin_device_removed (plugin, device);
		g_hash_table_remove (plugin->priv->devices, sysfs_path);
		return;
	}

	/* add */
	if (g_strcmp0 (action, "add") == 0) {
		cd_plugin_add (plugin, udev_device);
		return;
	}
}
Exemple #12
0
/**
 * cd_sensor_client_add:
 **/
static gboolean
cd_sensor_client_add (CdSensorClient *sensor_client,
		      GUdevDevice *device)
{
	CdSensor *sensor = NULL;
	const gchar *device_file;
	const gchar *tmp;
	gboolean ret = FALSE;
	GError *error = NULL;

	/* interesting device? */
	tmp = g_udev_device_get_property (device, "COLORD_SENSOR_KIND");
	if (tmp == NULL)
		goto out;
	tmp = g_udev_device_get_property (device, "COLORD_IGNORE");
	if (tmp != NULL)
		goto out;

	/* actual device? */
	device_file = g_udev_device_get_device_file (device);
	if (device_file == NULL)
		goto out;

	/* get data */
	g_debug ("adding color management device: %s [%s]",
		 g_udev_device_get_sysfs_path (device),
		 device_file);
	sensor = cd_sensor_new ();
	ret = cd_sensor_set_from_device (sensor, device, &error);
	if (!ret) {
		g_warning ("CdSensorClient: failed to set CM sensor: %s",
			   error->message);
		g_error_free (error);
		goto out;
	}

	/* set the index */
	cd_sensor_set_index (sensor, sensor_client->priv->idx);

	/* load the sensor */
	ret = cd_sensor_load (sensor, &error);
	if (!ret) {
		/* not fatal, non-native devices are still useable */
		g_debug ("CdSensorClient: failed to load native sensor: %s",
			 error->message);
		g_clear_error (&error);
	}

	/* signal the addition */
	g_debug ("emit: added");
	g_signal_emit (sensor_client, signals[SIGNAL_SENSOR_ADDED], 0, sensor);
	sensor_client->priv->idx++;

	/* keep track so we can remove with the same device */
	g_ptr_array_add (sensor_client->priv->array_sensors, g_object_ref (sensor));
out:
	if (sensor != NULL)
		g_object_unref (sensor);
	return ret;
}
/**
 * storaged_linux_block_object_trigger_uevent:
 * @object: A #StoragedLinuxBlockObject.
 *
 * Triggers a 'change' uevent in the kernel.
 *
 * The triggered event will bubble up from the kernel through the udev
 * stack and will eventually be received by the storaged daemon process
 * itself. This method does not wait for the event to be received.
 */
void
storaged_linux_block_object_trigger_uevent (StoragedLinuxBlockObject *object)
{
    gchar* path = NULL;
    gint fd = -1;

    g_return_if_fail (STORAGED_IS_LINUX_BLOCK_OBJECT (object));

    /* TODO: would be nice with a variant to wait until the request uevent has been received by ourselves */

    path = g_strconcat (g_udev_device_get_sysfs_path (object->device->udev_device), "/uevent", NULL);
    fd = open (path, O_WRONLY);
    if (fd < 0)
    {
        storaged_warning ("Error opening %s: %m", path);
        goto out;
    }

    if (write (fd, "change", sizeof "change" - 1) != sizeof "change" - 1)
    {
        storaged_warning ("Error writing 'change' to file %s: %m", path);
        goto out;
    }

out:
    if (fd >= 0)
        close (fd);
    g_free (path);
}
Exemple #14
0
/**
 * fu_provider_udev_get_id:
 **/
static gchar *
fu_provider_udev_get_id (GUdevDevice *device)
{
	gchar *id;
	id = g_strdup_printf ("ro-%s", g_udev_device_get_sysfs_path (device));
	g_strdelimit (id, "/:.-", '_');
	return id;
}
Exemple #15
0
static gboolean
hwmon_light_discover (GUdevDevice *device)
{
	if (g_strcmp0 (g_udev_device_get_property (device, "IIO_SENSOR_PROXY_TYPE"), "hwmon-als") != 0)
		return FALSE;

	g_debug ("Found HWMon light at %s", g_udev_device_get_sysfs_path (device));
	return TRUE;
}
Exemple #16
0
/**
 * cd_sensor_get_device_path:
 **/
const gchar *
cd_sensor_get_device_path (CdSensor *sensor)
{
#ifdef HAVE_GUDEV
	return g_udev_device_get_sysfs_path (sensor->priv->device);
#else
	return NULL;
#endif
}
static gboolean
iio_buffer_light_discover (GUdevDevice *device)
{
	if (g_strcmp0 (g_udev_device_get_property (device, "IIO_SENSOR_PROXY_TYPE"), "iio-buffer-als") != 0)
		return FALSE;

	g_debug ("Found IIO buffer ALS at %s", g_udev_device_get_sysfs_path (device));
	return TRUE;
}
Exemple #18
0
static void
device_removed (MMBaseManager *self,
                GUdevDevice *udev_device)
{
    MMDevice *device;
    const gchar *subsys;
    const gchar *name;

    g_return_if_fail (udev_device != NULL);

    subsys = g_udev_device_get_subsystem (udev_device);
    name = g_udev_device_get_name (udev_device);

    if (!g_str_has_prefix (subsys, "usb") ||
        (name && g_str_has_prefix (name, "cdc-wdm"))) {
        /* Handle tty/net/wdm port removal */
        device = find_device_by_port (self, udev_device);
        if (device) {
            mm_info ("(%s/%s): released by modem %s",
                     subsys,
                     name,
                     g_udev_device_get_sysfs_path (mm_device_peek_udev_device (device)));
            mm_device_release_port (device, udev_device);

            /* If port probe list gets empty, remove the device object iself */
            if (!mm_device_peek_port_probe_list (device)) {
                mm_dbg ("Removing empty device '%s'", mm_device_get_path (device));
                if (mm_plugin_manager_device_support_check_cancel (self->priv->plugin_manager, device))
                    mm_dbg ("Device support check has been cancelled");
                mm_device_remove_modem (device);
                g_hash_table_remove (self->priv->devices, mm_device_get_path (device));
            }
        }

        return;
    }

    /* This case is designed to handle the case where, at least with kernel 2.6.31, unplugging
     * an in-use ttyACMx device results in udev generating remove events for the usb, but the
     * ttyACMx device (subsystem tty) is not removed, since it was in-use.  So if we have not
     * found a modem for the port (above), we're going to look here to see if we have a modem
     * associated with the newly removed device.  If so, we'll remove the modem, since the
     * device has been removed.  That way, if the device is reinserted later, we'll go through
     * the process of exporting it.
     */
    device = find_device_by_udev_device (self, udev_device);
    if (device) {
        mm_dbg ("Removing device '%s'", mm_device_get_path (device));
        mm_device_remove_modem (device);
        g_hash_table_remove (self->priv->devices, mm_device_get_path (device));
        return;
    }

    /* Maybe a plugin is checking whether or not the port is supported.
     * TODO: Cancel every possible supports check in this port. */
}
Exemple #19
0
/**
 * cd_sensor_get_device_path:
 **/
const gchar *
cd_sensor_get_device_path (CdSensor *sensor)
{
#ifdef HAVE_UDEV
	CdSensorPrivate *priv = GET_PRIVATE (sensor);
	return g_udev_device_get_sysfs_path (priv->device);
#else
	return NULL;
#endif
}
Exemple #20
0
static void
uevent_received (GUdevClient *client,
		 gchar       *action,
		 GUdevDevice *device,
		 gpointer     user_data)
{
	if (g_strcmp0 (action, "change") != 0)
		return;

	if (g_strcmp0 (g_udev_device_get_sysfs_path (device), g_udev_device_get_sysfs_path (drv_data->parent)) != 0)
		return;

	if (!drv_data->sends_kevent) {
		drv_data->sends_kevent = TRUE;
		g_debug ("Received kevent, let's stop polling for accelerometer data on %s", drv_data->dev_path);
		input_accel_set_polling (FALSE);
	}

	accelerometer_changed ();
}
static gboolean
iio_buffer_light_discover (GUdevDevice *device)
{
	if (g_strcmp0 (g_udev_device_get_subsystem (device), "iio") != 0)
		return FALSE;

	if (g_strcmp0 ("als", g_udev_device_get_sysfs_attr (device, "name")) != 0)
		return FALSE;

	g_debug ("Found als at %s", g_udev_device_get_sysfs_path (device));
	return TRUE;
}
static gboolean
iio_poll_accel_discover (GUdevDevice *device)
{
    if (g_strcmp0 (g_udev_device_get_subsystem (device), "iio") != 0)
        return FALSE;

    if (g_strcmp0 ("i2c-SMO8500:00", g_udev_device_get_sysfs_attr (device, "name")) != 0)
        return FALSE;

    g_debug ("Found polling accelerometer at %s", g_udev_device_get_sysfs_path (device));
    return TRUE;
}
Exemple #23
0
static void
gudev_uevent_callback(G_GNUC_UNUSED GUdevClient *client,
		      gchar *action,
		      GUdevDevice *device,
		      gpointer user_data)
{
  g_debug("%s: received uevent %s for device %s", G_STRFUNC, action, g_udev_device_get_sysfs_path(device));

  SynceDevice *self = SYNCE_DEVICE (user_data);
  SynceDevicePrivate *priv = SYNCE_DEVICE_GET_PRIVATE (self);
  g_return_if_fail(priv->inited && !(priv->dispose_has_run));

  if ((g_str_has_suffix(g_udev_device_get_sysfs_path(device), priv->device_path) == FALSE) || (strcmp("remove", action) != 0)) 
    return;

  g_debug("%s: received uevent remove for our device", G_STRFUNC);

  synce_device_dbus_uninit(self);
  g_signal_emit(self, SYNCE_DEVICE_GET_CLASS(SYNCE_DEVICE(self))->signals[SYNCE_DEVICE_SIGNAL_DISCONNECTED], 0);

  return;
}
static gboolean
hwmon_light_discover (GUdevDevice *device)
{
	char *light_path;

	if (g_strcmp0 (g_udev_device_get_subsystem (device), "platform") != 0)
		return FALSE;

	if (g_strcmp0 (g_udev_device_get_property (device, "MODALIAS"), "platform:applesmc") != 0)
		return FALSE;

	light_path = g_build_filename (g_udev_device_get_sysfs_path (device),
				       "light", NULL);
	if (!g_file_test (light_path, G_FILE_TEST_EXISTS)) {
		g_free (light_path);
		return FALSE;
	}
	g_free (light_path);

	g_debug ("Found HWMon light at %s", g_udev_device_get_sysfs_path (device));
	return TRUE;
}
Exemple #25
0
static gboolean
hwmon_light_open (GUdevDevice        *device,
		 ReadingsUpdateFunc  callback_func,
		 gpointer            user_data)
{
	drv_data = g_new0 (DrvData, 1);
	drv_data->callback_func = callback_func;
	drv_data->user_data = user_data;

	drv_data->light_path = g_build_filename (g_udev_device_get_sysfs_path (device),
						 "light", NULL);

	return TRUE;
}
Exemple #26
0
/**
 * cd_sensor_client_uevent_cb:
 **/
static void
cd_sensor_client_uevent_cb (GUdevClient *gudev_client,
			    const gchar *action,
			    GUdevDevice *udev_device,
			    CdSensorClient *sensor_client)
{
	gboolean ret;

	/* remove */
	if (g_strcmp0 (action, "remove") == 0) {
		g_debug ("CdSensorClient: remove %s",
			 g_udev_device_get_sysfs_path (udev_device));
		ret = g_udev_device_has_property (udev_device, "COLORD_SENSOR_KIND");
		if (ret) {
			cd_sensor_client_remove (sensor_client,
						 udev_device);
			goto out;
		}
		goto out;
	}

	/* add */
	if (g_strcmp0 (action, "add") == 0) {
		g_debug ("CdSensorClient: add %s",
			 g_udev_device_get_sysfs_path (udev_device));
		ret = g_udev_device_has_property (udev_device, "COLORD_SENSOR_KIND");
		if (ret) {
			cd_sensor_client_add (sensor_client,
					      udev_device);
			goto out;
		}
		goto out;
	}
out:
	return;
}
static void
gs_plugin_modalias_uevent_cb (GUdevClient *client,
			      const gchar *action,
			      GUdevDevice *device,
			      GsPlugin *plugin)
{
	GsPluginData *priv = gs_plugin_get_data (plugin);
	if (g_strcmp0 (action, "add") == 0 ||
	    g_strcmp0 (action, "remove") == 0) {
		g_debug ("invalidating devices as '%s' sent action '%s'",
			 g_udev_device_get_sysfs_path (device),
			 action);
		g_ptr_array_set_size (priv->devices, 0);
	}
}
Exemple #28
0
static void
device_removed (MMManager *manager,
                GUdevDevice *device)
{
    MMBaseModem *modem;
    const char *subsys, *name;

    g_return_if_fail (device != NULL);

    subsys = g_udev_device_get_subsystem (device);
    name = g_udev_device_get_name (device);

    /* Ensure cached port probe infos get removed when the port is gone */
    mm_port_probe_cache_remove (device);

    if (strcmp (subsys, "usb") != 0) {
        /* find_modem_for_port handles tty and net removal */
        modem = find_modem_for_port (manager, subsys, name);
        if (modem) {
            mm_info ("(%s/%s): released by modem %s",
                     subsys,
                     name,
                     mm_base_modem_get_device (modem));
            mm_base_modem_release_port (modem, subsys, name);
            return;
        }
    } else {
        /* This case is designed to handle the case where, at least with kernel 2.6.31, unplugging
         * an in-use ttyACMx device results in udev generating remove events for the usb, but the
         * ttyACMx device (subsystem tty) is not removed, since it was in-use.  So if we have not
         * found a modem for the port (above), we're going to look here to see if we have a modem
         * associated with the newly removed device.  If so, we'll remove the modem, since the
         * device has been removed.  That way, if the device is reinserted later, we'll go through
         * the process of exporting it.
         */
        const char *sysfs_path = g_udev_device_get_sysfs_path (device);

        modem = find_modem_for_device (manager, sysfs_path);
        if (modem) {
            mm_dbg ("Removing modem claimed by removed device %s", sysfs_path);
            remove_modem (manager, modem);
            return;
        }
    }

    /* Maybe a plugin is checking whether or not the port is supported.
     * TODO: Cancel every possible supports check in this port. */
}
Exemple #29
0
static void
find_port_support_ready_cb (MMPluginManager *plugin_manager,
                            GAsyncResult *result,
                            FindPortSupportContext *ctx)
{
    GError *error = NULL;
    MMPlugin *best_plugin;

    best_plugin = mm_plugin_manager_find_port_support_finish (plugin_manager,
                                                              result,
                                                              &error);
    if (!best_plugin) {
        MMBaseModem *existing;

        if (error) {
            mm_dbg ("(%s/%s): error checking support: '%s'",
                    g_udev_device_get_subsystem (ctx->device),
                    g_udev_device_get_name (ctx->device),
                    error->message);
            g_error_free (error);
        } else {
            mm_dbg ("(%s/%s): not supported by any plugin",
                    g_udev_device_get_subsystem (ctx->device),
                    g_udev_device_get_name (ctx->device));
        }

        /* So we couldn't get a plugin for this port, we should anyway check if
         * there is already an existing modem for the physical device, and if
         * so, check if it can already be exported. */
        existing = find_modem_for_device (
            ctx->manager,
            g_udev_device_get_sysfs_path (ctx->physical_device));
        if (existing)
            check_export_modem (ctx->manager, existing);
    } else {
        mm_dbg ("(%s/%s): found plugin '%s' giving best support",
                g_udev_device_get_subsystem (ctx->device),
                g_udev_device_get_name (ctx->device),
                mm_plugin_get_name ((MMPlugin *)best_plugin));

        grab_port (ctx->manager,
                   best_plugin,
                   ctx->device,
                   ctx->physical_device);
    }

    find_port_support_context_free (ctx);
}
static gboolean
fake_compass_discover (GUdevDevice *device)
{
	if (g_getenv ("FAKE_COMPASS") == NULL)
		return FALSE;

	if (g_strcmp0 (g_udev_device_get_subsystem (device), "input") != 0)
		return FALSE;

	/* "Lid switch" is a random input device to latch onto */
	if (g_strcmp0 (g_udev_device_get_property (device, "NAME"), "\"Lid Switch\"") != 0)
		return FALSE;

	g_debug ("Found fake compass at %s", g_udev_device_get_sysfs_path (device));
	return TRUE;
}