Libframeworkd-glib

From Openmoko

(Difference between revisions)
Jump to: navigation, search
m
Line 2: Line 2:
  
 
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.
 
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 =
 
= Integration with other software =
Line 18: Line 20:
  
 
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.
 
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.
 +
 +
<pre>
 +
        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);
 +
</pre>
 +
 +
== Calling a method ==
 +
 +
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).
 +
 +
<pre>
 +
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();
 +
            }
 +
        }
 +
}
 +
</pre>
 +
 +
== Source code ==
 +
 
<pre>
 
<pre>
 
int main(int argc, char ** argv) {
 
int main(int argc, char ** argv) {

Revision as of 17:14, 7 August 2008

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.

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

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

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.

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

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

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.