Home | History | Annotate | Line # | Download | only in sysmon
sysmon_envsys_tables.c revision 1.10.8.1
      1  1.10.8.1       riz /* $NetBSD: sysmon_envsys_tables.c,v 1.10.8.1 2012/10/17 21:21:43 riz Exp $ */
      2       1.1   xtraeme 
      3       1.1   xtraeme /*-
      4       1.2   xtraeme  * Copyright (c) 2007 Juan Romero Pardines.
      5       1.1   xtraeme  * All rights reserved.
      6       1.1   xtraeme  *
      7       1.1   xtraeme  * Redistribution and use in source and binary forms, with or without
      8       1.1   xtraeme  * modification, are permitted provided that the following conditions
      9       1.1   xtraeme  * are met:
     10       1.1   xtraeme  * 1. Redistributions of source code must retain the above copyright
     11       1.1   xtraeme  *    notice, this list of conditions and the following disclaimer.
     12       1.1   xtraeme  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   xtraeme  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   xtraeme  *    documentation and/or other materials provided with the distribution.
     15       1.1   xtraeme  *
     16       1.2   xtraeme  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.2   xtraeme  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18       1.2   xtraeme  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19       1.2   xtraeme  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20       1.2   xtraeme  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21       1.2   xtraeme  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22       1.2   xtraeme  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23       1.2   xtraeme  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24       1.2   xtraeme  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25       1.2   xtraeme  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26       1.1   xtraeme  */
     27       1.1   xtraeme 
     28       1.1   xtraeme #include <sys/cdefs.h>
     29  1.10.8.1       riz __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.10.8.1 2012/10/17 21:21:43 riz Exp $");
     30       1.1   xtraeme 
     31       1.1   xtraeme #include <sys/types.h>
     32       1.1   xtraeme 
     33       1.1   xtraeme #include <dev/sysmon/sysmonvar.h>
     34       1.1   xtraeme #include <dev/sysmon/sysmon_envsysvar.h>
     35       1.1   xtraeme 
     36       1.1   xtraeme /*
     37       1.1   xtraeme  * Available units type descriptions.
     38       1.1   xtraeme  */
     39       1.6  pgoyette static const struct sme_descr_entry sme_units_description[] = {
     40       1.1   xtraeme 	{ ENVSYS_STEMP,		PENVSYS_TYPE_TEMP,	"Temperature" },
     41       1.1   xtraeme 	{ ENVSYS_SFANRPM,	PENVSYS_TYPE_FAN,	"Fan" },
     42       1.1   xtraeme 	{ ENVSYS_SVOLTS_AC,	PENVSYS_TYPE_VOLTAGE,	"Voltage AC" },
     43       1.1   xtraeme 	{ ENVSYS_SVOLTS_DC,	PENVSYS_TYPE_VOLTAGE,	"Voltage DC" },
     44       1.1   xtraeme 	{ ENVSYS_SOHMS,		PENVSYS_TYPE_RESISTANCE,"Ohms" },
     45       1.1   xtraeme 	{ ENVSYS_SWATTS,	PENVSYS_TYPE_POWER,	"Watts" },
     46       1.1   xtraeme 	{ ENVSYS_SAMPS,		PENVSYS_TYPE_POWER,	"Ampere" },
     47       1.1   xtraeme 	{ ENVSYS_SWATTHOUR,	PENVSYS_TYPE_BATTERY,	"Watt hour" },
     48       1.1   xtraeme 	{ ENVSYS_SAMPHOUR,	PENVSYS_TYPE_BATTERY,	"Ampere hour" },
     49       1.1   xtraeme 	{ ENVSYS_INDICATOR,	PENVSYS_TYPE_INDICATOR,	"Indicator" },
     50       1.1   xtraeme 	{ ENVSYS_INTEGER,	PENVSYS_TYPE_INDICATOR,	"Integer" },
     51       1.1   xtraeme 	{ ENVSYS_DRIVE,		PENVSYS_TYPE_DRIVE,	"Drive" },
     52       1.3   xtraeme 	{ ENVSYS_BATTERY_CAPACITY, PENVSYS_TYPE_BATTERY,"Battery capacity" },
     53       1.3   xtraeme 	{ ENVSYS_BATTERY_CHARGE, -1,			"Battery charge" },
     54       1.1   xtraeme 	{ -1,			-1,			"unknown" }
     55       1.1   xtraeme };
     56       1.1   xtraeme 
     57       1.1   xtraeme /*
     58       1.1   xtraeme  * Available sensor state descriptions.
     59       1.1   xtraeme  */
     60       1.6  pgoyette static const struct sme_descr_entry sme_state_description[] = {
     61       1.1   xtraeme 	{ ENVSYS_SVALID,	-1, 	"valid" },
     62       1.1   xtraeme 	{ ENVSYS_SINVALID,	-1, 	"invalid" },
     63       1.1   xtraeme 	{ ENVSYS_SCRITICAL,	-1, 	"critical" },
     64       1.1   xtraeme 	{ ENVSYS_SCRITUNDER,	-1, 	"critical-under" },
     65       1.1   xtraeme 	{ ENVSYS_SCRITOVER,	-1, 	"critical-over" },
     66       1.1   xtraeme 	{ ENVSYS_SWARNUNDER,	-1, 	"warning-under" },
     67       1.1   xtraeme 	{ ENVSYS_SWARNOVER,	-1, 	"warning-over" },
     68       1.1   xtraeme 	{ -1,			-1, 	"unknown" }
     69       1.1   xtraeme };
     70       1.1   xtraeme 
     71       1.1   xtraeme /*
     72       1.1   xtraeme  * Available drive state descriptions.
     73       1.1   xtraeme  */
     74       1.6  pgoyette static const struct sme_descr_entry sme_drivestate_description[] = {
     75       1.4   xtraeme 	{ ENVSYS_DRIVE_EMPTY,		-1, 	"unknown" },
     76       1.4   xtraeme 	{ ENVSYS_DRIVE_READY,		-1, 	"ready" },
     77       1.4   xtraeme 	{ ENVSYS_DRIVE_POWERUP,		-1, 	"powering up" },
     78       1.4   xtraeme 	{ ENVSYS_DRIVE_ONLINE,		-1, 	"online" },
     79       1.5   xtraeme 	{ ENVSYS_DRIVE_OFFLINE, 	-1, 	"offline" },
     80       1.4   xtraeme 	{ ENVSYS_DRIVE_IDLE,		-1, 	"idle" },
     81       1.4   xtraeme 	{ ENVSYS_DRIVE_ACTIVE,		-1, 	"active" },
     82       1.5   xtraeme 	{ ENVSYS_DRIVE_BUILD,		-1,	"building" },
     83       1.4   xtraeme 	{ ENVSYS_DRIVE_REBUILD,		-1, 	"rebuilding" },
     84       1.4   xtraeme 	{ ENVSYS_DRIVE_POWERDOWN,	-1, 	"powering down" },
     85       1.4   xtraeme 	{ ENVSYS_DRIVE_FAIL,		-1, 	"failed" },
     86       1.4   xtraeme 	{ ENVSYS_DRIVE_PFAIL,		-1, 	"degraded" },
     87       1.4   xtraeme 	{ ENVSYS_DRIVE_MIGRATING,	-1,	"migrating" },
     88       1.5   xtraeme 	{ ENVSYS_DRIVE_CHECK,		-1,	"checking" },
     89       1.1   xtraeme 	{ -1,				-1, 	"unknown" }
     90       1.1   xtraeme };
     91       1.1   xtraeme 
     92       1.1   xtraeme /*
     93       1.3   xtraeme  * Available battery capacity descriptions.
     94       1.1   xtraeme  */
     95       1.6  pgoyette static const struct sme_descr_entry sme_batterycap_description[] = {
     96       1.3   xtraeme 	{ ENVSYS_BATTERY_CAPACITY_NORMAL,	-1,	"NORMAL" },
     97       1.3   xtraeme 	{ ENVSYS_BATTERY_CAPACITY_WARNING,	-1, 	"WARNING" },
     98       1.3   xtraeme 	{ ENVSYS_BATTERY_CAPACITY_CRITICAL,	-1, 	"CRITICAL" },
     99       1.3   xtraeme 	{ ENVSYS_BATTERY_CAPACITY_LOW,		-1,	"LOW" },
    100       1.1   xtraeme 	{ -1,					-1, 	"UNKNOWN" }
    101       1.1   xtraeme };
    102       1.1   xtraeme 
    103  1.10.8.1       riz /*
    104  1.10.8.1       riz  * Available indicator descriptions.
    105  1.10.8.1       riz  */
    106  1.10.8.1       riz static const struct sme_descr_entry sme_indicator_description[] = {
    107  1.10.8.1       riz 	{ ENVSYS_INDICATOR_FALSE,		-1,	"FALSE" },
    108  1.10.8.1       riz 	{ ENVSYS_INDICATOR_TRUE,		-1, 	"TRUE" },
    109  1.10.8.1       riz 	{ -1,					-1, 	"UNKNOWN" }
    110  1.10.8.1       riz };
    111  1.10.8.1       riz 
    112       1.9    nonaka static const struct sme_descr_entry *
    113       1.8  christos sme_find_table(enum sme_descr_type table_id)
    114       1.1   xtraeme {
    115       1.6  pgoyette 	switch (table_id) {
    116       1.1   xtraeme 	case SME_DESC_UNITS:
    117       1.8  christos 		return sme_units_description;
    118       1.6  pgoyette 		break;
    119       1.1   xtraeme 	case SME_DESC_STATES:
    120       1.8  christos 		return sme_state_description;
    121       1.6  pgoyette 		break;
    122       1.1   xtraeme 	case SME_DESC_DRIVE_STATES:
    123       1.8  christos 		return sme_drivestate_description;
    124       1.6  pgoyette 		break;
    125       1.3   xtraeme 	case SME_DESC_BATTERY_CAPACITY:
    126       1.8  christos 		return sme_batterycap_description;
    127       1.6  pgoyette 		break;
    128  1.10.8.1       riz 	case SME_DESC_INDICATOR:
    129  1.10.8.1       riz 		return sme_indicator_description;
    130  1.10.8.1       riz 		break;
    131       1.8  christos 	default:
    132       1.8  christos 		return NULL;
    133       1.1   xtraeme 	}
    134       1.8  christos }
    135       1.8  christos 
    136       1.8  christos /*
    137       1.8  christos  * Returns the entry from specified table with type == key
    138       1.8  christos  */
    139       1.8  christos const struct sme_descr_entry *
    140       1.8  christos sme_find_table_entry(enum sme_descr_type table_id, int key)
    141       1.8  christos {
    142      1.10    nonaka 	const struct sme_descr_entry *table = sme_find_table(table_id);
    143       1.6  pgoyette 
    144       1.8  christos 	if (table != NULL)
    145       1.8  christos 		for (; table->type != -1; table++)
    146       1.8  christos 			if (table->type == key)
    147       1.8  christos 				return table;
    148       1.6  pgoyette 
    149       1.8  christos 	return NULL;
    150       1.1   xtraeme }
    151       1.8  christos 
    152       1.7  pgoyette const struct sme_descr_entry *
    153       1.7  pgoyette sme_find_table_desc(enum sme_descr_type table_id, const char *str)
    154       1.7  pgoyette {
    155      1.10    nonaka 	const struct sme_descr_entry *table = sme_find_table(table_id);
    156       1.7  pgoyette 
    157       1.8  christos 	if (table != NULL)
    158       1.8  christos 		for (; table->type != -1; table++)
    159       1.8  christos 			if (strcmp(table->desc, str) == 0)
    160       1.8  christos 				return table;
    161       1.8  christos 	return NULL;
    162       1.7  pgoyette }
    163