static void dummy_plugin_get_sensors(GList **sensors) {

    /* dummy HDD temp sensor */
    sensors_applet_plugin_add_sensor(sensors,
                                     "/sys/devices/platform/it87.656/hwmon/hwmon1/temp2_input",
                                     "temp2",
                                     "CPU",
                                     TEMP_SENSOR,
                                     TRUE,
                                     CPU_ICON,
                                     DEFAULT_GRAPH_COLOR);

    /* dummy HDD temp sensor */
    sensors_applet_plugin_add_sensor(sensors,
                                     "/sys/devices/platform/it87.656/hwmon/hwmon1/fan1_input",
                                     "fan1",
                                     "fan1",
                                     FAN_SENSOR,
                                     TRUE,
                                     FAN_ICON,
                                     DEFAULT_GRAPH_COLOR);

    /* dummy HDD temp sensor */
    sensors_applet_plugin_add_sensor(sensors,
                                     "HDD 2154884654-5648HG-546821",
                                     "Disk Temperature",
                                     "HDD 2154884654",
                                     TEMP_SENSOR,
                                     TRUE,
                                     HDD_ICON,
                                     DEFAULT_GRAPH_COLOR);

}
Ejemplo n.º 2
0
static void i2c_proc_plugin_add_sensor(GList **sensors, 
                                                  const gchar *path) {
	gchar *filename;
	gchar *label;
	gboolean enable;
	SensorType sensor_type;
	IconType icon_type = GENERIC_ICON;
	
	filename = g_path_get_basename(path);

	/* setup temp2 as CPU sensor and enable it */
	if (g_ascii_strcasecmp(filename, "temp2") == 0) {
		sensor_type = TEMP_SENSOR;
		label = g_strdup(_("CPU"));
		enable = TRUE;
		icon_type = CPU_ICON;
	} else {
		label = g_strdup(filename);
		
		switch(filename[0]) {
		case 'c':     /* currents are "curr?" */
			sensor_type = CURRENT_SENSOR;
			break;
		case 'f':     /* fans are "fan?" */
			sensor_type = FAN_SENSOR;
			icon_type = FAN_ICON;
			break;
		case 'i':     /* voltages are "in?" */
			sensor_type = VOLTAGE_SENSOR;
			break;
		case 't':     /* temps are "temp?" */
			sensor_type = TEMP_SENSOR;
			break;
		case 'v':     /* vids are just vid */
			sensor_type = VOLTAGE_SENSOR;
			break;
		default:
			/* SHOULDN'T BE ABLE
			 * TO GET HERE!! */
                        g_debug("error in i2c-proc sensor detection code - unhandled sensor filename %s", filename);
                        g_free(filename);
                        g_free(label);
                        return;
		}
		/* disable all other sensors */
		enable = FALSE;
	}
	sensors_applet_plugin_add_sensor(sensors,
                                         path,
                                         filename,
                                         label,
                                         sensor_type,
                                         enable,
                                         icon_type,
                                         DEFAULT_GRAPH_COLOR);


	g_free(filename);
	g_free(label);
}	
Ejemplo n.º 3
0
static void smu_sys_plugin_add_sensor(GList **sensors, const gchar *path) {
	gchar *filename;
	gchar *label = NULL;
	gboolean enable;
	SensorType sensor_type;
	IconType icon_type = GENERIC_ICON;

	filename = g_path_get_basename(path);

	if (g_ascii_strcasecmp(filename, SENSOR1 TEMPERATURE) == 0 || g_ascii_strcasecmp(filename, CPU TEMPERATURE) == 0) {
		label = g_strdup(_("CPU"));
		sensor_type = TEMP_SENSOR;
		enable = TRUE;
		icon_type = CPU_ICON;
	} else if (g_ascii_strcasecmp(filename, SENSOR2 TEMPERATURE) == 0 || g_ascii_strcasecmp(filename, GPU TEMPERATURE) == 0) {
		label = g_strdup(_("GPU"));
		sensor_type = TEMP_SENSOR;
		enable = TRUE;
		icon_type = GPU_ICON;
	} else if (g_ascii_strcasecmp(filename, SENSOR1 FAN_SPEED) == 0|| g_ascii_strcasecmp(filename, CPU FAN_SPEED) == 0) { 
		label = g_strdup(_("FAN"));
		sensor_type = FAN_SENSOR;
		enable = TRUE;
		icon_type = FAN_ICON;
	} else {
		/* disable all other sensors */
		enable = FALSE;
	}

	/* only add these 3 sensors */
	if (enable) {
		sensors_applet_plugin_add_sensor(sensors,
                                                 path,
                                                 filename,
                                                 label,
                                                 sensor_type,
                                                 enable,
                                                 icon_type,
                                                 DEFAULT_GRAPH_COLOR);
                
	}
	g_free(filename);
	if (label != NULL) {
		g_free(label);
	}
}	
GList *sonypi_plugin_init(void) {
        int fd;
        GList *sensors = NULL;
        
        if ( (fd = open(SONYPI_DEV, O_RDONLY)) != -1 ) {
                if ( close(fd) != -1 ) {
                        sensors_applet_plugin_add_sensor(&sensors,
                                                         SONYPI_DEV,
                                                         SONYPI_TEMP,
                                                         _("CPU TEMP"),
                                                         TEMP_SENSOR,
                                                         TRUE,
                                                         CPU_ICON,
                                                         DEFAULT_GRAPH_COLOR);
                }
        }
        return sensors;
}
static GList *aticonfig_plugin_init(void) 
{
  GList *sensors = NULL;

  g_debug("Initializing aticonfig plugin\n"); 

  int sensor_count = ati_get_temps(&gpu_temps, MAX_GPUS);
 
  int i;
  for (i = 0; i < sensor_count; i++) {
    gchar *id = g_strdup_printf("%s%d%s", SENSOR_ID_PREFIX, i, GPU_CORE_TEMP);
    sensors_applet_plugin_add_sensor(&sensors,
	GPU_CORE_TEMP,
	id,
	_("GPU"),
	TEMP_SENSOR,
	TRUE,
	GPU_ICON,
	DEFAULT_GRAPH_COLOR);
    g_free(id);
  }
  return sensors;
}
/* creates the connection to the X server and checks whether the
 * NV-CONTROL extension is loaded */
static GList *nvidia_plugin_init(void) {
    int dummy;
    int event_base, error_base;
    GList *sensors = NULL;

    /* create the connection to the X server */
    if (!(nvidia_sensors_dpy = XOpenDisplay(NULL))) {
        /* no connection to the X server avaible */
        return sensors;
    }

    /* check if the NV-CONTROL extension is available on this X
         * server - if so add the two sensors if they exist */
    if (XNVCTRLQueryExtension(nvidia_sensors_dpy, &event_base, &error_base)) {
        int i, cnt;

        if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy,
                        NV_CTRL_TARGET_TYPE_THERMAL_SENSOR,
                        &cnt)) {

            for (i = 0; i < cnt; i++) {
                gchar *id = g_strdup_printf("GPU%d%s", i, THERMAL_SENSOR_TEMP);

                sensors_applet_plugin_add_sensor(&sensors,
                                                 THERMAL_SENSOR_TEMP,
                                                 id,
                                                 _("GPU"),
                                                 TEMP_SENSOR,
                                                 TRUE,
                                                 GPU_ICON,
                                                 DEFAULT_GRAPH_COLOR);

                g_free(id);
            }
        }

        if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy,
                        NV_CTRL_TARGET_TYPE_COOLER,
                        &cnt)) {

            for (i = 0; i < cnt; i++) {
                gchar *id = g_strdup_printf("GPU%d%s", i, THERMAL_COOLER_LEVEL);

                sensors_applet_plugin_add_sensor(&sensors,
                                                 THERMAL_COOLER_LEVEL,
                                                 id,
                                                 _("GPU"),
                                                 FAN_SENSOR,
                                                 TRUE,
                                                 FAN_ICON,
                                                 DEFAULT_GRAPH_COLOR);

                g_free(id);
            }
        }

        if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy,
                        NV_CTRL_TARGET_TYPE_GPU,
                        &cnt)) {

            for (i = 0; i < cnt; i++) {
                if (XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy,
                                NV_CTRL_TARGET_TYPE_GPU,
                                i,
                                       0, NV_CTRL_GPU_CORE_TEMPERATURE, &dummy)) {

                    gchar *id = g_strdup_printf("GPU%d%s", i, GPU_CORE_TEMP);

                    sensors_applet_plugin_add_sensor(&sensors,
                                                     GPU_CORE_TEMP,
                                                     id,
                                                     _("GPU"),
                                                     TEMP_SENSOR,
                                                     TRUE,
                                                     GPU_ICON,
                                                     DEFAULT_GRAPH_COLOR);
                    g_free(id);
                }

                if (XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy,
                                NV_CTRL_TARGET_TYPE_GPU,
                                i,
                                       0, NV_CTRL_AMBIENT_TEMPERATURE, &dummy)) {
                    gchar *id = g_strdup_printf("GPU%d%s", i, AMBIENT_TEMP);

                    sensors_applet_plugin_add_sensor(&sensors,
                                                     AMBIENT_TEMP,
                                                     id,
                                                     _("Ambient"),
                                                     TEMP_SENSOR,
                                                     FALSE,
                                                     GENERIC_ICON,
                                                     DEFAULT_GRAPH_COLOR);
                    g_free(id);
                }
            }
        }

    }
    return sensors;
}
static void i2c_sys_plugin_add_sensor(GList **sensors, const gchar *path) {
    gchar *filename;
    gchar *id;
    gchar *label;
    gboolean enable;
    guint sensor_type;
    IconType icon_type = GENERIC_ICON;

    filename = g_path_get_basename(path);

    /* setup temp2 as CPU sensor and enable it */
    if (g_ascii_strcasecmp(filename, "temp2_input") == 0) {
        id = g_strndup(filename, 5);
        label = g_strdup(_("CPU"));
        sensor_type = TEMP_SENSOR;
        enable = TRUE;
        icon_type = CPU_ICON;
    } else {
        switch(filename[0]) {
            case 'c':    /* either current or cpu?_vid sensor */
                if (filename[1] == 'u') { /* currents are curr?_input */
                    id = g_strndup(filename, 5);
                    label = g_strndup(filename, 5);
                    sensor_type = CURRENT_SENSOR;
                } else { /* cpu_vid is cpu?_vid */
                    id = g_strdup(filename);
                    label = g_strdup(filename);
                    sensor_type = VOLTAGE_SENSOR;
                }
                break;

            case 'f':    /* fans are "fan?_input" */
                id = g_strndup(filename, 4);
                label = g_strndup(filename, 4);
                sensor_type = FAN_SENSOR;
                icon_type = FAN_ICON;
                break;

            case 't':    /* temps are "temp?_input" */
                id = g_strndup(filename, 5);
                label = g_strndup(filename, 5);
                sensor_type = TEMP_SENSOR;
                break;

            case 'i':    /* voltages are "in?_input" */
                id = g_strndup(filename, 3);
                label = g_strndup(filename, 3);
                sensor_type = VOLTAGE_SENSOR;
                break;

            default:
                /* SHOULDN'T BE ABLE * TO GET HERE!! */
                g_warning("filename:\"%s\" begins with a charater that is not covered by this switch statement... not adding sensor", filename);
                g_free(filename);
                g_free(id);
                g_free(label);

                return;
        }

        /* disable all other sensors */
        enable = FALSE;
    }

    sensors_applet_plugin_add_sensor(sensors,
                                         path,
                                         id,
                                         label,
                                         sensor_type,
                                         enable,
                                         icon_type,
                                         DEFAULT_GRAPH_COLOR);

    g_free(filename);
    g_free(id);
    g_free(label);
}
static void udisks_plugin_get_sensors(GList **sensors) {
	DBusGProxy *proxy, *sensor_proxy;
	GError *error = NULL;
	GPtrArray *paths;
	guint i;
	DevInfo *info;

	g_type_init();

	/* This connection will be used for everything, including the obtaining
	 * of sensor data
	 */
	connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
	if (connection == NULL)
	{
		g_debug("Failed to open connection to DBUS: %s",
							error->message);
		g_error_free(error);
		return;
	}

	/* This is the proxy which is only used once during the enumeration of
	 * the device object paths
	 */
	proxy = dbus_g_proxy_new_for_name(connection,
					  UDISKS_BUS_NAME,
					  UDISKS_OBJECT_PATH,
					  UDISKS_INTERFACE_NAME);

	/* The object paths of the disks are enumerated and placed in an array
	 * of object paths
	 */
	if (!dbus_g_proxy_call(proxy, "EnumerateDevices", &error,
			       G_TYPE_INVALID,
			       dbus_g_type_get_collection("GPtrArray",
							  DBUS_TYPE_G_OBJECT_PATH),
			       &paths,
			       G_TYPE_INVALID))
	{
		g_debug("Failed to enumerate disk devices: %s",
			   error->message);
		g_error_free(error);
		g_object_unref(proxy);
		dbus_g_connection_unref (connection);
		return;
	}

	for (i = 0; i < paths->len; i++) {
		/* This proxy is used to get the required data in order to build
		 * up the list of sensors
		 */
		GValue model = {0, }, id = {0, }, smart_available = {0, };
		gchar *path = (gchar *)g_ptr_array_index(paths, i);

		sensor_proxy = dbus_g_proxy_new_for_name(connection,
							 UDISKS_BUS_NAME,
							 path,
							 UDISKS_PROPERTIES_INTERFACE);

		if (dbus_g_proxy_call(sensor_proxy, "Get", &error,
				      G_TYPE_STRING,
				      UDISKS_BUS_NAME,
				      G_TYPE_STRING,
				      "DriveAtaSmartIsAvailable",
				      G_TYPE_INVALID,
				      G_TYPE_VALUE, &smart_available, G_TYPE_INVALID)) {
			gchar *id_str, *model_str;
			if (!g_value_get_boolean(&smart_available)) {
				g_debug("Drive at path '%s' does not support Smart monitoring... ignoring",
					path);
				g_object_unref(sensor_proxy);
				g_free (path);
				continue;
			}

			dbus_g_proxy_call(sensor_proxy, "Get", NULL,
					  G_TYPE_STRING, UDISKS_BUS_NAME,
					  G_TYPE_STRING, "DriveModel",
					  G_TYPE_INVALID,
					  G_TYPE_VALUE, &model,
					  G_TYPE_INVALID);

			dbus_g_proxy_call(sensor_proxy, "Get", NULL,
					  G_TYPE_STRING, UDISKS_BUS_NAME,
					  G_TYPE_STRING, "DeviceFile",
					  G_TYPE_INVALID,
					  G_TYPE_VALUE, &id,
					  G_TYPE_INVALID);

			g_object_unref(sensor_proxy);

			sensor_proxy = dbus_g_proxy_new_for_name(connection,
								 UDISKS_BUS_NAME,
								 path,
								 UDISKS_DEVICE_INTERFACE_NAME);

			/* Use the Changed() signal emitted from UDisks to
			 * get the temperature without always polling
			 */
			dbus_g_proxy_add_signal(sensor_proxy, "Changed",
						G_TYPE_INVALID);

			dbus_g_proxy_connect_signal(sensor_proxy, "Changed",
						    G_CALLBACK(udisks_changed_signal_cb),
						    path, NULL);

			info = g_malloc(sizeof(DevInfo));
			if (devices == NULL)
			{
				devices = g_hash_table_new(g_str_hash,
							   g_str_equal);
			}
			info->path = g_strdup(path);
			info->sensor_proxy = sensor_proxy;
			/* Set the device status changed as TRUE because we need
			 * to get the initial temperature reading
			 */
			info->changed = TRUE;
			g_hash_table_insert(devices, info->path, info);

			/* Write the sensor data */
			id_str = g_value_get_string(&id);
			model_str = g_value_get_string(&model);
			sensors_applet_plugin_add_sensor(sensors,
							 path,
							 id_str,
							 model_str,
							 TEMP_SENSOR,
							 FALSE,
							 HDD_ICON,
							 DEFAULT_GRAPH_COLOR);
			g_free(id_str);
			g_free(model_str);
		} else {
			g_debug ("Cannot obtain data for device: %s\n"
				    "Error: %s\n",
				    path,
				    error->message);
			g_error_free (error);
			error = NULL;
			g_object_unref(sensor_proxy);
		}
		g_free(path);
	}
	g_ptr_array_free(paths, TRUE);
	g_object_unref(proxy);
	if (devices == NULL)
		dbus_g_connection_unref (connection);
}