0
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-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 the License "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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include "sattimer.h" // sat timer class
|
|
22 |
#include "satmessaging.h" // sat messaging class
|
|
23 |
#include "satmesshandler.h" // sat message handler class
|
|
24 |
#include "osttracedefinitions.h"
|
|
25 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
26 |
#include "sattimertraces.h"
|
|
27 |
#endif
|
|
28 |
|
|
29 |
|
|
30 |
// CONSTANTS
|
|
31 |
const TInt KTimersEqual = 0;
|
|
32 |
const TInt KFirstBigger = 1;
|
|
33 |
const TInt KFirstSmaller = -1;
|
|
34 |
const TInt KTick = 500000; // 500 milliseconds
|
|
35 |
const TInt KMaxNumberOfStoredEnvelopes = 10;
|
|
36 |
const TInt KHiByteMask = 0xF0;
|
|
37 |
const TInt KTimerIdPosition = 8;
|
|
38 |
const TInt KDefaultDelay = 1; // Envelope resending delay
|
|
39 |
|
|
40 |
|
|
41 |
// ==================== MEMBER FUNCTIONS =======================================
|
|
42 |
// -----------------------------------------------------------------------------
|
|
43 |
// CSatTimer::CSatTimer
|
|
44 |
// C++ default constructor can NOT contain any code, that
|
|
45 |
// might leave.
|
|
46 |
// -----------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
CSatTimer::CSatTimer
|
|
49 |
(
|
|
50 |
CSatMessHandler* aSatMessHandler,
|
|
51 |
CTsySatMessaging* aSatMessaging
|
|
52 |
)
|
|
53 |
:
|
|
54 |
iSatMessHandler( aSatMessHandler ),
|
|
55 |
iSatMessaging( aSatMessaging ),
|
|
56 |
iSecondsPassed( 0 ),
|
|
57 |
iHalfSecondTick( EFalse ),
|
|
58 |
iProactiveCommandOnGoing( EFalse ),
|
|
59 |
iTimer( NULL ),
|
|
60 |
iTimerTable( NULL ),
|
|
61 |
iEnvelopeTable( NULL )
|
|
62 |
|
|
63 |
{
|
|
64 |
OstTrace0( TRACE_DETAILED, CSATTIMER_CSATTIMER, "CSatTimer::CSatTimer" );
|
|
65 |
}
|
|
66 |
|
|
67 |
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
// CSatTimer::ConstructL
|
|
70 |
// Symbian 2nd phase constructor can leave.
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
void CSatTimer::ConstructL()
|
|
74 |
{
|
|
75 |
OstTrace0( TRACE_DETAILED, CSATTIMER_CONSTRUCTL, "CSatTimer::ConstructL" );
|
|
76 |
TFLOGSTRING("TSY: CSatTimer::ConstructL");
|
|
77 |
|
|
78 |
iTimerTable = new ( ELeave ) RArray<TTimer>( 8 );
|
|
79 |
iEnvelopeTable = new ( ELeave ) RArray<TSatEnvelope>( 1 );
|
|
80 |
|
|
81 |
// Neutral priority, 0
|
|
82 |
iTimer = CPeriodic::NewL( CActive::EPriorityStandard );
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
// CSatTimer::NewL
|
|
88 |
// Two-phased constructor.
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
CSatTimer* CSatTimer::NewL
|
|
92 |
(
|
|
93 |
CSatMessHandler* aSatMessHandler,
|
|
94 |
CTsySatMessaging* aSatMessaging
|
|
95 |
)
|
|
96 |
{
|
|
97 |
OstTrace0( TRACE_DETAILED, CSATTIMER_NEWL, "CSatTimer::NewL" );
|
|
98 |
TFLOGSTRING("TSY: CSatTimer::NewL");
|
|
99 |
|
|
100 |
CSatTimer* self = new( ELeave ) CSatTimer( aSatMessHandler, aSatMessaging );
|
|
101 |
|
|
102 |
CleanupStack::PushL( self );
|
|
103 |
self->ConstructL();
|
|
104 |
CleanupStack::Pop( self );
|
|
105 |
|
|
106 |
return self;
|
|
107 |
}
|
|
108 |
|
|
109 |
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
// CSatTimer::~CSatTimer
|
|
112 |
// Destructor
|
|
113 |
// -----------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
CSatTimer::~CSatTimer()
|
|
116 |
{
|
|
117 |
OstTrace0( TRACE_DETAILED, DUP1_CSATTIMER_CSATTIMER, "CSatTimer::~CSatTimer" );
|
|
118 |
TFLOGSTRING("TSY: CSatTimer::~CSatTimer");
|
|
119 |
|
|
120 |
if ( iTimer )
|
|
121 |
{
|
|
122 |
iTimer->Cancel();
|
|
123 |
delete iTimer;
|
|
124 |
}
|
|
125 |
|
|
126 |
if ( iTimerTable )
|
|
127 |
{
|
|
128 |
iTimerTable->Close();
|
|
129 |
delete iTimerTable;
|
|
130 |
}
|
|
131 |
|
|
132 |
if ( iEnvelopeTable )
|
|
133 |
{
|
|
134 |
iEnvelopeTable->Close();
|
|
135 |
delete iEnvelopeTable;
|
|
136 |
}
|
|
137 |
}
|
|
138 |
|
|
139 |
|
|
140 |
// -----------------------------------------------------------------------------
|
|
141 |
// CSatTimer::StartTimer
|
|
142 |
// Starts a timer
|
|
143 |
// (other items were commented in a header).
|
|
144 |
// -----------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
void CSatTimer::Start()
|
|
147 |
{
|
|
148 |
OstTrace0( TRACE_DETAILED, CSATTIMER_START, "CSatTimer::Start" );
|
|
149 |
//Check if timer is active just in case
|
|
150 |
if ( !iTimer->IsActive() )
|
|
151 |
{
|
|
152 |
TFLOGSTRING("TSY: CSatTimer::Start: Timer started");
|
|
153 |
OstTrace0( TRACE_DETAILED, DUP1_CSATTIMER_START, "CSatTimer::Start: Timer started" );
|
|
154 |
//Timer will tick every half second
|
|
155 |
TCallBack callback( Tick, this );
|
|
156 |
iTimer->Start( KTick, KTick, callback );
|
|
157 |
}
|
|
158 |
}
|
|
159 |
|
|
160 |
// -----------------------------------------------------------------------------
|
|
161 |
// CSatTimer::StartTimer
|
|
162 |
// Starts a timer with specified id
|
|
163 |
// (other items were commented in a header).
|
|
164 |
// -----------------------------------------------------------------------------
|
|
165 |
//
|
|
166 |
TInt CSatTimer::StartTimer
|
|
167 |
(
|
|
168 |
TInt aTimerId,
|
|
169 |
TUint32 aTimerValue
|
|
170 |
)
|
|
171 |
{
|
|
172 |
OstTrace0( TRACE_DETAILED, CSATTIMER_STARTTIMER, "CSatTimer::StartTimer" );
|
|
173 |
TFLOGSTRING("TSY: CSatTimer::StartTimer");
|
|
174 |
TInt ret( KErrNone );
|
|
175 |
// Check if the entry is already in the table and delete if found.
|
|
176 |
if ( CheckTimerTable( aTimerId ) )
|
|
177 |
{
|
|
178 |
DeleteTimerById( aTimerId );
|
|
179 |
}
|
|
180 |
|
|
181 |
// Calculate the trigger time (actual beat amount + timeout)
|
|
182 |
TUint32 timeStamp = iSecondsPassed + aTimerValue;
|
|
183 |
|
|
184 |
// Create timer
|
|
185 |
TTimer timer( aTimerId, iSecondsPassed, timeStamp );
|
|
186 |
|
|
187 |
// Insert the entry in the table and start timer
|
|
188 |
ret = iTimerTable->InsertInOrder( timer, TTimer::OrderEntries );
|
|
189 |
|
|
190 |
// Start timer
|
|
191 |
if ( KErrNone == ret )
|
|
192 |
{
|
|
193 |
Start();
|
|
194 |
}
|
|
195 |
return ret;
|
|
196 |
}
|
|
197 |
|
|
198 |
// -----------------------------------------------------------------------------
|
|
199 |
// CSatTimer::RestartTimer
|
|
200 |
// Restarts the inactive timer with specified id
|
|
201 |
// (other items were commented in a header).
|
|
202 |
// -----------------------------------------------------------------------------
|
|
203 |
//
|
|
204 |
TInt CSatTimer::RestartTimer
|
|
205 |
(
|
|
206 |
TInt aTimerId
|
|
207 |
)
|
|
208 |
{
|
|
209 |
OstTrace0( TRACE_DETAILED, CSATTIMER_RESTARTTIMER, "CSatTimer::RestartTimer" );
|
|
210 |
TFLOGSTRING("TSY: CSatTimer::RestartTimer");
|
|
211 |
TInt ret( KErrNone );
|
|
212 |
|
|
213 |
// Find timer from TimerTable
|
|
214 |
TTimer helper( aTimerId, 0, 0 );
|
|
215 |
TInt index = iTimerTable->Find( helper, TTimer::CompareEntries );
|
|
216 |
|
|
217 |
if ( KErrNotFound != index )
|
|
218 |
{
|
|
219 |
// Reactivate timer if proactive command is not ongoing, otherwise
|
|
220 |
// set state to witing for terminal response
|
|
221 |
if ( iProactiveCommandOnGoing )
|
|
222 |
{
|
|
223 |
( *iTimerTable )[index].SetState( TTimer::EWaitingForTr );
|
|
224 |
}
|
|
225 |
else
|
|
226 |
{
|
|
227 |
( *iTimerTable )[index].SetState( TTimer::ETicking );
|
|
228 |
}
|
|
229 |
|
|
230 |
// Start clock
|
|
231 |
Start();
|
|
232 |
}
|
|
233 |
else
|
|
234 |
{
|
|
235 |
TFLOGSTRING2("TSY: CSatTimer::ReStart - Requested ID (%d) not found!",
|
|
236 |
aTimerId);
|
|
237 |
OstTrace1( TRACE_DETAILED, DUP1_CSATTIMER_RESTARTTIMER, "CSatTimer::RestartTimer - Requested ID (%d) not found!", aTimerId );
|
|
238 |
|
|
239 |
ret = KErrNotFound;
|
|
240 |
}
|
|
241 |
|
|
242 |
return ret;
|
|
243 |
}
|
|
244 |
|
|
245 |
|
|
246 |
// -----------------------------------------------------------------------------
|
|
247 |
// CSatTimer::Stop
|
|
248 |
// Stops the timer counting
|
|
249 |
// (other items were commented in a header).
|
|
250 |
// -----------------------------------------------------------------------------
|
|
251 |
//
|
|
252 |
void CSatTimer::Stop()
|
|
253 |
{
|
|
254 |
OstTrace0( TRACE_DETAILED, CSATTIMER_STOP, "CSatTimer::Stop" );
|
|
255 |
// If both timer and envelope arrays are empty, stop the timer.
|
|
256 |
// Also if timer table is empty, clear the second counter.
|
|
257 |
if ( iTimer->IsActive () )
|
|
258 |
{
|
|
259 |
if ( !iEnvelopeTable->Count()
|
|
260 |
&& !iTimerTable->Count() )
|
|
261 |
{
|
|
262 |
TFLOGSTRING("TSY: CSatTimer::Stop: Timer stopped");
|
|
263 |
OstTrace0( TRACE_DETAILED, DUP1_CSATTIMER_STOP, "CSatTimer::Stop: Timer stopped" );
|
|
264 |
iTimer->Cancel();
|
|
265 |
}
|
|
266 |
if ( !iTimerTable->Count() )
|
|
267 |
{
|
|
268 |
TFLOGSTRING("TSY: CSatTimer::Stop: Second counters cleared");
|
|
269 |
OstTrace0( TRACE_DETAILED, DUP2_CSATTIMER_STOP, "CSatTimer::Stop: Second counters cleared" );
|
|
270 |
iSecondsPassed = 0;
|
|
271 |
iHalfSecondTick = EFalse;
|
|
272 |
}
|
|
273 |
}
|
|
274 |
}
|
|
275 |
|
|
276 |
// -----------------------------------------------------------------------------
|
|
277 |
// CSatTimer::Tick
|
|
278 |
// Static callback method for CPeriodic timer.
|
|
279 |
// (other items were commented in a header).
|
|
280 |
// -----------------------------------------------------------------------------
|
|
281 |
//
|
|
282 |
TInt CSatTimer::Tick
|
|
283 |
(
|
|
284 |
TAny* aSatTimer
|
|
285 |
)
|
|
286 |
{
|
|
287 |
// Logging omitted to avoid excessive log output
|
|
288 |
|
|
289 |
// This is a static method, we need a pointer to parent class in
|
|
290 |
// order to utilize it's method and members
|
|
291 |
CSatTimer* satTimer = static_cast<CSatTimer*>( aSatTimer );
|
|
292 |
|
|
293 |
// Invert boolean value of half second boolean
|
|
294 |
satTimer->iHalfSecondTick = !satTimer->iHalfSecondTick;
|
|
295 |
|
|
296 |
// Update second counter and check timers only when there are active
|
|
297 |
// timers and whole second has passed since last update.
|
|
298 |
TInt tableSize( satTimer->iTimerTable->Count() );
|
|
299 |
if ( KZero != tableSize && !satTimer->iHalfSecondTick )
|
|
300 |
{
|
|
301 |
satTimer->iSecondsPassed++;
|
|
302 |
|
|
303 |
TFLOGSTRING2("TSY: CSatTimer::Tick, seconds %d",
|
|
304 |
satTimer->iSecondsPassed );
|
|
305 |
OstTrace1( TRACE_DETAILED, CSATTIMER_TICK, "CSatTimer::Tick, seconds %u", satTimer->iSecondsPassed );
|
|
306 |
|
|
307 |
for( TInt i = tableSize - 1; KZero <= i; i-- )
|
|
308 |
{
|
|
309 |
// Get reference to a timer in TimerTable
|
|
310 |
TTimer& timer = ( *satTimer->iTimerTable )[i];
|
|
311 |
|
|
312 |
// Send timer expiration envelope if:
|
|
313 |
// 1) Enough time has passed
|
|
314 |
// 2) Timer is active
|
|
315 |
// 3) Proactive command is not ongoing
|
|
316 |
if ( timer.TimeStamp() <= satTimer->iSecondsPassed
|
|
317 |
&& TTimer::ETicking == timer.State() )
|
|
318 |
{
|
|
319 |
// Deactive timer to avoid multiple envelopes
|
|
320 |
timer.SetState( TTimer::EBeingSent);
|
|
321 |
|
|
322 |
// Elapsed time
|
|
323 |
TInt time( satTimer->iSecondsPassed - timer.StartTime() );
|
|
324 |
|
|
325 |
satTimer->iSatMessaging->TimerExpiration( timer.Id(), time );
|
|
326 |
}
|
|
327 |
}
|
|
328 |
}
|
|
329 |
|
|
330 |
|
|
331 |
// Handle the stored envelopes. Look for envelopes activated for resending.
|
|
332 |
// Resend the oldest envelope if delay criteria has been met.
|
|
333 |
tableSize = satTimer->iEnvelopeTable->Count();
|
|
334 |
TBool done( EFalse );
|
|
335 |
|
|
336 |
if ( KZero != tableSize )
|
|
337 |
{
|
|
338 |
for ( TInt i = 0 ; i < tableSize && done == EFalse ; i++ )
|
|
339 |
{
|
|
340 |
TSatEnvelope& current = ( *satTimer->iEnvelopeTable )[i];
|
|
341 |
|
|
342 |
if ( current.iActive )
|
|
343 |
{
|
|
344 |
// Active envelope found. Decrease delay and send envelope
|
|
345 |
// if zero.
|
|
346 |
current.iDelay--;
|
|
347 |
|
|
348 |
if ( KZero >= current.iDelay )
|
|
349 |
{
|
|
350 |
TFLOGSTRING2("TSY: CSatTimer::Tick: \
|
|
351 |
Resending type %x envelope", current.iType );
|
|
352 |
OstTraceExt1( TRACE_DETAILED, DUP1_CSATTIMER_TICK, "CSatTimer::Tick Resending type %hhu envelope", current.iType );
|
|
353 |
|
|
354 |
// Deactivate envelope just in case. Get new transaction
|
|
355 |
// if for envelope and resend it. Finally remove the
|
|
356 |
// envelope from table.
|
|
357 |
current.iActive = EFalse;
|
|
358 |
|
|
359 |
satTimer->iSatMessHandler->UiccCatReqEnvelope(
|
|
360 |
current.iTId, current.iEnvelope, EFalse );
|
|
361 |
|
|
362 |
satTimer->RemoveEnvelope( current.iTId );
|
|
363 |
tableSize = satTimer->iEnvelopeTable->Count();
|
|
364 |
|
|
365 |
// Exit resending loop, only one resent envelope per tick
|
|
366 |
done = ETrue;
|
|
367 |
}
|
|
368 |
} // If active
|
|
369 |
} // For-loop
|
|
370 |
} // Table size not zero
|
|
371 |
|
|
372 |
return KErrNone;
|
|
373 |
}
|
|
374 |
|
|
375 |
// -----------------------------------------------------------------------------
|
|
376 |
// CSatTimer::CheckTimerTable
|
|
377 |
// Returns true if the timer exists in the timer table.
|
|
378 |
// (other items were commented in a header).
|
|
379 |
// -----------------------------------------------------------------------------
|
|
380 |
//
|
|
381 |
TBool CSatTimer::CheckTimerTable
|
|
382 |
(
|
|
383 |
TInt aTimerId
|
|
384 |
)
|
|
385 |
{
|
|
386 |
OstTrace0( TRACE_DETAILED, CSATTIMER_CHECKTIMERTABLE, "CSatTimer::CheckTimerTable" );
|
|
387 |
TFLOGSTRING("TSY: CSatTimer::CheckTimerTable");
|
|
388 |
|
|
389 |
TBool ret( EFalse );
|
|
390 |
|
|
391 |
// Create the helper entry with meaningful values only
|
|
392 |
TTimer timer( aTimerId, 0, 0 );
|
|
393 |
|
|
394 |
// Find the entry for this Handle in the list
|
|
395 |
TInt position = iTimerTable->Find( timer, TTimer::CompareEntries );
|
|
396 |
if ( KErrNotFound != position )
|
|
397 |
{
|
|
398 |
ret = ETrue;
|
|
399 |
}
|
|
400 |
return ret;
|
|
401 |
}
|
|
402 |
|
|
403 |
// -----------------------------------------------------------------------------
|
|
404 |
// CSatTimer::DeleteTimerById
|
|
405 |
// Deletes timer from the table
|
|
406 |
// (other items were commented in a header).
|
|
407 |
// -----------------------------------------------------------------------------
|
|
408 |
//
|
|
409 |
TInt CSatTimer::DeleteTimerById
|
|
410 |
(
|
|
411 |
TInt aTimerId // Timer identifier
|
|
412 |
)
|
|
413 |
{
|
|
414 |
OstTrace0( TRACE_DETAILED, CSATTIMER_DELETETIMERBYID, "CSatTimer::DeleteTimerById" );
|
|
415 |
TFLOGSTRING("TSY: CSatTimer::DeleteTimerById");
|
|
416 |
|
|
417 |
TInt ret( KErrNotFound );
|
|
418 |
|
|
419 |
// Create the entry with meaningful values only
|
|
420 |
TTimer timer( aTimerId, 0, 0 );
|
|
421 |
|
|
422 |
// Find the entry for this Handle in the list
|
|
423 |
TInt position = iTimerTable->Find (timer, TTimer::CompareEntries );
|
|
424 |
|
|
425 |
// Check if element is found
|
|
426 |
if ( KErrNotFound != position )
|
|
427 |
{
|
|
428 |
iTimerTable->Remove( position );
|
|
429 |
iTimerTable->Compress();
|
|
430 |
// Check if empty
|
|
431 |
if ( KZero == iTimerTable->Count())
|
|
432 |
{
|
|
433 |
// Request stopping of timer
|
|
434 |
Stop();
|
|
435 |
}
|
|
436 |
ret = KErrNone;
|
|
437 |
}
|
|
438 |
return ret;
|
|
439 |
}
|
|
440 |
|
|
441 |
// -----------------------------------------------------------------------------
|
|
442 |
// CSatTimer::GetCurrentValueOfTimerById
|
|
443 |
// Gets current value of timer by timer id
|
|
444 |
// (other items were commented in a header).
|
|
445 |
// -----------------------------------------------------------------------------
|
|
446 |
//
|
|
447 |
TUint32 CSatTimer::GetCurrentValueOfTimerById
|
|
448 |
(
|
|
449 |
TInt aTimerId // Timer identifier
|
|
450 |
)
|
|
451 |
{
|
|
452 |
OstTrace0( TRACE_DETAILED, CSATTIMER_GETCURRENTVALUEOFTIMERBYID, "CSatTimer::GetCurrentValueOfTimerById" );
|
|
453 |
TFLOGSTRING("TSY: CSatTimer::GetCurrentValueOfTimerById");
|
|
454 |
|
|
455 |
TInt ret( KErrNotFound );
|
|
456 |
|
|
457 |
// Create the entry with meaningful values only
|
|
458 |
TTimer timer( aTimerId, 0, 0 );
|
|
459 |
|
|
460 |
// Find the entry for this Handle in the list
|
|
461 |
TInt position = iTimerTable->Find( timer, TTimer::CompareEntries );
|
|
462 |
|
|
463 |
// Check if element is found
|
|
464 |
if ( KErrNotFound != position )
|
|
465 |
{
|
|
466 |
// Get the reference to the a timer in timer table
|
|
467 |
TTimer& timer = ( *iTimerTable )[ position ];
|
|
468 |
// Get timeStamp
|
|
469 |
TUint32 timeStamp = timer.TimeStamp();
|
|
470 |
// Current timer value = timer timeout value - current time
|
|
471 |
ret = timeStamp - iSecondsPassed;
|
|
472 |
// If current timer value is smaller than zero set value to 0
|
|
473 |
// this can happen if there is some kind of delay before
|
|
474 |
// timer is expired and iSecondsPassed is still counting...
|
|
475 |
if( KZero > ret )
|
|
476 |
{
|
|
477 |
ret = 0;
|
|
478 |
}
|
|
479 |
}
|
|
480 |
return ret;
|
|
481 |
}
|
|
482 |
|
|
483 |
// -----------------------------------------------------------------------------
|
|
484 |
// CSatTimer::StoreEnvelope
|
|
485 |
// Stores envelope for possible resending
|
|
486 |
// (other items were commented in a header).
|
|
487 |
// -----------------------------------------------------------------------------
|
|
488 |
//
|
|
489 |
TInt CSatTimer::StoreEnvelope
|
|
490 |
(
|
|
491 |
const TUint8 aTId,
|
|
492 |
const TDesC8& aEnvelope
|
|
493 |
)
|
|
494 |
{
|
|
495 |
OstTrace0( TRACE_DETAILED, CSATTIMER_STOREENVELOPE, "CSatTimer::StoreEnvelope" );
|
|
496 |
TFLOGSTRING("TSY: CSatTimer::StoreEnvelope");
|
|
497 |
|
|
498 |
TInt ret( KErrNone );
|
|
499 |
|
|
500 |
// Add envelope to array only if it is not already there,
|
|
501 |
// envelope has proper length a envelope data begins with
|
|
502 |
// envelope tag (D1..D8)
|
|
503 |
if ( KErrNotFound == LocateEnvelope( aTId )
|
|
504 |
&& KZero < aEnvelope.Length() )
|
|
505 |
{
|
|
506 |
if ( ( aEnvelope[KZero] & KHiByteMask ) == ETypeUnknown )
|
|
507 |
{
|
|
508 |
// Backup system. Oldest envelope is deleted if too
|
|
509 |
// many envelopes exist in the queue
|
|
510 |
if ( KMaxNumberOfStoredEnvelopes < iEnvelopeTable->Count() )
|
|
511 |
{
|
|
512 |
iEnvelopeTable->Remove( 0 );
|
|
513 |
iEnvelopeTable->Compress();
|
|
514 |
}
|
|
515 |
|
|
516 |
TSatEnvelope envelope;
|
|
517 |
|
|
518 |
envelope.iTId = aTId;
|
|
519 |
envelope.iDelay = KDefaultDelay;
|
|
520 |
envelope.iType = aEnvelope[KZero]; // Type is at index 0
|
|
521 |
envelope.iActive = EFalse;
|
|
522 |
envelope.iEnvelope.Copy( aEnvelope );
|
|
523 |
|
|
524 |
iEnvelopeTable->Append( envelope );
|
|
525 |
|
|
526 |
TFLOGSTRING2("CSatTimer::StoreEnvelope \
|
|
527 |
Stored envelopes: % d", iEnvelopeTable->Count() );
|
|
528 |
OstTrace1( TRACE_DETAILED, DUP1_CSATTIMER_STOREENVELOPE, "CSatTimer::StoreEnvelope Stored envelopes: %d", iEnvelopeTable->Count() );
|
|
529 |
|
|
530 |
}
|
|
531 |
else
|
|
532 |
{
|
|
533 |
TFLOGSTRING2("CSatTimer::StoreEnvelope \
|
|
534 |
Storing failed, not an envelope! %x", aEnvelope[KZero] );
|
|
535 |
OstTraceExt1( TRACE_DETAILED, DUP2_CSATTIMER_STOREENVELOPE, "CSatTimer::StoreEnvelope Storing failed, not an envelope! %s", aEnvelope[KZero] );
|
|
536 |
ret = KErrArgument;
|
|
537 |
}
|
|
538 |
|
|
539 |
}
|
|
540 |
else
|
|
541 |
{
|
|
542 |
TFLOGSTRING2(" CSatTimer::StoreEnvelope \
|
|
543 |
Envelope with requested ID %d already exist!", aTId );
|
|
544 |
OstTraceExt1( TRACE_DETAILED, DUP3_CSATTIMER_STOREENVELOPE, "CSatTimer::StoreEnvelope Envelope with requested ID %hhd already exists!", aTId );
|
|
545 |
ret = KErrAlreadyExists;
|
|
546 |
}
|
|
547 |
|
|
548 |
return ret;
|
|
549 |
}
|
|
550 |
|
|
551 |
|
|
552 |
// -----------------------------------------------------------------------------
|
|
553 |
// CSatTimer::ActivateEnvelopeResend
|
|
554 |
// Activates the resending procedure of stored envelope
|
|
555 |
// (other items were commented in a header).
|
|
556 |
// -----------------------------------------------------------------------------
|
|
557 |
//
|
|
558 |
TInt CSatTimer::ActivateEnvelopeResend
|
|
559 |
(
|
|
560 |
const TUint8 aTId,
|
|
561 |
const TUint8 aCause
|
|
562 |
)
|
|
563 |
{
|
|
564 |
OstTrace0( TRACE_DETAILED, CSATTIMER_ACTIVATEENVELOPERESEND, "CSatTimer::ActivateEnvelopeResend" );
|
|
565 |
TFLOGSTRING("TSY: CSatTimer::ActivateEnvelopeResend");
|
|
566 |
|
|
567 |
TInt ret( LocateEnvelope( aTId ) );
|
|
568 |
|
|
569 |
if ( KErrNotFound != ret )
|
|
570 |
{
|
|
571 |
TSatEnvelope& current = ( *iEnvelopeTable )[ret];
|
|
572 |
|
|
573 |
switch ( aCause )
|
|
574 |
{
|
|
575 |
case ESimBusy:
|
|
576 |
{
|
|
577 |
if ( ETimerExpiration == current.iType
|
|
578 |
&& KTimerIdPosition < current.iEnvelope.Length() )
|
|
579 |
{
|
|
580 |
// Resending of Timer envelope is different from others,
|
|
581 |
// because timer value has to be updated within the resent
|
|
582 |
// envelope. As a result, we can't just resend old message.
|
|
583 |
|
|
584 |
// Restart timer using ID.
|
|
585 |
RestartTimer( current.iEnvelope[KTimerIdPosition] );
|
|
586 |
|
|
587 |
// Old stored envelope has to be removed from envelope,
|
|
588 |
// but not from timer table in case of timer reactivation.
|
|
589 |
RemoveEnvelope( aTId, EFalse );
|
|
590 |
}
|
|
591 |
else
|
|
592 |
{
|
|
593 |
// For other envelope, just activate it
|
|
594 |
current.iActive = ETrue;
|
|
595 |
}
|
|
596 |
|
|
597 |
ret = KErrNone;
|
|
598 |
break;
|
|
599 |
}
|
|
600 |
case ERefManagement:
|
|
601 |
{
|
|
602 |
// Resending of envelope when SIM return Reference Management
|
|
603 |
// error, and active envelope is Call Control, is based on
|
|
604 |
// error item( No call after autolock). Because need for send
|
|
605 |
// is unclear (in other Nokia devices does it),
|
|
606 |
// only CC envelope are resent.
|
|
607 |
if ( ECallControl == current.iType )
|
|
608 |
{
|
|
609 |
current.iActive = ETrue;
|
|
610 |
ret = KErrNone;
|
|
611 |
}
|
|
612 |
else
|
|
613 |
{
|
|
614 |
ret = KErrNotSupported;
|
|
615 |
}
|
|
616 |
break;
|
|
617 |
}
|
|
618 |
default:
|
|
619 |
{
|
|
620 |
// Unexpected cause
|
|
621 |
ret = KErrNotSupported;
|
|
622 |
}
|
|
623 |
}
|
|
624 |
|
|
625 |
if ( KErrNone == ret )
|
|
626 |
{
|
|
627 |
TFLOGSTRING("TSY: CSatTimer::ActivateEnvelopeResend \
|
|
628 |
Resending activated");
|
|
629 |
OstTrace0( TRACE_DETAILED, DUP1_CSATTIMER_ACTIVATEENVELOPERESEND, "CSatTimer::ActivateEnvelopeResend Resending activated" );
|
|
630 |
// (Re)start the timer if needed
|
|
631 |
Start();
|
|
632 |
}
|
|
633 |
else
|
|
634 |
{
|
|
635 |
TFLOGSTRING2("TSY: CSatTimer::ActivateEnvelopeResend \
|
|
636 |
Resending NOT activated. Cause: %x", aCause );
|
|
637 |
OstTraceExt1( TRACE_DETAILED, DUP2_CSATTIMER_ACTIVATEENVELOPERESEND, "CSatTimer::ActivateEnvelopeResend Resending NOT activated. Cause: %hhu", aCause );
|
|
638 |
RemoveEnvelope( aTId );
|
|
639 |
}
|
|
640 |
}
|
|
641 |
|
|
642 |
return ret;
|
|
643 |
}
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
// -----------------------------------------------------------------------------
|
|
648 |
// CSatTimer::RemoveEnvelope
|
|
649 |
// Removes the envelope from the table by given id
|
|
650 |
// (other items were commented in a header).
|
|
651 |
// -----------------------------------------------------------------------------
|
|
652 |
//
|
|
653 |
TInt CSatTimer::RemoveEnvelope
|
|
654 |
(
|
|
655 |
const TUint8 aTId,
|
|
656 |
TBool aRemoveTimer
|
|
657 |
)
|
|
658 |
{
|
|
659 |
OstTrace0( TRACE_DETAILED, CSATTIMER_REMOVEENVELOPE, "CSatTimer::RemoveEnvelope" );
|
|
660 |
TFLOGSTRING("TSY: CSatTimer::RemoveEnvelope");
|
|
661 |
|
|
662 |
TInt ret( LocateEnvelope( aTId ) );
|
|
663 |
|
|
664 |
if ( KErrNotFound != ret )
|
|
665 |
{
|
|
666 |
TSatEnvelope& current = (*iEnvelopeTable)[ret];
|
|
667 |
|
|
668 |
// The timer corresponding the envelope must be removed from timer
|
|
669 |
// table if timer expiration envelope was sent successfully.
|
|
670 |
if ( ETimerExpiration == current.iType && aRemoveTimer )
|
|
671 |
{
|
|
672 |
DeleteTimerById( current.iEnvelope[KTimerIdPosition] );
|
|
673 |
}
|
|
674 |
|
|
675 |
iEnvelopeTable->Remove( ret );
|
|
676 |
iEnvelopeTable->Compress();
|
|
677 |
|
|
678 |
// Stop-method halts the timer only if there are no envelopes or
|
|
679 |
// timer expiration left
|
|
680 |
Stop();
|
|
681 |
|
|
682 |
ret = KErrNone;
|
|
683 |
}
|
|
684 |
|
|
685 |
return ret;
|
|
686 |
}
|
|
687 |
|
|
688 |
|
|
689 |
// -----------------------------------------------------------------------------
|
|
690 |
// CSatTimer::LocateEnvelope
|
|
691 |
// Locates the position of envelope in table by given id
|
|
692 |
// (other items were commented in a header).
|
|
693 |
// -----------------------------------------------------------------------------
|
|
694 |
//
|
|
695 |
TInt CSatTimer::LocateEnvelope
|
|
696 |
(
|
|
697 |
const TUint8 aTId
|
|
698 |
)
|
|
699 |
{
|
|
700 |
OstTrace0( TRACE_DETAILED, CSATTIMER_LOCATEENVELOPE, "CSatTimer::LocateEnvelope" );
|
|
701 |
TFLOGSTRING("TSY: CSatTimer::LocateEnvelope");
|
|
702 |
|
|
703 |
TInt ret( KErrNotFound );
|
|
704 |
TInt numEnvelopes( iEnvelopeTable->Count() );
|
|
705 |
|
|
706 |
for ( TInt i = 0 ; i < numEnvelopes && ret == KErrNotFound ; i++ )
|
|
707 |
{
|
|
708 |
if ( ( *iEnvelopeTable )[i].iTId == aTId )
|
|
709 |
{
|
|
710 |
TFLOGSTRING2("TSY: CSatTimer::LocateEnvelope \
|
|
711 |
Requested envelope was found at index %d", i );
|
|
712 |
OstTrace1( TRACE_DETAILED, DUP1_CSATTIMER_LOCATEENVELOPE, "CSatTimer::LocateEnvelope Requested envelope was found at index %d", i );
|
|
713 |
ret = i;
|
|
714 |
}
|
|
715 |
}
|
|
716 |
|
|
717 |
return ret;
|
|
718 |
}
|
|
719 |
|
|
720 |
|
|
721 |
// -----------------------------------------------------------------------------
|
|
722 |
// CSatTimer::SetProactiveCommandOnGoingStatus
|
|
723 |
// Sets status for ProactiveCommandOnGoing flag
|
|
724 |
// (other items were commented in a header).
|
|
725 |
// -----------------------------------------------------------------------------
|
|
726 |
//
|
|
727 |
void CSatTimer::SetProactiveCommandOnGoingStatus
|
|
728 |
(
|
|
729 |
TBool aStatus
|
|
730 |
)
|
|
731 |
{
|
|
732 |
OstTrace0( TRACE_DETAILED, CSATTIMER_SETPROACTIVECOMMANDONGOINGSTATUS, "CSatTimer::SetProactiveCommandOnGoingStatus" );
|
|
733 |
iProactiveCommandOnGoing = aStatus;
|
|
734 |
|
|
735 |
TInt tableSize( iTimerTable->Count() );
|
|
736 |
|
|
737 |
if ( !iProactiveCommandOnGoing && tableSize )
|
|
738 |
{
|
|
739 |
// Some of the timers has been deactivated because of ongoing pcmd
|
|
740 |
for ( TInt i( 0 ) ; i < tableSize ; i++ )
|
|
741 |
{
|
|
742 |
// Get reference to a timer in TimerTable
|
|
743 |
TTimer& timer = ( *iTimerTable )[i];
|
|
744 |
|
|
745 |
if ( TTimer::EWaitingForTr == timer.State() )
|
|
746 |
{
|
|
747 |
timer.SetState( TTimer::ETicking );
|
|
748 |
Start(); // Just in case
|
|
749 |
}
|
|
750 |
}
|
|
751 |
}
|
|
752 |
}
|
|
753 |
|
|
754 |
|
|
755 |
// -----------------------------------------------------------------------------
|
|
756 |
// CSatTimer::ClearTimerTable
|
|
757 |
// Clears the timer table
|
|
758 |
// (other items were commented in a header).
|
|
759 |
// -----------------------------------------------------------------------------
|
|
760 |
//
|
|
761 |
void CSatTimer::ClearTimerTable()
|
|
762 |
{
|
|
763 |
OstTrace0( TRACE_DETAILED, CSATTIMER_CLEARTIMERTABLE, "CSatTimer::ClearTimerTable" );
|
|
764 |
|
|
765 |
if ( KZero != iTimerTable->Count() )
|
|
766 |
{
|
|
767 |
// Clear the array
|
|
768 |
iTimerTable->Reset();
|
|
769 |
iTimerTable->Compress();
|
|
770 |
|
|
771 |
// Request timer stop till new entry is done
|
|
772 |
Stop();
|
|
773 |
}
|
|
774 |
}
|
|
775 |
|
|
776 |
|
|
777 |
// -----------------------------------------------------------------------------
|
|
778 |
// CSatTimer::TTimer::TTimer
|
|
779 |
// Non default Constructor, for nested class
|
|
780 |
// (other items were commented in a header).
|
|
781 |
// -----------------------------------------------------------------------------
|
|
782 |
//
|
|
783 |
CSatTimer::TTimer::TTimer
|
|
784 |
(
|
|
785 |
TInt aTimerId, // Timer id
|
|
786 |
TUint32 aStartTime, // Timer start time
|
|
787 |
TUint32 aTimeStamp // Time stamp
|
|
788 |
)
|
|
789 |
:
|
|
790 |
iTimerId( aTimerId ),
|
|
791 |
iStartTime( aStartTime ),
|
|
792 |
iTimeStamp( aTimeStamp ),
|
|
793 |
iState( ETicking )
|
|
794 |
{
|
|
795 |
}
|
|
796 |
|
|
797 |
|
|
798 |
// -----------------------------------------------------------------------------
|
|
799 |
// CSatTimer::TTimer::TimeStamp
|
|
800 |
// returns iTimeStamp from a TTimer
|
|
801 |
// (other items were commented in a header).
|
|
802 |
// -----------------------------------------------------------------------------
|
|
803 |
//
|
|
804 |
TUint32 CSatTimer::TTimer::TimeStamp()
|
|
805 |
{
|
|
806 |
return iTimeStamp;
|
|
807 |
}
|
|
808 |
|
|
809 |
// -----------------------------------------------------------------------------
|
|
810 |
// CSatTimer::TTimer::Id
|
|
811 |
// returns iTimerId from a TTimer
|
|
812 |
// (other items were commented in a header).
|
|
813 |
// -----------------------------------------------------------------------------
|
|
814 |
//
|
|
815 |
TInt CSatTimer::TTimer::Id()
|
|
816 |
{
|
|
817 |
return iTimerId;
|
|
818 |
}
|
|
819 |
|
|
820 |
// -----------------------------------------------------------------------------
|
|
821 |
// CSatTimer::TTimer::StartTime
|
|
822 |
// returns iStartTime from a TTimer
|
|
823 |
// (other items were commented in a header).
|
|
824 |
// -----------------------------------------------------------------------------
|
|
825 |
//
|
|
826 |
TUint32 CSatTimer::TTimer::StartTime()
|
|
827 |
{
|
|
828 |
return iStartTime;
|
|
829 |
}
|
|
830 |
|
|
831 |
// -----------------------------------------------------------------------------
|
|
832 |
// CSatTimer::TTimer::SetState
|
|
833 |
// Setter for timer's internal state.
|
|
834 |
// (other items were commented in a header).
|
|
835 |
// -----------------------------------------------------------------------------
|
|
836 |
//
|
|
837 |
void CSatTimer::TTimer::SetState
|
|
838 |
(
|
|
839 |
TState aState
|
|
840 |
)
|
|
841 |
{
|
|
842 |
iState = aState;
|
|
843 |
}
|
|
844 |
|
|
845 |
// -----------------------------------------------------------------------------
|
|
846 |
// CSatTimer::TTimer::IsActive
|
|
847 |
// Getter for timer's internal state.
|
|
848 |
// (other items were commented in a header).
|
|
849 |
// -----------------------------------------------------------------------------
|
|
850 |
//
|
|
851 |
CSatTimer::TTimer::TState CSatTimer::TTimer::State()
|
|
852 |
{
|
|
853 |
return iState;
|
|
854 |
}
|
|
855 |
|
|
856 |
// -----------------------------------------------------------------------------
|
|
857 |
// CSatTimer::TTimer::CompareEntries
|
|
858 |
// Returns if two entries are equal
|
|
859 |
// (other items were commented in a header).
|
|
860 |
// -----------------------------------------------------------------------------
|
|
861 |
//
|
|
862 |
TBool CSatTimer::TTimer::CompareEntries
|
|
863 |
(
|
|
864 |
const CSatTimer::TTimer& arg1, // First entry
|
|
865 |
const CSatTimer::TTimer& arg2 // Second entry
|
|
866 |
)
|
|
867 |
{
|
|
868 |
TBool ret( EFalse );
|
|
869 |
|
|
870 |
// We are interested only in the timer id
|
|
871 |
if ( arg1.iTimerId == arg2.iTimerId )
|
|
872 |
{
|
|
873 |
ret = ETrue;
|
|
874 |
}
|
|
875 |
return ret;
|
|
876 |
}
|
|
877 |
|
|
878 |
// -----------------------------------------------------------------------------
|
|
879 |
// CSatTimer::TTimer::OrderEntries
|
|
880 |
// Returns order between two entries
|
|
881 |
// (other items were commented in a header).
|
|
882 |
// -----------------------------------------------------------------------------
|
|
883 |
//
|
|
884 |
TInt CSatTimer::TTimer::OrderEntries
|
|
885 |
(
|
|
886 |
const CSatTimer::TTimer& arg1, // First entry
|
|
887 |
const CSatTimer::TTimer& arg2 // Second entry
|
|
888 |
)
|
|
889 |
{
|
|
890 |
TInt ret( KTimersEqual );
|
|
891 |
|
|
892 |
// We are interested only in the timer id
|
|
893 |
if ( arg1.iTimerId < arg2.iTimerId )
|
|
894 |
{
|
|
895 |
ret = KFirstSmaller;
|
|
896 |
}
|
|
897 |
else if( arg1.iTimerId > arg2.iTimerId )
|
|
898 |
{
|
|
899 |
ret = KFirstBigger;
|
|
900 |
}
|
|
901 |
else
|
|
902 |
{
|
|
903 |
// Timer Id's are equal. Return value already properly initialized.
|
|
904 |
}
|
|
905 |
return ret;
|
|
906 |
|
|
907 |
}
|
|
908 |
|
|
909 |
// End of file
|