|
1 // Copyright (c) 2003-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 // This contains CTestAsynchHandler which is an active object to |
|
15 // handle the asynch calls from the RootServer during testing |
|
16 // |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 // EPOC includes |
|
22 #include <e32base.h> |
|
23 |
|
24 // RootServer includes |
|
25 #include <rsshared.h> |
|
26 |
|
27 // Test system includes |
|
28 #include "TestAsynchHandler.h" |
|
29 |
|
30 |
|
31 CTestAsynchHandler* CTestAsynchHandler::NewLC(RRootServ* aRootServer) |
|
32 { |
|
33 CTestAsynchHandler* self = new(ELeave) CTestAsynchHandler; |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(aRootServer); |
|
36 return self; |
|
37 } |
|
38 |
|
39 CTestAsynchHandler::CTestAsynchHandler() : CActive(0) |
|
40 { |
|
41 } |
|
42 |
|
43 void CTestAsynchHandler::ConstructL(RRootServ* aRootServer) |
|
44 { |
|
45 iState = EIdle; |
|
46 iRootServer = aRootServer; |
|
47 User::LeaveIfError(iTimer.CreateLocal()); |
|
48 CActiveScheduler::Add(this); |
|
49 } |
|
50 |
|
51 CTestAsynchHandler::~CTestAsynchHandler() |
|
52 { |
|
53 Cancel(); |
|
54 iTimer.Close(); |
|
55 } |
|
56 |
|
57 // from CActive |
|
58 void CTestAsynchHandler::RunL() |
|
59 { |
|
60 switch(iState) |
|
61 { |
|
62 case ELoading: |
|
63 case EUnLoading: |
|
64 case EBinding: |
|
65 case EUnBinding: |
|
66 case EListeningforDeath: |
|
67 case EWaitingforTimer: |
|
68 case EIdle: |
|
69 default: |
|
70 CActiveScheduler::Stop(); |
|
71 break; |
|
72 } |
|
73 iState = EIdle; |
|
74 } |
|
75 |
|
76 void CTestAsynchHandler::DoCancel() |
|
77 { |
|
78 switch (iState) |
|
79 { |
|
80 case EListeningforDeath: |
|
81 iPropertyDeath.Cancel(); |
|
82 break; |
|
83 |
|
84 case EWaitingforTimer: |
|
85 iTimer.Cancel(); |
|
86 break; |
|
87 |
|
88 case ELoading: |
|
89 case EIdle: |
|
90 default: |
|
91 break; |
|
92 } |
|
93 } |
|
94 |
|
95 |
|
96 // requests |
|
97 void CTestAsynchHandler::TryLoad(const TRSStartModuleParams& aParams, |
|
98 const TDesC8& aIniData) |
|
99 { |
|
100 iState = ELoading; |
|
101 iRootServer->LoadCpm(iStatus, aParams, aIniData); |
|
102 SetActive(); |
|
103 } |
|
104 |
|
105 void CTestAsynchHandler::TryUnLoad(const TCFModuleName& aName, TRSUnLoadType aType) |
|
106 { |
|
107 iState = EUnLoading; |
|
108 iRootServer->UnloadCpm(iStatus, aName, aType); |
|
109 SetActive(); |
|
110 } |
|
111 |
|
112 void CTestAsynchHandler::TryBind( TRSBindingInfo& aBindInfo ) |
|
113 { |
|
114 iState = EBinding; |
|
115 iRootServer->Bind( iStatus, aBindInfo ); |
|
116 SetActive(); |
|
117 } |
|
118 |
|
119 void CTestAsynchHandler::TryUnBind( TRSUnBindingInfo& aUnbindInfo ) |
|
120 { |
|
121 iState = EUnBinding; |
|
122 iRootServer->Unbind( iStatus, aUnbindInfo ); |
|
123 SetActive(); |
|
124 } |
|
125 |
|
126 void CTestAsynchHandler::TryWaitForDeath(void) |
|
127 { |
|
128 iState = EListeningforDeath; |
|
129 TInt result = iPropertyDeath.Attach( KUidSystemCategory,KUidC32RootModuleDeathKey.iUid ); |
|
130 if(result != KErrNone) |
|
131 { |
|
132 _LIT( KAsynch, "Asynch" ); |
|
133 User::Panic( KAsynch, result ); |
|
134 } |
|
135 iPropertyDeath.Subscribe( iStatus ); |
|
136 SetActive(); |
|
137 } |
|
138 |
|
139 void CTestAsynchHandler::TryCancelDeath() |
|
140 { |
|
141 |
|
142 // we are already active cos we are waiting on our subscription |
|
143 // therefore we will simply cancel the property subscription |
|
144 iState=EIdle; |
|
145 DoCancel(); |
|
146 } |
|
147 |
|
148 void CTestAsynchHandler::WaitForTimer(TInt aTimeout_ms) |
|
149 { |
|
150 iState = EWaitingforTimer; |
|
151 |
|
152 DoCancel(); // in case timer already running |
|
153 iTimer.After(iStatus, aTimeout_ms * 1000); |
|
154 SetActive(); |
|
155 } |
|
156 |
|
157 |
|
158 |