Nokia N97 SDK
Example Applications Guide

Open C Hello World with Glib Events Example

1. About this Example
2. Prerequisites
3. Architecture and Design


1. About this Example

The purpose of this example is to demonstrate a simple method of receving events from Glib event sources in an application that uses the Symbian UI framework. This examples extends the standard "Hello World" UI example by adding a Glib "timeout" source. This example will open a another console which will print nothing. The user should switch the application. Switched application will show up UI. The example demonstrates that Glib events as well as Symbian events can be handled in the same application thread.


2. Prerequisites

This examples requires a basic understanding of the Symbian UI framework, Active Objects and Active Scheduler mechanism, and Glib event sources.


3. Architecture and Design

In the Symbian programming paradigm, the Active Scheduler is used as an event loop, and Active Objects encapsulate the asynchronous request and the handling of request completion (or cancellation). The Symbian UI framework creates an active scheduler, and starts it immediately after completing the construction of the UI.

The use of Glib event sources by Symbian UI-based applications therefore requires that somehow Glib event sources should also be scheduled in the context of the Active Scheduler.

In this example, a special active object is created and added to the active scheduler. The active object, once started (see COpenCHelloGlibEventExHandler::Start()), schedules itself based on a simple timer service. In the COpenCHelloGlibEventExHandler::RunL() function, this active object simply runs one non-blocking iteration of the Glib event loop, and reschedules itself.

In this way, Active Objects as well as Glib event sources get handled in the same thread without blocking each other. This is demonstrated in the example by creating a Glib Timeout Source (see COpenCHelloGlibEventExUi::ConstructL()) of 1000 milliseconds, and modifying the text message displayed by the view in the callback function of the the timeout source (see timeout_cb). The Glib events do not affect the Active Objects used by the Symbian UI framework, and the UI event handling and redrawing happens as before.


© Nokia 2009

Back to top