18c2aff776a775d34a4c9893a4c72e0434d68e36artem/***************************************************************************
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * CVSID: $Id$
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * property.c : HalProperty methods
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright (C) 2004 Novell, Inc.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Licensed under the Academic Free License version 2.1
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is free software; you can redistribute it and/or modify
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * it under the terms of the GNU General Public License as published by
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the Free Software Foundation; either version 2 of the License, or
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * (at your option) any later version.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is distributed in the hope that it will be useful,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * but WITHOUT ANY WARRANTY; without even the implied warranty of
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * GNU General Public License for more details.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * You should have received a copy of the GNU General Public License
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * along with this program; if not, write to the Free Software
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18c2aff776a775d34a4c9893a4c72e0434d68e36artem **************************************************************************/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (i = prop->v.strlist_value; i != NULL; i = g_slist_next (i)) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_new_string (const char *key, const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem prop->v.str_value = g_strdup (value != NULL ? value : "");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem (const char **) &endchar)) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_WARNING (("Key '%s' has invalid UTF-8 string '%s'",
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_new_int (const char *key, dbus_int32_t value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_new_uint64 (const char *key, dbus_uint64_t value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_new_bool (const char *key, dbus_bool_t value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_new_double (const char *key, double value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemconst char *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop != NULL, HAL_PROPERTY_TYPE_INVALID);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemconst char *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRING, NULL);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_INT32, -1);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_UINT64, -1);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_BOOLEAN, FALSE);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem return g_strdup_printf ("%llu", (long long unsigned int) prop->v.uint64_value);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* FIXME: Maybe use 1 and 0 here instead? */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem return g_strdup (prop->v.bool_value ? "true" : "false");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_DOUBLE, -1.0);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_set_string (HalProperty *prop, const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_if_fail (prop->type == HAL_PROPERTY_TYPE_STRING ||
18c2aff776a775d34a4c9893a4c72e0434d68e36artem (const char **) &endchar)) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_WARNING (("Key '%s' has invalid UTF-8 string '%s'",
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_set_int (HalProperty *prop, dbus_int32_t value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_if_fail (prop->type == HAL_PROPERTY_TYPE_INT32 ||
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_set_uint64 (HalProperty *prop, dbus_uint64_t value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_if_fail (prop->type == HAL_PROPERTY_TYPE_UINT64 ||
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_set_bool (HalProperty *prop, dbus_bool_t value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_if_fail (prop->type == HAL_PROPERTY_TYPE_BOOLEAN ||
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_set_double (HalProperty *prop, double value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_if_fail (prop->type == HAL_PROPERTY_TYPE_DOUBLE ||
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRLIST, NULL);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_strlist_append (HalProperty *prop, const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRLIST, FALSE);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem prop->v.strlist_value = g_slist_append (prop->v.strlist_value, g_strdup (value));
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_strlist_prepend (HalProperty *prop, const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRLIST, FALSE);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem prop->v.strlist_value = g_slist_prepend (prop->v.strlist_value, g_strdup (value));
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_strlist_remove_elem (HalProperty *prop, guint index)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRLIST, FALSE);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem prop->v.strlist_value = g_slist_delete_link (prop->v.strlist_value, elem);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_strlist_add (HalProperty *prop, const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRLIST, FALSE);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (elem = prop->v.strlist_value; elem != NULL; elem = g_slist_next (elem)) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_property_strlist_remove (HalProperty *prop, const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRLIST, FALSE);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (elem = prop->v.strlist_value, i = 0; elem != NULL; elem = g_slist_next (elem), i++) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRLIST, FALSE);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (elem = prop->v.strlist_value; elem != NULL; elem = g_slist_next (elem)) {