6c4da82b5e
envstat(8) and the envsys framework: - Modify the ENVSYS_SETDICTIONARY ioctl to support the following plist structure: <dict> <key>foo0</key> <array> <dict> <key>index</key> <string>sensor0</string> <key>description</key> <string>cpu temp</string> ... Another property for this sensor ... </dict> ... Another dictionary for other sensor ... </array> ... Another device as above ... </dict> Multiple devices with multiple sensors can now be specified, that means that to set the properties only one copyin(9) is needed now. - Added the ENVSYS_REMOVEPROPS ioctl, that accepts a boolean object "envsys-remove-props" and when set to true, all properties that were set previously by ENVSYS_SETDICTIONARY will be removed. That means that you can now set multiple critical limits, descriptions and all they will be removed or changed to its default value (for rfact and description objects). - Added the 'index' and 'allow-rfact' objects into the sensor dictionaries, for better interactivity with userland. To know the position of the sensor and to know if sensor allows to change the rfact. - Misc cosmetic changes for consistency. - Use a two clause license for all my code.
156 lines
4.1 KiB
C
156 lines
4.1 KiB
C
/* $NetBSD: sysmon_envsys_util.c,v 1.4 2007/10/07 04:11:16 xtraeme Exp $ */
|
|
|
|
/*-
|
|
* Copyright (c) 2007 Juan Romero Pardines.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_util.c,v 1.4 2007/10/07 04:11:16 xtraeme Exp $");
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/types.h>
|
|
#include <sys/conf.h>
|
|
#include <sys/kernel.h>
|
|
|
|
#include <dev/sysmon/sysmonvar.h>
|
|
#include <dev/sysmon/sysmon_envsysvar.h>
|
|
#include <prop/proplib.h>
|
|
|
|
/*
|
|
* Functions to create objects in a dictionary if they do not exist, or
|
|
* for updating its value if value provided doesn't match with the value
|
|
* in dictionary.
|
|
*/
|
|
|
|
int
|
|
sme_sensor_upbool(prop_dictionary_t dict, const char *key, bool val)
|
|
{
|
|
prop_object_t obj;
|
|
|
|
KASSERT(dict != NULL);
|
|
|
|
obj = prop_dictionary_get(dict, key);
|
|
if (obj) {
|
|
if (prop_bool_true(obj) != val) {
|
|
if (!prop_dictionary_set_bool(dict, key, val)) {
|
|
DPRINTF(("%s: (up) set_bool %s:%d\n",
|
|
__func__, key, val));
|
|
return EINVAL;
|
|
}
|
|
SENSOR_OBJUPDATED(key, val);
|
|
}
|
|
} else {
|
|
if (!prop_dictionary_set_bool(dict, key, val)) {
|
|
DPRINTF(("%s: (set) set_bool %s:%d\n",
|
|
__func__, key, val));
|
|
return EINVAL;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
sme_sensor_upint32(prop_dictionary_t dict, const char *key, int32_t val)
|
|
{
|
|
prop_object_t obj;
|
|
|
|
KASSERT(dict != NULL);
|
|
|
|
obj = prop_dictionary_get(dict, key);
|
|
if (obj) {
|
|
if (!prop_number_equals_integer(obj, val)) {
|
|
if (!prop_dictionary_set_int32(dict, key, val)) {
|
|
DPRINTF(("%s: (up) set_int32 %s:%d\n",
|
|
__func__, key, val));
|
|
return EINVAL;
|
|
}
|
|
SENSOR_OBJUPDATED(key, val);
|
|
}
|
|
} else {
|
|
if (!prop_dictionary_set_int32(dict, key, val)) {
|
|
DPRINTF(("%s: (set) set_int32 %s:%d\n",
|
|
__func__, key, val));
|
|
return EINVAL;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
sme_sensor_upuint32(prop_dictionary_t dict, const char *key, uint32_t val)
|
|
{
|
|
prop_object_t obj;
|
|
|
|
KASSERT(dict != NULL);
|
|
|
|
obj = prop_dictionary_get(dict, key);
|
|
if (obj) {
|
|
if (!prop_number_equals_unsigned_integer(obj, val)) {
|
|
if (!prop_dictionary_set_uint32(dict, key, val)) {
|
|
DPRINTF(("%s: (up) set_uint32 %s:%d\n",
|
|
__func__, key, val));
|
|
return EINVAL;
|
|
}
|
|
SENSOR_OBJUPDATED(key, val);
|
|
}
|
|
} else {
|
|
if (!prop_dictionary_set_uint32(dict, key, val)) {
|
|
DPRINTF(("%s: (set) set_uint32 %s:%d\n",
|
|
__func__, key, val));
|
|
return EINVAL;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
sme_sensor_upstring(prop_dictionary_t dict, const char *key, const char *str)
|
|
{
|
|
prop_object_t obj;
|
|
|
|
KASSERT(dict != NULL);
|
|
|
|
obj = prop_dictionary_get(dict, key);
|
|
if (obj == NULL) {
|
|
if (!prop_dictionary_set_cstring(dict, key, str)) {
|
|
DPRINTF(("%s: (up) set_cstring %s:%s\n",
|
|
__func__, key, str));
|
|
return EINVAL;
|
|
}
|
|
} else {
|
|
if (!prop_string_equals_cstring(obj, str)) {
|
|
if (!prop_dictionary_set_cstring(dict, key, str)) {
|
|
DPRINTF(("%s: (set) set_cstring %s:%s\n",
|
|
__func__, key, str));
|
|
return EINVAL;
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|