Move the functions to create/update objects in a dictionary into its
own file, and DO NOT MAKE THEM inline AS IT IS WRONG. Looks like I'm very stupid and I didn't know what inline meant. Thank you very much YAMAMOTO Takashi.
This commit is contained in:
parent
2eb0397ad6
commit
7282589dc3
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: files.sysmon,v 1.6 2007/07/01 07:36:43 xtraeme Exp $
|
||||
# $NetBSD: files.sysmon,v 1.7 2007/07/20 14:10:22 xtraeme Exp $
|
||||
|
||||
define sysmon_taskq
|
||||
file dev/sysmon/sysmon_taskq.c sysmon_taskq
|
||||
|
@ -7,8 +7,9 @@ define sysmon_power
|
|||
file dev/sysmon/sysmon_power.c sysmon_power needs-flag
|
||||
|
||||
define sysmon_envsys: sysmon_power, sysmon_taskq
|
||||
file dev/sysmon/sysmon_envsys.c sysmon_envsys needs-flag
|
||||
file dev/sysmon/sysmon_envsys.c sysmon_envsys needs-flag
|
||||
file dev/sysmon/sysmon_envsys_events.c sysmon_envsys
|
||||
file dev/sysmon/sysmon_envsys_util.c sysmon_envsys
|
||||
|
||||
define sysmon_wdog
|
||||
file dev/sysmon/sysmon_wdog.c sysmon_wdog needs-flag
|
||||
|
|
|
@ -0,0 +1,163 @@
|
|||
/* $NetBSD: sysmon_envsys_util.c,v 1.1 2007/07/20 14:10:22 xtraeme Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Juan Romero Pardines.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Juan Romero Pardines
|
||||
* for the NetBSD Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``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 FOUNDATION OR CONTRIBUTORS
|
||||
* 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.1 2007/07/20 14:10:22 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 it value provided doesn't match with the value
|
||||
* in dictionary.
|
||||
*/
|
||||
int
|
||||
sme_sensor_upbool(prop_object_t obj, prop_dictionary_t dict,
|
||||
const char *key, bool val)
|
||||
{
|
||||
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_object_t obj, prop_dictionary_t dict,
|
||||
const char *key, int32_t val)
|
||||
{
|
||||
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_object_t obj, prop_dictionary_t dict,
|
||||
const char *key, uint32_t val)
|
||||
{
|
||||
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_object_t obj, prop_dictionary_t dict,
|
||||
const char *key, const char *str)
|
||||
{
|
||||
KASSERT(dict != NULL);
|
||||
|
||||
obj = prop_dictionary_get(dict, key);
|
||||
if (obj == NULL) {
|
||||
if (!prop_dictionary_set_cstring_nocopy(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_nocopy(dict,
|
||||
key,
|
||||
str)) {
|
||||
DPRINTF(("%s: (set) set_cstring %s:%s\n",
|
||||
__func__, key, str));
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: sysmon_envsysvar.h,v 1.7 2007/07/20 10:40:08 xtraeme Exp $ */
|
||||
/* $NetBSD: sysmon_envsysvar.h,v 1.8 2007/07/20 14:10:22 xtraeme Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 The NetBSD Foundation, Inc.
|
||||
|
@ -46,6 +46,7 @@
|
|||
#include <sys/systm.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/workqueue.h>
|
||||
#include <sys/condvar.h>
|
||||
|
||||
#include <dev/sysmon/sysmonvar.h>
|
||||
#include <prop/proplib.h>
|
||||
|
@ -68,120 +69,6 @@ do { \
|
|||
DPRINTFOBJ(("%s: obj (%s:%d) updated\n", __func__, (a), (b))); \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
|
||||
/*
|
||||
* Functions to create objects in a dictionary if they do not exist, or
|
||||
* for updating its value it value provided doesn't match with the value
|
||||
* in dictionary.
|
||||
*/
|
||||
static inline int
|
||||
sme_sensor_upbool(prop_object_t obj, prop_dictionary_t dict,
|
||||
const char *key, bool val)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static inline int
|
||||
sme_sensor_upint32(prop_object_t obj, prop_dictionary_t dict,
|
||||
const char *key, int32_t val)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static inline int
|
||||
sme_sensor_upuint32(prop_object_t obj, prop_dictionary_t dict,
|
||||
const char *key, uint32_t val)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static inline int
|
||||
sme_sensor_upstring(prop_object_t obj, prop_dictionary_t dict,
|
||||
const char *key, const char *str)
|
||||
{
|
||||
KASSERT(dict != NULL);
|
||||
|
||||
obj = prop_dictionary_get(dict, key);
|
||||
if (obj == NULL) {
|
||||
if (!prop_dictionary_set_cstring_nocopy(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_nocopy(dict,
|
||||
key,
|
||||
str)) {
|
||||
DPRINTF(("%s: (set) set_cstring %s:%s\n",
|
||||
__func__, key, str));
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* struct used by a sysmon envsys event */
|
||||
typedef struct sme_event {
|
||||
/* to add works into our workqueue */
|
||||
|
@ -234,4 +121,14 @@ int sme_events_init(void);
|
|||
void sme_events_check(void *);
|
||||
void sme_events_worker(struct work *, void *);
|
||||
|
||||
/* common functions to create/update objects in a dictionary */
|
||||
int sme_sensor_upbool(prop_object_t, prop_dictionary_t,
|
||||
const char *, bool);
|
||||
int sme_sensor_upint32(prop_object_t, prop_dictionary_t,
|
||||
const char *, int32_t);
|
||||
int sme_sensor_upuint32(prop_object_t, prop_dictionary_t,
|
||||
const char *, uint32_t);
|
||||
int sme_sensor_upstring(prop_object_t, prop_dictionary_t,
|
||||
const char *, const char *);
|
||||
|
||||
#endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
|
||||
|
|
Loading…
Reference in New Issue