1 /***************************************************************************
4 * libhal.h : HAL daemon C convenience library headers
6 * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
7 * Copyright (C) 2007 Codethink Ltd. Author Rob Taylor <rob.taylor@codethink.co.uk>
9 * Licensed under the Academic Free License version 2.1
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 **************************************************************************/
30 #include <dbus/dbus.h>
32 #if defined(__cplusplus)
35 } /* shut up emacs indenting */
40 #define LIBHAL_DEPRECATED __attribute__ ((deprecated))
42 #define LIBHAL_DEPRECATED
46 #define LIBHAL_FREE_DBUS_ERROR(_dbus_error_) \
48 if (dbus_error_is_set(_dbus_error_)) \
49 dbus_error_free (_dbus_error_); \
54 * LIBHAL_CHECK_LIBHALCONTEXT:
56 * @_ret_: what to use for return value if context is invalid
58 * Handy macro for checking whether a context is valid.
60 #define LIBHAL_CHECK_LIBHALCONTEXT(_ctx_, _ret_) \
62 if (_ctx_ == NULL) { \
64 "%s %d : LibHalContext *ctx is NULL\n", \
65 __FILE__, __LINE__); \
73 * Possible types for properties on hal device objects
76 /** Used to report error condition */
77 LIBHAL_PROPERTY_TYPE_INVALID
= DBUS_TYPE_INVALID
,
79 /** Type for 32-bit signed integer property */
80 LIBHAL_PROPERTY_TYPE_INT32
= DBUS_TYPE_INT32
,
82 /** Type for 64-bit unsigned integer property */
83 LIBHAL_PROPERTY_TYPE_UINT64
= DBUS_TYPE_UINT64
,
85 /** Type for double precision floating point property */
86 LIBHAL_PROPERTY_TYPE_DOUBLE
= DBUS_TYPE_DOUBLE
,
88 /** Type for boolean property */
89 LIBHAL_PROPERTY_TYPE_BOOLEAN
= DBUS_TYPE_BOOLEAN
,
91 /** Type code marking a D-Bus array type */
92 LIBHAL_PROPERTY_TYPE_ARRAY
= DBUS_TYPE_ARRAY
,
94 /** Type for UTF-8 string property */
95 LIBHAL_PROPERTY_TYPE_STRING
= DBUS_TYPE_STRING
,
97 /** Type for list of UTF-8 strings property */
98 LIBHAL_PROPERTY_TYPE_STRLIST
= ((int) (DBUS_TYPE_STRING
<<8)+('l'))
102 typedef struct LibHalContext_s LibHalContext
;
105 * LibHalIntegrateDBusIntoMainLoop:
106 * @ctx: context for connection to hald
107 * @dbus_connection: DBus connection to use in ctx
109 * Type for function in application code that integrates a
110 * DBusConnection object into its own mainloop.
112 typedef void (*LibHalIntegrateDBusIntoMainLoop
) (LibHalContext
*ctx
,
113 DBusConnection
*dbus_connection
);
117 * @ctx: context for connection to hald
118 * @udi: the Unique Device Id
120 * Type for callback when a device is added.
122 typedef void (*LibHalDeviceAdded
) (LibHalContext
*ctx
,
126 * LibHalDeviceRemoved:
127 * @ctx: context for connection to hald
128 * @udi: the Unique Device Id
130 * Type for callback when a device is removed.
132 typedef void (*LibHalDeviceRemoved
) (LibHalContext
*ctx
,
136 * LibHalDeviceNewCapability:
137 * @ctx: context for connection to hald
138 * @udi: the Unique Device Id
139 * @capability: capability of the device
141 * Type for callback when a device gains a new capability.
144 typedef void (*LibHalDeviceNewCapability
) (LibHalContext
*ctx
,
146 const char *capability
);
149 * LibHalDeviceLostCapability:
150 * @ctx: context for connection to hald
151 * @udi: the Unique Device Id
152 * @capability: capability of the device
154 * Type for callback when a device loses a capability.
157 typedef void (*LibHalDeviceLostCapability
) (LibHalContext
*ctx
,
159 const char *capability
);
162 * LibHalDevicePropertyModified:
163 * @ctx: context for connection to hald
164 * @udi: the Unique Device Id
165 * @key: name of the property that has changed
166 * @is_removed: whether or not property was removed
167 * @is_added: whether or not property was added
169 * Type for callback when a property of a device changes.
171 typedef void (*LibHalDevicePropertyModified
) (LibHalContext
*ctx
,
174 dbus_bool_t is_removed
,
175 dbus_bool_t is_added
);
178 * LibHalDeviceCondition:
179 * @ctx: context for connection to hald
180 * @udi: the Unique Device Id
181 * @condition_name: name of the condition, e.g. ProcessorOverheating. Consult the HAL spec for details
182 * @condition_detail: detail of condition
184 * Type for callback when a non-continuous condition occurs on a device.
186 typedef void (*LibHalDeviceCondition
) (LibHalContext
*ctx
,
188 const char *condition_name
,
189 const char *condition_detail
);
192 /* Create a new context for a connection with hald */
193 LibHalContext
*libhal_ctx_new (void);
195 /* Enable or disable caching */
196 dbus_bool_t
libhal_ctx_set_cache (LibHalContext
*ctx
, dbus_bool_t use_cache
);
198 /* Set DBus connection to use to talk to hald. */
199 dbus_bool_t
libhal_ctx_set_dbus_connection (LibHalContext
*ctx
, DBusConnection
*conn
);
201 /* Get DBus connection to use to talk to hald. */
202 DBusConnection
*libhal_ctx_get_dbus_connection (LibHalContext
*ctx
);
204 /* Set user data for the context */
205 dbus_bool_t
libhal_ctx_set_user_data (LibHalContext
*ctx
, void *user_data
);
207 /* Get user data for the context */
208 void* libhal_ctx_get_user_data (LibHalContext
*ctx
);
210 /* Set the callback for when a device is added */
211 dbus_bool_t
libhal_ctx_set_device_added (LibHalContext
*ctx
, LibHalDeviceAdded callback
);
213 /* Set the callback for when a device is removed */
214 dbus_bool_t
libhal_ctx_set_device_removed (LibHalContext
*ctx
, LibHalDeviceRemoved callback
);
216 /* Set the callback for when a device gains a new capability */
217 dbus_bool_t
libhal_ctx_set_device_new_capability (LibHalContext
*ctx
, LibHalDeviceNewCapability callback
);
219 /* Set the callback for when a device loses a capability */
220 dbus_bool_t
libhal_ctx_set_device_lost_capability (LibHalContext
*ctx
, LibHalDeviceLostCapability callback
);
222 /* Set the callback for when a property is modified on a device */
223 dbus_bool_t
libhal_ctx_set_device_property_modified (LibHalContext
*ctx
, LibHalDevicePropertyModified callback
);
225 /* Set the callback for when a device emits a condition */
226 dbus_bool_t
libhal_ctx_set_device_condition (LibHalContext
*ctx
, LibHalDeviceCondition callback
);
228 /* Initialize the connection to hald */
229 dbus_bool_t
libhal_ctx_init (LibHalContext
*ctx
, DBusError
*error
);
231 /* Shut down a connection to hald */
232 dbus_bool_t
libhal_ctx_shutdown (LibHalContext
*ctx
, DBusError
*error
);
234 /* Free a LibHalContext resource */
235 dbus_bool_t
libhal_ctx_free (LibHalContext
*ctx
);
237 /* Create an already initialized connection to hald */
238 LibHalContext
*libhal_ctx_init_direct (DBusError
*error
);
240 /* Get all devices in the Global Device List (GDL). */
241 char **libhal_get_all_devices (LibHalContext
*ctx
, int *num_devices
, DBusError
*error
);
243 /* Determine if a device exists. */
244 dbus_bool_t
libhal_device_exists (LibHalContext
*ctx
, const char *udi
, DBusError
*error
);
246 /* Print a device to stdout; useful for debugging. */
247 dbus_bool_t
libhal_device_print (LibHalContext
*ctx
, const char *udi
, DBusError
*error
);
249 /* Determine if a property on a device exists. */
250 dbus_bool_t
libhal_device_property_exists (LibHalContext
*ctx
,
255 /* Get the value of a property of type string. */
256 char *libhal_device_get_property_string (LibHalContext
*ctx
,
261 /* Get the value of a property of type signed integer. */
262 dbus_int32_t
libhal_device_get_property_int (LibHalContext
*ctx
,
267 /* Get the value of a property of type unsigned integer. */
268 dbus_uint64_t
libhal_device_get_property_uint64 (LibHalContext
*ctx
,
273 /* Get the value of a property of type double. */
274 double libhal_device_get_property_double (LibHalContext
*ctx
,
279 /* Get the value of a property of type bool. */
280 dbus_bool_t
libhal_device_get_property_bool (LibHalContext
*ctx
,
285 /* Get the value of a property of type string list. */
286 char **libhal_device_get_property_strlist (LibHalContext
*ctx
,
291 /* Set a property of type string. */
292 dbus_bool_t
libhal_device_set_property_string (LibHalContext
*ctx
,
298 /* Set a property of type signed integer. */
299 dbus_bool_t
libhal_device_set_property_int (LibHalContext
*ctx
,
305 /* Set a property of type unsigned integer. */
306 dbus_bool_t
libhal_device_set_property_uint64 (LibHalContext
*ctx
,
312 /* Set a property of type double. */
313 dbus_bool_t
libhal_device_set_property_double (LibHalContext
*ctx
,
319 /* Set a property of type bool. */
320 dbus_bool_t
libhal_device_set_property_bool (LibHalContext
*ctx
,
326 /* Append to a property of type strlist. */
327 dbus_bool_t
libhal_device_property_strlist_append (LibHalContext
*ctx
,
333 /* Prepend to a property of type strlist. */
334 dbus_bool_t
libhal_device_property_strlist_prepend (LibHalContext
*ctx
,
340 /* Remove a specified string from a property of type strlist. */
341 dbus_bool_t
libhal_device_property_strlist_remove_index (LibHalContext
*ctx
,
347 /* Remove a specified string from a property of type strlist. */
348 dbus_bool_t
libhal_device_property_strlist_remove (LibHalContext
*ctx
,
354 /* Remove a property. */
355 dbus_bool_t
libhal_device_remove_property (LibHalContext
*ctx
,
360 /* Query a property type of a device. */
361 LibHalPropertyType
libhal_device_get_property_type (LibHalContext
*ctx
,
366 struct LibHalChangeSet_s
;
367 typedef struct LibHalChangeSet_s LibHalChangeSet
;
369 LibHalChangeSet
*libhal_device_new_changeset (const char *udi
);
371 dbus_bool_t
libhal_changeset_set_property_string (LibHalChangeSet
*changeset
,
375 dbus_bool_t
libhal_changeset_set_property_int (LibHalChangeSet
*changeset
,
379 dbus_bool_t
libhal_changeset_set_property_uint64 (LibHalChangeSet
*changeset
,
381 dbus_uint64_t value
);
383 dbus_bool_t
libhal_changeset_set_property_double (LibHalChangeSet
*changeset
,
387 dbus_bool_t
libhal_changeset_set_property_bool (LibHalChangeSet
*changeset
,
391 dbus_bool_t
libhal_changeset_set_property_strlist (LibHalChangeSet
*changeset
,
395 dbus_bool_t
libhal_device_commit_changeset (LibHalContext
*ctx
,
396 LibHalChangeSet
*changeset
,
399 void libhal_device_free_changeset (LibHalChangeSet
*changeset
);
402 struct LibHalProperty_s
;
403 typedef struct LibHalProperty_s LibHalProperty
;
405 struct LibHalPropertySet_s
;
406 typedef struct LibHalPropertySet_s LibHalPropertySet
;
409 /* Retrieve all the properties on a device. */
410 LibHalPropertySet
*libhal_device_get_all_properties (LibHalContext
*ctx
,
414 /* Free a property set earlier obtained with libhal_device_get_all_properties(). */
415 void libhal_free_property_set (LibHalPropertySet
*set
);
417 /* Get the number of properties in a property set. */
418 unsigned int libhal_property_set_get_num_elems (LibHalPropertySet
*set
);
420 /* Get type of property. */
421 LibHalPropertyType
libhal_ps_get_type (const LibHalPropertySet
*set
, const char *key
);
423 /* Get the value of a property of type string. */
424 const char *libhal_ps_get_string (const LibHalPropertySet
*set
, const char *key
);
426 /* Get the value of a property of type signed integer. */
427 dbus_int32_t
libhal_ps_get_int32 (const LibHalPropertySet
*set
, const char *key
);
429 /* Get the value of a property of type unsigned integer. */
430 dbus_uint64_t
libhal_ps_get_uint64 (const LibHalPropertySet
*set
, const char *key
);
432 /* Get the value of a property of type double. */
433 double libhal_ps_get_double (const LibHalPropertySet
*set
, const char *key
);
435 /* Get the value of a property of type bool. */
436 dbus_bool_t
libhal_ps_get_bool (const LibHalPropertySet
*set
, const char *key
);
438 /* Get the value of a property of type string list. */
439 const char * const *libhal_ps_get_strlist (const LibHalPropertySet
*set
, const char *key
);
443 * LibHalPropertySetIterator:
445 * Iterator for inspecting all properties. Do not access any members;
446 * use the libhal_psi_* family of functions instead.
448 struct LibHalPropertySetIterator_s
{
449 LibHalPropertySet
*set
; /**< Property set we are iterating over */
450 unsigned int idx
; /**< Index into current element */
451 LibHalProperty
*cur_prop
; /**< Current property being visited */
452 void *reservered0
; /**< Reserved for future use */
453 void *reservered1
; /**< Reserved for future use */
457 typedef struct LibHalPropertySetIterator_s LibHalPropertySetIterator
;
459 /* Initialize a property set iterator. */
460 void libhal_psi_init (LibHalPropertySetIterator
*iter
, LibHalPropertySet
*set
);
462 /* Determine whether there are more properties to iterate over */
463 dbus_bool_t
libhal_psi_has_more (LibHalPropertySetIterator
*iter
);
465 /* Advance iterator to next property. */
466 void libhal_psi_next (LibHalPropertySetIterator
*iter
);
468 /* Get type of property. */
469 LibHalPropertyType
libhal_psi_get_type (LibHalPropertySetIterator
*iter
);
471 /* Get the key of a property. */
472 char *libhal_psi_get_key (LibHalPropertySetIterator
*iter
);
474 /* Get the value of a property of type string. */
475 char *libhal_psi_get_string (LibHalPropertySetIterator
*iter
);
477 /* Get the value of a property of type signed integer. */
478 dbus_int32_t
libhal_psi_get_int (LibHalPropertySetIterator
*iter
);
480 /* Get the value of a property of type unsigned integer. */
481 dbus_uint64_t
libhal_psi_get_uint64 (LibHalPropertySetIterator
*iter
);
483 /* Get the value of a property of type double. */
484 double libhal_psi_get_double (LibHalPropertySetIterator
*iter
);
486 /* Get the value of a property of type bool. */
487 dbus_bool_t
libhal_psi_get_bool (LibHalPropertySetIterator
*iter
);
489 /* Get the value of a property of type string list. */
490 char **libhal_psi_get_strlist (LibHalPropertySetIterator
*iter
);
492 /* Get the length of an array of strings */
493 unsigned int libhal_string_array_length (char **str_array
);
495 /* Frees a NULL-terminated array of strings. If passed NULL, does nothing. */
496 void libhal_free_string_array (char **str_array
);
498 /* Frees a nul-terminated string */
499 void libhal_free_string (char *str
);
501 /* Create a new device object which will be hidden from applications
502 * until the CommitToGdl(), ie. libhal_device_commit_to_gdl(), method is called.
504 char *libhal_new_device (LibHalContext
*ctx
, DBusError
*error
);
506 /* When a hidden device has been built using the NewDevice method, ie.
507 * libhal_new_device(), and the org.freedesktop.Hal.Device interface
508 * this function will commit it to the global device list.
510 dbus_bool_t
libhal_device_commit_to_gdl (LibHalContext
*ctx
,
511 const char *temp_udi
,
515 /* This method can be invoked when a device is removed. The HAL daemon
516 * will shut down the device. Note that the device may still be in the device
517 * list if the Persistent property is set to true.
519 dbus_bool_t
libhal_remove_device (LibHalContext
*ctx
,
523 /* Merge properties from one device to another. */
524 dbus_bool_t
libhal_merge_properties (LibHalContext
*ctx
,
525 const char *target_udi
,
526 const char *source_udi
,
529 /* Check a set of properties for two devices matches. */
530 dbus_bool_t
libhal_device_matches (LibHalContext
*ctx
,
533 const char *property_namespace
,
536 /* Find a device in the GDL where a single string property matches a
539 char **libhal_manager_find_device_string_match (LibHalContext
*ctx
,
545 /* Assign a capability to a device. */
546 dbus_bool_t
libhal_device_add_capability (LibHalContext
*ctx
,
548 const char *capability
,
551 /* Check if a device has a capability. The result is undefined if the
552 * device doesn't exist.
554 dbus_bool_t
libhal_device_query_capability (LibHalContext
*ctx
,
556 const char *capability
,
559 /* Find devices with a given capability. */
560 char **libhal_find_device_by_capability (LibHalContext
*ctx
,
561 const char *capability
,
565 /* Watch all devices, ie. the device_property_changed callback is
566 * invoked when the properties on any device changes.
568 dbus_bool_t
libhal_device_property_watch_all (LibHalContext
*ctx
,
571 /* Add a watch on a device, so the device_property_changed callback is
572 * invoked when the properties on the given device changes.
574 dbus_bool_t
libhal_device_add_property_watch (LibHalContext
*ctx
,
578 /* Remove a watch on a device */
579 dbus_bool_t
libhal_device_remove_property_watch (LibHalContext
*ctx
,
583 /* Take an advisory lock on the device. */
584 dbus_bool_t
libhal_device_lock (LibHalContext
*ctx
,
586 const char *reason_to_lock
,
587 char **reason_why_locked
,
590 /* Release an advisory lock on the device. */
591 dbus_bool_t
libhal_device_unlock (LibHalContext
*ctx
,
595 dbus_bool_t
libhal_device_rescan (LibHalContext
*ctx
,
599 dbus_bool_t
libhal_device_reprobe (LibHalContext
*ctx
,
603 /* Emit a condition from a device (for hald helpers only) */
604 dbus_bool_t
libhal_device_emit_condition (LibHalContext
*ctx
,
606 const char *condition_name
,
607 const char *condition_details
,
610 /* Claim an interface for a device (for hald helpers only) */
611 dbus_bool_t
libhal_device_claim_interface (LibHalContext
*ctx
,
613 const char *interface_name
,
614 const char *introspection_xml
,
617 /* hald waits for all addons to call this function before announcing the addon (for hald helpers only) */
618 dbus_bool_t
libhal_device_addon_is_ready (LibHalContext
*ctx
, const char *udi
, DBusError
*error
);
621 #if defined(__cplusplus)
625 #endif /* LIBHAL_H */