|
1 // Copyright (c) 1999-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 // |
|
15 |
|
16 #include "ASSrvIteratorBase.h" |
|
17 |
|
18 // System includes |
|
19 |
|
20 // User includes |
|
21 #include "ASSrvAlarmQueue.h" |
|
22 |
|
23 // Type definitions |
|
24 |
|
25 // Constants |
|
26 const TInt KInitialIndexValue = -1; |
|
27 |
|
28 // Enumerations |
|
29 |
|
30 // Classes referenced |
|
31 |
|
32 |
|
33 // |
|
34 // ----> RASSrvIteratorBase (source) |
|
35 // |
|
36 |
|
37 //************************************************************************************* |
|
38 RASSrvIteratorBase::RASSrvIteratorBase(CASSrvAlarmQueue& aQueue) |
|
39 : iQueue(aQueue), iCurrentIndex(KInitialIndexValue), iType(EASSrvIteratorTypeSecondary), iAttachedIterator(NULL) |
|
40 { |
|
41 } |
|
42 |
|
43 |
|
44 //************************************************************************************* |
|
45 /** |
|
46 * Only the primary iterator should ever be opened. |
|
47 */ |
|
48 void RASSrvIteratorBase::Open() |
|
49 { |
|
50 iType = EASSrvIteratorTypePrimary; |
|
51 |
|
52 // Restore back to default state |
|
53 Reset(); |
|
54 } |
|
55 |
|
56 |
|
57 // |
|
58 // |
|
59 // |
|
60 |
|
61 |
|
62 //************************************************************************************* |
|
63 /** |
|
64 * Is another alarm available? |
|
65 */ |
|
66 TBool RASSrvIteratorBase::NextAlarmAvailable() const |
|
67 { |
|
68 RASSrvIteratorBase& self = const_cast<RASSrvIteratorBase&>(*this); |
|
69 const TInt count = AlarmCount(); |
|
70 TInt index = iCurrentIndex; |
|
71 // |
|
72 while(++index < count) |
|
73 { |
|
74 const TASSrvAlarm& alarm = self.AlarmAt(index); |
|
75 if (Matches(alarm)) |
|
76 return ETrue; |
|
77 } |
|
78 return EFalse; |
|
79 } |
|
80 |
|
81 |
|
82 //************************************************************************************* |
|
83 /** |
|
84 * Return the next available alarm |
|
85 */ |
|
86 TASSrvAlarm& RASSrvIteratorBase::NextAlarm() |
|
87 { |
|
88 const TInt count = AlarmCount(); |
|
89 while (++iCurrentIndex < count) |
|
90 { |
|
91 TASSrvAlarm& alarm = AlarmAt(iCurrentIndex); |
|
92 if (Matches(alarm)) |
|
93 { |
|
94 IteratorSynchronize(*this); |
|
95 return alarm; |
|
96 } |
|
97 } |
|
98 |
|
99 // Panic because there isn't another available alarm. |
|
100 Panic(EASSrvIteratorPanicNoNextAlarmForIterator); |
|
101 TASSrvAlarm* dummy = NULL; |
|
102 return *dummy; |
|
103 } |
|
104 |
|
105 |
|
106 //************************************************************************************* |
|
107 /** |
|
108 * Resets the iterator back to the start of the queue |
|
109 */ |
|
110 void RASSrvIteratorBase::Reset() |
|
111 { |
|
112 iCurrentIndex = KInitialIndexValue; |
|
113 IteratorSynchronize(*this); |
|
114 } |
|
115 |
|
116 |
|
117 //************************************************************************************* |
|
118 /** |
|
119 * Attaches another iterator to this one. Allows iterators to be chained |
|
120 * together so that different conditions can be satisfied without complex |
|
121 * (custom-written) individual iterator combinations. |
|
122 */ |
|
123 void RASSrvIteratorBase::IteratorAttach(RASSrvIteratorBase& aIterator) |
|
124 { |
|
125 __ASSERT_ALWAYS(&aIterator != this, Panic(EASSrvIteratorPanicCyclicAttach)); |
|
126 iAttachedIterator = &aIterator; |
|
127 } |
|
128 |
|
129 |
|
130 //************************************************************************************* |
|
131 /** |
|
132 * Release a previously attached iterator |
|
133 */ |
|
134 void RASSrvIteratorBase::IteratorRelease() |
|
135 { |
|
136 iAttachedIterator = NULL; |
|
137 } |
|
138 |
|
139 |
|
140 // |
|
141 // |
|
142 // |
|
143 |
|
144 |
|
145 //************************************************************************************* |
|
146 /** |
|
147 * Is an iterator attached? |
|
148 */ |
|
149 TBool RASSrvIteratorBase::IteratorAttached() const |
|
150 { |
|
151 return (iAttachedIterator != NULL); |
|
152 } |
|
153 |
|
154 |
|
155 //************************************************************************************* |
|
156 /** |
|
157 * Access the attached iterator |
|
158 */ |
|
159 RASSrvIteratorBase& RASSrvIteratorBase::Iterator() |
|
160 { |
|
161 __ASSERT_ALWAYS(IteratorAttached(), Panic(EASSrvIteratorPanicNoneAttached)); |
|
162 return *iAttachedIterator; |
|
163 } |
|
164 |
|
165 |
|
166 //************************************************************************************* |
|
167 /** |
|
168 * Access a constant handle to the attached iterator |
|
169 */ |
|
170 const RASSrvIteratorBase& RASSrvIteratorBase::Iterator() const |
|
171 { |
|
172 __ASSERT_ALWAYS(IteratorAttached(), Panic(EASSrvIteratorPanicNoneAttached)); |
|
173 return *iAttachedIterator; |
|
174 } |
|
175 |
|
176 |
|
177 //************************************************************************************* |
|
178 /** |
|
179 * Synchronise this iterator with another |
|
180 */ |
|
181 void RASSrvIteratorBase::IteratorSynchronize(RASSrvIteratorBase& aInterator) |
|
182 { |
|
183 iCurrentIndex = aInterator.iCurrentIndex; |
|
184 if (IteratorAttached()) |
|
185 Iterator().IteratorSynchronize(*this); |
|
186 } |
|
187 |
|
188 |
|
189 //************************************************************************************* |
|
190 /** |
|
191 * Does the specified alarm satisfy the criteria associated with |
|
192 * this iterator? |
|
193 */ |
|
194 TBool RASSrvIteratorBase::Matches(const TASSrvAlarm& aAlarm) const |
|
195 { |
|
196 // If we have an attached iterator, then we should |
|
197 // check with that too. |
|
198 TBool matches = ETrue; |
|
199 // |
|
200 if (IteratorAttached()) |
|
201 matches = Iterator().Matches(aAlarm); |
|
202 // |
|
203 return matches; |
|
204 } |
|
205 |
|
206 |
|
207 //************************************************************************************* |
|
208 /** |
|
209 * Return a reference to the alarm at the specified index |
|
210 */ |
|
211 TASSrvAlarm& RASSrvIteratorBase::AlarmAt(TInt aIndex) |
|
212 { |
|
213 __ASSERT_ALWAYS(iType == EASSrvIteratorTypePrimary, Panic(EASSrvIteratorPanicTypeMismatch)); |
|
214 return iQueue.QueueAlarmAt(aIndex); |
|
215 } |
|
216 |
|
217 |
|
218 //************************************************************************************* |
|
219 /** |
|
220 * Return the number of alarms |
|
221 */ |
|
222 TInt RASSrvIteratorBase::AlarmCount() const |
|
223 { |
|
224 __ASSERT_ALWAYS(iType == EASSrvIteratorTypePrimary, Panic(EASSrvIteratorPanicTypeMismatch)); |
|
225 return iQueue.QueueAlarmCount(); |
|
226 } |
|
227 |
|
228 |
|
229 // |
|
230 // |
|
231 // |
|
232 |
|
233 |
|
234 //************************************************************************************* |
|
235 /** |
|
236 * Panic the Alarm Server |
|
237 */ |
|
238 void RASSrvIteratorBase::Panic(TASSrvIteratorPanic aPanic) |
|
239 { |
|
240 _LIT(KPanicCategory, "ASSrvIterator"); |
|
241 User::Panic(KPanicCategory, aPanic); |
|
242 } |
|
243 |
|
244 |
|
245 |
|
246 |