/***************************************************************************
* CVSID: $Id$
*
* libhal.c : HAL daemon C convenience library
*
* Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
* Copyright (C) 2007 Codethink Ltd. Author Rob Taylor <rob.taylor@codethink.co.uk>
*
* Licensed under the Academic Free License version 2.1
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libhal.h"
#ifdef ENABLE_NLS
# include <libintl.h>
# ifdef gettext_noop
# else
# endif
#else
/* Stubs that do something close enough. */
# define _(String)
#endif
/**
* LIBHAL_CHECK_PARAM_VALID:
* @_param_: the prameter to check for
* @_name_: the name of the prameter (for debug output)
* @_ret_: what to use for return value if the prameter is NULL
*
* Handy macro for checking whether a parameter is valid and not NULL.
*/
do { \
"%s %d : invalid parameter. %s is NULL.\n", \
return _ret_; \
} \
} while(0)
static dbus_bool_t libhal_property_fill_value_from_variant (LibHalProperty *p, DBusMessageIter *var_iter);
/**
* libhal_free_string_array:
* @str_array: the array to be freed
*
* Frees a NULL-terminated array of strings. If passed NULL, does nothing.
*/
void
{
int i;
}
}
}
/**
* libhal_get_string_array_from_iter:
* @iter: the message iterator to extract the strings from
* @num_elements: pointer to an integer where to store number of elements (can be NULL)
*
* Creates a NULL terminated array of strings from a dbus message iterator.
*
* Returns: pointer to the string array
*/
static char **
{
int count;
char **buffer;
count = 0;
goto oom;
const char *value;
char *str;
goto oom;
}
goto oom;
count++;
}
if ((count % 8) == 0) {
goto oom;
}
if (num_elements != NULL)
*num_elements = count;
return buffer;
oom:
return NULL;
}
/**
* libhal_free_string:
* @str: the nul-terminated sting to free
*
* Used to free strings returned by libhal.
*/
void
{
}
}
/**
* LibHalPropertySet:
*
* Represents a set of properties. Opaque; use the
* libhal_property_set_*() family of functions to access it.
*/
struct LibHalPropertySet_s {
/**< Pointer to first property or NULL
* if there are no properties */
};
/**
* LibHalProperty:
*
* Represents a property. Opaque.
*/
struct LibHalProperty_s {
/** Possible values of the property */
union {
/**< 32-bit signed integer */
/**< 64-bit unsigned integer */
/**< Truth value */
} v;
* the last */
};
/**
* LibHalContext:
*
* Context for connection to the HAL daemon. Opaque, use the
* libhal_ctx_*() family of functions to access it.
*/
struct LibHalContext_s {
/** Device added */
/** Device removed */
/** Device got a new capability */
/** Device got a new capability */
/** A property of a device changed */
/** A non-continous event on the device occured */
};
/**
* libhal_ctx_set_user_data:
* @ctx: the context for the connection to hald
* @user_data: user data
*
* Set user data for the context.
*
* Returns: TRUE if user data was successfully set, FALSE if otherwise
*/
{
return TRUE;
}
/**
* libhal_ctx_get_user_data:
* @ctx: the context for the connection to hald
*
* Get user data for the context.
*
* Returns: opaque pointer stored through libhal_ctx_set_user_data() or NULL if not set.
*/
void*
{
}
/**
* libhal_property_fill_value_from_variant:
* @p: the property to fill in
* @var_iter: variant iterator to extract the value from
*
* Fills in the value for the LibHalProperty given a variant iterator.
*
* Returns: Whether the value was put in.
*/
static dbus_bool_t
{
switch (p->type) {
case DBUS_TYPE_ARRAY:
return FALSE;
break;
case DBUS_TYPE_STRING:
{
const char *v;
return FALSE;
break;
}
case DBUS_TYPE_INT32:
{
dbus_int32_t v;
p->v.int_value = v;
break;
}
case DBUS_TYPE_UINT64:
{
p->v.uint64_value = v;
break;
}
case DBUS_TYPE_DOUBLE:
{
double v;
p->v.double_value = v;
break;
}
case DBUS_TYPE_BOOLEAN:
{
double v;
p->v.double_value = v;
break;
}
default:
/** @todo report error */
break;
}
return TRUE;
}
/**
* libhal_device_get_all_properties:
* @ctx: the context for the connection to hald
* @udi: the Unique id of device
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Retrieve all the properties on a device.
*
* Returns: An object represent all properties. Must be freed with libhal_free_property_set().
*/
{
"org.freedesktop.Hal.Device",
"GetAllProperties");
"%s %d : Couldn't allocate D-BUS message\n",
return NULL;
}
message, -1,
&_error);
"%s %d : %s\n",
return NULL;
}
return NULL;
}
goto oom;
/*
result->properties = malloc(sizeof(LibHalProperty)*result->num_properties);
if( result->properties==NULL )
{
/// @todo cleanup
return NULL;
}
*/
result->num_properties = 0;
return NULL;
}
{
const char *key;
LibHalProperty *p;
p = malloc (sizeof (LibHalProperty));
if (p == NULL)
goto oom;
if (result->num_properties == 0)
result->properties_head = p;
p_last = p;
goto oom;
result->num_properties++;
if(!libhal_property_fill_value_from_variant (p, &var_iter))
goto oom;
}
return result;
oom:
"%s %d : error allocating memory\n",
/** @todo FIXME cleanup */
return NULL;
}
/**
* libhal_free_property_set:
* @set: property-set to free
*
* Free a property set earlier obtained with libhal_device_get_all_properties().
*/
void
{
LibHalProperty *p;
LibHalProperty *q;
return;
if (p->type == DBUS_TYPE_STRING)
if (p->type == LIBHAL_PROPERTY_TYPE_STRLIST)
q = p->next;
free (p);
}
}
/**
* libhal_property_set_get_num_elems:
* @set: property set to consider
*
* Get the number of properties in a property set.
*
* Returns: number of properties in given property set
*/
unsigned int
{
unsigned int num_elems;
LibHalProperty *p;
return 0;
num_elems = 0;
num_elems++;
return num_elems;
}
static LibHalProperty *
{
LibHalProperty *p;
return p;
return NULL;
}
/**
* libhal_ps_get_type:
* @set: property set
* @key: name of property to inspect
*
* Get the type of a given property.
*
* Returns: the #LibHalPropertyType of the given property,
* LIBHAL_PROPERTY_TYPE_INVALID if property is not in the set
*/
{
if (p) return p->type;
else return LIBHAL_PROPERTY_TYPE_INVALID;
}
/**
* libhal_ps_get_string:
* @set: property set
* @key: name of property to inspect
*
* Get the value of a property of type string.
*
* Returns: UTF8 nul-terminated string. This pointer is only valid
* until libhal_free_property_set() is invoked on the property set
* this property belongs to. NULL if property is not in the set or not a string
*/
const char *
{
LibHalProperty *p;
if (p && p->type == LIBHAL_PROPERTY_TYPE_STRING)
return p->v.str_value;
else return NULL;
}
/**
* libhal_ps_get_int:
* @set: property set
* @key: name of property to inspect
*
* Get the value of a property of type signed integer.
*
* Returns: property value (32-bit signed integer)
*/
{
LibHalProperty *p;
if (p && p->type == LIBHAL_PROPERTY_TYPE_INT32)
return p->v.int_value;
else return 0;
}
/**
* libhal_ps_get_uint64:
* @set: property set
* @key: name of property to inspect
*
* Get the value of a property of type unsigned integer.
*
* Returns: property value (64-bit unsigned integer)
*/
{
LibHalProperty *p;
if (p && p->type == LIBHAL_PROPERTY_TYPE_UINT64)
return p->v.uint64_value;
else return 0;
}
/**
* libhal_ps_get_double:
* @set: property set
* @key: name of property to inspect
*
* Get the value of a property of type double.
*
* Returns: property value (IEEE754 double precision float)
*/
double
{
LibHalProperty *p;
if (p && p->type == LIBHAL_PROPERTY_TYPE_DOUBLE)
return p->v.double_value;
else return 0.0;
}
/**
* libhal_ps_get_bool:
* @set: property set
* @key: name of property to inspect
*
* Get the value of a property of type bool.
*
* Returns: property value (bool)
*/
{
LibHalProperty *p;
if (p && p->type == LIBHAL_PROPERTY_TYPE_BOOLEAN)
return p->v.bool_value;
else return FALSE;
}
/**
* libhal_ps_get_strlist:
* @set: property set
* @key: name of property to inspect
*
* Get the value of a property of type string list.
*
* Returns: pointer to array of strings, this is owned by the property set
*/
const char *const *
{
LibHalProperty *p;
if (p && p->type == LIBHAL_PROPERTY_TYPE_STRLIST)
return (const char *const *) p->v.strlist_value;
else return NULL;
}
/**
* libhal_psi_init:
* @iter: iterator object
* @set: property set to iterate over
*
* Initialize a property set iterator.
*
*/
void
{
return;
}
/**
* libhal_psi_has_more:
* @iter: iterator object
*
* Determine whether there are more properties to iterate over.
*
* Returns: TRUE if there are more properties, FALSE otherwise.
*/
{
}
/**
* libhal_psi_next:
* @iter: iterator object
*
* Advance iterator to next property.
*/
void
{
}
/**
* libhal_psi_get_type:
* @iter: iterator object
*
* Get type of property.
*
* Returns: the property type at the iterator's position
*/
{
}
/**
* libhal_psi_get_key:
* @iter: iterator object
*
* Get the key of a property.
*
* Returns: ASCII nul-terminated string. This pointer is only valid
* until libhal_free_property_set() is invoked on the property set
* this property belongs to.
*/
char *
{
}
/**
* libhal_psi_get_string:
* @iter: iterator object
*
* Get the value of a property of type string.
*
* Returns: UTF8 nul-terminated string. This pointer is only valid
* until libhal_free_property_set() is invoked on the property set
* this property belongs to.
*/
char *
{
}
/**
* libhal_psi_get_int:
* @iter: iterator object
*
* Get the value of a property of type signed integer.
*
* Returns: property value (32-bit signed integer)
*/
{
}
/**
* libhal_psi_get_uint64:
* @iter: iterator object
*
* Get the value of a property of type unsigned integer.
*
* Returns: property value (64-bit unsigned integer)
*/
{
}
/**
* libhal_psi_get_double:
* @iter: iterator object
*
* Get the value of a property of type double.
*
* Returns: property value (IEEE754 double precision float)
*/
double
{
}
/**
* libhal_psi_get_bool:
* @iter: iterator object
*
* Get the value of a property of type bool.
*
* Returns: property value (bool)
*/
{
}
/**
* libhal_psi_get_strlist:
* @iter: iterator object
*
* Get the value of a property of type string list.
*
* Returns: pointer to array of strings
*/
char **
{
}
static DBusHandlerResult
{
const char *object_path;
if (ctx->is_shutdown)
dbus_error_init (&error);
/*printf("*** in filter_func, object_path=%s\n", object_path);*/
"DeviceAdded")) {
char *udi;
}
} else {
}
char *udi;
}
} else {
}
char *udi;
char *capability;
}
} else {
}
char *condition_name;
char *condition_detail;
}
} else {
}
int i;
char *key;
int num_modifications;
for (i = 0; i < num_modifications; i++) {
added);
}
}
}
}
/* for i18n purposes */
/**
* libhal_get_all_devices:
* @ctx: the context for the connection to hald
* @num_devices: the number of devices will be stored here
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Get all devices in the Global Device List (GDL).
*
* Returns: An array of device identifiers terminated with NULL. It is
* the responsibility of the caller to free with
* libhal_free_string_array(). If an error occurs NULL is returned.
*/
char **
{
char **hal_device_names;
*num_devices = 0;
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"GetAllDevices");
return NULL;
}
return NULL;
}
return NULL;
}
/* now analyze reply */
return NULL;
}
return hal_device_names;
}
/**
* libhal_device_get_property_type:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Query a property type of a device.
*
* Returns: A LibHalPropertyType. LIBHAL_PROPERTY_TYPE_INVALID is
* return if the property doesn't exist.
*/
libhal_device_get_property_type (LibHalContext *ctx, const char *udi, const char *key, DBusError *error)
{
int type;
"org.freedesktop.Hal.Device",
"GetPropertyType");
return LIBHAL_PROPERTY_TYPE_INVALID;
}
message, -1,
&_error);
return LIBHAL_PROPERTY_TYPE_INVALID;
}
return LIBHAL_PROPERTY_TYPE_INVALID;
}
return type;
}
/**
* libhal_device_get_property_strlist:
* @ctx: the context for the connection to hald
* @udi: unique Device Id
* @key: name of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Get the value of a property of type string list.
*
* Returns: Array of pointers to UTF8 nul-terminated strings
* terminated by NULL. The caller is responsible for freeing this
* string array with the function libhal_free_string_array(). Returns
* NULL if the property didn't exist or we are OOM
*/
char **
libhal_device_get_property_strlist (LibHalContext *ctx, const char *udi, const char *key, DBusError *error)
{
char **our_strings;
"org.freedesktop.Hal.Device",
"GetPropertyStringList");
"%s %d : Couldn't allocate D-BUS message\n",
return NULL;
}
message, -1,
&_error);
return NULL;
}
return NULL;
}
/* now analyse reply */
return NULL;
}
return our_strings;
}
/**
* libhal_device_get_property_string:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: the name of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Get the value of a property of type string.
*
* Returns: UTF8 nul-terminated string. The caller is responsible for
* freeing this string with the function libhal_free_string(). Returns
* NULL if the property didn't exist or we are OOM.
*/
char *
{
char *value;
char *dbus_str;
"org.freedesktop.Hal.Device",
"GetPropertyString");
"%s %d : Couldn't allocate D-BUS message\n",
return NULL;
}
message, -1,
&_error);
return NULL;
}
return NULL;
}
/* now analyze reply */
if (dbus_message_iter_get_arg_type (&reply_iter) !=
return NULL;
}
/** @todo FIXME cleanup */
return NULL;
}
return value;
}
/**
* libhal_device_get_property_int:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Get the value of a property of type integer.
*
* Returns: Property value (32-bit signed integer)
*/
{
"org.freedesktop.Hal.Device",
"GetPropertyInteger");
"%s %d : Couldn't allocate D-BUS message\n",
return -1;
}
message, -1,
&_error);
return -1;
}
return -1;
}
/* now analyze reply */
if (dbus_message_iter_get_arg_type (&reply_iter) !=
"%s %d : property '%s' for device '%s' is not "
udi);
return -1;
}
return value;
}
/**
* libhal_device_get_property_uint64:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Get the value of a property of type signed integer.
*
* Returns: Property value (64-bit unsigned integer)
*/
{
"org.freedesktop.Hal.Device",
"GetPropertyInteger");
"%s %d : Couldn't allocate D-BUS message\n",
return -1;
}
message, -1,
&_error);
return -1;
}
return -1;
}
/* now analyze reply */
if (dbus_message_iter_get_arg_type (&reply_iter) !=
"%s %d : property '%s' for device '%s' is not "
udi);
return -1;
}
return value;
}
/**
* libhal_device_get_property_double:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Get the value of a property of type double.
*
* Returns: Property value (IEEE754 double precision float)
*/
double
{
double value;
"org.freedesktop.Hal.Device",
"GetPropertyDouble");
"%s %d : Couldn't allocate D-BUS message\n",
return -1.0f;
}
message, -1,
&_error);
return -1.0f;
}
return -1.0f;
}
/* now analyze reply */
if (dbus_message_iter_get_arg_type (&reply_iter) !=
"%s %d : property '%s' for device '%s' is not "
return -1.0f;
}
return (double) value;
}
/**
* libhal_device_get_property_bool:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Get the value of a property of type bool.
*
* Returns: Property value (boolean)
*/
{
"org.freedesktop.Hal.Device",
"GetPropertyBoolean");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
&_error);
return FALSE;
}
return FALSE;
}
/* now analyze reply */
if (dbus_message_iter_get_arg_type (&reply_iter) !=
"%s %d : property '%s' for device '%s' is not "
return FALSE;
}
return value;
}
/* generic helper */
static dbus_bool_t
const char *udi,
const char *key,
int type,
const char *str_value,
double double_value,
{
/** @todo sanity check incoming params */
switch (type) {
case DBUS_TYPE_INVALID:
method_name = "RemoveProperty";
break;
case DBUS_TYPE_STRING:
method_name = "SetPropertyString";
break;
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT64:
method_name = "SetPropertyInteger";
break;
case DBUS_TYPE_DOUBLE:
method_name = "SetPropertyDouble";
break;
case DBUS_TYPE_BOOLEAN:
method_name = "SetPropertyBoolean";
break;
default:
/* cannot happen; is not callable from outside this file */
break;
}
"org.freedesktop.Hal.Device",
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
switch (type) {
case DBUS_TYPE_STRING:
break;
case DBUS_TYPE_INT32:
break;
case DBUS_TYPE_UINT64:
break;
case DBUS_TYPE_DOUBLE:
break;
case DBUS_TYPE_BOOLEAN:
break;
}
message, -1,
error);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_device_set_property_string:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @value: value of the property; a UTF8 string
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Set a property of type string.
*
* Returns: TRUE if the property was set, FALSE if the device didn't
* exist or the property had a different type.
*/
const char *udi,
const char *key,
const char *value,
{
}
/**
* libhal_device_set_property_int:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @value: value of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Set a property of type signed integer.
*
* Returns: TRUE if the property was set, FALSE if the device didn't
* exist or the property had a different type.
*/
{
}
/**
* libhal_device_set_property_uint64:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @value: value of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Set a property of type unsigned integer.
*
* Returns: TRUE if the property was set, FALSE if the device didn't
* exist or the property had a different type.
*/
{
}
/**
* libhal_device_set_property_double:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @value: value of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Set a property of type double.
*
* Returns: TRUE if the property was set, FALSE if the device didn't
* exist or the property had a different type.
*/
{
}
/**
* libhal_device_set_property_bool:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @value: value of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Set a property of type bool.
*
* Returns: TRUE if the property was set, FALSE if the device didn't
* exist or the property had a different type.
*/
{
}
/**
* libhal_device_remove_property:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Remove a property.
*
* Returns: TRUE if the property was set, FALSE if the device didn't
* exist
*/
{
/* DBUS_TYPE_INVALID means remove */
}
/**
* libhal_device_property_strlist_append:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @value: value to append to property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Append to a property of type strlist.
*
* Returns: TRUE if the value was appended, FALSE if the device didn't
* exist or the property had a different type.
*/
const char *udi,
const char *key,
const char *value,
{
"org.freedesktop.Hal.Device",
"StringListAppend");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_device_property_strlist_prepend:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @value: value to prepend to property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Prepend to a property of type strlist.
*
* Returns: TRUE if the value was prepended, FALSE if the device
* didn't exist or the property had a different type.
*/
const char *udi,
const char *key,
const char *value,
{
"org.freedesktop.Hal.Device",
"StringListPrepend");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_device_property_strlist_remove_index:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @idx: index of string to remove in the strlist
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Remove a specified string from a property of type strlist.
*
* Returns: TRUE if the string was removed, FALSE if the device didn't
* exist or the property had a different type.
*/
const char *udi,
const char *key,
unsigned int idx,
{
"org.freedesktop.Hal.Device",
"StringListRemoveIndex");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_device_property_strlist_remove:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @key: name of the property
* @value: the string to remove
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Remove a specified string from a property of type strlist.
*
* Returns: TRUE if the string was removed, FALSE if the device didn't
* exist or the property had a different type.
*/
const char *udi,
const char *key,
{
"org.freedesktop.Hal.Device",
"StringListRemove");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_device_lock:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @reason_to_lock: a user-presentable reason why the device is locked.
* @reason_why_locked: a pointer to store the reason why the device cannot be locked on failure, or NULL
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Take an advisory lock on the device.
*
* Returns: TRUE if the lock was obtained, FALSE otherwise
*/
const char *udi,
const char *reason_to_lock,
{
if (reason_why_locked != NULL)
udi,
"org.freedesktop.Hal.Device",
"Lock");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
"org.freedesktop.Hal.DeviceAlreadyLocked") == 0) {
if (reason_why_locked != NULL) {
}
}
return FALSE;
}
return FALSE;
return TRUE;
}
/**
* libhal_device_unlock:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Release an advisory lock on the device.
*
* Returns: TRUE if the device was successfully unlocked,
* FALSE otherwise
*/
{
udi,
"org.freedesktop.Hal.Device",
"Unlock");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
return TRUE;
}
/**
* libhal_new_device:
* @ctx: the context for the connection to hald
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Create a new device object which will be hidden from applications
* until the CommitToGdl(), ie. libhal_device_commit_to_gdl(), method
* is called. Note that the program invoking this method needs to run
* with super user privileges.
*
* Returns: Temporary device unique id or NULL if there was a
* problem. This string must be freed by the caller.
*/
char *
{
char *value;
char *dbus_str;
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"NewDevice");
"%s %d : Couldn't allocate D-BUS message\n",
return NULL;
}
message, -1,
error);
return NULL;
}
return NULL;
}
/* now analyze reply */
"%s %d : expected a string in reply to NewDevice\n",
return NULL;
}
}
return value;
}
/**
* libhal_device_commit_to_gdl:
* @ctx: the context for the connection to hald
* @temp_udi: the temporary unique device id as returned by libhal_new_device()
* @udi: the new unique device id.
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* When a hidden device has been built using the NewDevice method,
* ie. libhal_new_device(), and the org.freedesktop.Hal.Device
* interface this function will commit it to the global device list.
*
* This means that the device object will be visible to applications
* and the HAL daemon will possibly attempt to boot the device
* (depending on the property RequireEnable).
*
* Note that the program invoking this method needs to run with super
* user privileges.
*
* Returns: FALSE if the given unique device id is already in use.
*/
{
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"CommitToGdl");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_remove_device:
* @ctx: the context for the connection to hald
* @udi: the Unique device id.
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* This method can be invoked when a device is removed. The HAL daemon
* will shut down the device. Note that the device may still be in the
* device list if the Persistent property is set to true.
*
* Note that the program invoking this method needs to run with super
* user privileges.
*
* Returns: TRUE if the device was removed, FALSE otherwise
*/
{
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"Remove");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_device_exists:
* @ctx: the context for the connection to hald
* @udi: the Unique device id.
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Determine if a device exists.
*
* Returns: TRUE if the device exists
*/
{
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"DeviceExists");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
&_error);
return FALSE;
}
return FALSE;
}
/* now analyze reply */
"%s %d : expected a bool in reply to DeviceExists\n",
return FALSE;
}
return value;
}
/**
* libhal_device_property_exists:
* @ctx: the context for the connection to hald
* @udi: the Unique device id.
* @key: name of the property
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Determine if a property on a device exists.
*
* Returns: TRUE if the device exists, FALSE otherwise
*/
{
"org.freedesktop.Hal.Device",
"PropertyExists");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
&_error);
return FALSE;
}
return FALSE;
}
/* now analyse reply */
return FALSE;
}
return value;
}
/**
* libhal_merge_properties:
* @ctx: the context for the connection to hald
* @target_udi: the Unique device id of target device to merge to
* @source_udi: the Unique device id of device to merge from
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Merge properties from one device to another.
*
* Returns: TRUE if the properties were merged, FALSE otherwise
*/
{
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"MergeProperties");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_device_matches:
* @ctx: the context for the connection to hald
* @udi1: the Unique Device Id for device 1
* @udi2: the Unique Device Id for device 2
* @property_namespace: the namespace for set of devices, e.g. "usb"
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Check a set of properties for two devices matches.
*
* Checks that all properties where keys, starting with a given value
* (namespace), of the first device is in the second device and that
* they got the same value and type.
*
* Note that the other inclusion isn't tested, so there could be
* properties (from the given namespace) in the second device not
* present in the first device.
*
* Returns: TRUE if all properties starting with the given namespace
* parameter from one device is in the other and have the same value.
*/
{
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"DeviceMatches");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
&_error);
return FALSE;
}
return FALSE;
}
/* now analyse reply */
"%s %d : expected a bool in reply to DeviceMatches\n",
return FALSE;
}
return value;
}
/**
* libhal_device_print:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Print a device to stdout; useful for debugging.
*
* Returns: TRUE if device's information could be obtained, FALSE otherwise
*/
{
int type;
char *key;
return FALSE;
libhal_psi_next (&i)) {
type = libhal_psi_get_type (&i);
key = libhal_psi_get_key (&i);
switch (type) {
libhal_psi_get_string (&i));
break;
libhal_psi_get_int (&i),
libhal_psi_get_int (&i));
break;
(long long unsigned int) libhal_psi_get_uint64 (&i),
(long long unsigned int) libhal_psi_get_uint64 (&i));
break;
(libhal_psi_get_bool (&i) ? "true" :
"false"));
break;
libhal_psi_get_double (&i));
break;
{
unsigned int j;
char **str_list;
str_list = libhal_psi_get_strlist (&i);
printf (", ");
}
printf ("] (string list)\n");
break;
}
default:
break;
}
}
return TRUE;
}
/**
* libhal_manager_find_device_string_match:
* @ctx: the context for the connection to hald
* @key: name of the property
* @value: the value to match
* @num_devices: pointer to store number of devices
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Find a device in the GDL where a single string property matches a
* given value.
*
* Returns: UDI of devices; free with libhal_free_string_array()
*/
char **
const char *key,
{
char **hal_device_names;
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"FindDeviceStringMatch");
"%s %d : Couldn't allocate D-BUS message\n",
return NULL;
}
message, -1,
&_error);
return NULL;
}
return NULL;
}
/* now analyse reply */
return NULL;
}
return hal_device_names;
}
/**
* libhal_device_add_capability:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @capability: the capability name to add
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Assign a capability to a device.
*
* Returns: TRUE if the capability was added, FALSE if the device didn't exist
*/
{
"org.freedesktop.Hal.Device",
"AddCapability");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_device_query_capability:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @capability: the capability name
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Check if a device has a capability. The result is undefined if the
* device doesn't exist.
*
* Returns: TRUE if the device has the capability, otherwise FALSE
*/
libhal_device_query_capability (LibHalContext *ctx, const char *udi, const char *capability, DBusError *error)
{
char **caps;
unsigned int i;
break;
}
}
}
return ret;
}
/**
* libhal_find_device_by_capability:
* @ctx: the context for the connection to hald
* @capability: the capability name
* @num_devices: pointer to store number of devices
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Find devices with a given capability.
*
* Returns: UDI of devices; free with libhal_free_string_array()
*/
char **
{
char **hal_device_names;
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"FindDeviceByCapability");
"%s %d : Couldn't allocate D-BUS message\n",
return NULL;
}
message, -1,
&_error);
return NULL;
}
return NULL;
}
/* now analyse reply */
return NULL;
}
return hal_device_names;
}
/**
* libhal_device_property_watch_all:
* @ctx: the context for the connection to hald
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Watch all devices, ie. the device_property_changed callback is
* invoked when the properties on any device changes.
*
* Returns: TRUE only if the operation succeeded
*/
{
"type='signal',"
"interface='org.freedesktop.Hal.Device',"
"sender='org.freedesktop.Hal'", error);
return FALSE;
}
return TRUE;
}
/**
* libhal_device_add_property_watch:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Add a watch on a device, so the device_property_changed callback is
* invoked when the properties on the given device changes.
*
* The application itself is responsible for deleting the watch, using
* libhal_device_remove_property_watch, if the device is removed.
*
* Returns: TRUE only if the operation succeeded
*/
{
"type='signal',"
"interface='org.freedesktop.Hal.Device',"
"sender='org.freedesktop.Hal'," "path=%s", udi);
return FALSE;
}
return TRUE;
}
/**
* libhal_device_remove_property_watch:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Remove a watch on a device.
*
* Returns: TRUE only if the operation succeeded
*/
{
"type='signal',"
"interface='org.freedesktop.Hal.Device',"
"sender='org.freedesktop.Hal'," "path=%s", udi);
return FALSE;
}
return TRUE;
}
/**
* libhal_ctx_new:
*
* Create a new LibHalContext
*
* Returns: a new uninitialized LibHalContext object
*/
libhal_ctx_new (void)
{
if (!libhal_already_initialized_once) {
}
"%s %d : Failed to allocate %d bytes\n",
return NULL;
}
return ctx;
}
/**
* libhal_ctx_set_cache:
* @use_cache: whether or not to use cache
*
* Enable or disable caching. Note: Caching is not actually
* implemented yet.
*
*/
{
return TRUE;
}
/**
* libhal_ctx_set_dbus_connection:
* @ctx: context to set connection for
* @conn: DBus connection to use
*
* Set DBus connection to use to talk to hald.
*
* Returns: TRUE if connection was successfully set, FALSE otherwise
*/
{
return FALSE;
return TRUE;
}
/**
* libhal_ctx_get_dbus_connection:
* @ctx: context to get connection for
*
* Get DBus connection used for talking to hald.
*
* Returns: DBus connection to use or NULL
*/
{
return ctx->connection;
}
/**
* libhal_ctx_init:
* @ctx: Context for connection to hald (D-BUS connection should be set with libhal_ctx_set_dbus_connection)
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Initialize the connection to hald.
*
* Returns: TRUE if initialization succeeds, FALSE otherwise
*/
{
return FALSE;
return FALSE;
}
if (!hald_exists) {
return FALSE;
}
return FALSE;
}
"type='signal',"
"interface='org.freedesktop.Hal.Manager',"
"sender='org.freedesktop.Hal',"
"path='/org/freedesktop/Hal/Manager'", &_error);
return FALSE;
}
return TRUE;
}
/**
* libhal_ctx_init_direct:
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Create an already initialized connection to hald. This function should only be used by HAL helpers.
*
* Returns: A pointer to an already initialized LibHalContext
*/
{
char *hald_addr;
ctx = libhal_ctx_new ();
goto out;
goto out;
}
goto out;
}
out:
return ctx;
}
/**
* libhal_ctx_shutdown:
* @ctx: the context for the connection to hald
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Shut down a connection to hald.
*
* Returns: TRUE if connection successfully shut down, FALSE otherwise
*/
{
/* for some reason dbus_connection_set_exit_on_disconnect doesn't work yet so don't unref */
/*dbus_connection_unref (ctx->connection);*/
} else {
"type='signal',"
"interface='org.freedesktop.Hal.Manager',"
"sender='org.freedesktop.Hal',"
"path='/org/freedesktop/Hal/Manager'", &myerror);
/** @todo clean up */
}
/* TODO: remove other matches */
}
return TRUE;
}
/**
* libhal_ctx_free:
* @ctx: pointer to a LibHalContext
*
* Free a LibHalContext resource.
*
* Returns: TRUE
*/
{
return TRUE;
}
/**
* libhal_ctx_set_device_added:
* @ctx: the context for the connection to hald
* @callback: the function to call when a device is added
*
* Set the callback for when a device is added
*
* Returns: TRUE if callback was successfully set, FALSE otherwise
*/
{
return TRUE;
}
/**
* libhal_ctx_set_device_removed:
* @ctx: the context for the connection to hald
* @callback: the function to call when a device is removed
*
* Set the callback for when a device is removed.
*
* Returns: TRUE if callback was successfully set, FALSE otherwise
*/
{
return TRUE;
}
/**
* libhal_ctx_set_device_new_capability:
* @ctx: the context for the connection to hald
* @callback: the function to call when a device gains a new capability
*
* Set the callback for when a device gains a new capability.
*
* Returns: TRUE if callback was successfully set, FALSE otherwise
*/
{
return TRUE;
}
/**
* libhal_ctx_set_device_lost_capability:
* @ctx: the context for the connection to hald
* @callback: the function to call when a device loses a capability
*
* Set the callback for when a device loses a capability
*
* Returns: TRUE if callback was successfully set, FALSE otherwise
*/
{
return TRUE;
}
/**
* libhal_ctx_set_device_property_modified:
* @ctx: the context for the connection to hald
* @callback: the function to call when a property is modified on a device
*
* Set the callback for when a property is modified on a device.
*
* Returns: TRUE if callback was successfully set, FALSE otherwise
*/
{
return TRUE;
}
/**
* libhal_ctx_set_device_condition:
* @ctx: the context for the connection to hald
* @callback: the function to call when a device emits a condition
*
* Set the callback for when a device emits a condition
*
* Returns: TRUE if callback was successfully set, FALSE otherwise
*/
{
return TRUE;
}
/**
* libhal_string_array_length:
* @str_array: array of strings to consider
*
* Get the length of an array of strings.
*
* Returns: Number of strings in array
*/
unsigned int
{
unsigned int i;
return 0;
;
return i;
}
/**
* libhal_device_rescan:
* @ctx: the context for the connection to hald
* @udi: the Unique id of device
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* TODO document me.
*
* Returns: Whether the operation succeeded
*/
{
"org.freedesktop.Hal.Device",
"Rescan");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
if (dbus_message_iter_get_arg_type (&reply_iter) !=
return FALSE;
}
return result;
}
/**
* libhal_device_reprobe:
* @ctx: the context for the connection to hald
* @udi: the Unique id of device
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* TODO document me.
*
* Returns: Whether the operation succeeded
*/
{
udi,
"org.freedesktop.Hal.Device",
"Reprobe");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
if (dbus_message_iter_get_arg_type (&reply_iter) !=
return FALSE;
}
return result;
}
/**
* libhal_device_emit_condition:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @condition_name: user-readable name of condition
* @condition_details: user-readable details of condition
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Emit a condition from a device. Can only be used from hald helpers.
*
* Returns: TRUE if condition successfully emitted,
* FALSE otherwise
*/
const char *udi,
const char *condition_name,
const char *condition_details,
{
udi,
"org.freedesktop.Hal.Device",
"EmitCondition");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
if (dbus_message_iter_get_arg_type (&reply_iter) !=
return FALSE;
}
return result;
}
/**
* libhal_device_addon_is_ready:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* HAL addon's must call this method when they are done initializing the device object. The HAL
* daemon will wait for all addon's to call this.
*
* Can only be used from hald helpers.
*
* Returns: TRUE if the HAL daemon received the message, FALSE otherwise
*/
{
udi,
"org.freedesktop.Hal.Device",
"AddonIsReady");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
return FALSE;
}
return result;
}
/**
* libhal_device_claim_interface:
* @ctx: the context for the connection to hald
* @udi: the Unique Device Id
* @interface_name: Name of interface to claim, e.g. org.freedesktop.Hal.Device.FoobarKindOfThing
* @introspection_xml: Introspection XML containing what would be inside the interface XML tag
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Claim an interface for a device. All messages to this interface
* will be forwarded to the helper. Can only be used from hald
* helpers.
*
* Returns: TRUE if interface was claimed, FALSE otherwise
*/
const char *udi,
const char *interface_name,
const char *introspection_xml,
{
udi,
"org.freedesktop.Hal.Device",
"ClaimInterface");
"%s %d : Couldn't allocate D-BUS message\n",
return FALSE;
}
message, -1,
error);
return FALSE;
}
return FALSE;
if (dbus_message_iter_get_arg_type (&reply_iter) !=
return FALSE;
}
return result;
}
struct LibHalChangeSetElement_s;
struct LibHalChangeSetElement_s {
char *key;
int change_type;
union {
char *val_str;
double val_double;
char **val_strlist;
} value;
};
struct LibHalChangeSet_s {
char *udi;
};
/**
* libhal_device_new_changeset:
* @udi: unique device identifier
*
* Request a new changeset object. Used for changing multiple properties at once. Useful when
* performance is critical and also for atomically updating several properties.
*
* Returns: A new changeset object or NULL on error
*/
{
goto out;
goto out;
}
out:
return changeset;
}
static void
{
} else {
}
}
/**
* libhal_device_set_property_string:
* @changeset: the changeset
* @key: key of property
* @value: the value to set
*
* Set a property.
*
* Returns: FALSE on OOM
*/
libhal_changeset_set_property_string (LibHalChangeSet *changeset, const char *key, const char *value)
{
goto out;
goto out;
}
goto out;
}
out:
}
/**
* libhal_device_set_property_int:
* @changeset: the changeset
* @key: key of property
* @value: the value to set
*
* Set a property.
*
* Returns: FALSE on OOM
*/
{
goto out;
goto out;
}
out:
}
/**
* libhal_device_set_property_uint64:
* @changeset: the changeset
* @key: key of property
* @value: the value to set
*
* Set a property.
*
* Returns: FALSE on OOM
*/
libhal_changeset_set_property_uint64 (LibHalChangeSet *changeset, const char *key, dbus_uint64_t value)
{
goto out;
goto out;
}
out:
}
/**
* libhal_device_set_property_double:
* @changeset: the changeset
* @key: key of property
* @value: the value to set
*
* Set a property.
*
* Returns: FALSE on OOM
*/
{
goto out;
goto out;
}
out:
}
/**
* libhal_device_set_property_bool:
* @changeset: the changeset
* @key: key of property
* @value: the value to set
*
* Set a property.
*
* Returns: FALSE on OOM
*/
{
goto out;
goto out;
}
out:
}
/**
* libhal_device_set_property_strlist:
* @changeset: the changeset
* @key: key of property
* @value: the value to set - NULL terminated array of strings
*
* Set a property.
*
* Returns: FALSE on OOM
*/
libhal_changeset_set_property_strlist (LibHalChangeSet *changeset, const char *key, const char **value)
{
char **value_copy;
int len;
int i, j;
goto out;
goto out;
}
;
len = i;
if (value_copy == NULL) {
goto out;
}
for (i = 0; i < len; i++) {
if (value_copy[i] == NULL) {
for (j = 0; j < i; j++) {
free (value_copy[j]);
}
free (value_copy);
goto out;
}
}
value_copy[i] = NULL;
out:
}
/**
* libhal_device_commit_changeset:
* @ctx: the context for the connection to hald
* @changeset: the changeset to commit
* @error: pointer to an initialized dbus error object for returning errors or NULL
*
* Commit a changeset to the daemon.
*
* Returns: True if the changeset was committed on the daemon side
*/
{
int i;
return TRUE;
}
"org.freedesktop.Hal.Device",
"SetMultipleProperties");
return FALSE;
}
&sub);
NULL,
&sub2);
switch (elem->change_type) {
break;
}
break;
break;
break;
break;
break;
default:
break;
}
}
message, -1,
&_error);
"%s %d : %s\n",
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
* libhal_device_free_changeset:
* @changeset: the changeset to free
*
* Free a changeset.
*/
void
{
switch (elem->change_type) {
break;
break;
/* explicit fallthrough */
break;
default:
break;
}
}
}