×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    34

    Error: HAL context initializing failure

    Please can anybody tell me why am I getting this error in foll code?
    Do I need to start hal first and if yes how do i need to do that.
    Your help is appreciated


    Code:

    DBusConnection *connection;
    DBusError error;
    LibHalContext *ctx;
    dbus_error_init(&error);
    if((connection = dbus_bus_get(DBUS_BUS_SYSTEM,&error)) == NULL)
    {
    printf("Error %s\n",error.message);
    return 1;
    }
    if ( dbus_error_is_set(&error) )
    {
    printf("Unable to connect to DBus: %s\n",error.message);
    return 1;
    }
    if((ctx = libhal_ctx_new())==NULL)
    {
    printf("Error %s\n",error.message);
    return 1;
    }
    if ( !libhal_ctx_set_dbus_connection(ctx, connection) )
    {
    printf("Error %s\n",error.message);
    return 1;
    }
    if ( !libhal_ctx_init(ctx, &error) )
    {
    printf("Hal context initializing failure %s\n",error.message);
    return 1;
    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Error: HAL context initializing failure

    This is an example how you do it
    Code:
        DBusError error;
        DBusConnection *conn;
    
        LibHalContext *ctx = libhal_ctx_new();
    
        dbus_error_init(&error);
        conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
        if (!conn) {
            g_critical("%s", error.message);
            dbus_error_free(&error);
        }
    
        dbus_connection_setup_with_g_main(conn, NULL);
        if (!libhal_ctx_set_dbus_connection(ctx, conn))
            g_critical("Cannot init HAL context with DBus");
    
        if (!libhal_ctx_init(ctx, &error)) {
            g_critical("%s", error.message);
            dbus_error_free(&error);
        }

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    34

    Re: Error: HAL context initializing failure

    Hi divanov,
    Thanks for the reply. I tried using ur code too. But still i get the same error as "Hal failed to initialize" in the below lines of code:
    (!libhal_ctx_init(ctx, &error)) {..}
    When i debug the code it says : Cannot access memory at address 0x0

    Pls can u help me any further?

  4. #4
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Error: HAL context initializing failure

    Quote Originally Posted by Pallavi_K View Post
    Hi divanov,
    Thanks for the reply. I tried using ur code too. But still i get the same error as "Hal failed to initialize" in the below lines of code:
    (!libhal_ctx_init(ctx, &error)) {..}
    When i debug the code it says : Cannot access memory at address 0x0
    This is rather weird and I start to suspect that problem is not in the code.
    Try this sample application, which is working for sure
    http://wiki.forum.nokia.com/index.ph...atus_using_HAL

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    34

    Re: Error: HAL context initializing failure

    Hi Divanov,
    Actually i am coding in Maemo, but APIs are the same and method is also the same.
    I had a look at the link u fwd to me. Previously i had coded taking help from that link only. But still error is not going.
    For ur reference I am attaching the source code here. Please do have a look at the code:



    int main( int argc, char* argv[] )
    {
    /* Create needed variables */
    HildonProgram *program;
    HildonWindow *window;
    GtkWidget *button;
    osso_context_t *osso_cont;
    osso_return_t ret;

    locale_init();

    osso_cont = osso_initialize(APP_NAME, APP_VER, TRUE, NULL);
    if (osso_cont == NULL)
    {
    fprintf (stderr, "osso_initialize failed.\n");
    exit (1);
    }

    /* Initialize the GTK. */
    gtk_init( &argc, &argv );

    /* Create the hildon program and setup the title */
    program = HILDON_PROGRAM(hildon_program_get_instance());
    g_set_application_name("Hello World");

    /* Create HildonWindow and set it to HildonProgram */
    window = HILDON_WINDOW(hildon_window_new());
    hildon_program_add_window(program, window);

    /* Quit program when window is closed. */
    g_signal_connect (G_OBJECT (window), "delete_event",
    G_CALLBACK (gtk_main_quit), NULL);

    /* Quit program when window is otherwise destroyed. */
    g_signal_connect (G_OBJECT (window), "destroy",
    G_CALLBACK (gtk_main_quit), NULL);

    /* Create button and add it to main view */
    button = gtk_button_new_with_label(_("Hello World!!!"));
    gtk_container_add(GTK_CONTAINER(window),
    button);

    g_signal_connect (G_OBJECT (button), "clicked",
    G_CALLBACK (button_clicked), NULL);

    ret = osso_rpc_set_cb_f (osso_cont,
    APP_SERVICE,
    APP_METHOD,
    APP_SERVICE,
    dbus_callback, GTK_WIDGET( window ));
    if (ret != OSSO_OK) {
    fprintf (stderr, "osso_rpc_set_cb_f failed: %d.\n", ret);
    exit (1);
    }

    int getn = mem_info();

    /* Begin the main application */
    gtk_widget_show_all ( GTK_WIDGET ( window ) );
    gtk_main();

    /* Exit */
    return 0;
    }


    int mem_info()
    {
    DBusError error;
    DBusConnection *connection;

    LibHalContext *ctx = libhal_ctx_new();
    const char *udi = "/sdrom";

    dbus_error_init(&error);

    connection = dbus_bus_get(DBUS_BUS_SYSTEM,&error);
    if(!connection)
    {
    printf("Error %s\n",error.message);
    dbus_error_free(&error);
    return 1;
    }

    if ( dbus_error_is_set(&error) )
    {
    printf("Unable to connect to DBus: %s\n",error.message);
    dbus_error_free(&error);
    return 1;
    }

    //set dbus connection to talk to hald
    if ( !libhal_ctx_set_dbus_connection(ctx, connection) )
    {
    printf("Error %s\n",error.message);
    dbus_error_free(&error);
    return 1;
    }

    //Initialize connection to hald
    if ( !libhal_ctx_init(ctx, &error) )
    {
    printf("Hal context initializing failure %s\n",error.message);
    dbus_error_free(&error);
    return 1;
    }
    else
    {
    printf("Successful");
    return 0;
    }
    }

    Thanks & Regards.

  6. #6
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Error: HAL context initializing failure

    Quote Originally Posted by Pallavi_K View Post
    Actually i am coding in Maemo, but APIs are the same and method is also the same.
    It seems you are using Gtk2, and example is using Qt, however, this is irrelevant to using HAL.

    Quote Originally Posted by Pallavi_K View Post
    I had a look at the link u fwd to me. Previously i had coded taking help from that link only. But still error is not going.
    For ur reference I am attaching the source code here. Please do have a look at the code:
    Can you create a folder example, copy the example to main.cpp, run
    Code:
    qmake -project
    than add
    Code:
    unix {
        CONFIG += link_pkgconfig
        PKGCONFIG += hal
    }
    to the example.pro
    run
    Code:
    qmake
    make
    and then try to execute resulting binary and report here if it works or not?

  7. #7
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Error: HAL context initializing failure

    I've modified your application to make it compile
    Code:
    /* gcc hal.c -o hal -Wall $(pkg-config --cflags --libs gtk+-2.0 hildon-1 hal hal-storage dbus-glib-1 libosso) */
    
    #include <gtk/gtk.h>
    #include <glib.h>
    #include <stdlib.h>
    #include <hildon/hildon.h>
    #include <libhal.h>
    #include <libosso.h>
    #include <libhal-storage.h>
    #include <dbus/dbus-glib-lowlevel.h>
    
    int main( int argc, char* argv[] )
    {
      /* Create needed variables */
      HildonProgram *program;
      HildonWindow *window;
      GtkWidget *button;
      osso_context_t *osso_cont;
      osso_return_t ret;
    
      /*
      locale_init();
      */
    
      osso_cont = osso_initialize("APP_NAME", "1.0", TRUE, NULL);
      if (osso_cont == NULL)
      {
        fprintf (stderr, "osso_initialize failed.\n");
       exit (1);
      }
    
      /* Initialize the GTK. */
      gtk_init( &argc, &argv );
    
      /* Create the hildon program and setup the title */
      program = HILDON_PROGRAM(hildon_program_get_instance());
      g_set_application_name("Hello World");
    
      /* Create HildonWindow and set it to HildonProgram */
      window = HILDON_WINDOW(hildon_window_new());
      hildon_program_add_window(program, window);
    
      /* Quit program when window is closed. */
      g_signal_connect (G_OBJECT (window), "delete_event",
      G_CALLBACK (gtk_main_quit), NULL);
    
      /* Quit program when window is otherwise destroyed. */
      g_signal_connect (G_OBJECT (window), "destroy",
      G_CALLBACK (gtk_main_quit), NULL);
    
      /* Create button and add it to main view */
      button = gtk_button_new_with_label("Hello World!!!");
      gtk_container_add(GTK_CONTAINER(window),
      button);
    
      /*
      g_signal_connect (G_OBJECT (button), "clicked",
      G_CALLBACK (button_clicked), NULL);
    
      ret = osso_rpc_set_cb_f (osso_cont,
      APP_SERVICE,
      APP_METHOD,
      APP_SERVICE,
      dbus_callback, GTK_WIDGET( window ));
      if (ret != OSSO_OK) {
      fprintf (stderr, "osso_rpc_set_cb_f failed: %d.\n", ret);
      exit (1);
      }
      */
    
      int getn = mem_info();
    
      /* Begin the main application */
      gtk_widget_show_all ( GTK_WIDGET ( window ) );
      gtk_main();
    
      /* Exit */
      return 0;
    }
    
    
    int mem_info()
    {
    DBusError error;
    DBusConnection *connection;
    
    LibHalContext *ctx = libhal_ctx_new();
    const char *udi = "/sdrom";
    
    dbus_error_init(&error);
    
    connection = dbus_bus_get(DBUS_BUS_SYSTEM,&error);
    if(!connection)
    {
    printf("Error %s\n",error.message);
    dbus_error_free(&error);
    return 1;
    }
    
    if ( dbus_error_is_set(&error) )
    {
    printf("Unable to connect to DBus: %s\n",error.message);
    dbus_error_free(&error);
    return 1;
    }
    
    //set dbus connection to talk to hald
    if ( !libhal_ctx_set_dbus_connection(ctx, connection) )
    {
    printf("Error %s\n",error.message);
    dbus_error_free(&error);
    return 1;
    }
    
    //Initialize connection to hald
    if ( !libhal_ctx_init(ctx, &error) )
    {
    printf("Hal context initializing failure %s\n",error.message);
    dbus_error_free(&error);
    return 1;
    }
    else
    {
    printf("Successful\n");
    return 0;
    }
    }
    And this is output when I run it on N900:
    Code:
    ~ $ ./hal 
    Successful
    Ok, you were running the app in scratchbox, where HAL is not supported.
    Last edited by divanov; 2010-05-18 at 14:01. Reason: update

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    34

    Re: Error: HAL context initializing failure

    Hi Divanov,
    Thanks for your continuous support.

  9. #9
    Registered User
    Join Date
    Jul 2008
    Posts
    34

    Re: Error: HAL context initializing failure

    Hi Divanov,
    I tried running the above code from Linux Desktop.
    It gives foll errors:

    pallavi@pallavi-desktop:~$ gcc -ggdb `pkg-config --cflags hal dbus-1` try.c -o hal `pkg-config --libs hal dbus-1`
    Package hal was not found in the pkg-config search path.
    Perhaps you should add the directory containing `hal.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'hal' found
    Package dbus-1 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `dbus-1.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'dbus-1' found
    Package hal was not found in the pkg-config search path.
    Perhaps you should add the directory containing `hal.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'hal' found
    Package dbus-1 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `dbus-1.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'dbus-1' found
    /usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
    /build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'
    collect2: ld returned 1 exit status
    pallavi@pallavi-desktop:~$


    Pls tell me how do i solve this error?

  10. #10
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Error: HAL context initializing failure

    Quote Originally Posted by Pallavi_K View Post
    Hi Divanov,
    I tried running the above code from Linux Desktop.
    It gives foll errors:

    pallavi@pallavi-desktop:~$ gcc -ggdb `pkg-config --cflags hal dbus-1` try.c -o hal `pkg-config --libs hal dbus-1`
    Package hal was not found in the pkg-config search path.
    Perhaps you should add the directory containing `hal.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'hal' found
    Package dbus-1 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `dbus-1.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'dbus-1' found
    Package hal was not found in the pkg-config search path.
    Perhaps you should add the directory containing `hal.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'hal' found
    Package dbus-1 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `dbus-1.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'dbus-1' found
    /usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
    /build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'
    collect2: ld returned 1 exit status
    pallavi@pallavi-desktop:~$


    Pls tell me how do i solve this error?
    Please, install libhal-dev and libdbus-1-dev.

  11. #11
    Registered User
    Join Date
    Jul 2008
    Posts
    34

    Re: Error: HAL context initializing failure

    Thanks , it worked for me

Similar Threads

  1. Replies: 1
    Last Post: 2009-12-21, 10:34
  2. Java Application running on WTK but not on S60 SDK
    By roman.benz in forum Mobile Java Tools & SDKs
    Replies: 6
    Last Post: 2009-06-09, 14:38
  3. Context pane icon not visible sometimes.
    By AgaMichalik in forum Symbian User Interface
    Replies: 0
    Last Post: 2008-05-27, 14:36
  4. PDP Context question
    By panslaw in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2006-05-09, 11:51
  5. Exceptions while loading application
    By avinash_rs in forum Mobile Java General
    Replies: 0
    Last Post: 2003-06-09, 10:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •