18c2aff776a775d34a4c9893a4c72e0434d68e36artem/***************************************************************************
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * CVSID: $Id$
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * device.c : HalDevice 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 printf ("************* in finalize for udi=%s\n", device->udi);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_slist_foreach (device->properties, (GFunc) hal_property_free, NULL);
8b80e8cb6855118d46f605e91b5ed4ce83417395Lin Guo - Sun Microsystems g_slist_free (device->properties);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->udi = g_strdup_printf ("/org/freedesktop/Hal/devices/temp/%d",
18c2aff776a775d34a4c9893a4c72e0434d68e36artem "HalDevice",
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Merge all properties from source where the key starts with
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * source_namespace and put them onto target replacing source_namespace
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * with target_namespace
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param target Device to put properties onto
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param source Device to retrieve properties from
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param target_namespace Replace source namespace with this namespace
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param source_namespace Source namespace that property keys must match
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* doesn't handle info.capabilities */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* device_property_atomic_update_begin (); */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (iter = source->properties; iter != NULL; iter = iter->next) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* only care about properties that match source namespace */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (strncmp(key, source_namespace, source_ns_len) != 0)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem target_key = g_strdup_printf("%s%s", target_namespace,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* only remove target if it exists with a different type */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem target_type = hal_device_property_get_type (target, key);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (target_type != HAL_PROPERTY_TYPE_INVALID && target_type != type)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* device_property_atomic_update_end (); */
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_merge (HalDevice *target, HalDevice *source)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* device_property_atomic_update_begin (); */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (iter = source->properties; iter != NULL; iter = iter->next) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* handle info.capabilities in a special way */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* only remove target if it exists with a different type */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem target_type = hal_device_property_get_type (target, key);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (target_type != HAL_PROPERTY_TYPE_INVALID && target_type != type)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* device_property_atomic_update_end (); */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem caps = hal_device_property_get_strlist (source, "info.capabilities");
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_matches (HalDevice *device1, HalDevice *device2,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *namespace)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (iter = device1->properties; iter != NULL; iter = iter->next) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artemconst char *
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_set_udi (HalDevice *device, const char *udi)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_add_capability (HalDevice *device, const char *capability)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_device_property_strlist_add (device, "info.capabilities", capability))
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_signal_emit (device, signals[CAPABILITY_ADDED], 0, capability);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_has_capability (HalDevice *device, const char *capability)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem caps = hal_device_property_get_strlist (device, "info.capabilities");
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_has_property (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem return hal_device_property_find (device, key) != NULL;
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_find (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (iter = device->properties; iter != NULL; iter = iter->next) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_to_string (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (iter = device->properties; iter != NULL; iter = iter->next) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_get_type (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (device != NULL, HAL_PROPERTY_TYPE_INVALID);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_return_val_if_fail (key != NULL, HAL_PROPERTY_TYPE_INVALID);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemconst char *
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_get_string (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemconst char *
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_get_as_string (HalDevice *device, const char *key, char *buf, size_t bufsize)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem strncpy (buf, hal_property_get_string (prop), bufsize);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem snprintf (buf, bufsize, "%d", hal_property_get_int (prop));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem snprintf (buf, bufsize, "%llu", (long long unsigned int) hal_property_get_uint64 (prop));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem snprintf (buf, bufsize, "%f", hal_property_get_double (prop));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem strncpy (buf, hal_property_get_bool (prop) ? "true" : "false", bufsize);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* print out as "\tval1\tval2\val3\t" */
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_get_int (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_get_uint64 (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_get_bool (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_get_double (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem return -1.0;
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_set_string (HalDevice *device, const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRING)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* don't bother setting the same value */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_prepend (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_set_int (HalDevice *device, const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_INT32)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* don't bother setting the same value */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_prepend (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_set_uint64 (HalDevice *device, const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_UINT64)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* don't bother setting the same value */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_prepend (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_set_bool (HalDevice *device, const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_BOOLEAN)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* don't bother setting the same value */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_prepend (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_set_double (HalDevice *device, const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_DOUBLE)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* don't bother setting the same value */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_prepend (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_copy_property (HalDevice *from_device, const char *from, HalDevice *to_device, const char *to)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem switch (hal_device_property_get_type (from_device, from)) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem to_device, to, hal_device_property_get_string (from_device, from));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem to_device, to, hal_device_property_get_int (from_device, from));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem to_device, to, hal_device_property_get_uint64 (from_device, from));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem to_device, to, hal_device_property_get_bool (from_device, from));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem to_device, to, hal_device_property_get_double (from_device, from));
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_remove (HalDevice *device, const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_remove (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem fprintf (stderr, "device udi = %s\n", hal_device_get_udi (device));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (iter = device->properties; iter != NULL; iter = iter->next) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem (long long unsigned int) hal_property_get_uint64 (p),
18c2aff776a775d34a4c9893a4c72e0434d68e36artem (long long unsigned int) hal_property_get_uint64 (p));
18c2aff776a775d34a4c9893a4c72e0434d68e36artemtypedef struct {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_signal_handler_disconnect (ai->device, ai->prop_signal_id);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* the property is no longer there */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem ai->prop_signal_id = g_signal_connect (device, "property_changed",
18c2aff776a775d34a4c9893a4c72e0434d68e36artem ai->timeout_id = g_timeout_add (timeout, async_wait_timeout, ai);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_signal_emit (device, signals[CALLOUTS_FINISHED], 0);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Used when giving up on a device, e.g. if no device file appeared
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemconst char *
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_get_strlist_elem (HalDevice *device,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem strlist = hal_device_property_get_strlist (device, key);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem return (const char *) i->data;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_prepend (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_strlist_prepend (HalDevice *device,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_prepend (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_strlist_remove_elem (HalDevice *device,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_prepend (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem device->properties = g_slist_prepend (device->properties, prop);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *value)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* check if property already exists */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_device_property_strlist_is_empty (HalDevice *device,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const char *key)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem strlist = hal_device_property_get_strlist (device, key);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_ERROR (("In hal_device_inc_num_ready_addons for udi=%s but all addons are already ready!",