|
1 /* |
|
2 * Copyright (c) 2006-2006 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: CFContextManager. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef C_CFCONTEXTMANAGER_H |
|
21 #define C_CFCONTEXTMANAGER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include "cfcontextobject.h" |
|
25 #include "CFSecurityChecker.h" |
|
26 |
|
27 #include <e32base.h> |
|
28 #include <f32file.h> |
|
29 |
|
30 #include "CFContextQueryImpl.h" |
|
31 #include "CFContextObjectImpl.h" |
|
32 |
|
33 |
|
34 // FORWARD DECLARATIONS |
|
35 //class TCFSubscription; |
|
36 class CCFCacheElement; |
|
37 class CCFContextSubscription; |
|
38 class CCFContextSubscriptionImpl; |
|
39 class MCFContextSubscriptionListener; |
|
40 class MCFContextSource; |
|
41 class CCFContextDataObject; |
|
42 |
|
43 typedef TBool ( CCFContextQueryImpl::*queryMatchFunction ) |
|
44 ( const TDesC&, const TDesC& ) const; |
|
45 |
|
46 |
|
47 /** |
|
48 * Front-end class for data storage access. |
|
49 * Data storage service provider for CF Server. This manager stores contexts |
|
50 * into a cache. |
|
51 * |
|
52 * The cache stores the latest context for each type for fast change |
|
53 * comparison (and quick query latest response). |
|
54 */ |
|
55 NONSHARABLE_CLASS( CCFContextManager ): public CBase |
|
56 { |
|
57 public: // constructors and destructor |
|
58 |
|
59 static CCFContextManager* NewL( MCFSecurityChecker& aSecurityChecker ); |
|
60 static CCFContextManager* NewLC( MCFSecurityChecker& aSecurityChecker ); |
|
61 |
|
62 ~CCFContextManager(); |
|
63 |
|
64 public: // new functions |
|
65 |
|
66 /** |
|
67 * Defines a new context in Context Framework. |
|
68 * Every context needs to be defined before it can be published |
|
69 * and subscribed. |
|
70 * If the context is already defined KErrPermissionDenied is |
|
71 * returned. |
|
72 * |
|
73 * @since S60 5.0 |
|
74 * @param aContextSource Source of the context. |
|
75 * @param aContextType Type of the context. |
|
76 * @param aReadSecurityPolicy Needed read capabilities for the context. |
|
77 * @param aWriteSecurityPolicy Needed write capabilities for the context |
|
78 * @return None |
|
79 */ |
|
80 void DefineContextL( const TDesC& aContextSource, |
|
81 const TDesC& aContextType, |
|
82 const TSecurityPolicy& aReadSecurityPolicy, |
|
83 const TSecurityPolicy& aWriteSecurityPolicy); |
|
84 |
|
85 /** |
|
86 * Defines a new context in Context Framework. |
|
87 * Every context needs to be defined before it can be published |
|
88 * and subscribed. |
|
89 * If the context is already defined KErrPermissionDenied is |
|
90 * returned. |
|
91 * |
|
92 * @since S60 5.0 |
|
93 * @param aContextSource Source of the context. |
|
94 * @param aContextType Type of the context. |
|
95 * @param aReadSecurityPolicy Needed read capabilities for the context. |
|
96 * @param aWriteSecurityPolicy Needed write capabilities for the context |
|
97 * @param aContextPublisher Interface to which the information whether |
|
98 * this context has subscribers or not is reported, can be also NULL. |
|
99 * @param aPublisherUid Secure UID of the process which registered |
|
100 * this context. Only process with the same SID is able to reregister |
|
101 * context in the purpose registering aContextPublisher. |
|
102 * @return None |
|
103 */ |
|
104 void DefineContextL( const TDesC& aContextSource, |
|
105 const TDesC& aContextType, |
|
106 const TSecurityPolicy& aReadSecurityPolicy, |
|
107 const TSecurityPolicy& aWriteSecurityPolicy, |
|
108 MCFContextSource* aContextPublisher, |
|
109 const TUid& aPublisherUid ); |
|
110 |
|
111 /** |
|
112 * Publishes a new context object. |
|
113 * The new context value is cached and needed indications |
|
114 * for context subscribers are sent. |
|
115 * Leaves with: |
|
116 * - KErrNotFound, context not defined |
|
117 * - KErrAccessDenied, insufficient capabilities to write the context |
|
118 * |
|
119 * @since S60 5.0 |
|
120 * @param aContext New context object. |
|
121 * @param aClientThread Handle to the current client. |
|
122 * @return None. |
|
123 */ |
|
124 void PublishContextL( CCFContextObject& aContext, |
|
125 RThread& aClientThread ); |
|
126 |
|
127 /** |
|
128 * Publishes a new context object. |
|
129 * The new context value is cached and needed indications |
|
130 * for context subscribers are sent. |
|
131 * The data object is also sent to subscribers currently |
|
132 * interested from the data. |
|
133 * |
|
134 * @since S60 5.0 |
|
135 * @param aContext New context object. |
|
136 * @param aClientThread Handle to the current client. |
|
137 * @param aData Data object associated with the context. |
|
138 * @return None. |
|
139 */ |
|
140 void PublishContextL( CCFContextObject& aContext, |
|
141 RThread& aClientThread, |
|
142 CCFContextDataObject& aData ); |
|
143 |
|
144 /** |
|
145 * Gets contexts of specified type. |
|
146 * Tries to retrieve from cache the requested contexts using the given |
|
147 * request (query) type. The requested context type can be partial |
|
148 * ontology path. |
|
149 * |
|
150 * @param aResultBuffer Storage for the requested contexts. |
|
151 * @param aContextQuery Settings for the request (query). |
|
152 */ |
|
153 void RequestContextL( |
|
154 RContextObjectArray& aResultBuffer, |
|
155 CCFContextQuery& aContextQuery, |
|
156 RThread& aClientThread ); |
|
157 |
|
158 /** |
|
159 * Requests specified context object. |
|
160 * @param aContextType: Specifies the context type requested |
|
161 * @param aContextSource: Specifies the context source |
|
162 * @return CCFContextObject* |
|
163 */ |
|
164 CCFContextObject* RequestContextL( |
|
165 const TDesC& aContextType, |
|
166 const TDesC& aContextSource, |
|
167 RThread& aClientThread ); |
|
168 |
|
169 /** |
|
170 * |
|
171 * @since S60 5.0 |
|
172 * @param aParam1 Explanation. |
|
173 * @param aParam2 Explanation. |
|
174 * @return None |
|
175 */ |
|
176 void SubscribeContextL( CCFContextSubscription* aSubscription, |
|
177 MCFContextSubscriptionListener* aListener, |
|
178 RThread& aClientThread ); |
|
179 |
|
180 /** |
|
181 * |
|
182 * @since S60 5.0 |
|
183 * @param aParam1 Explanation. |
|
184 * @param aParam2 Explanation. |
|
185 * @return ETrue if cache element(s) was added to cleanup array |
|
186 * (subscription was nullified, not removed), EFalse otherwise. |
|
187 */ |
|
188 TBool RemoveSubscription( CCFContextSubscription& aSubscription, |
|
189 MCFContextSubscriptionListener& aListener ); |
|
190 |
|
191 /** |
|
192 * |
|
193 * @since S60 5.0 |
|
194 * @param aParam1 Explanation. |
|
195 * @param aParam2 Explanation. |
|
196 * @return ETrue if cache element(s) was added to cleanup array |
|
197 * (subscription(s) was nullified, not removed), EFalse otherwise. |
|
198 */ |
|
199 TBool RemoveSubscriptions( |
|
200 MCFContextSubscriptionListener* aListener ); |
|
201 |
|
202 /** |
|
203 * Cleanups context cache element's subscriptions by removing nullified |
|
204 * subscriptions for all cache elements added to the cleanup array. |
|
205 * |
|
206 * @since S60 5.0 |
|
207 * @return None. |
|
208 */ |
|
209 void CleanupCacheElementSubscriptions(); |
|
210 |
|
211 /** |
|
212 * Gets the read security policy of particular action. |
|
213 * |
|
214 * @param aContextSource Context Source. |
|
215 * @param aContextType Context Type. |
|
216 * @param aPolicy security policy which will be set by this method. |
|
217 * @return None. |
|
218 */ |
|
219 void GetReadSecurityPolicyL( const TDesC& aContextSource, |
|
220 const TDesC& aContextType, |
|
221 TSecurityPolicy& aPolicy ); |
|
222 |
|
223 /** |
|
224 * Gets the write security policy of particular action. |
|
225 * |
|
226 * @param aContextSource Context Source. |
|
227 * @param aContextType Context Type. |
|
228 * @param aPolicy security policy which will be set by this method. |
|
229 * @return None. |
|
230 */ |
|
231 void GetWriteSecurityPolicyL( const TDesC& aContextSource, |
|
232 const TDesC& aContextType, |
|
233 TSecurityPolicy& aPolicy ); |
|
234 |
|
235 /** |
|
236 * Deregister context publisher for all contexts it has been |
|
237 * registered as a publisher. |
|
238 * This has to be called before context publisher can be deleted. |
|
239 * @param aPublisher Publisher to be deregistered. |
|
240 */ |
|
241 void DeregisterPublisher( MCFContextSource& aPublisher ); |
|
242 |
|
243 /** |
|
244 * Validates that the context can be published. |
|
245 * Checks that the context is defined and the client has sufficient |
|
246 * capabilities to write to the context. |
|
247 * |
|
248 * Leaves with: |
|
249 * - KErrNotFound, context not defined |
|
250 * - KErrAccessDenied, insufficient capabilities to write the context |
|
251 * |
|
252 * @since S60 5.0 |
|
253 * @param aContext New context object. |
|
254 * @param aClientThread Handle to the current client. |
|
255 * @return None. |
|
256 */ |
|
257 void ValidatePublishContextL( CCFContextObject& aContext, |
|
258 RThread& aClientThread ); |
|
259 |
|
260 /** |
|
261 * Executes the actual publishing for the context. |
|
262 * ValidatePublishContextL() must have been called before calling this |
|
263 * because security is not checked by this function. |
|
264 * |
|
265 * Leaves with: |
|
266 * - KErrNotFound, context not defined |
|
267 * - any other system-wide error code |
|
268 * |
|
269 * @since S60 5.0 |
|
270 * @param aContext New context object. |
|
271 * @param aData Data object associated with the context. |
|
272 * @return None. |
|
273 */ |
|
274 void DoPublishContextL( CCFContextObject& aContext, |
|
275 CCFContextDataObject* aData = NULL ); |
|
276 |
|
277 private: // Constructors |
|
278 |
|
279 CCFContextManager( MCFSecurityChecker& aSecurityChecker ); |
|
280 void ConstructL(); |
|
281 |
|
282 private: // New functions |
|
283 |
|
284 |
|
285 // Notifies data manager that new subscription has been added. |
|
286 void SubscriptionAddedL( CCFContextSubscriptionImpl& aSubscription, |
|
287 RThread& aClientThread ); |
|
288 |
|
289 // Notifies data manager that subscription has been removed. |
|
290 // Returns value ETrue if cache element(s) was added to cleanup array, |
|
291 // EFalse otherwise. |
|
292 TBool SubscriptionRemoved( CCFContextSubscriptionImpl& aSubscription ); |
|
293 |
|
294 // Finalizes security check. |
|
295 TInt DoReadSecurityCheck( CCFCacheElement& aContextCache, |
|
296 RThread& aClientThread ); |
|
297 |
|
298 // Checks if the particular client has write access to particular |
|
299 // cache element |
|
300 TInt DoWriteSecurityCheck( CCFCacheElement& aContextCache, |
|
301 RThread& aClientThread ); |
|
302 |
|
303 // Gets latest context values from context cache based on the specified |
|
304 // query. |
|
305 void GetLatestFromCacheL( |
|
306 RContextObjectArray& aLatestContexts, |
|
307 queryMatchFunction aMatchFunction, |
|
308 const CCFContextQueryImpl& aContextQuery, |
|
309 RThread* aClientThread ); |
|
310 |
|
311 // Logs context cache |
|
312 void LogContextCache(); |
|
313 |
|
314 // Checks if the current client is from the same process |
|
315 TBool RequestFromSameProcess( RThread& aClientThread ); |
|
316 |
|
317 // Request contexts |
|
318 void DoRequestContextL( RContextObjectArray& aResultBuffer, |
|
319 CCFContextQuery& aContextQuery, |
|
320 RThread* aClientThread ); |
|
321 |
|
322 // From MCFSubscriptionManager |
|
323 void CacheElementAddedL( CCFCacheElement& aCacheElement ); |
|
324 |
|
325 // Checks if context re-define is allowed |
|
326 TBool RedefineAllowed( CCFCacheElement& aElement, |
|
327 const MCFContextSource* aSource, |
|
328 const TUid& aUid ) const; |
|
329 |
|
330 private: // Member variables |
|
331 |
|
332 // Previous context instance for subscriber indications. |
|
333 CCFContextObject* iPreviousContext; |
|
334 |
|
335 // Context cache. |
|
336 RPointerArray<CCFCacheElement> iContextCache; |
|
337 |
|
338 // A "linear order" instance. |
|
339 TLinearOrder<CCFCacheElement>* iCacheOrder; |
|
340 |
|
341 // |
|
342 CCFCacheElement* iCacheSearchKey; |
|
343 |
|
344 // Own: Subscriptions |
|
345 RPointerArray<CCFContextSubscriptionImpl> iSubscriptions; |
|
346 |
|
347 // Security checker interface. |
|
348 MCFSecurityChecker* iSecurityChecker; |
|
349 |
|
350 // Signals SubscriptionRemoved() that manager is in the middle of |
|
351 // publishing context. Needed for context operations and context sources |
|
352 // removing their subscriptions based on context indication, and doing |
|
353 // it as a synchronous operation during the indication process. |
|
354 // Not owned. |
|
355 CCFCacheElement* iPublishingForCacheElement; |
|
356 |
|
357 // Cleanup array for cache elements having nullified subscriptions, |
|
358 // pointers are not owned. |
|
359 RPointerArray< CCFCacheElement > iCleanupCacheElements; |
|
360 }; |
|
361 |
|
362 #endif // C_CFCONTEXTMANAGER_H |
|
363 |
|
364 // End of File |