|
1 /* |
|
2 * Copyright (c) 2002-2009 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: Notifier engine* |
|
15 */ |
|
16 |
|
17 #ifndef __MDSNOTIFIER_H__ |
|
18 #define __MDSNOTIFIER_H__ |
|
19 |
|
20 #include <e32base.h> |
|
21 |
|
22 #include "mdscommoninternal.h" |
|
23 |
|
24 |
|
25 // forward declarations |
|
26 class CMdSServerSession; |
|
27 class CMdSNotifyComparator; |
|
28 class CMdSSchema; |
|
29 class CMdCSerializationBuffer; |
|
30 |
|
31 /** |
|
32 * A class that contains notification profiles for clients. |
|
33 * The class compares events against each profile and |
|
34 * triggers the client side which then calls back the observer. |
|
35 */ |
|
36 class CMdSNotifier : public CBase |
|
37 { |
|
38 public: // public construction |
|
39 |
|
40 /** static construction */ |
|
41 static CMdSNotifier* NewL(); |
|
42 static CMdSNotifier* NewLC(); |
|
43 |
|
44 /** destructor */ |
|
45 virtual ~CMdSNotifier(); |
|
46 |
|
47 private: // private construction |
|
48 |
|
49 /** constructor */ |
|
50 CMdSNotifier(); |
|
51 |
|
52 /** 2nd phase constructor */ |
|
53 void ConstructL(); |
|
54 |
|
55 public: // methods |
|
56 |
|
57 /** |
|
58 * An inner class for an entry in the array of listeners to |
|
59 * notify for different notification profiles.Each entry |
|
60 * contains the notification profiles against which to |
|
61 * compare the event and the parameters required to perform |
|
62 * the asynchronous notification. |
|
63 */ |
|
64 class TEntry |
|
65 { |
|
66 friend class CMdSNotifier; // accessible by host |
|
67 |
|
68 public: |
|
69 |
|
70 /** |
|
71 * sets the entry up for asynchronous callback |
|
72 * @param aMessage the asynchronous message |
|
73 * @param aRemoteSize the pointer to remote message size buffer |
|
74 */ |
|
75 void SetupForCallback( RMessage2 aMessage, TInt aRemoteSizeMsgSlot ); |
|
76 |
|
77 /** |
|
78 * Whether or not this entry has an asynchronous message |
|
79 * pending |
|
80 */ |
|
81 TBool IsPending() { return ( iRemoteSizeMsgSlot!=KErrNotFound ); } |
|
82 |
|
83 /** the criteria folder */ |
|
84 CMdCSerializationBuffer& Condition() |
|
85 { |
|
86 return *iSerializedCondition; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Does this entry allow confidential data |
|
91 * @return EFalse if not allowed |
|
92 */ |
|
93 TBool AllowConfidential() |
|
94 { |
|
95 return iConfidential; |
|
96 } |
|
97 |
|
98 /** |
|
99 * Return the id of this entry |
|
100 * @return The id |
|
101 */ |
|
102 TInt Id() |
|
103 { |
|
104 return iId; |
|
105 } |
|
106 |
|
107 /** |
|
108 * Return the id of this entry |
|
109 * @return The id |
|
110 */ |
|
111 TDefId NamespaceDefId() |
|
112 { |
|
113 return iNamespaceDefId; |
|
114 } |
|
115 |
|
116 /** |
|
117 * Trigger a previously cached notification |
|
118 * @param aCompleteCode The code to complete the message |
|
119 * @param aData The data hierarchy to send to the client, |
|
120 * ownership changes only if method doesn't leave |
|
121 * @return none |
|
122 */ |
|
123 void TriggerCachedL(TUint32 aCompleteCode, CMdCSerializationBuffer* aData); |
|
124 |
|
125 /** |
|
126 * Get the data buffer |
|
127 * @return the serialised data buffer |
|
128 */ |
|
129 CMdCSerializationBuffer* GetDataBuffer(); |
|
130 |
|
131 private: // methods for host class |
|
132 |
|
133 /** constructor */ |
|
134 TEntry( TInt aId, TConditionType aType, |
|
135 CMdCSerializationBuffer* aSerializedBuffer, |
|
136 TDefId aNamespaceDefId, |
|
137 CMdSServerSession& aSession, TBool aConfidential ); |
|
138 |
|
139 /** |
|
140 * Triggers the notifier causing the observer to be |
|
141 * notifier with the given code. |
|
142 * @param aCompleteCode either added/removed/modified |
|
143 * @param aItem the target of the event |
|
144 */ |
|
145 void TriggerL( TUint32 aCompleteCode, |
|
146 const RArray<TItemId>& aIdArray ); |
|
147 |
|
148 /** |
|
149 * Triggers the notifier causing the observer to be |
|
150 * notifier with the given code. |
|
151 * |
|
152 * @param aCompleteCode either added/removed/modified |
|
153 * @param aBuffer relation items of the event |
|
154 * @param aRelationIdArray matched relation ids |
|
155 */ |
|
156 void TriggerRelationItemsL( TUint32 aCompleteCode, |
|
157 CMdCSerializationBuffer& aBuffer, |
|
158 const RArray<TItemId>& aRelationIdArray ); |
|
159 |
|
160 /** |
|
161 * Trigger a notification of a schema change |
|
162 */ |
|
163 void TriggerSchema(); |
|
164 |
|
165 /** |
|
166 * The entry has currently no message active, |
|
167 * wait until one is available. |
|
168 */ |
|
169 void CacheL(TUint32 aCompleteCode, const RArray<TItemId>& aIdArray ); |
|
170 |
|
171 /** |
|
172 * The entry has currently no message active, |
|
173 * wait until one is available. |
|
174 */ |
|
175 void CacheRelationItemsL(TUint32 aCompleteCode, |
|
176 CMdCSerializationBuffer& aBuffer, |
|
177 const RArray<TItemId>& aRelationIdArray); |
|
178 |
|
179 /** |
|
180 * cache schema notification |
|
181 */ |
|
182 void CacheL(TUint32 aCompleteCode); |
|
183 |
|
184 /** |
|
185 * Triggers the notifier with an error code |
|
186 * @param aErrorCode one of system-wide error codes |
|
187 */ |
|
188 void TriggerError( TInt aErrorCode ); |
|
189 |
|
190 /** |
|
191 * Copy all IDs from the array in to the buffer |
|
192 * |
|
193 * @param aIdArray ID array |
|
194 * @return new buffer |
|
195 */ |
|
196 CMdCSerializationBuffer* CopyToBufferL( |
|
197 const RArray<TItemId>& aIdArray); |
|
198 |
|
199 /** |
|
200 * Copy matched relation IDs to a buffer |
|
201 * |
|
202 * @param aRelationItemsBuffer serialized items |
|
203 * @param aIdArray matched IDs |
|
204 * @return new buffer |
|
205 */ |
|
206 CMdCSerializationBuffer* CopyItemsToBufferL( |
|
207 CMdCSerializationBuffer& aRelationItemsBuffer, |
|
208 const RArray<TItemId>& aIdArray); |
|
209 private: |
|
210 |
|
211 /** id */ |
|
212 TInt iId; |
|
213 |
|
214 /** type of the notification */ |
|
215 TUint32 iType; |
|
216 |
|
217 /** namespace definition ID */ |
|
218 TDefId iNamespaceDefId; |
|
219 |
|
220 /** actual serialized condition */ |
|
221 CMdCSerializationBuffer* iSerializedCondition; |
|
222 |
|
223 /** |
|
224 * serialised id or relation items buffer. |
|
225 * Used instead of iDataObject when |
|
226 * sending object ids to the clients |
|
227 */ |
|
228 CMdCSerializationBuffer* iDataBuffer; |
|
229 |
|
230 /** asynchronous message */ |
|
231 RMessage2 iMessage; |
|
232 |
|
233 /** pointer to remote size buffer */ |
|
234 TInt iRemoteSizeMsgSlot; |
|
235 |
|
236 /** the session */ |
|
237 CMdSServerSession& iSession; |
|
238 |
|
239 TBool iConfidential; |
|
240 }; |
|
241 |
|
242 /** |
|
243 * creates a notifier entry |
|
244 * @param aId id of the entry to be created |
|
245 * @param aType type of the notifier (object/relation/event) |
|
246 * @param aCriteria the serialized criteria to compare against |
|
247 * @param aSession the session that owns the notificant |
|
248 * @param aConfidential Does the session get notifications of confidential items |
|
249 * @return reference to the created entry |
|
250 */ |
|
251 TEntry& CreateEntryL( TInt aId, TConditionType aType, |
|
252 CMdCSerializationBuffer* aSerializedBuffer, TDefId aNamespaceDefId, |
|
253 CMdSServerSession& aSession, TBool aConfidential); |
|
254 |
|
255 /** |
|
256 * finds an entry by its id, if not found leaves with KErrNotFound |
|
257 * @param aId id of the entry |
|
258 * @return reference to the entry found |
|
259 */ |
|
260 TEntry& FindEntryL( TInt aId ); |
|
261 |
|
262 /** |
|
263 * removes a notifier entry, if not found leaves with KErrNotFound |
|
264 * @param aId id of the entry to be removed |
|
265 */ |
|
266 void RemoveEntryL( TInt aId ); |
|
267 |
|
268 /** |
|
269 * removes all notifier entries that belong to a certain session |
|
270 * @param aSession session who's notify entries are to be removed |
|
271 */ |
|
272 void RemoveEntriesBySession(const CMdSServerSession& aSession ); |
|
273 |
|
274 /** |
|
275 * notifiers that items has been added |
|
276 * @param aSerializedItems serialized items |
|
277 * @param aSerializedItemIds serialized item IDs |
|
278 */ |
|
279 void NotifyAddedL(CMdCSerializationBuffer& aSerializedItems, |
|
280 CMdCSerializationBuffer& aSerializedItemIds); |
|
281 |
|
282 /** |
|
283 * notifiers that items has been modified |
|
284 * @param aSerializedItems serialized items |
|
285 * @param aSerializedItemIds serialized item IDs |
|
286 */ |
|
287 void NotifyModifiedL(CMdCSerializationBuffer& aSerializedItems, |
|
288 CMdCSerializationBuffer& aSerializedItemIds); |
|
289 |
|
290 /** |
|
291 * notifiers that items has been modified |
|
292 * @param aObjectIds object IDs |
|
293 */ |
|
294 void NotifyModifiedL(const RArray<TItemId>& aObjectIds); |
|
295 |
|
296 /** |
|
297 * notifiers that objects has been set to present or not present state |
|
298 * @param aPresent are object present state changed to present or not present |
|
299 * @param aObjectIds object IDs |
|
300 */ |
|
301 void NotifyObjectPresent(TBool aPresent, const RArray<TItemId>& aObjectIds); |
|
302 |
|
303 /** |
|
304 * notifiers that objects has been set to present or not present state |
|
305 * @param aPresent are object present state changed to present or not present |
|
306 * @param aObjectIds object IDs |
|
307 */ |
|
308 void NotifyRelationPresent(TBool aPresent, const RArray<TItemId>& aObjectIds); |
|
309 |
|
310 /** |
|
311 * notify about removed relation items |
|
312 * |
|
313 * @param aRemovedRelations removed relations |
|
314 * @param aAdditionalRemovedRelations possible additional removed relations |
|
315 */ |
|
316 void NotifyRemovedRelationItemsL( CMdCSerializationBuffer& aBuffer ); |
|
317 |
|
318 /** |
|
319 * Notifiers that items has been removed. |
|
320 * Can be only used for default namespace. |
|
321 * |
|
322 * @param aItemIdArray modified item IDs |
|
323 */ |
|
324 void NotifyRemovedL(const RArray<TItemId>& aItemIdArray); |
|
325 |
|
326 /** |
|
327 * notifiers that items has been removed |
|
328 * @param aSerializedItemIds serialized item IDs |
|
329 * @param aItemIsConfidential are items confidential |
|
330 */ |
|
331 void NotifyRemovedL(CMdCSerializationBuffer& aSerializedItemIds, TBool aItemIsConfidential ); |
|
332 |
|
333 void NotifySchemaAddedL(); |
|
334 |
|
335 TBool CheckForNotifier( TUint32 aNotifyTypes ); |
|
336 |
|
337 private: // data members |
|
338 |
|
339 /** the entry array */ |
|
340 RArray<TEntry> iEntries; |
|
341 |
|
342 /** the comparator */ |
|
343 CMdSNotifyComparator* iComparator; |
|
344 |
|
345 TInt iDataAccessCount; |
|
346 }; |
|
347 |
|
348 #endif // __MDSNOTIFIER_H__ |