1 /* |
|
2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Active object wrapper for SAT Server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "csatsactivewrapper.h" |
|
20 #include "SatLog.h" |
|
21 |
|
22 const TInt KShortWait = 200; // 200 microseconds |
|
23 const TInt KWaitTimes = 5; // Number of retries |
|
24 |
|
25 // ================= MEMBER FUNCTIONS ========================================== |
|
26 |
|
27 // Class constructor. |
|
28 CSatSActiveWrapper::CSatSActiveWrapper() : |
|
29 CActive( EPriorityStandard ) |
|
30 { |
|
31 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::CSatSActiveWrapper \ |
|
32 calling-exiting" ) |
|
33 CActiveScheduler::Add( this ); |
|
34 } |
|
35 |
|
36 // Destructor |
|
37 CSatSActiveWrapper::~CSatSActiveWrapper() |
|
38 { |
|
39 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::~CSatSActiveWrapper calling" ) |
|
40 |
|
41 if ( iTimer ) |
|
42 { |
|
43 iTimer->Cancel(); |
|
44 delete iTimer; |
|
45 } |
|
46 |
|
47 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::~CSatSActiveWrapper exiting" ) |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSatSActiveWrapper::RequestStatus |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 TRequestStatus& CSatSActiveWrapper::RequestStatus() |
|
55 { |
|
56 LOG( DETAILED, "SATENGINE: CSatSActiveWrapper::RequestStatus calling" ) |
|
57 |
|
58 TInt retries( 0 ); |
|
59 while ( IsActive() && ( retries++ < KWaitTimes ) ) |
|
60 { |
|
61 // If this wrapper is already active, wait little bit |
|
62 After( KShortWait ); |
|
63 } |
|
64 LOG2( DETAILED, "SATENGINE: CSatSActiveWrapper::RequestStatus retries: %d", |
|
65 retries ) |
|
66 // Double check. If still active, cancel |
|
67 if ( IsActive() ) |
|
68 { |
|
69 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::RequestStatus active" ) |
|
70 CancelWrapper(); |
|
71 } |
|
72 |
|
73 LOG( DETAILED, "SATENGINE: CSatSActiveWrapper::RequestStatus exiting" ) |
|
74 return iStatus; |
|
75 } |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CSatSActiveWrapper::SetActiveAndWait |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 TInt CSatSActiveWrapper::SetActiveAndWait() |
|
81 { |
|
82 LOG( DETAILED, "SATENGINE: CSatSActiveWrapper::SetActiveAndWait calling" ) |
|
83 |
|
84 TInt returnValue( KErrInUse ); |
|
85 if ( !IsActive() && !iWait.IsStarted() ) |
|
86 { |
|
87 LOG( DETAILED, |
|
88 "SATENGINE: CSatSActiveWrapper::SetActiveAndWait setActiveAndWait" ) |
|
89 SetActive(); |
|
90 iWait.Start(); // Blocks until request is complete or cancelled |
|
91 returnValue = iStatus.Int(); |
|
92 } |
|
93 |
|
94 LOG( DETAILED, "SATENGINE: CSatSActiveWrapper::SetActiveAndWait exiting" ) |
|
95 return returnValue; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CSatSActiveWrapper::After |
|
100 // ----------------------------------------------------------------------------- |
|
101 void CSatSActiveWrapper::After( |
|
102 const TTimeIntervalMicroSeconds32& aDelay, |
|
103 const TTimeIntervalMicroSeconds32& aInterval ) |
|
104 { |
|
105 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::After calling" ) |
|
106 |
|
107 if ( !iAfterWait.IsStarted() ) |
|
108 { |
|
109 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::After start iAfterWait" ) |
|
110 TRAP_IGNORE( ( iTimer = CPeriodic::NewL( EPriorityStandard ) ) ) |
|
111 iTimer->Start( aDelay, aInterval, TCallBack( DelayCallBack, this ) ); |
|
112 iAfterWait.Start(); |
|
113 |
|
114 delete iTimer; |
|
115 iTimer = NULL; |
|
116 } |
|
117 |
|
118 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::After exiting" ) |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CSatSActiveWrapper::DelayCallBack |
|
123 // Timer call back function |
|
124 // ----------------------------------------------------------------------------- |
|
125 TInt CSatSActiveWrapper::DelayCallBack( TAny* aPtr ) |
|
126 { |
|
127 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::DelayCallBack calling" ) |
|
128 CSatSActiveWrapper* ptrThis = static_cast<CSatSActiveWrapper*>( aPtr ); |
|
129 if ( ptrThis && ( ptrThis->iAfterWait.IsStarted() ) ) |
|
130 { |
|
131 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::DelayCallBack stop \ |
|
132 iAfterWait" ) |
|
133 ptrThis->iAfterWait.AsyncStop(); |
|
134 } |
|
135 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::DelayCallBack exiting" ) |
|
136 return ( EFalse ); |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CSatSActiveWrapper::AddSubSessionL |
|
141 // ----------------------------------------------------------------------------- |
|
142 void CSatSActiveWrapper::CancelWrapper() |
|
143 { |
|
144 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::CancelWrapper calling" ) |
|
145 |
|
146 // If pending for request, cancel active |
|
147 if ( IsActive() ) |
|
148 { |
|
149 LOG( SIMPLE, |
|
150 "SATENGINE: CSatSActiveWrapper::CancelWrapper cancel iWait" ) |
|
151 // Calls DoCancel which cancels iWait |
|
152 Cancel(); |
|
153 } |
|
154 else if ( iAfterWait.IsStarted() ) |
|
155 { |
|
156 LOG( SIMPLE, |
|
157 "SATENGINE: CSatSActiveWrapper::CancelWrapper cancel timer" ) |
|
158 // Cancels timer |
|
159 iAfterWait.AsyncStop(); |
|
160 } |
|
161 else |
|
162 { |
|
163 LOG( SIMPLE, |
|
164 "SATENGINE: CSatSActiveWrapper::CancelWrapper Wrapper not active" ) |
|
165 } |
|
166 |
|
167 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::CancelWrapper exiting" ) |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CSatSActiveWrapper::Release |
|
172 // ----------------------------------------------------------------------------- |
|
173 void CSatSActiveWrapper::Release() |
|
174 { |
|
175 LOG( SIMPLE, "SATENGINE: CSatSActiveWrapper::Release calling-exiting" ) |
|
176 delete this; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CSatSActiveWrapper::RunL |
|
181 // Synchronous request complete |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CSatSActiveWrapper::RunL() |
|
185 { |
|
186 LOG( DETAILED, "SATENGINE: CSatSActiveWrapper::RunL calling" ) |
|
187 |
|
188 iWait.AsyncStop(); |
|
189 |
|
190 LOG( DETAILED, "SATENGINE: CSatSActiveWrapper::RunL exiting" ) |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CSatSActiveWrapper::DoCancel |
|
195 // Synchronous request complete |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 void CSatSActiveWrapper::DoCancel() |
|
199 { |
|
200 LOG( SIMPLE, "SATENGINE: CSatBIPUtils::DoCancel calling" ) |
|
201 |
|
202 iWait.AsyncStop(); |
|
203 |
|
204 LOG( SIMPLE, "SATENGINE: CSatBIPUtils::DoCancel exiting" ) |
|
205 } |
|