1 /* $NetBSD: sysmon_envsys_util.c,v 1.4 2007/10/07 04:11:16 xtraeme Exp $ */
4 * Copyright (c) 2007 Juan Romero Pardines.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_util.c,v 1.4 2007/10/07 04:11:16 xtraeme Exp $");
31 #include <sys/param.h>
32 #include <sys/types.h>
34 #include <sys/kernel.h>
36 #include <dev/sysmon/sysmonvar.h>
37 #include <dev/sysmon/sysmon_envsysvar.h>
38 #include <prop/proplib.h>
41 * Functions to create objects in a dictionary if they do not exist, or
42 * for updating its value if it doesn't match with the value in dictionary.
46 sme_sensor_upbool(prop_dictionary_t dict
, const char *key
, bool val
)
50 KASSERT(dict
!= NULL
);
52 obj
= prop_dictionary_get(dict
, key
);
54 if (prop_bool_true(obj
) != val
) {
55 if (!prop_dictionary_set_bool(dict
, key
, val
)) {
56 DPRINTF(("%s: (up) set_bool %s:%d\n",
62 if (!prop_dictionary_set_bool(dict
, key
, val
)) {
63 DPRINTF(("%s: (set) set_bool %s:%d\n",
73 sme_sensor_upint32(prop_dictionary_t dict
, const char *key
, int32_t val
)
77 KASSERT(dict
!= NULL
);
79 obj
= prop_dictionary_get(dict
, key
);
81 if (!prop_number_equals_integer(obj
, val
)) {
82 if (!prop_dictionary_set_int32(dict
, key
, val
)) {
83 DPRINTF(("%s: (up) set_int32 %s:%d\n",
89 if (!prop_dictionary_set_int32(dict
, key
, val
)) {
90 DPRINTF(("%s: (set) set_int32 %s:%d\n",
100 sme_sensor_upuint32(prop_dictionary_t dict
, const char *key
, uint32_t val
)
104 KASSERT(dict
!= NULL
);
106 obj
= prop_dictionary_get(dict
, key
);
108 if (!prop_number_equals_unsigned_integer(obj
, val
)) {
109 if (!prop_dictionary_set_uint32(dict
, key
, val
)) {
110 DPRINTF(("%s: (up) set_uint32 %s:%d\n",
111 __func__
, key
, val
));
116 if (!prop_dictionary_set_uint32(dict
, key
, val
)) {
117 DPRINTF(("%s: (set) set_uint32 %s:%d\n",
118 __func__
, key
, val
));
127 sme_sensor_upstring(prop_dictionary_t dict
, const char *key
, const char *str
)
131 KASSERT(dict
!= NULL
);
133 obj
= prop_dictionary_get(dict
, key
);
135 if (!prop_dictionary_set_cstring(dict
, key
, str
)) {
136 DPRINTF(("%s: (up) set_cstring %s:%s\n",
137 __func__
, key
, str
));
141 if (!prop_string_equals_cstring(obj
, str
)) {
142 if (!prop_dictionary_set_cstring(dict
, key
, str
)) {
143 DPRINTF(("%s: (set) set_cstring %s:%s\n",
144 __func__
, key
, str
));