|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32std.h> |
|
17 #include "MENTACT.H" |
|
18 #include "MSVPANIC.H" |
|
19 |
|
20 |
|
21 // |
|
22 // CMsgActive framework |
|
23 // |
|
24 |
|
25 |
|
26 EXPORT_C CMsgActive::CMsgActive(TInt aPriority) |
|
27 :CActive(aPriority) |
|
28 {} |
|
29 |
|
30 |
|
31 EXPORT_C CMsgActive::~CMsgActive() |
|
32 { |
|
33 Cancel(); // framework requirement |
|
34 } |
|
35 |
|
36 |
|
37 EXPORT_C void CMsgActive::Queue(TRequestStatus& aStatus) |
|
38 // |
|
39 // call this last when an asynch operation has been requested |
|
40 // |
|
41 { |
|
42 __ASSERT_DEBUG(iReport==NULL, PanicServer(EMsvCMsgActiveAlreadyActive)); |
|
43 // |
|
44 aStatus=KRequestPending; |
|
45 iReport=&aStatus; |
|
46 } |
|
47 |
|
48 |
|
49 EXPORT_C void CMsgActive::DoCancel() |
|
50 // |
|
51 // must be called at end of derived classes DoCancel() |
|
52 // |
|
53 { |
|
54 TInt result=KErrCancel; |
|
55 Complete(result); // can be done safely as asynch reporting |
|
56 } |
|
57 |
|
58 |
|
59 EXPORT_C void CMsgActive::RunL() |
|
60 // |
|
61 // When the AO is state driven, this form of Run() is very effective |
|
62 // DoRunL() takes the AO through the states, queuing another asynch step as required |
|
63 // if DoRunL() detects the end of the cycle it returns without queuing another cycle. |
|
64 // |
|
65 // If Run() would exit without queuing another cycle it reports completion to the client. |
|
66 // This is true if the asynch step or DoRunL fails, or the state cycle is complete |
|
67 // |
|
68 { |
|
69 TInt status=iStatus.Int(); |
|
70 if (status>=KErrNone) |
|
71 { |
|
72 TRAPD(error,DoRunL()); // continue operations, may re-queue |
|
73 __ASSERT_DEBUG(error==KErrNone || !IsActive(),User::Invariant()); // must not requeue in error situations |
|
74 if (IsActive()) // requeud |
|
75 return; |
|
76 status=error; |
|
77 } |
|
78 Complete(status); |
|
79 } |
|
80 |
|
81 |
|
82 EXPORT_C void CMsgActive::Complete(TInt aStatus) |
|
83 { |
|
84 if (iReport) |
|
85 { |
|
86 // only complete properly once. |
|
87 // this allows a derived class to complete and then cancel, reporting the desired state instead of KErrCancel |
|
88 DoComplete(aStatus); |
|
89 User::RequestComplete(iReport,aStatus); |
|
90 } |
|
91 } |
|
92 |
|
93 |
|
94 EXPORT_C void CMsgActive::DoComplete(TInt&) |
|
95 // |
|
96 // Default implementation does nothing |
|
97 // |
|
98 {} |