Wed Jun 8 18:22:24 2011 UTC ()
Factor out some duplicated code to simplify maintenance.  Reduces
the source file by ~100 lines, and amd64 object file shrinks by
~650 bytes.

No functional change intended.


(pgoyette)
diff -r1.113 -r1.114 src/sys/dev/sysmon/sysmon_envsys.c
diff -r1.38 -r1.39 src/sys/dev/sysmon/sysmon_envsysvar.h

cvs diff -r1.113 -r1.114 src/sys/dev/sysmon/sysmon_envsys.c (expand / switch to unified diff)

--- src/sys/dev/sysmon/sysmon_envsys.c 2011/06/04 13:24:33 1.113
+++ src/sys/dev/sysmon/sysmon_envsys.c 2011/06/08 18:22:24 1.114
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sysmon_envsys.c,v 1.113 2011/06/04 13:24:33 pgoyette Exp $ */ 1/* $NetBSD: sysmon_envsys.c,v 1.114 2011/06/08 18:22:24 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2008 Juan Romero Pardines. 4 * Copyright (c) 2007, 2008 Juan Romero Pardines.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -54,27 +54,27 @@ @@ -54,27 +54,27 @@
54 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 54 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 */ 59 */
60 60
61/* 61/*
62 * Environmental sensor framework for sysmon, exported to userland 62 * Environmental sensor framework for sysmon, exported to userland
63 * with proplib(3). 63 * with proplib(3).
64 */ 64 */
65 65
66#include <sys/cdefs.h> 66#include <sys/cdefs.h>
67__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.113 2011/06/04 13:24:33 pgoyette Exp $"); 67__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.114 2011/06/08 18:22:24 pgoyette Exp $");
68 68
69#include <sys/param.h> 69#include <sys/param.h>
70#include <sys/types.h> 70#include <sys/types.h>
71#include <sys/conf.h> 71#include <sys/conf.h>
72#include <sys/errno.h> 72#include <sys/errno.h>
73#include <sys/fcntl.h> 73#include <sys/fcntl.h>
74#include <sys/kernel.h> 74#include <sys/kernel.h>
75#include <sys/systm.h> 75#include <sys/systm.h>
76#include <sys/proc.h> 76#include <sys/proc.h>
77#include <sys/mutex.h> 77#include <sys/mutex.h>
78#include <sys/kmem.h> 78#include <sys/kmem.h>
79 79
80/* #define ENVSYS_DEBUG */ 80/* #define ENVSYS_DEBUG */
@@ -1253,234 +1253,125 @@ out: @@ -1253,234 +1253,125 @@ out:
1253} 1253}
1254 1254
1255/* 1255/*
1256 * sme_add_sensor_dictionary: 1256 * sme_add_sensor_dictionary:
1257 * 1257 *
1258 * + Adds the sensor objects into the dictionary and returns a pointer 1258 * + Adds the sensor objects into the dictionary and returns a pointer
1259 * to a sme_event_drv_t object if a monitoring flag was set 1259 * to a sme_event_drv_t object if a monitoring flag was set
1260 * (or NULL otherwise). 1260 * (or NULL otherwise).
1261 */ 1261 */
1262static sme_event_drv_t * 1262static sme_event_drv_t *
1263sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array, 1263sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
1264 prop_dictionary_t dict, envsys_data_t *edata) 1264 prop_dictionary_t dict, envsys_data_t *edata)
1265{ 1265{
1266 const struct sme_descr_entry *sdt_state, *sdt_units, *sdt_battcap; 1266 const struct sme_descr_entry *sdt;
1267 const struct sme_descr_entry *sdt_drive; 1267 int error;
1268 sme_event_drv_t *sme_evdrv_t = NULL; 1268 sme_event_drv_t *sme_evdrv_t = NULL;
1269 char indexstr[ENVSYS_DESCLEN]; 1269 char indexstr[ENVSYS_DESCLEN];
1270 1270
1271 /*  
1272 * Find the correct units for this sensor. 
1273 */ 
1274 sdt_units = sme_find_table_entry(SME_DESC_UNITS, edata->units); 
1275 
1276 /* 1271 /*
1277 * Add the index sensor string. 1272 * Add the index sensor string.
1278 * 1273 *
1279 * ... 1274 * ...
1280 * <key>index</eyr 1275 * <key>index</eyr
1281 * <string>sensor0</string> 1276 * <string>sensor0</string>
1282 * ... 1277 * ...
1283 */ 1278 */
1284 (void)snprintf(indexstr, sizeof(indexstr), "sensor%d", edata->sensor); 1279 (void)snprintf(indexstr, sizeof(indexstr), "sensor%d", edata->sensor);
1285 if (sme_sensor_upstring(dict, "index", indexstr)) 1280 if (sme_sensor_upstring(dict, "index", indexstr))
1286 goto bad; 1281 goto bad;
1287 1282
1288 /* 1283 /*
1289 * ... 1284 * ...
1290 * <key>type</key> 
1291 * <string>foo</string> 
1292 * <key>description</key> 1285 * <key>description</key>
1293 * <string>blah blah</string> 1286 * <string>blah blah</string>
1294 * ... 1287 * ...
1295 */ 1288 */
1296 if (sme_sensor_upstring(dict, "type", sdt_units->desc)) 
1297 goto bad; 
1298 
1299 if (sme_sensor_upstring(dict, "description", edata->desc)) 1289 if (sme_sensor_upstring(dict, "description", edata->desc))
1300 goto bad; 1290 goto bad;
1301 1291
1302 /* 1292 /*
1303 * Add sensor's state description. 
1304 * 
1305 * ... 
1306 * <key>state</key> 
1307 * <string>valid</string> 
1308 * ... 
1309 */ 
1310 sdt_state = sme_find_table_entry(SME_DESC_STATES, edata->state); 
1311 
1312 DPRINTF(("%s: sensor desc=%s type=%d state=%d\n", 
1313 __func__, edata->desc, edata->units, edata->state)); 
1314 
1315 if (sme_sensor_upstring(dict, "state", sdt_state->desc)) 
1316 goto bad; 
1317 
1318 /* 
1319 * Add the monitoring boolean object: 1293 * Add the monitoring boolean object:
1320 * 1294 *
1321 * ... 1295 * ...
1322 * <key>monitoring-supported</key> 1296 * <key>monitoring-supported</key>
1323 * <true/> 1297 * <true/>
1324 * ... 1298 * ...
1325 *  1299 *
1326 * always false on Battery {capacity,charge}, Drive and Indicator types. 1300 * always false on Battery {capacity,charge}, Drive and Indicator types.
1327 * They cannot be monitored. 1301 * They cannot be monitored.
1328 * 1302 *
1329 */ 1303 */
1330 if ((edata->flags & ENVSYS_FMONNOTSUPP) || 1304 if ((edata->flags & ENVSYS_FMONNOTSUPP) ||
1331 (edata->units == ENVSYS_INDICATOR) || 1305 (edata->units == ENVSYS_INDICATOR) ||
1332 (edata->units == ENVSYS_DRIVE) || 1306 (edata->units == ENVSYS_DRIVE) ||
1333 (edata->units == ENVSYS_BATTERY_CAPACITY) || 1307 (edata->units == ENVSYS_BATTERY_CAPACITY) ||
1334 (edata->units == ENVSYS_BATTERY_CHARGE)) { 1308 (edata->units == ENVSYS_BATTERY_CHARGE)) {
1335 if (sme_sensor_upbool(dict, "monitoring-supported", false)) 1309 if (sme_sensor_upbool(dict, "monitoring-supported", false))
1336 goto out; 1310 goto out;
1337 } else { 1311 } else {
1338 if (sme_sensor_upbool(dict, "monitoring-supported", true)) 1312 if (sme_sensor_upbool(dict, "monitoring-supported", true))
1339 goto out; 1313 goto out;
1340 } 1314 }
1341 1315
1342 /* 1316 /*
1343 * Add the percentage boolean object, true if ENVSYS_FPERCENT 
1344 * is set or false otherwise. 
1345 * 
1346 * ... 
1347 * <key>want-percentage</key> 
1348 * <true/> 
1349 * ... 
1350 */ 
1351 if (edata->flags & ENVSYS_FPERCENT) 
1352 if (sme_sensor_upbool(dict, "want-percentage", true)) 
1353 goto out; 
1354 
1355 /* 
1356 * Add the allow-rfact boolean object, true if 1317 * Add the allow-rfact boolean object, true if
1357 * ENVSYS_FCHANGERFACT if set or false otherwise. 1318 * ENVSYS_FCHANGERFACT is set, false otherwise.
1358 * 1319 *
1359 * ... 1320 * ...
1360 * <key>allow-rfact</key> 1321 * <key>allow-rfact</key>
1361 * <true/> 1322 * <true/>
1362 * ... 1323 * ...
1363 */ 1324 */
1364 if (edata->units == ENVSYS_SVOLTS_DC || 1325 if (edata->units == ENVSYS_SVOLTS_DC ||
1365 edata->units == ENVSYS_SVOLTS_AC) { 1326 edata->units == ENVSYS_SVOLTS_AC) {
1366 if (edata->flags & ENVSYS_FCHANGERFACT) { 1327 if (edata->flags & ENVSYS_FCHANGERFACT) {
1367 if (sme_sensor_upbool(dict, "allow-rfact", true)) 1328 if (sme_sensor_upbool(dict, "allow-rfact", true))
1368 goto out; 1329 goto out;
1369 } else { 1330 } else {
1370 if (sme_sensor_upbool(dict, "allow-rfact", false)) 1331 if (sme_sensor_upbool(dict, "allow-rfact", false))
1371 goto out; 1332 goto out;
1372 } 1333 }
1373 } 1334 }
1374 1335
1375 /* 1336 error = sme_update_sensor_dictionary(dict, edata,
1376 * Add the object for battery capacity sensors: 1337 (edata->state == ENVSYS_SVALID));
1377 * 1338 if (error < 0)
1378 * ... 1339 goto bad;
1379 * <key>battery-capacity</key> 1340 else if (error)
1380 * <string>NORMAL</string> 1341 goto out;
1381 * ... 
1382 */ 
1383 if (edata->units == ENVSYS_BATTERY_CAPACITY) { 
1384 sdt_battcap = sme_find_table_entry(SME_DESC_BATTERY_CAPACITY, 
1385 edata->value_cur); 
1386 if (sme_sensor_upstring(dict, "battery-capacity", 
1387 sdt_battcap->desc)) 
1388 goto out; 
1389 } 
1390 
1391 /* 
1392 * Add the drive-state object for drive sensors: 
1393 * 
1394 * ... 
1395 * <key>drive-state</key> 
1396 * <string>drive is online</string> 
1397 * ... 
1398 */ 
1399 if (edata->units == ENVSYS_DRIVE) { 
1400 sdt_drive = sme_find_table_entry(SME_DESC_DRIVE_STATES, 
1401 edata->value_cur); 
1402 if (sme_sensor_upstring(dict, "drive-state", sdt_drive->desc)) 
1403 goto out; 
1404 } 
1405 
1406 /* 
1407 * Add the following objects if sensor is enabled... 
1408 */ 
1409 if (edata->state == ENVSYS_SVALID) { 
1410 /* 
1411 * Add the following objects: 
1412 * 
1413 * ... 
1414 * <key>rpms</key> 
1415 * <integer>2500</integer> 
1416 * <key>rfact</key> 
1417 * <integer>10000</integer> 
1418 * <key>cur-value</key> 
1419 * <integer>1250</integer> 
1420 * <key>min-value</key> 
1421 * <integer>800</integer> 
1422 * <key>max-value</integer> 
1423 * <integer>3000</integer> 
1424 * ... 
1425 */ 
1426 if (edata->units == ENVSYS_SFANRPM) 
1427 if (sme_sensor_upuint32(dict, "rpms", edata->rpms)) 
1428 goto out; 
1429 
1430 if (edata->units == ENVSYS_SVOLTS_AC || 
1431 edata->units == ENVSYS_SVOLTS_DC) 
1432 if (sme_sensor_upint32(dict, "rfact", edata->rfact)) 
1433 goto out; 
1434 
1435 if (sme_sensor_upint32(dict, "cur-value", edata->value_cur)) 
1436 goto out; 
1437 
1438 if (edata->flags & ENVSYS_FVALID_MIN) { 
1439 if (sme_sensor_upint32(dict, 
1440 "min-value", 
1441 edata->value_min)) 
1442 goto out; 
1443 } 
1444 
1445 if (edata->flags & ENVSYS_FVALID_MAX) { 
1446 if (sme_sensor_upint32(dict, 
1447 "max-value", 
1448 edata->value_max)) 
1449 goto out; 
1450 } 
1451 } 
1452 1342
1453 /* 1343 /*
1454 * ... 1344 * ...
1455 * </dict> 1345 * </dict>
1456 * 1346 *
1457 * Add the dictionary into the array. 1347 * Add the dictionary into the array.
1458 * 1348 *
1459 */ 1349 */
1460 if (!prop_array_add(array, dict)) { 1350 if (!prop_array_add(array, dict)) {
1461 DPRINTF(("%s: prop_array_add\n", __func__)); 1351 DPRINTF(("%s: prop_array_add\n", __func__));
1462 goto bad; 1352 goto bad;
1463 } 1353 }
1464 1354
1465 /* 1355 /*
1466 * Register new event(s) if any monitoring flag was set. 1356 * Register new event(s) if any monitoring flag was set.
1467 */ 1357 */
1468 if (edata->flags & ENVSYS_FMONANY) { 1358 if (edata->flags & ENVSYS_FMONANY) {
1469 sme_evdrv_t = kmem_zalloc(sizeof(*sme_evdrv_t), KM_SLEEP); 1359 sme_evdrv_t = kmem_zalloc(sizeof(*sme_evdrv_t), KM_SLEEP);
1470 sme_evdrv_t->sed_sdict = dict; 1360 sme_evdrv_t->sed_sdict = dict;
1471 sme_evdrv_t->sed_edata = edata; 1361 sme_evdrv_t->sed_edata = edata;
1472 sme_evdrv_t->sed_sme = sme; 1362 sme_evdrv_t->sed_sme = sme;
1473 sme_evdrv_t->sed_powertype = sdt_units->crittype; 1363 sdt = sme_find_table_entry(SME_DESC_UNITS, edata->units);
 1364 sme_evdrv_t->sed_powertype = sdt->crittype;
1474 } 1365 }
1475 1366
1476out: 1367out:
1477 return sme_evdrv_t; 1368 return sme_evdrv_t;
1478 1369
1479bad: 1370bad:
1480 prop_object_release(dict); 1371 prop_object_release(dict);
1481 return NULL; 1372 return NULL;
1482} 1373}
1483 1374
1484/* 1375/*
1485 * Find the maximum of all currently reported values. 1376 * Find the maximum of all currently reported values.
1486 * The provided callback decides wether a sensor is part of the 1377 * The provided callback decides wether a sensor is part of the
@@ -1545,27 +1436,26 @@ sme_get_max_value(struct sysmon_envsys * @@ -1545,27 +1436,26 @@ sme_get_max_value(struct sysmon_envsys *
1545 1436
1546 return maxv; 1437 return maxv;
1547} 1438}
1548 1439
1549/* 1440/*
1550 * sme_update_dictionary: 1441 * sme_update_dictionary:
1551 * 1442 *
1552 * + Update per-sensor dictionaries with new values if there were 1443 * + Update per-sensor dictionaries with new values if there were
1553 * changes, otherwise the object in dictionary is untouched. 1444 * changes, otherwise the object in dictionary is untouched.
1554 */ 1445 */
1555int 1446int
1556sme_update_dictionary(struct sysmon_envsys *sme) 1447sme_update_dictionary(struct sysmon_envsys *sme)
1557{ 1448{
1558 const struct sme_descr_entry *sdt; 
1559 envsys_data_t *edata; 1449 envsys_data_t *edata;
1560 prop_object_t array, dict, obj, obj2; 1450 prop_object_t array, dict, obj, obj2;
1561 int error = 0; 1451 int error = 0;
1562 1452
1563 /*  1453 /*
1564 * Retrieve the array of dictionaries in device. 1454 * Retrieve the array of dictionaries in device.
1565 */ 1455 */
1566 array = prop_dictionary_get(sme_propd, sme->sme_name); 1456 array = prop_dictionary_get(sme_propd, sme->sme_name);
1567 if (prop_object_type(array) != PROP_TYPE_ARRAY) { 1457 if (prop_object_type(array) != PROP_TYPE_ARRAY) {
1568 DPRINTF(("%s: not an array (%s)\n", __func__, sme->sme_name)); 1458 DPRINTF(("%s: not an array (%s)\n", __func__, sme->sme_name));
1569 return EINVAL; 1459 return EINVAL;
1570 } 1460 }
1571 1461
@@ -1618,143 +1508,147 @@ sme_update_dictionary(struct sysmon_envs @@ -1618,143 +1508,147 @@ sme_update_dictionary(struct sysmon_envs
1618 /*  1508 /*
1619 * retrieve sensor's dictionary. 1509 * retrieve sensor's dictionary.
1620 */ 1510 */
1621 dict = prop_array_get(array, edata->sensor); 1511 dict = prop_array_get(array, edata->sensor);
1622 if (prop_object_type(dict) != PROP_TYPE_DICTIONARY) { 1512 if (prop_object_type(dict) != PROP_TYPE_DICTIONARY) {
1623 DPRINTF(("%s: not a dictionary (%d:%s)\n", 1513 DPRINTF(("%s: not a dictionary (%d:%s)\n",
1624 __func__, edata->sensor, sme->sme_name)); 1514 __func__, edata->sensor, sme->sme_name));
1625 return EINVAL; 1515 return EINVAL;
1626 } 1516 }
1627 1517
1628 /*  1518 /*
1629 * update sensor's state. 1519 * update sensor's state.
1630 */ 1520 */
1631 sdt = sme_find_table_entry(SME_DESC_STATES, edata->state); 1521 error = sme_update_sensor_dictionary(dict, edata, true);
1632 1522
1633 DPRINTFOBJ(("%s: sensor #%d type=%d (%s) flags=%d\n", 
1634 __func__, edata->sensor, sdt->type, sdt->desc, 
1635 edata->flags)); 
1636 
1637 error = sme_sensor_upstring(dict, "state", sdt->desc); 
1638 if (error) 1523 if (error)
1639 break; 1524 break;
 1525 }
1640 1526
1641 /*  1527 return error;
1642 * update sensor's type. 1528}
1643 */ 1529
1644 sdt = sme_find_table_entry(SME_DESC_UNITS, edata->units); 1530int
 1531sme_update_sensor_dictionary(prop_object_t dict, envsys_data_t *edata,
 1532 bool value_update)
 1533{
 1534 const struct sme_descr_entry *sdt;
 1535 int error = 0;
 1536
 1537 sdt = sme_find_table_entry(SME_DESC_STATES, edata->state);
 1538
 1539 DPRINTFOBJ(("%s: sensor #%d type=%d (%s) flags=%d\n", __func__,
 1540 edata->sensor, sdt->type, sdt->desc, edata->flags));
1645 1541
1646 DPRINTFOBJ(("%s: sensor #%d units=%d (%s)\n", 1542 error = sme_sensor_upstring(dict, "state", sdt->desc);
1647 __func__, edata->sensor, sdt->type, sdt->desc)); 1543 if (error)
 1544 return (-error);
1648 1545
1649 error = sme_sensor_upstring(dict, "type", sdt->desc); 1546 /*
 1547 * update sensor's type.
 1548 */
 1549 sdt = sme_find_table_entry(SME_DESC_UNITS, edata->units);
 1550
 1551 DPRINTFOBJ(("%s: sensor #%d units=%d (%s)\n", __func__, edata->sensor,
 1552 sdt->type, sdt->desc));
 1553
 1554 error = sme_sensor_upstring(dict, "type", sdt->desc);
 1555 if (error)
 1556 return (-error);
 1557
 1558 /*
 1559 * Battery charge and Indicator types do not
 1560 * need the remaining objects, so skip them.
 1561 */
 1562 if (edata->units == ENVSYS_INDICATOR ||
 1563 edata->units == ENVSYS_BATTERY_CHARGE)
 1564 return error;
 1565
 1566 /*
 1567 * update sensor flags.
 1568 */
 1569 if (edata->flags & ENVSYS_FPERCENT) {
 1570 error = sme_sensor_upbool(dict, "want-percentage", true);
1650 if (error) 1571 if (error)
1651 break; 1572 return error;
 1573 }
1652 1574
 1575 if (value_update) {
1653 /*  1576 /*
1654 * update sensor's current value. 1577 * update sensor's current value.
1655 */ 1578 */
1656 error = sme_sensor_upint32(dict, 1579 error = sme_sensor_upint32(dict, "cur-value", edata->value_cur);
1657 "cur-value", 
1658 edata->value_cur); 
1659 if (error) 1580 if (error)
1660 break; 1581 return error;
1661 
1662 /* 
1663 * Battery charge, Integer and Indicator types do not 
1664 * need the following objects, so skip them. 
1665 */ 
1666 if (edata->units == ENVSYS_INTEGER || 
1667 edata->units == ENVSYS_INDICATOR || 
1668 edata->units == ENVSYS_BATTERY_CHARGE) 
1669 continue; 
1670 
1671 /*  
1672 * update sensor flags. 
1673 */ 
1674 if (edata->flags & ENVSYS_FPERCENT) { 
1675 error = sme_sensor_upbool(dict, 
1676 "want-percentage", 
1677 true); 
1678 if (error) 
1679 break; 
1680 } 
1681 1582
1682 /* 1583 /*
1683 * update sensor's {max,min}-value. 1584 * update sensor's {max,min}-value.
1684 */ 1585 */
1685 if (edata->flags & ENVSYS_FVALID_MAX) { 1586 if (edata->flags & ENVSYS_FVALID_MAX) {
1686 error = sme_sensor_upint32(dict, 1587 error = sme_sensor_upint32(dict, "max-value",
1687 "max-value", 
1688 edata->value_max); 1588 edata->value_max);
1689 if (error) 1589 if (error)
1690 break; 1590 return error;
1691 } 1591 }
1692  1592
1693 if (edata->flags & ENVSYS_FVALID_MIN) { 1593 if (edata->flags & ENVSYS_FVALID_MIN) {
1694 error = sme_sensor_upint32(dict, 1594 error = sme_sensor_upint32(dict, "min-value",
1695 "min-value", 
1696 edata->value_min); 1595 edata->value_min);
1697 if (error) 1596 if (error)
1698 break; 1597 return error;
1699 } 1598 }
1700 1599
1701 /*  1600 /*
1702 * update 'rpms' only for ENVSYS_SFANRPM sensors. 1601 * update 'rpms' only for ENVSYS_SFANRPM sensors.
1703 */ 1602 */
1704 if (edata->units == ENVSYS_SFANRPM) { 1603 if (edata->units == ENVSYS_SFANRPM) {
1705 error = sme_sensor_upuint32(dict, 1604 error = sme_sensor_upuint32(dict, "rpms", edata->rpms);
1706 "rpms", 
1707 edata->rpms); 
1708 if (error) 1605 if (error)
1709 break; 1606 return error;
1710 } 1607 }
1711 1608
1712 /*  1609 /*
1713 * update 'rfact' only for ENVSYS_SVOLTS_[AD]C sensors. 1610 * update 'rfact' only for ENVSYS_SVOLTS_[AD]C sensors.
1714 */ 1611 */
1715 if (edata->units == ENVSYS_SVOLTS_AC || 1612 if (edata->units == ENVSYS_SVOLTS_AC ||
1716 edata->units == ENVSYS_SVOLTS_DC) { 1613 edata->units == ENVSYS_SVOLTS_DC) {
1717 error = sme_sensor_upint32(dict, 1614 error = sme_sensor_upint32(dict, "rfact", edata->rfact);
1718 "rfact", 
1719 edata->rfact); 
1720 if (error) 1615 if (error)
1721 break; 1616 return error;
1722 } 
1723  
1724 /*  
1725 * update 'drive-state' only for ENVSYS_DRIVE sensors. 
1726 */ 
1727 if (edata->units == ENVSYS_DRIVE) { 
1728 sdt = sme_find_table_entry(SME_DESC_DRIVE_STATES, 
1729 edata->value_cur); 
1730 error = sme_sensor_upstring(dict, "drive-state", 
1731 sdt->desc); 
1732 if (error) 
1733 break; 
1734 } 1617 }
 1618 }
1735 1619
1736 /*  1620 /*
1737 * update 'battery-capacity' only for ENVSYS_BATTERY_CAPACITY 1621 * update 'drive-state' only for ENVSYS_DRIVE sensors.
1738 * sensors. 1622 */
1739 */ 1623 if (edata->units == ENVSYS_DRIVE) {
1740 if (edata->units == ENVSYS_BATTERY_CAPACITY) { 1624 sdt = sme_find_table_entry(SME_DESC_DRIVE_STATES,
1741 sdt = sme_find_table_entry(SME_DESC_BATTERY_CAPACITY, 1625 edata->value_cur);
1742 edata->value_cur); 1626 error = sme_sensor_upstring(dict, "drive-state", sdt->desc);
1743 error = sme_sensor_upstring(dict, "battery-capacity", 1627 if (error)
1744 sdt->desc); 1628 return error;
1745 if (error) 1629 }
1746 break; 1630
1747 } 1631 /*
 1632 * update 'battery-capacity' only for ENVSYS_BATTERY_CAPACITY
 1633 * sensors.
 1634 */
 1635 if (edata->units == ENVSYS_BATTERY_CAPACITY) {
 1636 sdt = sme_find_table_entry(SME_DESC_BATTERY_CAPACITY,
 1637 edata->value_cur);
 1638 error = sme_sensor_upstring(dict, "battery-capacity",
 1639 sdt->desc);
 1640 if (error)
 1641 return error;
1748 } 1642 }
1749 1643
1750 return error; 1644 return error;
1751} 1645}
1752 1646
1753/* 1647/*
1754 * sme_userset_dictionary: 1648 * sme_userset_dictionary:
1755 * 1649 *
1756 * + Parse the userland dictionary and run the appropiate tasks 1650 * + Parse the userland dictionary and run the appropiate tasks
1757 * that were specified. 1651 * that were specified.
1758 */ 1652 */
1759int 1653int
1760sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict, 1654sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,

cvs diff -r1.38 -r1.39 src/sys/dev/sysmon/sysmon_envsysvar.h (expand / switch to unified diff)

--- src/sys/dev/sysmon/sysmon_envsysvar.h 2010/12/30 03:59:59 1.38
+++ src/sys/dev/sysmon/sysmon_envsysvar.h 2011/06/08 18:22:24 1.39
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sysmon_envsysvar.h,v 1.38 2010/12/30 03:59:59 pgoyette Exp $ */ 1/* $NetBSD: sysmon_envsysvar.h,v 1.39 2011/06/08 18:22:24 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2008 Juan Romero Pardines. 4 * Copyright (c) 2007, 2008 Juan Romero Pardines.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -101,26 +101,27 @@ struct sme_descr_entry { @@ -101,26 +101,27 @@ struct sme_descr_entry {
101 */ 101 */
102extern kmutex_t sme_global_mtx; /* for the sme linked list and dict */ 102extern kmutex_t sme_global_mtx; /* for the sme linked list and dict */
103extern prop_dictionary_t sme_propd; /* the global sensor dictionary */ 103extern prop_dictionary_t sme_propd; /* the global sensor dictionary */
104 104
105/*  105/*
106 * linked list for the sysmon envsys devices. 106 * linked list for the sysmon envsys devices.
107 */ 107 */
108LIST_HEAD(, sysmon_envsys) sysmon_envsys_list; 108LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
109 109
110/*  110/*
111 * functions to handle sysmon envsys devices. 111 * functions to handle sysmon envsys devices.
112 */ 112 */
113int sme_update_dictionary(struct sysmon_envsys *); 113int sme_update_dictionary(struct sysmon_envsys *);
 114int sme_update_sensor_dictionary(prop_object_t, envsys_data_t *, bool);
114int sme_userset_dictionary(struct sysmon_envsys *, 115int sme_userset_dictionary(struct sysmon_envsys *,
115 prop_dictionary_t, prop_array_t); 116 prop_dictionary_t, prop_array_t);
116prop_dictionary_t sme_sensor_dictionary_get(prop_array_t, const char *); 117prop_dictionary_t sme_sensor_dictionary_get(prop_array_t, const char *);
117struct sysmon_envsys *sysmon_envsys_find(const char *); 118struct sysmon_envsys *sysmon_envsys_find(const char *);
118void sysmon_envsys_acquire(struct sysmon_envsys *, bool); 119void sysmon_envsys_acquire(struct sysmon_envsys *, bool);
119void sysmon_envsys_release(struct sysmon_envsys *, bool); 120void sysmon_envsys_release(struct sysmon_envsys *, bool);
120 121
121/*  122/*
122 * functions to handle sysmon envsys events. 123 * functions to handle sysmon envsys events.
123 */ 124 */
124int sme_event_register(prop_dictionary_t, envsys_data_t *, 125int sme_event_register(prop_dictionary_t, envsys_data_t *,
125 struct sysmon_envsys *, sysmon_envsys_lim_t *, 126 struct sysmon_envsys *, sysmon_envsys_lim_t *,
126 uint32_t, int, int); 127 uint32_t, int, int);