Logo Search packages:      
Sourcecode: hal version File versions

LibHalContext * hal_initialize ( const LibHalFunctions cb_functions,
dbus_bool_t  use_cache 

Initialize the HAL library.

cb_functions Callback functions. If this is set top NULL then the library will not listen for notifications.
use_cache Retrieve all device information and cache it. This is expensive both in terms of memory (there may be 50 device objects with 20 properties each) and in terms of processing power (your process will be woken up every time a property is changed). Use with caution. NOTE NOTE NOTE: Caching isn't actually implemented yet, this is just a placeholder to preserve API compatibility.
A LibHalContext object if succesful, and NULL if an error occured

Definition at line 608 of file libhal.c.

References LibHalContext_s::cache_enabled, LibHalContext_s::connection, LibHalContext_s::functions, LibHalContext_s::is_initialized, LibHalContext_s::is_shutdown, and LibHalFunctions_s::main_loop_integration.

Referenced by main().

      DBusError error;
      LibHalContext *ctx;

      if (!hal_already_initialized_once) {
            bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
            bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
            hal_already_initialized_once = TRUE;
      ctx = malloc (sizeof (LibHalContext));
      if (ctx == NULL) {
            fprintf (stderr, "%s %d : Cannot allocated %d bytes!\n",
                   __FILE__, __LINE__, sizeof (LibHalContext));
            return NULL;

      ctx->is_initialized = FALSE;
      ctx->is_shutdown = FALSE;

      ctx->cache_enabled = use_cache;

      ctx->functions = cb_functions;
      /* allow caller to pass NULL */
      if (ctx->functions == NULL)
            ctx->functions = &hal_null_functions;

      /* connect to hald service on the system bus */
      dbus_error_init (&error);
      ctx->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
      if (ctx->connection == NULL) {
            fprintf (stderr,
                   "%s %d : Error connecting to system bus: %s\n",
                   __FILE__, __LINE__, error.message);
            dbus_error_free (&error);
            return NULL;

      if (ctx->functions->main_loop_integration != NULL) {

            ctx->functions->main_loop_integration (ctx, ctx->connection);

      if (!dbus_connection_add_filter
          (ctx->connection, filter_func, ctx, NULL)) {
            fprintf (stderr,
                   "%s %d : Error creating connection handler\r\n",
                   __FILE__, __LINE__);
            /** @todo  clean up */
            return NULL;

      dbus_bus_add_match (ctx->connection,
                      "path='/org/freedesktop/Hal/Manager'", &error);
      if (dbus_error_is_set (&error)) {
            fprintf (stderr, "%s %d : Error subscribing to signals, "
                   __FILE__, __LINE__, error.message);
            /** @todo  clean up */
            return NULL;

      ctx->is_initialized = TRUE;
      return ctx;

Generated by  Doxygen 1.6.0   Back to index