dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / hal / libhal / common / libhal.h
blob7f62feff73dcb45b416ea7da0949e0a106e76933
1 /***************************************************************************
2 * CVSID: $Id$
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 **************************************************************************/
27 #ifndef LIBHAL_H
28 #define LIBHAL_H
30 #include <dbus/dbus.h>
32 #if defined(__cplusplus)
33 extern "C" {
34 #if 0
35 } /* shut up emacs indenting */
36 #endif
37 #endif
39 #if defined(__GNUC__)
40 #define LIBHAL_DEPRECATED __attribute__ ((deprecated))
41 #else
42 #define LIBHAL_DEPRECATED
43 #endif
46 #define LIBHAL_FREE_DBUS_ERROR(_dbus_error_) \
47 do { \
48 if (dbus_error_is_set(_dbus_error_)) \
49 dbus_error_free (_dbus_error_); \
50 } while (0)
53 /**
54 * LIBHAL_CHECK_LIBHALCONTEXT:
55 * @_ctx_: the context
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_) \
61 do { \
62 if (_ctx_ == NULL) { \
63 fprintf (stderr, \
64 "%s %d : LibHalContext *ctx is NULL\n", \
65 __FILE__, __LINE__); \
66 return _ret_; \
67 } \
68 } while(0)
70 /**
71 * LibHalPropertyType:
73 * Possible types for properties on hal device objects
75 typedef enum {
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'))
99 } LibHalPropertyType;
102 typedef struct LibHalContext_s LibHalContext;
104 /**
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);
115 /**
116 * LibHalDeviceAdded:
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,
123 const char *udi);
125 /**
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,
133 const char *udi);
135 /**
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,
145 const char *udi,
146 const char *capability);
148 /**
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,
158 const char *udi,
159 const char *capability);
161 /**
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,
172 const char *udi,
173 const char *key,
174 dbus_bool_t is_removed,
175 dbus_bool_t is_added);
177 /**
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,
187 const char *udi,
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,
251 const char *udi,
252 const char *key,
253 DBusError *error);
255 /* Get the value of a property of type string. */
256 char *libhal_device_get_property_string (LibHalContext *ctx,
257 const char *udi,
258 const char *key,
259 DBusError *error);
261 /* Get the value of a property of type signed integer. */
262 dbus_int32_t libhal_device_get_property_int (LibHalContext *ctx,
263 const char *udi,
264 const char *key,
265 DBusError *error);
267 /* Get the value of a property of type unsigned integer. */
268 dbus_uint64_t libhal_device_get_property_uint64 (LibHalContext *ctx,
269 const char *udi,
270 const char *key,
271 DBusError *error);
273 /* Get the value of a property of type double. */
274 double libhal_device_get_property_double (LibHalContext *ctx,
275 const char *udi,
276 const char *key,
277 DBusError *error);
279 /* Get the value of a property of type bool. */
280 dbus_bool_t libhal_device_get_property_bool (LibHalContext *ctx,
281 const char *udi,
282 const char *key,
283 DBusError *error);
285 /* Get the value of a property of type string list. */
286 char **libhal_device_get_property_strlist (LibHalContext *ctx,
287 const char *udi,
288 const char *key,
289 DBusError *error);
291 /* Set a property of type string. */
292 dbus_bool_t libhal_device_set_property_string (LibHalContext *ctx,
293 const char *udi,
294 const char *key,
295 const char *value,
296 DBusError *error);
298 /* Set a property of type signed integer. */
299 dbus_bool_t libhal_device_set_property_int (LibHalContext *ctx,
300 const char *udi,
301 const char *key,
302 dbus_int32_t value,
303 DBusError *error);
305 /* Set a property of type unsigned integer. */
306 dbus_bool_t libhal_device_set_property_uint64 (LibHalContext *ctx,
307 const char *udi,
308 const char *key,
309 dbus_uint64_t value,
310 DBusError *error);
312 /* Set a property of type double. */
313 dbus_bool_t libhal_device_set_property_double (LibHalContext *ctx,
314 const char *udi,
315 const char *key,
316 double value,
317 DBusError *error);
319 /* Set a property of type bool. */
320 dbus_bool_t libhal_device_set_property_bool (LibHalContext *ctx,
321 const char *udi,
322 const char *key,
323 dbus_bool_t value,
324 DBusError *error);
326 /* Append to a property of type strlist. */
327 dbus_bool_t libhal_device_property_strlist_append (LibHalContext *ctx,
328 const char *udi,
329 const char *key,
330 const char *value,
331 DBusError *error);
333 /* Prepend to a property of type strlist. */
334 dbus_bool_t libhal_device_property_strlist_prepend (LibHalContext *ctx,
335 const char *udi,
336 const char *key,
337 const char *value,
338 DBusError *error);
340 /* Remove a specified string from a property of type strlist. */
341 dbus_bool_t libhal_device_property_strlist_remove_index (LibHalContext *ctx,
342 const char *udi,
343 const char *key,
344 unsigned int idx,
345 DBusError *error);
347 /* Remove a specified string from a property of type strlist. */
348 dbus_bool_t libhal_device_property_strlist_remove (LibHalContext *ctx,
349 const char *udi,
350 const char *key,
351 const char *value,
352 DBusError *error);
354 /* Remove a property. */
355 dbus_bool_t libhal_device_remove_property (LibHalContext *ctx,
356 const char *udi,
357 const char *key,
358 DBusError *error);
360 /* Query a property type of a device. */
361 LibHalPropertyType libhal_device_get_property_type (LibHalContext *ctx,
362 const char *udi,
363 const char *key,
364 DBusError *error);
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,
372 const char *key,
373 const char *value);
375 dbus_bool_t libhal_changeset_set_property_int (LibHalChangeSet *changeset,
376 const char *key,
377 dbus_int32_t value);
379 dbus_bool_t libhal_changeset_set_property_uint64 (LibHalChangeSet *changeset,
380 const char *key,
381 dbus_uint64_t value);
383 dbus_bool_t libhal_changeset_set_property_double (LibHalChangeSet *changeset,
384 const char *key,
385 double value);
387 dbus_bool_t libhal_changeset_set_property_bool (LibHalChangeSet *changeset,
388 const char *key,
389 dbus_bool_t value);
391 dbus_bool_t libhal_changeset_set_property_strlist (LibHalChangeSet *changeset,
392 const char *key,
393 const char **value);
395 dbus_bool_t libhal_device_commit_changeset (LibHalContext *ctx,
396 LibHalChangeSet *changeset,
397 DBusError *error);
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,
411 const char *udi,
412 DBusError *error);
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);
442 /**
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,
512 const char *udi,
513 DBusError *error);
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,
520 const char *udi,
521 DBusError *error);
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,
527 DBusError *error);
529 /* Check a set of properties for two devices matches. */
530 dbus_bool_t libhal_device_matches (LibHalContext *ctx,
531 const char *udi1,
532 const char *udi2,
533 const char *property_namespace,
534 DBusError *error);
536 /* Find a device in the GDL where a single string property matches a
537 * given value.
539 char **libhal_manager_find_device_string_match (LibHalContext *ctx,
540 const char *key,
541 const char *value,
542 int *num_devices,
543 DBusError *error);
545 /* Assign a capability to a device. */
546 dbus_bool_t libhal_device_add_capability (LibHalContext *ctx,
547 const char *udi,
548 const char *capability,
549 DBusError *error);
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,
555 const char *udi,
556 const char *capability,
557 DBusError *error);
559 /* Find devices with a given capability. */
560 char **libhal_find_device_by_capability (LibHalContext *ctx,
561 const char *capability,
562 int *num_devices,
563 DBusError *error);
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,
569 DBusError *error);
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,
575 const char *udi,
576 DBusError *error);
578 /* Remove a watch on a device */
579 dbus_bool_t libhal_device_remove_property_watch (LibHalContext *ctx,
580 const char *udi,
581 DBusError *error);
583 /* Take an advisory lock on the device. */
584 dbus_bool_t libhal_device_lock (LibHalContext *ctx,
585 const char *udi,
586 const char *reason_to_lock,
587 char **reason_why_locked,
588 DBusError *error);
590 /* Release an advisory lock on the device. */
591 dbus_bool_t libhal_device_unlock (LibHalContext *ctx,
592 const char *udi,
593 DBusError *error);
595 dbus_bool_t libhal_device_rescan (LibHalContext *ctx,
596 const char *udi,
597 DBusError *error);
599 dbus_bool_t libhal_device_reprobe (LibHalContext *ctx,
600 const char *udi,
601 DBusError *error);
603 /* Emit a condition from a device (for hald helpers only) */
604 dbus_bool_t libhal_device_emit_condition (LibHalContext *ctx,
605 const char *udi,
606 const char *condition_name,
607 const char *condition_details,
608 DBusError *error);
610 /* Claim an interface for a device (for hald helpers only) */
611 dbus_bool_t libhal_device_claim_interface (LibHalContext *ctx,
612 const char *udi,
613 const char *interface_name,
614 const char *introspection_xml,
615 DBusError *error);
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)
623 #endif
625 #endif /* LIBHAL_H */