Exemplo n.º 1
0
static void
update_sensor_from_max(IsMaxPlugin *self)
{
  IsMaxPluginPrivate *priv;
  gchar *label;

  priv = self->priv;

  label = g_strdup_printf("↑%s", is_sensor_get_label(priv->max));
  is_sensor_set_label(priv->sensor, label);
  is_sensor_set_icon(priv->sensor, is_sensor_get_icon(priv->max));
  is_sensor_set_value(priv->sensor, is_sensor_get_value(priv->max));
  is_sensor_set_units(priv->sensor, is_sensor_get_units(priv->max));
  is_sensor_set_digits(priv->sensor, is_sensor_get_digits(priv->max));
  g_free(label);
}
Exemplo n.º 2
0
static void
on_sensor_disabled(IsManager *manager,
                   IsSensor *sensor,
                   gpointer data)
{
  IsMaxPlugin *self = (IsMaxPlugin *)data;
  IsMaxPluginPrivate *priv = self->priv;

  // don't bother monitoring non-temperature sensors
  if (IS_IS_TEMPERATURE_SENSOR(sensor))
  {
    is_debug("max", "sensor disabled: %s", is_sensor_get_label(sensor));
    g_signal_handlers_disconnect_by_func(sensor,
                                         G_CALLBACK(on_sensor_value_notify),
                                         self);
    if (priv->max == sensor)
    {
      // get all sensors and find the one with the maximum value and switch to
      // this
      GSList *sensors, *_list;

      priv->max = NULL;
      priv->max_value = 0.0;

      is_sensor_set_label(priv->sensor, "Δ");
      is_sensor_set_icon(priv->sensor, IS_STOCK_CHIP);
      is_sensor_set_value(priv->sensor, 0.0);
      is_sensor_set_units(priv->sensor, "");
      is_sensor_set_digits(priv->sensor, 1);

      sensors = is_manager_get_enabled_sensors_list(manager);
      for (_list = sensors;
           _list != NULL;
           _list = _list->next)
      {
        if (IS_IS_TEMPERATURE_SENSOR(_list->data))
        {
          on_sensor_value_notify(IS_SENSOR(_list->data),
                                 NULL,
                                 self);
        }
      }
    }
  }
}
Exemplo n.º 3
0
static void
is_fake_plugin_activate(PeasActivatable *activatable)
{
	IsFakePlugin *self = IS_FAKE_PLUGIN(activatable);
	IsFakePluginPrivate *priv = self->priv;
	int i;
	int n_fans = 0;

	/* generate some fake sensors */
	for (i = 0; i < 5; i++) {
		gchar *path;
		gchar *label;
		IsSensor *sensor;

		path = g_strdup_printf("fake/sensor%d", i);
		if (g_rand_boolean(priv->rand)) {
			n_fans++;
			sensor = is_fan_sensor_new(path);
			is_sensor_set_low_value(sensor, 100.0);
			is_sensor_set_high_value(sensor, 5000.0);
			label = g_strdup_printf(_("Fake Fan %d"),
						n_fans);

		} else {
			sensor = is_temperature_sensor_new(path);
			is_sensor_set_icon(sensor, IS_STOCK_CPU);
			label = g_strdup_printf(_("Fake CPU %d"),
						i - n_fans + 1);
		}
		/* no decimal places to display */
		is_sensor_set_digits(sensor, 0);
		is_sensor_set_label(sensor, label);
		/* connect to update-value signal */
		g_signal_connect(sensor, "update-value",
				 G_CALLBACK(update_sensor_value),
				 self);
		is_manager_add_sensor(is_application_get_manager(priv->application),
				      sensor);
		g_free(label);
		g_free(path);
	}
}
Exemplo n.º 4
0
static void
is_max_plugin_activate(PeasActivatable *activatable)
{
  IsMaxPlugin *self = IS_MAX_PLUGIN(activatable);
  IsMaxPluginPrivate *priv = self->priv;
  IsManager *manager;
  GSList *sensors, *_list;
  int i = 0;

  manager = is_application_get_manager(priv->application);

  // create our virtual sensor which mimics the current highest value sensor's
  // value and label
  is_debug("max", "creating virtual sensor");
  priv->sensor = is_sensor_new(MAX_SENSOR_PATH);
  is_sensor_set_label(priv->sensor, "Δ");
  is_sensor_set_icon(priv->sensor, IS_STOCK_CHIP);
  is_sensor_set_value(priv->sensor, 0.0);
  is_sensor_set_units(priv->sensor, "");
  is_sensor_set_digits(priv->sensor, 1);
  is_manager_add_sensor(manager, priv->sensor);

  is_debug("max", "attaching to signals");
  sensors = is_manager_get_enabled_sensors_list(manager);
  for (_list = sensors;
       _list != NULL;
       _list = _list->next)
  {
    IsSensor *sensor = IS_SENSOR(_list->data);
    on_sensor_enabled(manager, sensor, i, self);
    g_object_unref(sensor);
    i++;
  }
  g_slist_free(sensors);
  g_signal_connect(manager, "sensor-enabled",
                   G_CALLBACK(on_sensor_enabled), self);
  g_signal_connect(manager, "sensor-disabled",
                   G_CALLBACK(on_sensor_disabled), self);

}
Exemplo n.º 5
0
static void
is_udisks_plugin_activate(PeasActivatable *activatable)
{
	IsUdisksPlugin *self = IS_UDISKS_PLUGIN(activatable);
	IsUdisksPluginPrivate *priv = self->priv;
	GDBusProxy *proxy;
	GError *error = NULL;
	GVariant *container, *paths;
	GVariantIter iter;
	gchar *path;

	priv->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
	if (!priv->connection)
	{
		is_warning("udisks", "Failed to open connection to system dbus: %s",
			  error->message);
		g_error_free(error);
		goto out;
	}

	/* This is the proxy which is only used once during the enumeration of
	 * the device object paths
	 */
	proxy = g_dbus_proxy_new_sync(priv->connection,
				      G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
				      G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,

				      NULL,
				      UDISKS_BUS_NAME,
				      UDISKS_OBJECT_PATH,
				      UDISKS_INTERFACE_NAME,
				      NULL, &error);

	if (!proxy) {
		is_warning("udisks", "Error getting proxy to udisks on system bus: %s",
			  error->message);
		g_error_free(error);
		goto out;
	}

	/* The object paths of the disks are enumerated and placed in an array
	 * of object paths
	 */
	container = g_dbus_proxy_call_sync(proxy, "EnumerateDevices", NULL,
				       G_DBUS_CALL_FLAGS_NONE, -1, NULL,
				       &error);
	if (!container) {
		is_warning("udisks", "Failed to enumerate disk devices: %s",
			  error->message);
		g_error_free(error);
		g_object_unref(proxy);
		goto out;
	}

	paths = g_variant_get_child_value(container, 0);
	g_variant_unref(container);

	g_variant_iter_init(&iter, paths);
	while (g_variant_iter_loop(&iter, "o", &path)) {
		/* This proxy is used to get the required data in order to build
		 * up the list of sensors
		 */
		GDBusProxy *sensor_proxy;
		GVariant *model, *smart_available;
		IsSensor *sensor;
		gchar *name, *sensor_path;

		sensor_proxy = g_dbus_proxy_new_sync(priv->connection,
						     G_DBUS_PROXY_FLAGS_NONE,
						     NULL,
						     UDISKS_BUS_NAME,
						     path,
						     UDISKS_DEVICE_INTERFACE_NAME,
						     NULL,
						     &error);

		if (!sensor_proxy) {
			is_debug("udisks", "error getting sensor proxy for disk %s: %s",
				path, error->message);
			g_clear_error(&error);
			g_object_unref(sensor_proxy);
			continue;
		}

		smart_available = g_dbus_proxy_get_cached_property(sensor_proxy,
								   "DriveAtaSmartIsAvailable");
		if (!smart_available) {
			is_debug("udisks", "error getting smart status for disk %s",
				path);
			g_object_unref(sensor_proxy);
			continue;
		}
		if (!g_variant_get_boolean(smart_available)) {
			is_debug("udisks", "drive %s does not support SMART monitoring, ignoring...",
				path);
			g_variant_unref(smart_available);
			g_object_unref(sensor_proxy);
			continue;
		}

		g_variant_unref(smart_available);
		model = g_dbus_proxy_get_cached_property(sensor_proxy,
							 "DriveModel");
		if (!model) {
			is_debug("udisks", "error getting drive model for disk %s",
				path);
			g_clear_error(&error);
			g_object_unref(sensor_proxy);
			continue;
		}
		name = g_path_get_basename(path);
		sensor_path = g_strdup_printf("udisks/%s", name);
		sensor = is_temperature_sensor_new(sensor_path);
		is_sensor_set_label(sensor, g_variant_get_string(model, NULL));
		is_sensor_set_digits(sensor, 0);
		is_sensor_set_icon(sensor, IS_STOCK_DISK);
		/* only update every minute to avoid waking disk too much */
		is_sensor_set_update_interval(sensor, 60);
		g_signal_connect(sensor, "update-value",
				 G_CALLBACK(update_sensor_value), self);
		is_manager_add_sensor(is_application_get_manager(priv->application),
                                      sensor);

		g_free(sensor_path);
		g_free(name);
		g_object_unref(sensor);
		g_object_unref(sensor_proxy);
	}
	g_variant_unref(paths);
	g_object_unref(proxy);

out:
	return;
}
static void
is_nvidia_plugin_activate(PeasActivatable *activatable)
{
	IsNvidiaPlugin *self = IS_NVIDIA_PLUGIN(activatable);
	IsNvidiaPluginPrivate *priv = self->priv;
	Bool ret;
	int event_base, error_base;
	gint n;
	int i;

	/* search for sensors and add them to manager */
	if (!priv->inited) {
		is_warning("nvidia", "not inited, unable to find sensors");
		goto out;
	}

	is_debug("nvidia", "searching for sensors");

	/* check if the NV-CONTROL extension is available on this X
         * server */
	ret = XNVCTRLQueryExtension(priv->display, &event_base, &error_base);
	if (!ret) {
		goto out;
	}

	/* get number of GPUs, then for each GPU get any thermal_sensors and
	   coolers used by it */
	ret = XNVCTRLQueryTargetCount(priv->display,
				      NV_CTRL_TARGET_TYPE_GPU,
				      &n);
	if (!ret) {
		goto out;
	}

	for (i = 0; i < n; i++) {
		guint j;
		char *label = NULL;
		ret = XNVCTRLQueryTargetStringAttribute(priv->display,
							NV_CTRL_TARGET_TYPE_GPU,
							i,
							0,
							NV_CTRL_STRING_PRODUCT_NAME,
							&label);
		for (j = 0; j < G_N_ELEMENTS(map); j++) {
			int32_t *data;
			int len;
			int k;

			ret = XNVCTRLQueryTargetBinaryData(priv->display,
							   NV_CTRL_TARGET_TYPE_GPU,
							   i,
							   0,
							   map[j].gpu_attribute,
							   (unsigned char **)&data,
							   &len);
			if (!ret) {
				continue;
			}
			/* data[0] contains number of sensors, and each sensor
			   indice follows */
			for (k = 1; k <= data[0]; k++) {
				int idx = data[k];
				gint value;
				IsSensor *sensor;
				gchar *path;

				ret = XNVCTRLQueryTargetAttribute(priv->display,
								  map[j].target,
								  idx,
								  0,
								  map[j].attribute,
								  &value);
				if (!ret) {
					continue;
				}

				path = g_strdup_printf("nvidia/%s%d", map[j].description, idx);
				if (map[j].target == NV_CTRL_TARGET_TYPE_COOLER) {
					/* fan sensors are given as a percentage
					   from 0 to 100 */
					sensor = is_sensor_new(path);
					is_sensor_set_icon(sensor, IS_STOCK_FAN);
					is_sensor_set_units(sensor, "%");
					is_sensor_set_low_value(sensor, 0.0);
					is_sensor_set_high_value(sensor, 100.0);
				} else {
					sensor = is_temperature_sensor_new(path);
					is_sensor_set_icon(sensor, IS_STOCK_GPU);
				}
				/* no decimal places to display */
				is_sensor_set_digits(sensor, 0);
				is_sensor_set_label(sensor, label);
				/* connect to update-value signal */
				g_signal_connect(sensor, "update-value",
						 G_CALLBACK(update_sensor_value),
						 self);
				is_manager_add_sensor(is_application_get_manager(priv->application),
                                                      sensor);
				g_free(path);
			}
			free(data);
		}
		free(label);
	}

out:
	return;
}
static void
is_aticonfig_plugin_activate(PeasActivatable *activatable)
{
	IsATIConfigPlugin *self = IS_ATICONFIG_PLUGIN(activatable);
        IsManager *manager;
        gchar *output = NULL;
	GError *error = NULL;
	GRegex *regex = NULL;
	GMatchInfo *match = NULL;
	gboolean ret;

        manager = is_application_get_manager(self->priv->application);

	/* search for sensors and add them to manager */
	is_debug("aticonfig", "searching for sensors");

	/* call aticonfig with --list-adapters to get available adapters,
	 * then test if each can do temperature and fan speed - if so add
	 * appropriate sensors */
	ret = g_spawn_command_line_sync("aticonfig --list-adapters",
					&output, NULL, NULL, &error);
	if (!ret) {
		is_warning("aticonfig", "Error calling aticonfig to detect available sensors: %s",
			   error->message);
		g_error_free(error);
		goto out;
	}

	regex = g_regex_new("^.*([0-9]+)\\. ([0-9][0-9]:[0-9][0-9]\\.[0-9])\\s*(.*?)\\s*$",
			    G_REGEX_MULTILINE, 0, &error);
	if (!regex) {
		is_warning("aticonfig", "Error compiling regex to detect listed sensors: %s",
			   error->message);
		g_error_free(error);
		goto out;
	}

	ret = g_regex_match(regex, output, 0, &match);
	if (!ret) {
		is_warning("aticonfig", "No sensors found in aticonfig output: %s", output);
		goto out;
	}
	while (g_match_info_matches(match)) {
		gint i;
		gchar *idx, *pci, *name;
		gdouble value;
		gchar *path;
		IsSensor *sensor;

		idx = g_match_info_fetch(match, 1);
		pci = g_match_info_fetch(match, 2);
		name = g_match_info_fetch(match, 3);

		i = g_ascii_strtoull(idx, NULL, 10);
		/* we have an adapter - see if we can get its temperature and
		   fanspeed */
		ret = aticonfig_get_temperature(self, i, &value, &error);
		if (!ret) {
			is_warning("aticonfig", "Error getting temperature for adapter %d: %s",
				   i, error->message);
			g_clear_error(&error);
		} else {
			path = g_strdup_printf("%s%d%s", ATICONFIG_PATH_PREFIX, i, _("Temperature"));
			sensor = is_temperature_sensor_new(path);
			is_sensor_set_label(sensor, name);
			is_sensor_set_icon(sensor, IS_STOCK_GPU);
			g_signal_connect(sensor, "update-value",
					 G_CALLBACK(update_sensor_value),
					 self);
			is_manager_add_sensor(manager, sensor);
			g_object_unref(sensor);
			g_free(path);
		}

		ret = aticonfig_get_fanspeed(self, i, &value, &error);
		if (!ret) {
			is_warning("aticonfig", "Error getting fanpeed for adapter %d: %s",
				   i, error->message);
			g_clear_error(&error);
		} else {
			path = g_strdup_printf("%s%d%s", ATICONFIG_PATH_PREFIX, i, _("Fan"));
			sensor = is_sensor_new(path);
			is_sensor_set_label(sensor, name);
			/* fan sensors are given as a percentage from 0 to 100 */
			is_sensor_set_units(sensor, "%");
			is_sensor_set_low_value(sensor, 0.0);
			is_sensor_set_high_value(sensor, 100.0);
			is_sensor_set_digits(sensor, 0);
			is_sensor_set_icon(sensor, IS_STOCK_FAN);
			g_signal_connect(sensor, "update-value",
					 G_CALLBACK(update_sensor_value),
					 self);
			is_manager_add_sensor(manager, sensor);
			g_object_unref(sensor);
			g_free(path);
		}

		g_free(idx);
		g_free(pci);
		g_free(name);

		g_match_info_next(match, &error);
	}

out:
	g_match_info_free(match);
	if (regex) {
		g_regex_unref(regex);
	}
	g_free(output);
	return;
}