S60 Open C
Introduction to Glib

Introduction to Glib

Table of Contents

How to get Glib events in Symbian UI applications

 


How to get Glib events in Symbian UI applications

Symbian UI applications run an event loop that is based on CActiveScheduler. The active scheduler is started by the UI framework immediately after the UI has been created (that is., after ConstructL() of CEikAppUi-derived class).

In order to receive events from Glib event sources, an active object can be added to the active scheduler especially for this purpose. The active object runs one iteration of the glib event loop every time it gets scheduled.

NOTE! The scheduling logic in the sample code provided below is based on a simple timer; more complex scheduling logic can be implemented depending on the requirement of the application.

/********* GlibEventHandler.h *********************/

class CGlibEventHandler: public CActive
{
public:
	static CGlibEventHandler* NewL();
	~CGlibEventHandler();
       void RunL();
       void DoCancel();
       void Start();
       void Stop();
private:
       CGlibEventHandler();
       void ConstructL();	
       RTimer iTimer;
};

/********* GlibEventHandler.h *********************/


/********* GlibEventHandler.cpp *******************/

CGlibEventHandler* CGlibEventHandler::NewL()
{
       CGlibEventHandler* self = new(ELeave) CGlibEventHandler();
       CleanupStack::PushL(self);
       self->ConstructL();
       CleanupStack::Pop();
       return self;
}

CGlibEventHandler::CGlibEventHandler():CActive(EPriorityStandard)
{
}
	
void CGlibEventHandler::ConstructL()
{
	User::LeaveIfError(iTimer.CreateLocal());
	CActiveScheduler::Add(this);	
}

CGlibEventHandler::~CGlibEventHandler()
{
	Cancel();
	iTimer.Close();		
}

void CGlibEventHandler::Start()
{
	iTimer.After(iStatus, TTimeIntervalMicroSeconds32(1000));
	SetActive();	
}
	
void CGlibEventHandler::Stop()
{
	Cancel();
}
	
void CGlibEventHandler::RunL()
{
	g_main_context_iteration(NULL, FALSE);
	iTimer.After(iStatus, TTimeIntervalMicroSeconds32(1000));
	SetActive();	
}
	
void CGlibEventHandler::DoCancel()
{
	iTimer.Cancel();	
}

/********* GlibEventHandler.cpp *******************/

The following is done in the application:

GMainLoop* mainloop = g_main_loop_new(NULL, FALSE);
CGlibEventHandler* glibeventhandler = NULL;
glibeventhandler = CGlibEventHandler::NewL();
glibeventhandler->Start();

Give feedback of this section


©Nokia 2007

Back to top


This material, including documentation and any related computer programs, is protected by copyright controlled by Nokia. All rights are reserved. Copying, including reproducing, storing, adapting or translating, any or all of this material requires the prior written consent of Nokia. This material also contains confidential information, which may not be disclosed to others without the prior written consent of Nokia.

Nokia is a registered trademark of Nokia Corporation. S60 and logo is a trademark of Nokia Corporation. Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. Other company and product names mentioned herein may be trademarks or tradenames of their respective owners.