libhal.h

00001 /***************************************************************************
00002  * CVSID: $Id$
00003  *
00004  * libhal.h : HAL daemon C convenience library headers
00005  *
00006  * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
00007  *
00008  * Licensed under the Academic Free License version 2.1
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  **************************************************************************/
00025 
00026 #ifndef LIBHAL_H
00027 #define LIBHAL_H
00028 
00029 #ifndef DBUS_API_SUBJECT_TO_CHANGE
00030 #define DBUS_API_SUBJECT_TO_CHANGE
00031 #endif
00032 
00033 #include <dbus/dbus.h>
00034 
00035 #if defined(__cplusplus)
00036 extern "C" {
00037 #if 0
00038 } /* shut up emacs indenting */
00039 #endif
00040 #endif
00041 
00043 #define LIBHAL_CHECK_LIBHALCONTEXT(_ctx_, _ret_)                    \
00044     do {                                    \
00045         if (_ctx_ == NULL) {                        \
00046             fprintf (stderr,                    \
00047                  "%s %d : LibHalContext *ctx is NULL\n",    \
00048                  __FILE__, __LINE__);               \
00049             return _ret_;                       \
00050         }                               \
00051     } while(0)
00052 
00053 #define LIBHAL_FREE_DBUS_ERROR(_dbus_error_)        \
00054     do {                        \
00055         if (dbus_error_is_set(_dbus_error_))    \
00056             dbus_error_free (_dbus_error_); \
00057     } while (0)
00058 
00059 
00067 typedef enum {
00069     LIBHAL_PROPERTY_TYPE_INVALID     =    DBUS_TYPE_INVALID,
00070 
00072     LIBHAL_PROPERTY_TYPE_INT32   =    DBUS_TYPE_INT32,
00073 
00075     LIBHAL_PROPERTY_TYPE_UINT64  =    DBUS_TYPE_UINT64,
00076 
00078     LIBHAL_PROPERTY_TYPE_DOUBLE  =    DBUS_TYPE_DOUBLE,
00079 
00081     LIBHAL_PROPERTY_TYPE_BOOLEAN =    DBUS_TYPE_BOOLEAN,
00082 
00084     LIBHAL_PROPERTY_TYPE_STRING  =    DBUS_TYPE_STRING,
00085 
00087     LIBHAL_PROPERTY_TYPE_STRLIST =     ((int) (DBUS_TYPE_STRING<<8)+('l'))
00088 } LibHalPropertyType;
00089 
00090 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00091 typedef struct LibHalContext_s LibHalContext;
00092 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00093 
00100 typedef void (*LibHalIntegrateDBusIntoMainLoop) (LibHalContext *ctx,
00101                          DBusConnection *dbus_connection);
00102 
00108 typedef void (*LibHalDeviceAdded) (LibHalContext *ctx, 
00109                    const char *udi);
00110 
00116 typedef void (*LibHalDeviceRemoved) (LibHalContext *ctx, 
00117                      const char *udi);
00118 
00125 typedef void (*LibHalDeviceNewCapability) (LibHalContext *ctx, 
00126                        const char *udi,
00127                        const char *capability);
00128 
00135 typedef void (*LibHalDeviceLostCapability) (LibHalContext *ctx, 
00136                         const char *udi,
00137                         const char *capability);
00138 
00147 typedef void (*LibHalDevicePropertyModified) (LibHalContext *ctx,
00148                           const char *udi,
00149                           const char *key,
00150                           dbus_bool_t is_removed,
00151                           dbus_bool_t is_added);
00152 
00162 typedef void (*LibHalDeviceCondition) (LibHalContext *ctx,
00163                        const char *udi,
00164                        const char *condition_name,
00165                        const char *condition_detail);
00166 
00167 
00168 /* Create a new context for a connection with hald */
00169 LibHalContext *libhal_ctx_new                          (void);
00170 
00171 /* Enable or disable caching */
00172 dbus_bool_t    libhal_ctx_set_cache                    (LibHalContext *ctx, dbus_bool_t use_cache);
00173 
00174 /* Set DBus connection to use to talk to hald. */
00175 dbus_bool_t    libhal_ctx_set_dbus_connection          (LibHalContext *ctx, DBusConnection *conn);
00176 
00177 /* Set user data for the context */
00178 dbus_bool_t    libhal_ctx_set_user_data                (LibHalContext *ctx, void *user_data);
00179 
00180 /* Get user data for the context */
00181 void*          libhal_ctx_get_user_data                (LibHalContext *ctx);
00182 
00183 /* Set the callback for when a device is added */
00184 dbus_bool_t    libhal_ctx_set_device_added             (LibHalContext *ctx, LibHalDeviceAdded callback);
00185 
00186 /* Set the callback for when a device is removed */
00187 dbus_bool_t    libhal_ctx_set_device_removed           (LibHalContext *ctx, LibHalDeviceRemoved callback);
00188 
00189 /* Set the callback for when a device gains a new capability */
00190 dbus_bool_t    libhal_ctx_set_device_new_capability    (LibHalContext *ctx, LibHalDeviceNewCapability callback);
00191 
00192 /* Set the callback for when a device loses a capability */
00193 dbus_bool_t    libhal_ctx_set_device_lost_capability   (LibHalContext *ctx, LibHalDeviceLostCapability callback);
00194 
00195 /* Set the callback for when a property is modified on a device */
00196 dbus_bool_t    libhal_ctx_set_device_property_modified (LibHalContext *ctx, LibHalDevicePropertyModified callback);
00197 
00198 /* Set the callback for when a device emits a condition */
00199 dbus_bool_t    libhal_ctx_set_device_condition         (LibHalContext *ctx, LibHalDeviceCondition callback);
00200 
00201 /* Initialize the connection to hald */
00202 dbus_bool_t    libhal_ctx_init                         (LibHalContext *ctx, DBusError *error);
00203 
00204 /* Shut down a connection to hald */
00205 dbus_bool_t    libhal_ctx_shutdown                     (LibHalContext *ctx, DBusError *error);
00206 
00207 /* Free a LibHalContext resource */
00208 dbus_bool_t    libhal_ctx_free                         (LibHalContext *ctx);
00209 
00210 /* Create an already initialized connection to hald */
00211 LibHalContext *libhal_ctx_init_direct                  (DBusError *error);
00212 
00213 /* Get all devices in the Global Device List (GDL). */
00214 char        **libhal_get_all_devices (LibHalContext *ctx, int *num_devices, DBusError *error);
00215 
00216 /* Determine if a device exists. */
00217 dbus_bool_t   libhal_device_exists   (LibHalContext *ctx, const char *udi,  DBusError *error);
00218 
00219 /* Print a device to stdout; useful for debugging. */
00220 dbus_bool_t   libhal_device_print    (LibHalContext *ctx, const char *udi,  DBusError *error);
00221 
00222 /* Determine if a property on a device exists. */
00223 dbus_bool_t libhal_device_property_exists (LibHalContext *ctx, 
00224                        const char *udi,
00225                        const char *key,
00226                        DBusError *error);
00227 
00228 /* Get the value of a property of type string. */
00229 char *libhal_device_get_property_string (LibHalContext *ctx, 
00230                      const char *udi,
00231                      const char *key,
00232                      DBusError *error);
00233 
00234 /* Get the value of a property of type signed integer. */
00235 dbus_int32_t libhal_device_get_property_int (LibHalContext *ctx, 
00236                          const char *udi,
00237                          const char *key,
00238                          DBusError *error);
00239 
00240 /* Get the value of a property of type unsigned integer. */
00241 dbus_uint64_t libhal_device_get_property_uint64 (LibHalContext *ctx, 
00242                          const char *udi,
00243                          const char *key,
00244                          DBusError *error);
00245 
00246 /* Get the value of a property of type double. */
00247 double libhal_device_get_property_double (LibHalContext *ctx, 
00248                       const char *udi,
00249                       const char *key,
00250                       DBusError *error);
00251 
00252 /* Get the value of a property of type bool. */
00253 dbus_bool_t libhal_device_get_property_bool (LibHalContext *ctx, 
00254                          const char *udi,
00255                          const char *key,
00256                          DBusError *error);
00257 
00258 /* Get the value of a property of type string list. */
00259 char **libhal_device_get_property_strlist (LibHalContext *ctx, 
00260                        const char *udi, 
00261                        const char *key,
00262                        DBusError *error);
00263 
00264 /* Set a property of type string. */
00265 dbus_bool_t libhal_device_set_property_string (LibHalContext *ctx, 
00266                            const char *udi,
00267                            const char *key,
00268                            const char *value,
00269                            DBusError *error);
00270 
00271 /* Set a property of type signed integer. */
00272 dbus_bool_t libhal_device_set_property_int (LibHalContext *ctx, 
00273                         const char *udi,
00274                         const char *key,
00275                         dbus_int32_t value,
00276                         DBusError *error);
00277 
00278 /* Set a property of type unsigned integer. */
00279 dbus_bool_t libhal_device_set_property_uint64 (LibHalContext *ctx, 
00280                            const char *udi,
00281                            const char *key,
00282                            dbus_uint64_t value,
00283                            DBusError *error);
00284 
00285 /* Set a property of type double. */
00286 dbus_bool_t libhal_device_set_property_double (LibHalContext *ctx, 
00287                            const char *udi,
00288                            const char *key,
00289                            double value,
00290                            DBusError *error);
00291 
00292 /* Set a property of type bool. */
00293 dbus_bool_t libhal_device_set_property_bool (LibHalContext *ctx, 
00294                          const char *udi,
00295                          const char *key,
00296                          dbus_bool_t value,
00297                          DBusError *error);
00298 
00299 /* Append to a property of type strlist. */
00300 dbus_bool_t libhal_device_property_strlist_append (LibHalContext *ctx, 
00301                            const char *udi,
00302                            const char *key,
00303                            const char *value,
00304                            DBusError *error);
00305 
00306 /* Prepend to a property of type strlist. */
00307 dbus_bool_t libhal_device_property_strlist_prepend (LibHalContext *ctx, 
00308                             const char *udi,
00309                             const char *key,
00310                             const char *value,
00311                             DBusError *error);
00312 
00313 /* Remove a specified string from a property of type strlist. */
00314 dbus_bool_t libhal_device_property_strlist_remove_index (LibHalContext *ctx, 
00315                              const char *udi,
00316                              const char *key,
00317                              unsigned int index,
00318                              DBusError *error);
00319 
00320 /* Remove a specified string from a property of type strlist. */
00321 dbus_bool_t libhal_device_property_strlist_remove (LibHalContext *ctx, 
00322                            const char *udi,
00323                            const char *key,
00324                            const char *value,
00325                            DBusError *error);
00326 
00327 /* Remove a property. */
00328 dbus_bool_t libhal_device_remove_property (LibHalContext *ctx, 
00329                        const char *udi,
00330                        const char *key,
00331                        DBusError *error);
00332 
00333 /* Query a property type of a device. */
00334 LibHalPropertyType libhal_device_get_property_type (LibHalContext *ctx, 
00335                             const char *udi,
00336                             const char *key,
00337                             DBusError *error);
00338 
00339 
00340 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00341 struct LibHalProperty_s;
00342 typedef struct LibHalProperty_s LibHalProperty;
00343 
00344 struct LibHalPropertySet_s;
00345 typedef struct LibHalPropertySet_s LibHalPropertySet;
00346 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00347 
00348 /* Retrieve all the properties on a device. */
00349 LibHalPropertySet *libhal_device_get_all_properties (LibHalContext *ctx, 
00350                              const char *udi,
00351                              DBusError *error);
00352 
00353 /* Free a property set earlier obtained with libhal_device_get_all_properties(). */
00354 void libhal_free_property_set (LibHalPropertySet *set);
00355 
00356 /* Get the number of properties in a property set. */
00357 unsigned int libhal_property_set_get_num_elems (LibHalPropertySet *set);
00358 
00360 struct LibHalPropertySetIterator_s {
00361     LibHalPropertySet *set;    
00362     unsigned int index;        
00363     LibHalProperty *cur_prop;  
00364     void *reservered0;         
00365     void *reservered1;         
00366 };
00367 
00368 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00369 typedef struct LibHalPropertySetIterator_s LibHalPropertySetIterator;
00370 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00371 
00372 /* Initialize a property set iterator. */
00373 void libhal_psi_init (LibHalPropertySetIterator *iter, LibHalPropertySet *set);
00374 
00375 /* Determine whether there are more properties to iterate over */
00376 dbus_bool_t libhal_psi_has_more (LibHalPropertySetIterator *iter);
00377 
00378 /* Advance iterator to next property. */
00379 void libhal_psi_next (LibHalPropertySetIterator *iter);
00380 
00381 /* Get type of property. */
00382 LibHalPropertyType libhal_psi_get_type (LibHalPropertySetIterator *iter);
00383 
00384 /* Get the key of a property. */
00385 char *libhal_psi_get_key (LibHalPropertySetIterator *iter);
00386 
00387 /* Get the value of a property of type string. */
00388 char *libhal_psi_get_string (LibHalPropertySetIterator *iter);
00389 
00390 /* Get the value of a property of type signed integer. */
00391 dbus_int32_t libhal_psi_get_int (LibHalPropertySetIterator *iter);
00392 
00393 /* Get the value of a property of type unsigned integer. */
00394 dbus_uint64_t libhal_psi_get_uint64 (LibHalPropertySetIterator *iter);
00395 
00396 /* Get the value of a property of type double. */
00397 double libhal_psi_get_double (LibHalPropertySetIterator *iter);
00398 
00399 /* Get the value of a property of type bool. */
00400 dbus_bool_t libhal_psi_get_bool (LibHalPropertySetIterator *iter);
00401 
00402 /* Get the value of a property of type string list. */
00403 char **libhal_psi_get_strlist (LibHalPropertySetIterator *iter);
00404 
00405 /* Get the length of an array of strings */
00406 unsigned int libhal_string_array_length (char **str_array);
00407 
00408 /* Frees a NULL-terminated array of strings. If passed NULL, does nothing. */
00409 void libhal_free_string_array (char **str_array);
00410 
00411 /* Frees a nul-terminated string */
00412 void libhal_free_string (char *str);
00413 
00414 /* Create a new device object which will be hidden from applications
00415  * until the CommitToGdl(), ie. libhal_device_commit_to_gdl(), method is called.
00416  */
00417 char *libhal_new_device (LibHalContext *ctx, DBusError *error);
00418 
00419 /* When a hidden device has been built using the NewDevice method, ie.
00420  * libhal_new_device(), and the org.freedesktop.Hal.Device interface
00421  * this function will commit it to the global device list. 
00422  */
00423 dbus_bool_t libhal_device_commit_to_gdl (LibHalContext *ctx,
00424                      const char *temp_udi,
00425                      const char *udi,
00426                      DBusError *error);
00427 
00428 /* This method can be invoked when a device is removed. The HAL daemon
00429  * will shut down the device. Note that the device may still be in the device
00430  * list if the Persistent property is set to true. 
00431  */
00432 dbus_bool_t libhal_remove_device (LibHalContext *ctx, 
00433                     const char *udi,
00434                     DBusError *error);
00435 
00436 /* Merge properties from one device to another. */
00437 dbus_bool_t libhal_merge_properties (LibHalContext *ctx,
00438                        const char *target_udi,
00439                        const char *source_udi,
00440                        DBusError *error);
00441 
00442 /* Check a set of properties for two devices matches. */
00443 dbus_bool_t libhal_device_matches (LibHalContext *ctx,
00444                      const char *udi1,
00445                      const char *udi2,
00446                      const char *property_namespace,
00447                      DBusError *error);
00448 
00449 /* Find a device in the GDL where a single string property matches a
00450  * given value.
00451  */
00452 char **libhal_manager_find_device_string_match (LibHalContext *ctx,
00453                         const char *key,
00454                         const char *value,
00455                         int *num_devices,
00456                         DBusError *error);
00457 
00458 /* Assign a capability to a device. */
00459 dbus_bool_t libhal_device_add_capability (LibHalContext *ctx,
00460                       const char *udi,
00461                       const char *capability,
00462                       DBusError *error);
00463 
00464 /* Check if a device has a capability. The result is undefined if the
00465  * device doesn't exist.
00466  */
00467 dbus_bool_t libhal_device_query_capability (LibHalContext *ctx,
00468                         const char *udi,
00469                         const char *capability,
00470                         DBusError *error);
00471 
00472 /* Find devices with a given capability. */
00473 char **libhal_find_device_by_capability (LibHalContext *ctx,
00474                      const char *capability,
00475                      int *num_devices,
00476                      DBusError *error);
00477 
00478 /* Watch all devices, ie. the device_property_changed callback is
00479  * invoked when the properties on any device changes.
00480  */
00481 dbus_bool_t libhal_device_property_watch_all (LibHalContext *ctx,
00482                           DBusError *error);
00483 
00484 /* Add a watch on a device, so the device_property_changed callback is
00485  * invoked when the properties on the given device changes.
00486  */
00487 dbus_bool_t libhal_device_add_property_watch (LibHalContext *ctx, 
00488                           const char *udi,
00489                           DBusError *error);
00490 
00491 /* Remove a watch on a device */
00492 dbus_bool_t libhal_device_remove_property_watch (LibHalContext *ctx, 
00493                          const char *udi,
00494                          DBusError *error);
00495 
00496 /* Take an advisory lock on the device. */
00497 dbus_bool_t libhal_device_lock (LibHalContext *ctx,
00498                 const char *udi,
00499                 const char *reason_to_lock,
00500                 char **reason_why_locked,
00501                 DBusError *error);
00502 
00503 /* Release an advisory lock on the device. */
00504 dbus_bool_t libhal_device_unlock (LibHalContext *ctx,
00505                   const char *udi,
00506                   DBusError *error);
00507 
00508 dbus_bool_t libhal_device_rescan (LibHalContext *ctx,
00509                   const char *udi,
00510                   DBusError *error);
00511 
00512 dbus_bool_t libhal_device_reprobe (LibHalContext *ctx,
00513                    const char *udi,
00514                    DBusError *error);
00515 
00516 /* Emit a condition from a device */
00517 dbus_bool_t libhal_device_emit_condition (LibHalContext *ctx,
00518                       const char *udi,
00519                       const char *condition_name,
00520                       const char *condition_details,
00521                       DBusError *error);
00522 
00525 #if defined(__cplusplus)
00526 }
00527 #endif
00528 
00529 #endif /* LIBHAL_H */

Generated on Tue Oct 19 11:26:36 2010 for HAL by  doxygen 1.4.6