Symbian3/SDK/Source/GUID-5329C067-60B8-4E0E-A2B3-9423B75E189D.dita
changeset 7 51a74ef9ed63
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Symbian3/SDK/Source/GUID-5329C067-60B8-4E0E-A2B3-9423B75E189D.dita	Wed Mar 31 11:11:55 2010 +0100
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
+<!-- This component and the accompanying materials are made available under the terms of the License 
+"Eclipse Public License v1.0" which accompanies this distribution, 
+and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
+<!-- Initial Contributors:
+    Nokia Corporation - initial contribution.
+Contributors: 
+-->
+<!DOCTYPE concept
+  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
+<concept id="GUID-5329C067-60B8-4E0E-A2B3-9423B75E189D" xml:lang="en"><title>Getting
+GLib events in Symbian UI applications</title><shortdesc>Symbian UI applications run an event loop that is based on <codeph>CActiveScheduler</codeph>.
+The active scheduler is started by the UI framework immediately after the
+UI has been created (that is after <codeph>ConstructL()</codeph> of <codeph>CEikAppUi</codeph>-derived
+class).</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
+<p>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.</p>
+<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.</note>
+<codeblock xml:space="preserve">/********* 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-&gt;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 *******************/
+</codeblock>
+<p>The following is done in the application:</p>
+<codeblock xml:space="preserve">GMainLoop* mainloop = g_main_loop_new(NULL, FALSE);
+CGlibEventHandler* glibeventhandler = NULL;
+glibeventhandler = CGlibEventHandler::NewL();
+glibeventhandler-&gt;Start();
+</codeblock>
+</conbody></concept>
\ No newline at end of file