|
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 "ASSrvDataPool.h" |
|
17 |
|
18 // System includes |
|
19 |
|
20 // User includes |
|
21 #include "ASSrvAlarmQueue.h" |
|
22 #include "ASSrvStaticUtils.h" |
|
23 #include "ASSrvServerWideData.h" |
|
24 |
|
25 // Type definitions |
|
26 |
|
27 // Constants |
|
28 |
|
29 // Enumerations |
|
30 |
|
31 // Classes referenced |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 // |
|
39 // ----> CASSrvAlarmDataMapplet (header) |
|
40 // |
|
41 |
|
42 //************************************************************************************* |
|
43 CASSrvDataPool::CASSrvAlarmDataMapplet::CASSrvAlarmDataMapplet(TAlarmId aAlarmId, HBufC8* aAlarmData) |
|
44 : iAlarmId(aAlarmId), iAlarmData(aAlarmData) |
|
45 { |
|
46 } |
|
47 |
|
48 |
|
49 //************************************************************************************* |
|
50 CASSrvDataPool::CASSrvAlarmDataMapplet::~CASSrvAlarmDataMapplet() |
|
51 { |
|
52 delete iAlarmData; |
|
53 } |
|
54 |
|
55 |
|
56 //************************************************************************************* |
|
57 CASSrvDataPool::CASSrvAlarmDataMapplet* CASSrvDataPool::CASSrvAlarmDataMapplet::NewLC(TAlarmId aAlarmId, HBufC8* aAlarmData) |
|
58 { |
|
59 __ASSERT_ALWAYS(aAlarmData, ASSrvStaticUtils::Fault(ASSrvStaticUtils::EASSrvFaultNoData)); |
|
60 // |
|
61 CleanupStack::PushL(aAlarmData); |
|
62 CASSrvAlarmDataMapplet* self = new(ELeave) CASSrvAlarmDataMapplet(aAlarmId, aAlarmData); |
|
63 CleanupStack::Pop(aAlarmData); |
|
64 CleanupStack::PushL(self); |
|
65 return self; |
|
66 } |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 // |
|
79 // ----> CASSrvDataPool (source) |
|
80 // |
|
81 |
|
82 //************************************************************************************* |
|
83 CASSrvDataPool::CASSrvDataPool(CASSrvServerWideData& aServerWideData) |
|
84 : iServerWideData(aServerWideData) |
|
85 { |
|
86 } |
|
87 |
|
88 |
|
89 //************************************************************************************* |
|
90 CASSrvDataPool::~CASSrvDataPool() |
|
91 { |
|
92 iDataEntries.ResetAndDestroy(); |
|
93 iDataEntries.Close(); |
|
94 if(iInternalizeDataEntries.Count() != 0) |
|
95 iInternalizeDataEntries.ResetAndDestroy(); |
|
96 iInternalizeDataEntries.Close(); |
|
97 ServerData().Queue().NotificationPoolChangeCancel(*this); |
|
98 } |
|
99 |
|
100 |
|
101 //************************************************************************************* |
|
102 void CASSrvDataPool::ConstructL() |
|
103 { |
|
104 ServerData().Queue().NotificationPoolChangeL(*this); |
|
105 } |
|
106 |
|
107 |
|
108 //************************************************************************************* |
|
109 CASSrvDataPool* CASSrvDataPool::NewL(CASSrvServerWideData& aServerWideData) |
|
110 { |
|
111 CASSrvDataPool* self = new(ELeave) CASSrvDataPool(aServerWideData); |
|
112 CleanupStack::PushL(self); |
|
113 self->ConstructL(); |
|
114 CleanupStack::Pop(self); |
|
115 return self; |
|
116 } |
|
117 |
|
118 |
|
119 // |
|
120 // |
|
121 // |
|
122 |
|
123 |
|
124 //************************************************************************************* |
|
125 /** |
|
126 * Does the specified alarm have any associated arbitrary data? |
|
127 */ |
|
128 TBool CASSrvDataPool::DataPoolContainsEntry(TAlarmId aAlarmId) const |
|
129 { |
|
130 return (FindEntry(aAlarmId) != KErrNotFound); |
|
131 } |
|
132 |
|
133 |
|
134 //************************************************************************************* |
|
135 /** |
|
136 * Return the associated arbitrary data for the specified alarm. |
|
137 */ |
|
138 const TDesC8& CASSrvDataPool::DataPoolEntry(TAlarmId aAlarmId) const |
|
139 { |
|
140 const TInt index = FindEntry(aAlarmId); |
|
141 __ASSERT_ALWAYS(index >= 0, ASSrvStaticUtils::Fault(ASSrvStaticUtils::EASSrvFaultAlarmDataEntryNotFound)); |
|
142 return iDataEntries[index]->Data(); |
|
143 } |
|
144 |
|
145 |
|
146 //************************************************************************************* |
|
147 /** |
|
148 * Add a new data mapping to the pool. |
|
149 */ |
|
150 void CASSrvDataPool::DataPoolAddDataL(TAlarmId aAlarmId, HBufC8* aData) |
|
151 { |
|
152 CleanupStack::PushL(aData); |
|
153 const TInt index = FindEntry(aAlarmId); |
|
154 if (index < KErrNone) |
|
155 { |
|
156 CleanupStack::Pop(aData); |
|
157 CASSrvAlarmDataMapplet* mapplet = CASSrvAlarmDataMapplet::NewLC(aAlarmId, aData); |
|
158 User::LeaveIfError(iDataEntries.Append(mapplet)); |
|
159 CleanupStack::Pop(mapplet); |
|
160 ServerData().AnyEventManager().MASAnyEventManagerObserverNotifyChanges(EAlarmChangeEventAlarmData, aAlarmId); |
|
161 } |
|
162 else |
|
163 User::Leave(KErrInUse); |
|
164 } |
|
165 |
|
166 |
|
167 //************************************************************************************* |
|
168 /** |
|
169 * Release the data associated with the specified entry |
|
170 */ |
|
171 void CASSrvDataPool::DataPoolRemoveDataL(TAlarmId aAlarmId) |
|
172 { |
|
173 const TInt index = FindEntry(aAlarmId); |
|
174 if (index < KErrNone) |
|
175 User::Leave(index); |
|
176 // |
|
177 delete iDataEntries[index]; |
|
178 iDataEntries.Remove(index); |
|
179 // |
|
180 ServerData().AnyEventManager().MASAnyEventManagerObserverNotifyChanges(EAlarmChangeEventAlarmData, aAlarmId); |
|
181 } |
|
182 |
|
183 |
|
184 // |
|
185 // |
|
186 // |
|
187 |
|
188 |
|
189 //************************************************************************************* |
|
190 /** |
|
191 * Internalize the contents of the datapool from a stream |
|
192 */ |
|
193 void CASSrvDataPool::InternalizeL(RReadStream& aStream) |
|
194 { |
|
195 const TInt count = aStream.ReadInt32L(); |
|
196 if(iInternalizeDataEntries.Count() != 0) |
|
197 iInternalizeDataEntries.ResetAndDestroy(); |
|
198 // |
|
199 for(TInt i=0; i<count; i++) |
|
200 { |
|
201 const TAlarmId id = aStream.ReadInt32L(); |
|
202 HBufC8* data = HBufC8::NewLC(aStream, KMaxTInt); |
|
203 // |
|
204 CASSrvAlarmDataMapplet* mapplet = CASSrvAlarmDataMapplet::NewLC(id, data); |
|
205 CleanupStack::Pop(2, data); |
|
206 CleanupStack::PushL(mapplet); |
|
207 // |
|
208 User::LeaveIfError(iInternalizeDataEntries.Append(mapplet)); |
|
209 CleanupStack::Pop(mapplet); |
|
210 } |
|
211 } |
|
212 |
|
213 |
|
214 //************************************************************************************* |
|
215 /** |
|
216 * Externalize the contents of the datapool to a stream |
|
217 */ |
|
218 void CASSrvDataPool::ExternalizeL(RWriteStream& aStream) const |
|
219 { |
|
220 const TInt count = iDataEntries.Count(); |
|
221 aStream.WriteInt32L(count); |
|
222 // |
|
223 for(TInt i=0; i<count; i++) |
|
224 { |
|
225 const CASSrvAlarmDataMapplet& mapplet = *iDataEntries[i]; |
|
226 aStream.WriteInt32L(mapplet.Id()); |
|
227 aStream << mapplet.Data(); |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 //************************************************************************************* |
|
233 /** |
|
234 * Whether to use the Internalize buffer, or throw it away |
|
235 */ |
|
236 void CASSrvDataPool::ApplyInternalizedData(TBool aUseNewData) |
|
237 { |
|
238 if (aUseNewData) |
|
239 { |
|
240 // Internalize Success |
|
241 |
|
242 // free old entries |
|
243 iDataEntries.ResetAndDestroy(); |
|
244 |
|
245 // new data pool entries |
|
246 iDataEntries = iInternalizeDataEntries; |
|
247 |
|
248 // re-initialise source pointer array, by re-running its constructor |
|
249 new(&iInternalizeDataEntries) RPointerArray<CASSrvAlarmDataMapplet>; |
|
250 } |
|
251 else |
|
252 { |
|
253 // Internalize Failure |
|
254 iInternalizeDataEntries.ResetAndDestroy(); |
|
255 } |
|
256 } |
|
257 |
|
258 |
|
259 // |
|
260 // |
|
261 // |
|
262 |
|
263 |
|
264 //************************************************************************************* |
|
265 /** |
|
266 * @see MASSrvAlarmQueueObserver |
|
267 */ |
|
268 void CASSrvDataPool::MAlarmQueueObserverHandleEvent(TASSrvAlarmQueueEvent aEvent, TAlarmId aAlarmId) |
|
269 { |
|
270 // If an alarm is deleted, then we must also remove any associated |
|
271 // arbitrary data. |
|
272 if (aEvent == EASSrvAlarmQueueEventAlarmDeleted && DataPoolContainsEntry(aAlarmId)) |
|
273 { |
|
274 TRAP_IGNORE(DataPoolRemoveDataL(aAlarmId)); |
|
275 } |
|
276 } |
|
277 |
|
278 |
|
279 // |
|
280 // |
|
281 // |
|
282 |
|
283 |
|
284 //************************************************************************************* |
|
285 /** |
|
286 * Find a specific data pool entry based upon an alarm id |
|
287 */ |
|
288 TInt CASSrvDataPool::FindEntry(TAlarmId aAlarmId) const |
|
289 { |
|
290 const TInt count = iDataEntries.Count(); |
|
291 for(TInt i=0; i<count; i++) |
|
292 { |
|
293 if (iDataEntries[i]->Id() == aAlarmId) |
|
294 return i; |
|
295 } |
|
296 return KErrNotFound; |
|
297 } |
|
298 |