Libframeworkd-glib

From Openmoko

Revision as of 20:25, 11 September 2008 by MinhHaDuong (Talk | contribs)

Jump to: navigation, search

Contents

Purpose

libframeworkd-glib is a library conceived to help users develop with frameworkd without bothering about the dbus calls/marshalling/etc... while building a C glib software.

It uses dbus-glib to bind to frameworkd, then calls the asynchronous methods of the interfaces. Thus, in order to use one method, you have to implement a callback.

Integration with other software

As for now, libframeworkd-glib is used mostly in SHR in order to be able to port openmoko-dialer2, openmoko-messages2, openmoko-panel-gsm, etc.

Current status

Today (August 7th), libframeworkd-glib almost implements the whole GSM stack from frameworkd.

Sources

You can find the sources on the SHR project page.

Or, use clone the git repository:

git clone git://git.freesmartphone.org/libframeworkd-glib.git

Example

ophonekitd is a simple example on how to use libframeworkd-glib to listen to events on frameworkd, and then launch the appropriate UI. It handles, in SHR, the whole "call" UI.

Connecting to the bus

To connect to the bus, you have to explicitly ask for it. You also have to give to libframeworkd-glib a list of handlers for the events you want to listen to.

        FrameworkdHandlers fwHandler;
        fwHandler.networkStatus = NULL;
        fwHandler.simAuthStatus = ophonekitd_sim_auth_status_handler;
        fwHandler.callCallStatus = NULL;
        fwHandler.smsMessageSent = NULL;
        fwHandler.smsIncomingMessage = NULL;
        fwHandler.networkSignalStrength = NULL;
        dbus_connect_to_bus(&fwHandler);

Calling a method

Libframeworkd-glib reflects the asynchronous nature of dbus. Calls to dbus return immediately, with the return values (or error values) coming back in a later call.

In order to call a method you have to provide a callback which will give you the information you asked for, or some other stuff (errors as an example).

boolean power_up_antenna() {
        device_set_antenna_power(TRUE, power_up_antenna_callback, NULL);

        return false; // End timeout
}

void power_up_antenna_callback(GError *error, gpointer userdata) {
        if(error != NULL) {
            if(IS_SIM_ERROR(error, SIM_ERROR_AUTH_FAILED)) {
                sim_display_code_UI();
            }
        }
}

Source code

#include <glib-2.0/glib.h>
#include <glib-2.0/glib-object.h>
#include <frameworkd-glib/frameworkd-glib-dbus.h>

int main(int argc, char ** argv) {
        GMainLoop *mainloop = NULL;
        FrameworkdHandlers fwHandler;
        g_type_init();
        mainloop = g_main_loop_new (NULL, FALSE);

        fwHandler.networkStatus = NULL;
        fwHandler.simAuthStatus = ophonekitd_sim_auth_status_handler;
        fwHandler.callCallStatus = NULL;
        fwHandler.smsMessageSent = NULL;
        fwHandler.smsIncomingMessage = NULL;
        fwHandler.networkSignalStrength = NULL;
        dbus_connect_to_bus(&fwHandler);
        g_timeout_add(5000, power_up_antenna, NULL);
        g_main_loop_run (mainloop);

        exit(EXIT_SUCCESS);
}

boolean power_up_antenna() {
        device_set_antenna_power(TRUE, power_up_antenna_callback, NULL);

        return false; // End timeout
}

void power_up_antenna_callback(GError *error, gpointer userdata) {
        if(error != NULL) {
            if(IS_SIM_ERROR(error, SIM_ERROR_AUTH_FAILED)) {
                sim_display_code_UI();
            }
        }
}

void ophonekitd_sim_auth_status_handler(const int status) {
        if(status == SIM_READY) {
                phonegui_destroy_pin_UI();
        }
        else {
                phonegui_display_pin_UI(status);
        }
}

This example, built with the appropriate headers, listens to events on SIM authentication. It powers up the antenna, and presents the SIM "code" UI, that is to say the UI prompting the user for its PIN.

Personal tools

Purpose

libframeworkd-glib is a library conceived to help users develop with frameworkd without bothering about the dbus calls/marshalling/etc... while building a C glib software.

It uses dbus-glib to bind to frameworkd, then calls the asynchronous methods of the interfaces. Thus, in order to use one method, you have to implement a callback.

Integration with other software

As for now, libframeworkd-glib is used mostly in SHR in order to be able to port openmoko-dialer2, openmoko-messages2, openmoko-panel-gsm, etc.

Current status

Today (August 7th), libframeworkd-glib almost implements the whole GSM stack from frameworkd.

Sources

You can find the sources on the SHR project page.

Or, use clone the git repository:

git clone git://git.freesmartphone.org/libframeworkd-glib.git

Example

ophonekitd is a simple example on how to use libframeworkd-glib to listen to events on frameworkd, and then launch the appropriate UI. It handles, in SHR, the whole "call" UI.

Connecting to the bus

To connect to the bus, you have to explicitly ask for it. You also have to give to libframeworkd-glib a list of handlers for the events you want to listen to.

        FrameworkdHandlers fwHandler;
        fwHandler.networkStatus = NULL;
        fwHandler.simAuthStatus = ophonekitd_sim_auth_status_handler;
        fwHandler.callCallStatus = NULL;
        fwHandler.smsMessageSent = NULL;
        fwHandler.smsIncomingMessage = NULL;
        fwHandler.networkSignalStrength = NULL;
        dbus_connect_to_bus(&fwHandler);

Calling a method

Libframeworkd-glib reflects the asynchronous nature of dbus. Calls to dbus return immediately, with the return values (or error values) coming back in a later call.

In order to call a method you have to provide a callback which will give you the information you asked for, or some other stuff (errors as an example).

boolean power_up_antenna() {
        device_set_antenna_power(TRUE, power_up_antenna_callback, NULL);

        return false; // End timeout
}

void power_up_antenna_callback(GError *error, gpointer userdata) {
        if(error != NULL) {
            if(IS_SIM_ERROR(error, SIM_ERROR_AUTH_FAILED)) {
                sim_display_code_UI();
            }
        }
}

Source code

#include <glib-2.0/glib.h>
#include <glib-2.0/glib-object.h>
#include <frameworkd-glib/frameworkd-glib-dbus.h>

int main(int argc, char ** argv) {
        GMainLoop *mainloop = NULL;
        FrameworkdHandlers fwHandler;
        g_type_init();
        mainloop = g_main_loop_new (NULL, FALSE);

        fwHandler.networkStatus = NULL;
        fwHandler.simAuthStatus = ophonekitd_sim_auth_status_handler;
        fwHandler.callCallStatus = NULL;
        fwHandler.smsMessageSent = NULL;
        fwHandler.smsIncomingMessage = NULL;
        fwHandler.networkSignalStrength = NULL;
        dbus_connect_to_bus(&fwHandler);
        g_timeout_add(5000, power_up_antenna, NULL);
        g_main_loop_run (mainloop);

        exit(EXIT_SUCCESS);
}

boolean power_up_antenna() {
        device_set_antenna_power(TRUE, power_up_antenna_callback, NULL);

        return false; // End timeout
}

void power_up_antenna_callback(GError *error, gpointer userdata) {
        if(error != NULL) {
            if(IS_SIM_ERROR(error, SIM_ERROR_AUTH_FAILED)) {
                sim_display_code_UI();
            }
        }
}

void ophonekitd_sim_auth_status_handler(const int status) {
        if(status == SIM_READY) {
                phonegui_destroy_pin_UI();
        }
        else {
                phonegui_display_pin_UI(status);
        }
}

This example, built with the appropriate headers, listens to events on SIM authentication. It powers up the antenna, and presents the SIM "code" UI, that is to say the UI prompting the user for its PIN.