|
1 // Copyright (c) 2005-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 // Name : timerstore.cpp |
|
15 // Part of : LightWeightTimer |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "SipAssert.h" |
|
22 #include "timerstore.h" |
|
23 #include "timerrequest.h" |
|
24 |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CTimerStore::NewL |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CTimerStore* CTimerStore::NewL() |
|
31 { |
|
32 CTimerStore* self = new (ELeave) CTimerStore(); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CTimerStore::CTimerStore |
|
41 // For unit tests the array granularity is set to 1 to cause it to allocate |
|
42 // memory every time an item is added. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CTimerStore::CTimerStore() |
|
46 #ifdef CPPUNIT_TEST |
|
47 : iTimerRequests(1) |
|
48 #endif |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CTimerStore::ConstructL |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CTimerStore::ConstructL() |
|
57 { |
|
58 iSearchCond = CTimerRequest::NewL(); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CTimerStore::~CTimerStore |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CTimerStore::~CTimerStore() |
|
66 { |
|
67 delete iSearchCond; |
|
68 |
|
69 iTimerRequests.ResetAndDestroy(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CTimerStore::AddL |
|
74 // aObserver is NULL when aTimerId == MTimerManager::KReservedTimer |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void CTimerStore::AddL(MExpirationHandler* aObserver, |
|
78 TTime aExpirationTime, |
|
79 TTimerId aTimerId, |
|
80 TAny* aTimerParam) |
|
81 { |
|
82 __SIP_ASSERT_LEAVE(aObserver || aTimerId == MTimerManager::KReservedTimer, |
|
83 KErrArgument); |
|
84 __SIP_ASSERT_LEAVE(aTimerId != MTimerManager::KNoSuchTimer, KErrArgument); |
|
85 |
|
86 CTimerRequest* newItem = CTimerRequest::NewL(aTimerId, |
|
87 aExpirationTime, |
|
88 aObserver, |
|
89 aTimerParam); |
|
90 TLinearOrder<CTimerRequest> order(CTimerRequest::Compare); |
|
91 CleanupStack::PushL(newItem); |
|
92 User::LeaveIfError(iTimerRequests.InsertInOrderAllowRepeats(newItem, |
|
93 order)); |
|
94 CleanupStack::Pop(newItem); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CTimerStore::SearchById |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 CTimerRequest* CTimerStore::SearchById(TTimerId aTimerId, TInt& aIndex) const |
|
102 { |
|
103 //There is never a timer in store with the "empty" TimerId value |
|
104 if (aTimerId == MTimerManager::KNoSuchTimer) |
|
105 { |
|
106 return NULL; |
|
107 } |
|
108 |
|
109 iSearchCond->SetTimerId(aTimerId); |
|
110 TIdentityRelation<CTimerRequest> compareId(CTimerRequest::CompareId); |
|
111 aIndex = iTimerRequests.Find(iSearchCond, compareId); |
|
112 |
|
113 if (aIndex == KErrNotFound) |
|
114 { |
|
115 return NULL; |
|
116 } |
|
117 |
|
118 return iTimerRequests[aIndex]; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CTimerStore::ShortestTimer |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TBool CTimerStore::ShortestTimer(TTimerId& aTimerId, |
|
126 TTime& aExpirationTime) const |
|
127 { |
|
128 if (iTimerRequests.Count() < 1) |
|
129 { |
|
130 return EFalse; |
|
131 } |
|
132 |
|
133 aTimerId = iTimerRequests[0]->TimerId(); |
|
134 aExpirationTime = iTimerRequests[0]->ExpirationTime(); |
|
135 |
|
136 return ETrue; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CTimerStore::Remove |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 TBool CTimerStore::Remove(TInt aIndex) |
|
144 { |
|
145 __SIP_ASSERT_RETURN_VALUE(aIndex >= 0, KErrArgument); |
|
146 |
|
147 if (aIndex >= iTimerRequests.Count()) |
|
148 { |
|
149 return EFalse; |
|
150 } |
|
151 |
|
152 CTimerRequest* req = iTimerRequests[aIndex]; |
|
153 iTimerRequests.Remove(aIndex); |
|
154 delete req; |
|
155 |
|
156 iTimerRequests.Compress(); |
|
157 |
|
158 return ETrue; |
|
159 } |