|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-9C36CF76-6ED2-5674-908F-A3DF8930CEB0" xml:lang="en"><title>How |
|
13 to renew a request from the active scheduler</title><shortdesc>This document describes how to maintain an outstanding request |
|
14 from an active scheduler.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
15 <p>It is possible to maintain an outstanding request from the active scheduler, |
|
16 by overriding the <codeph>CActiveScheduler::WaitForAnyRequest()</codeph> function.</p> |
|
17 <p>In this case, it is useful for the active scheduler to have a data member |
|
18 which points to the active object for which it will maintain an outstanding |
|
19 request. Implement the active scheduler as follows:</p> |
|
20 <codeblock id="GUID-92FD6B7D-54E8-5E1D-828F-AEE77C45CA3A" xml:space="preserve">class CExampleScheduler : public CActiveScheduler |
|
21 { |
|
22 public: |
|
23 void Error (TInt aError) const; |
|
24 void WaitForAnyRequest(); |
|
25 void SetActiveObject(CActiveConsole* aActiveConsole); |
|
26 private: |
|
27 CActiveConsole* iActiveConsole; |
|
28 };</codeblock> |
|
29 <codeblock id="GUID-156BDAD4-B9EB-55AB-827A-16739A66AC2D" xml:space="preserve">void CExampleScheduler::SetActiveObject(CActiveConsole* aActiveConsole) |
|
30 { |
|
31 iActiveConsole = aActiveConsole; |
|
32 }</codeblock> |
|
33 <p>where <codeph>iActiveConsole</codeph> is a pointer to an active object, |
|
34 initialized by call to <codeph>SetActiveObject()</codeph> during the construction |
|
35 of the controlling active object:</p> |
|
36 <codeblock id="GUID-721C2A53-CE4F-5C37-9599-DE359A586C9C" xml:space="preserve">void CMessageKeyProcessor::ConstructL() |
|
37 { |
|
38 CActiveScheduler::Add(this); |
|
39 (CExampleScheduler*)(CActiveScheduler::Current())->SetActiveObject(this); |
|
40 }</codeblock> |
|
41 <p>Now override <codeph>CActiveScheduler::WaitForAnyRequest()</codeph>:</p> |
|
42 <codeblock id="GUID-7646ED79-B891-5F94-BCBC-37A025FA5270" xml:space="preserve">void CExampleScheduler::WaitForAnyRequest() |
|
43 { |
|
44 if (!(iActiveConsole->IsActive())) |
|
45 { |
|
46 iActiveConsole->RequestCharacter(); |
|
47 } |
|
48 CActiveScheduler::WaitForAnyRequest(); |
|
49 }</codeblock> |
|
50 <section id="GUID-52635F6A-E5F8-4F08-A77F-136FC80C39BF"><title>Notes</title> <ul> |
|
51 <li id="GUID-76CC4644-1909-5423-BF85-44F6AA4053A3"><p>The state of the active |
|
52 request flag is examined and a request is not issued if it is active. This |
|
53 check is important because the function may be called as a result of other |
|
54 active objects completing (for example, a timed messenger) and in these cases |
|
55 it would be inappropriate to renew the keyboard service request.</p> </li> |
|
56 <li id="GUID-5DA7C2E5-4BB2-54B1-9800-53FB2E41793D"><p>It is no longer necessary |
|
57 to call <codeph>RequestCharacter()</codeph> either before starting the active |
|
58 scheduler, or as part of key processing.</p> </li> |
|
59 <li id="GUID-7535854A-24C9-581C-9B49-FE17E2252E8E"><p>The static function <codeph>CActiveScheduler::Current()</codeph> is |
|
60 used to fetch a pointer to the currently installed active scheduler (in this |
|
61 example, an object of type <codeph>CExampleScheduler</codeph>). This is necessary |
|
62 in order to access the <codeph>SetActiveObject()</codeph> member function |
|
63 of <codeph>CExampleScheduler</codeph>.</p> </li> |
|
64 </ul> </section> |
|
65 </conbody></concept> |