Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / sysmon / sysmon_envsys_util.c
blob4b3633daab8507eb4f4e0e958abe22ff61668b71
1 /* $NetBSD: sysmon_envsys_util.c,v 1.4 2007/10/07 04:11:16 xtraeme Exp $ */
3 /*-
4 * Copyright (c) 2007 Juan Romero Pardines.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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>
33 #include <sys/conf.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.
45 int
46 sme_sensor_upbool(prop_dictionary_t dict, const char *key, bool val)
48 prop_object_t obj;
50 KASSERT(dict != NULL);
52 obj = prop_dictionary_get(dict, key);
53 if (obj) {
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",
57 __func__, key, val));
58 return EINVAL;
61 } else {
62 if (!prop_dictionary_set_bool(dict, key, val)) {
63 DPRINTF(("%s: (set) set_bool %s:%d\n",
64 __func__, key, val));
65 return EINVAL;
69 return 0;
72 int
73 sme_sensor_upint32(prop_dictionary_t dict, const char *key, int32_t val)
75 prop_object_t obj;
77 KASSERT(dict != NULL);
79 obj = prop_dictionary_get(dict, key);
80 if (obj) {
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",
84 __func__, key, val));
85 return EINVAL;
88 } else {
89 if (!prop_dictionary_set_int32(dict, key, val)) {
90 DPRINTF(("%s: (set) set_int32 %s:%d\n",
91 __func__, key, val));
92 return EINVAL;
96 return 0;
99 int
100 sme_sensor_upuint32(prop_dictionary_t dict, const char *key, uint32_t val)
102 prop_object_t obj;
104 KASSERT(dict != NULL);
106 obj = prop_dictionary_get(dict, key);
107 if (obj) {
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));
112 return EINVAL;
115 } else {
116 if (!prop_dictionary_set_uint32(dict, key, val)) {
117 DPRINTF(("%s: (set) set_uint32 %s:%d\n",
118 __func__, key, val));
119 return EINVAL;
123 return 0;
127 sme_sensor_upstring(prop_dictionary_t dict, const char *key, const char *str)
129 prop_object_t obj;
131 KASSERT(dict != NULL);
133 obj = prop_dictionary_get(dict, key);
134 if (obj == NULL) {
135 if (!prop_dictionary_set_cstring(dict, key, str)) {
136 DPRINTF(("%s: (up) set_cstring %s:%s\n",
137 __func__, key, str));
138 return EINVAL;
140 } else {
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));
145 return EINVAL;
150 return 0;