|
1 /* |
|
2 * Copyright (c) 2007 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: Timeout controller |
|
15 * |
|
16 */ |
|
17 |
|
18 // Version : %version: 3 % |
|
19 |
|
20 |
|
21 #include "timeoutcontroller.h" |
|
22 #include "mpxvideo_debug.h" |
|
23 |
|
24 /* |
|
25 ------------------------------------------------------------------------------- |
|
26 Class: CSimpleTimeout |
|
27 Method: CSimpleTimeout |
|
28 Description: Default constructor |
|
29 C++ default constructor can NOT contain any code, that might leave. |
|
30 Parameters: None |
|
31 Return Values: None |
|
32 Errors/Exceptions: None |
|
33 Status: Approved |
|
34 ------------------------------------------------------------------------------- |
|
35 */ |
|
36 CSimpleTimeout::CSimpleTimeout() |
|
37 : CActive (CActive::EPriorityStandard) |
|
38 { |
|
39 MPX_DEBUG(_L("CSimpleTimeout::CSimpleTimeout")); |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CSimpleTimeout::ConstructL() |
|
44 // Symbian OS second phase constructor. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void |
|
48 CSimpleTimeout::ConstructL( MTimeoutObserver* aObserver, CStifLogger* aLogger ) |
|
49 { |
|
50 MPX_DEBUG(_L("CSimpleTimeout::ConstructL")); |
|
51 |
|
52 iObserver = aObserver; |
|
53 iLog = aLogger; |
|
54 iTimer.CreateLocal(); |
|
55 iTestCaseTimeout = 0; // Initialize |
|
56 |
|
57 // Add to active scheduler |
|
58 CActiveScheduler::Add ( this ); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CSimpleTimeout::NewL() |
|
63 // Two-phased constructor. |
|
64 // Returns: CSimpleTimeout* : pointer to created object |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CSimpleTimeout* |
|
68 CSimpleTimeout::NewL( MTimeoutObserver* aTestClass, CStifLogger* aLogger ) |
|
69 { |
|
70 MPX_DEBUG(_L("CSimpleTimeout::NewL")); |
|
71 |
|
72 CSimpleTimeout* self = new ( ELeave ) CSimpleTimeout(); |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL( aTestClass, aLogger); |
|
75 CleanupStack::Pop( self ); |
|
76 |
|
77 return self; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CSimpleTimeout::~CSimpleTimeout() |
|
82 // Destructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CSimpleTimeout::~CSimpleTimeout() |
|
86 { |
|
87 MPX_DEBUG(_L("CSimpleTimeout::~CSimpleTimeout")); |
|
88 Cancel(); |
|
89 iTimer.Close(); |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CSimpleTimeout::Start() |
|
94 // Start timeout counting. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void |
|
98 CSimpleTimeout::Start( TTimeIntervalMicroSeconds aTimeout ) |
|
99 { |
|
100 MPX_DEBUG(_L("CSimpleTimeout::Start")); |
|
101 |
|
102 if ( IsActive() ) |
|
103 { |
|
104 Cancel(); |
|
105 } |
|
106 |
|
107 // Request timer |
|
108 TTime endTime; |
|
109 endTime.HomeTime(); |
|
110 endTime = endTime + aTimeout; |
|
111 |
|
112 TInt64 miliseconds = aTimeout.Int64(); |
|
113 miliseconds /= 1000; |
|
114 |
|
115 TBuf<30> dateString; |
|
116 TRAP_IGNORE(endTime.FormatL(dateString, KFormatTimeStamp)); |
|
117 iLog->Log(_L("Timer=%LD ms, EndTime=%S"), miliseconds, &dateString); |
|
118 |
|
119 // Store absolute timeout |
|
120 iTestCaseTimeout = endTime; |
|
121 |
|
122 // Taken from STIF engine |
|
123 // Note: iTimer.After() method cannot use because there needed |
|
124 // TTimeIntervalMicroSeconds32 and it is 32 bit. So then cannot create |
|
125 // timeout time that is long enough. At() uses 64 bit value=>Long enough. |
|
126 iTimer.At( iStatus, endTime ); |
|
127 SetActive(); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CSimpleTimeout::Stop() |
|
132 // Start timeout counting. |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void |
|
136 CSimpleTimeout::Stop() |
|
137 { |
|
138 MPX_DEBUG(_L("CSimpleTimeout::Stop")); |
|
139 |
|
140 if ( IsActive() ) |
|
141 { |
|
142 Cancel(); |
|
143 } |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CSimpleTimeout::RunL() |
|
148 // RunL handles completed timeouts. |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void |
|
152 CSimpleTimeout::RunL() |
|
153 { |
|
154 MPX_DEBUG(_L("CSimpleTimeout::RunL")); |
|
155 |
|
156 iLog->Log(_L("CSimpleTimeout::RunL")); |
|
157 |
|
158 TTime timeout; |
|
159 timeout.HomeTime(); |
|
160 |
|
161 // Handle the abort case when system time gets changed, but timeout is |
|
162 // still valid. All other cases should timeout since they invalidate the |
|
163 // logic of the timers. |
|
164 if ( iStatus == KErrAbort) |
|
165 { |
|
166 if ( iTestCaseTimeout > timeout ) |
|
167 { |
|
168 MPX_DEBUG(_L( |
|
169 "Absolute timer still valid. Restaring timer. iStatus: %d" ), |
|
170 iStatus.Int() ); |
|
171 |
|
172 // Start new timer |
|
173 iStatus = KErrNone; // reset value |
|
174 iTimer.At ( iStatus, iTestCaseTimeout ); // restart timer |
|
175 SetActive(); |
|
176 } |
|
177 else |
|
178 { |
|
179 // Absolute timer no longer valid. Must timeout. |
|
180 iLog->Log(_L("Absolute timeout no longer valid")); |
|
181 iObserver->HandleTimeout(KErrNone); |
|
182 } |
|
183 |
|
184 } |
|
185 else |
|
186 { |
|
187 // Status was not KErrAbort. Timing out! |
|
188 // iLog->Log(_L("CSimpleTimeout::RunL - Timeout !!"), iTimeout); |
|
189 iLog->Log(_L("Timing out")); |
|
190 iObserver->HandleTimeout(KErrNone); |
|
191 } |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CSimpleTimeout::DoCancel() |
|
196 // Cancel active request. |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void |
|
200 CSimpleTimeout::DoCancel() |
|
201 { |
|
202 MPX_DEBUG(_L("CSimpleTimeout::DoCancel")); |
|
203 iTimer.Cancel(); |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CSimpleTimeout::RunError() |
|
208 // Handle errors. Just let framework handle errors because |
|
209 // RunL does not leave. |
|
210 // Returns: Symbian OS error code |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 TInt CSimpleTimeout::RunError( TInt aError ) |
|
214 { |
|
215 MPX_DEBUG(_L("CSimpleTimeout::RunError")); |
|
216 iLog->Log(_L("Timeout error %d"), aError); |
|
217 iObserver->HandleTimeout(aError); |
|
218 return aError; |
|
219 } |
|
220 |
|
221 // EOF |