|
1 /* |
|
2 * Copyright (c) 2003-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: This module defines event mediator and the services of it. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 * @file eventmediator.h |
|
22 * |
|
23 * This module defines event mediator and the services of it. |
|
24 * |
|
25 */ |
|
26 |
|
27 #ifndef __EVENTMEDIATOR_H__ |
|
28 #define __EVENTMEDIATOR_H__ |
|
29 |
|
30 // INCLUDES |
|
31 #include <e32base.h> |
|
32 #include <f32file.h> |
|
33 #include "eventmediatorapi.h" |
|
34 #include "eventmediatordefs.h" |
|
35 |
|
36 #include "sitdeathobserver.h" |
|
37 |
|
38 // FORWARD DECLARATIONS |
|
39 class CEventMediatorSession; |
|
40 class TEventContainer; |
|
41 class CEventLogger; |
|
42 |
|
43 class CSit; |
|
44 |
|
45 class CListenerContainer; |
|
46 |
|
47 // CLASS DECLARATION |
|
48 |
|
49 /** |
|
50 * Defines the event mediator server. |
|
51 */ |
|
52 class CEventMediatorServer : public CPolicyServer, public MSitDeathListener |
|
53 { |
|
54 friend class CEventMediatorSession; // Friend class |
|
55 |
|
56 public: //Methods |
|
57 |
|
58 // Constructors and destructor |
|
59 |
|
60 /** |
|
61 * Static constructor |
|
62 */ |
|
63 static CEventMediatorServer* NewL(void); |
|
64 |
|
65 /** |
|
66 * Static constructor |
|
67 */ |
|
68 static CEventMediatorServer* NewLC(void); |
|
69 |
|
70 /** |
|
71 * Destructor |
|
72 */ |
|
73 ~CEventMediatorServer(void); |
|
74 |
|
75 /** |
|
76 * Creates a new session. |
|
77 */ |
|
78 CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const; |
|
79 |
|
80 // Other methods |
|
81 |
|
82 /** |
|
83 * Reports new envent to the eventmediator server. |
|
84 * @param aType: type of the event. |
|
85 * @param aSpec: additional info on event. |
|
86 * @param aData: a descriptor containing event data. |
|
87 */ |
|
88 void ReportEventL(const TEventType aType, TDesC8* aSpec, |
|
89 TDesC8* aData, TInt aStatus = KErrNone); |
|
90 |
|
91 /** |
|
92 * Completes the last message in error case. |
|
93 * @param aError: Cause of the call of this function. |
|
94 */ |
|
95 void CompleteLastMessage(TInt aError); |
|
96 |
|
97 /** |
|
98 * Finds out whether the specified client thread is a SIT |
|
99 * thread or not |
|
100 */ |
|
101 TBool IsClientTheSitL(const RMessage2& aMessage); |
|
102 |
|
103 /** |
|
104 * Starts the SIT thread if it is not running |
|
105 */ |
|
106 void MakeSureSitIsRunningL(); |
|
107 |
|
108 /** |
|
109 * Saves a pointer to the listening request that represents the |
|
110 * task arrival observation request |
|
111 */ |
|
112 void SetTaskArrivalListenerL(CListenerContainer* aListener); |
|
113 |
|
114 /** |
|
115 * Clears the pointer to the listening request that represents the |
|
116 * task arrival observation request |
|
117 */ |
|
118 void ClearTaskArrivalListener(); |
|
119 |
|
120 /** |
|
121 * Returns the pointer to the task arrival observation request |
|
122 */ |
|
123 CListenerContainer* TaskArrivalListener(); |
|
124 |
|
125 /** |
|
126 * Notifies the server about a new task request that has arrived |
|
127 */ |
|
128 void TaskRequestArrivedL(CListenerContainer* aTaskRequest); |
|
129 |
|
130 /** |
|
131 * Notifies the server about a new task arrival |
|
132 * observation request that has arrived from the SIT |
|
133 */ |
|
134 void TaskArrivalObservationRequestArrivedL(); |
|
135 |
|
136 /** |
|
137 * Notifies the server about a new task request event |
|
138 * specification fetching request that has arrived from |
|
139 * the SIT. |
|
140 */ |
|
141 void TaskRequestEventSpecFetchingRequestArrivedL(CListenerContainer* aFetchingRequest); |
|
142 |
|
143 /** |
|
144 * Notifies the server about a new task cancellation |
|
145 * observation request that has arrived from the SIT. |
|
146 */ |
|
147 void TaskCancellationObservationRequestArrivedL(CListenerContainer* aRequest); |
|
148 |
|
149 /** |
|
150 * Completes a pending task arrival observation |
|
151 * request when a new task request has arrived. |
|
152 */ |
|
153 void CompleteTaskArrivalObservationRequestL(TEventType aEventType, TDesC8* aSpec); |
|
154 |
|
155 /** |
|
156 * Completes a pending task request event |
|
157 * specification fetching request. |
|
158 */ |
|
159 void CompleteTaskRequestEventSpecFetchingRequestL(TInt aStatus, TDesC8* aEventSpec, |
|
160 TDesC8* aTaskRequestEventSpec); |
|
161 |
|
162 /** |
|
163 * Tries to find a task request that is not yet |
|
164 * being fulfilled by the SIT. |
|
165 */ |
|
166 CListenerContainer* FindWaitingTaskRequest(); |
|
167 |
|
168 /** |
|
169 * Retrieves the event listener object, if any, that has the |
|
170 * specified event type and event specification ID. |
|
171 */ |
|
172 CListenerContainer* FindListener(TEventType aEventType, TInt aEventSpecId); |
|
173 |
|
174 /** |
|
175 * Retrieves the event listener object, if any, that is using |
|
176 * the SIT that has the specified thread ID and is fulfilling |
|
177 * the specified event. |
|
178 */ |
|
179 CListenerContainer* FindListener(TEventType aEventType, const TDesC8* aEventSpec); |
|
180 |
|
181 /** |
|
182 * Completes the listener that matches the specified search |
|
183 * criteria. |
|
184 */ |
|
185 void CompleteListener(TEventType aEventType, const TDesC8* aEventSpec, TInt aStatus); |
|
186 |
|
187 /** |
|
188 * Completes the listener that matches the specified search |
|
189 * criteria. |
|
190 */ |
|
191 void CompleteListener(CListenerContainer* aListenerPtr, TInt aStatus); |
|
192 |
|
193 /** |
|
194 * Returns the number of "normal" (non-sit) |
|
195 * sessions that are present |
|
196 */ |
|
197 TInt NormalSessionCount(); |
|
198 |
|
199 /** |
|
200 * Completes all task requests with the specified status |
|
201 */ |
|
202 void CompleteTaskRequests(TInt aStatus); |
|
203 |
|
204 /** |
|
205 * Returns a new event specification ID. |
|
206 */ |
|
207 TInt NewEventSpecId(); |
|
208 |
|
209 TPtrC EventLogFileName(void); |
|
210 |
|
211 public: // From MSitDeathListener |
|
212 void SitDied(); |
|
213 |
|
214 protected: |
|
215 /** |
|
216 * Process any errors |
|
217 * |
|
218 * @param aError the leave code reported |
|
219 */ |
|
220 TInt RunError(TInt aError); |
|
221 |
|
222 private: // Methods |
|
223 |
|
224 // Constructors and destructor |
|
225 |
|
226 /** |
|
227 * Default constructor |
|
228 */ |
|
229 CEventMediatorServer(void); |
|
230 |
|
231 /** |
|
232 * Perform the second phase construction of a CVpnManagerServer |
|
233 * object. |
|
234 * @param aServer Pointer to the server itself. |
|
235 */ |
|
236 void ConstructL(CEventMediatorServer* aServer); |
|
237 |
|
238 // Other methods |
|
239 |
|
240 /** |
|
241 * Stops the server if the session count is zero. |
|
242 */ |
|
243 void StopEventMediator(void); |
|
244 |
|
245 /** |
|
246 * Copies data describing an event to the client. |
|
247 * @param aMessge: a message from client side sent by RConnection::FetchData |
|
248 * @return error code, KErrNone if successfull |
|
249 */ |
|
250 TInt CopyEventDataL(const RMessage2& aMessage); |
|
251 |
|
252 /** |
|
253 * Reduces listener count of a stored event by one and destroys it if count becomes zero. |
|
254 * @param aIndex: the index of the stored event in the list. |
|
255 */ |
|
256 void MarkStoredEventListened(TInt aIndex); |
|
257 |
|
258 /** |
|
259 * Sets the iShuttingDown flag. |
|
260 */ |
|
261 void SetShuttingDown(TBool aShuttingDown); |
|
262 |
|
263 private: //Data |
|
264 // List of Events that have been reported but not handled by all listeners. |
|
265 CArrayFixFlat<TEventContainer*> iStoredEvents; |
|
266 // Number of currently existing sessions. |
|
267 TInt iSessionCount; |
|
268 // Log writer |
|
269 CEventLogger* iLogger; |
|
270 // The next event specification ID |
|
271 // (used with SIT event listening requests) |
|
272 TInt iNextEventSpecId; |
|
273 // The single SIT instance |
|
274 CSit* iSit; |
|
275 // The single task arrival listener |
|
276 CListenerContainer* iTaskArrivalListener; |
|
277 |
|
278 // A flag that is set to true when |
|
279 // the server starts going down |
|
280 TBool iShuttingDown; |
|
281 |
|
282 TFileName iEventLogFileName; |
|
283 |
|
284 static const TUint iRangeCount; |
|
285 static const TInt iRanges[]; |
|
286 static const TUint8 iElementIndex[]; |
|
287 |
|
288 static const CPolicyServer::TPolicyElement iElements[]; |
|
289 static const CPolicyServer::TPolicy iPolicy; |
|
290 |
|
291 }; |
|
292 |
|
293 // CLASS DECLARATION |
|
294 |
|
295 /** |
|
296 * Defines the session to the VPN manager server. |
|
297 */ |
|
298 class CEventMediatorSession : public CSession2 |
|
299 { |
|
300 public: //Message types |
|
301 enum |
|
302 { |
|
303 KEventMediatorListen, |
|
304 KEventMediatorListenWithSpec, |
|
305 KEventMediatorCancel, |
|
306 KEventMediatorCancelWithSpec, |
|
307 KEventMediatorCancelAll, |
|
308 KEventMediatorReportEvent, |
|
309 KEventMediatorReportEventWithSpec, |
|
310 KEventMediatorFetchData, |
|
311 KEventMediatorReportLogEvent, |
|
312 KEventMediatorNewEventSpecId, |
|
313 KEventMediatorDeletePrivateFiles, |
|
314 KEventMediatorGetEventLogSize, |
|
315 KEventMediatorGetEventLogHeader, |
|
316 KEventMediatorGetEventLogData, |
|
317 KEventMediatorClearEventLog |
|
318 }; |
|
319 |
|
320 public: // Methods |
|
321 |
|
322 // Constructors and destructor |
|
323 |
|
324 /** |
|
325 * Static constructor |
|
326 */ |
|
327 static CEventMediatorSession* NewL(CEventMediatorServer* aServer, const RMessage2& aMessage); |
|
328 |
|
329 /** |
|
330 * Default destructor |
|
331 */ |
|
332 ~CEventMediatorSession(void); |
|
333 |
|
334 /** |
|
335 * Wrapper function which Dispatches and executes the client's service calls |
|
336 * (See Message type definition). |
|
337 */ |
|
338 void ServiceL(const RMessage2& aMessage); |
|
339 |
|
340 /** |
|
341 * Checks if client is listening events of the given type and completes message |
|
342 * sent by clients ListenToEvent function. The length of the event data and |
|
343 * the pointer to that data are written to the message. |
|
344 * @param aType: type of the event. |
|
345 * @param aSpec: additional info on event. |
|
346 * @param aData: event data. |
|
347 * @return number of listeners for the event was listened. |
|
348 */ |
|
349 TInt CheckEventL(const TEventType aType, const TDesC8* aSpec, const TDesC8* aData, TInt aStatus); |
|
350 |
|
351 /** |
|
352 * Tries to find a task request that is not being fulfilled |
|
353 * already |
|
354 */ |
|
355 CListenerContainer* FindWaitingTaskRequest(); |
|
356 |
|
357 /** |
|
358 * Retrieves the event listener object, if any, that is using |
|
359 * the SIT that is fulfilling the specified event. |
|
360 */ |
|
361 CListenerContainer* FindListener(TEventType aEventType, TInt aEventSpecId); |
|
362 |
|
363 /** |
|
364 * Retrieves the event listener object, if any, that is using |
|
365 * the SIT that is fulfilling the specified event. |
|
366 */ |
|
367 CListenerContainer* FindListener(TEventType aEventType, const TDesC8* aEventSpec); |
|
368 |
|
369 /** |
|
370 * Completes the specified listener if it is owned by the |
|
371 * session. Returns ETrue is the listener was found and |
|
372 * completed, EFalse otherwise. |
|
373 */ |
|
374 void CompleteListener(TEventType aEventType, const TDesC8* aEventSpec, TInt aStatus); |
|
375 |
|
376 void CompleteTaskRequests(TInt aStatus); |
|
377 |
|
378 TBool IsASitSession(); |
|
379 |
|
380 private: //Methods |
|
381 // Constructors and destructor |
|
382 |
|
383 /** |
|
384 * Constructor |
|
385 */ |
|
386 CEventMediatorSession(CEventMediatorServer* aServer); |
|
387 |
|
388 /** |
|
389 * Starts listening events of requesteed type by coping the message to iListenedEvents. |
|
390 * @param aMessage: aMessage sent by clients ListenToEvent function. |
|
391 * @return: error code, KErrNone if successfull. |
|
392 */ |
|
393 TInt ListenToEventWithSpecL(const RMessage2& aMessage); |
|
394 |
|
395 /** |
|
396 * Starts listening events of requesteed type by coping the message to iListenedEvents. |
|
397 * @param aMessage: aMessage sent by clients ListenToEvent function. |
|
398 * @return: error code, KErrNone if successfull. |
|
399 */ |
|
400 TInt ListenToEventL(const RMessage2& aMessage); |
|
401 |
|
402 /** |
|
403 * Reports the event contained in the message to the event mediator server. |
|
404 * @param aMessage: aMessage sent by clients ReportEvent function. |
|
405 * @return: error code, KErrNone if successfull. |
|
406 */ |
|
407 void ReportEventL(const RMessage2& aMessage); |
|
408 |
|
409 /** |
|
410 * Reports a log event contained in the message to the event mediator server. |
|
411 * @param aMessage: aMessage sent by clients ReportLogEvent function. |
|
412 * @return: error code, KErrNone if successfull. |
|
413 */ |
|
414 void ReportLogEventL(const RMessage2& aMessage); |
|
415 |
|
416 /** |
|
417 * Reports the event contained in the message to the event mediator server. |
|
418 * @param aMessage: aMessage sent by clients ReportEvent function. |
|
419 * @return: error code, KErrNone if successfull. |
|
420 */ |
|
421 void ReportEventWithSpecL(const RMessage2& aMessage); |
|
422 |
|
423 /** |
|
424 * Cancels listning of one event type. |
|
425 * @param aMessage: aMessage sent by clients CancelListenToEvent function. |
|
426 */ |
|
427 void CancelListening(const RMessage2& aMessage); |
|
428 |
|
429 /** |
|
430 * Cancels listning of one event type. |
|
431 * @param aMessage: aMessage sent by clients CancelListenToEvent function. |
|
432 */ |
|
433 void CancelListeningWithSpecL(const RMessage2& aMessage); |
|
434 |
|
435 /** |
|
436 * Cancels all listening. |
|
437 * @param aMessage: aMessage sent by clients CancelAllListening function. |
|
438 */ |
|
439 void CancelAll(); |
|
440 |
|
441 /** |
|
442 * Copies event data from the server to the client. |
|
443 * @param aMessage: aMessage sent by clients FetchData function. |
|
444 * @return: error code, KErrNone if successfull. |
|
445 */ |
|
446 TInt FetchDataL(const RMessage2& aMessage); |
|
447 |
|
448 /** |
|
449 * Looks up a message from iListenedEvents. |
|
450 * @param aType: type of the event the message is listening to. |
|
451 * @param aIndex: the position of the message in iListenedEvents. |
|
452 * @return ETrue if message exists, EFalse if not. |
|
453 */ |
|
454 TBool FindListenerMsg(const TEventType aType,TInt& index); |
|
455 |
|
456 /** |
|
457 * Looks up a message from iListenedEvents. |
|
458 * @param aType: type of the event the message is listening to. |
|
459 * @param aIndex: the position of the message in iListenedEvents. |
|
460 * @return ETrue if message exists, EFalse if not. |
|
461 */ |
|
462 TBool FindListenerMsg(const TEventType aType,const TDesC8* aSpec,TInt& index); |
|
463 |
|
464 /** |
|
465 * Searches for a task request type event listening request |
|
466 */ |
|
467 TBool FindTaskRequestListenerMsg(TInt& index); |
|
468 |
|
469 /** |
|
470 * Reads data that was reported with the event from client. Allocates a buffer |
|
471 * for data and gives ownership of that buffer to caller. |
|
472 * @param aMessage: aMessage sent by clients ReportEvent function. |
|
473 * @return pointer to the newly created buffer containig data. |
|
474 */ |
|
475 HBufC8* ReadEventDataFromClientL(const RMessage2& aMessage); |
|
476 |
|
477 /** |
|
478 * Reads specification describing the event from client. Allocates a buffer |
|
479 * for secification and gives ownership of that buffer to caller. |
|
480 * @param aMessage: aMessage sent with event specification. |
|
481 * @return pointer to the newly created buffer containig data. |
|
482 */ |
|
483 HBufC8* ReadSpecificationFromClientL(const RMessage2& aMessage); |
|
484 |
|
485 /** |
|
486 * Completes the specified listener and deletes it from the |
|
487 * listener list |
|
488 */ |
|
489 void CompleteListener(TInt aIndex, TInt aStatus); |
|
490 |
|
491 /** |
|
492 * Returns to the client a new event specification ID |
|
493 */ |
|
494 void NewEventSpecIdL(const RMessage2& aMessage); |
|
495 |
|
496 TInt DeletePrivateFiles(); |
|
497 void DeletePrivateFilesL(); |
|
498 |
|
499 TInt GetEventLogSize(const RMessage2& aMessage); |
|
500 TInt GetEventLogHeader(const RMessage2& aMessage); |
|
501 TInt GetEventLogData(const RMessage2& aMessage); |
|
502 TInt ClearEventLog(); |
|
503 |
|
504 private: //Data |
|
505 // List of messages listening to events |
|
506 CArrayFixFlat<CListenerContainer*> iListenedEvents; |
|
507 // Event mediator server |
|
508 CEventMediatorServer* iServer; |
|
509 |
|
510 RFs iFs; |
|
511 RFile iEventLogFile; |
|
512 TBool iEventLogFileOpen; |
|
513 // Is this session from a SIT or not |
|
514 |
|
515 public: |
|
516 TBool iIsSitSession; |
|
517 }; |
|
518 |
|
519 // CLASS DECLARATION |
|
520 |
|
521 /** |
|
522 * Container for one reported event from witch it can be read by all listening sessions. |
|
523 */ |
|
524 class TEventContainer |
|
525 { |
|
526 public: //Methods |
|
527 // Constructors and destructor |
|
528 |
|
529 /** |
|
530 * Inline constructor |
|
531 */ |
|
532 inline TEventContainer(TInt aCount, TDesC8* aData) : iData(aData), iListenerCount(aCount){}; |
|
533 |
|
534 public: //Data |
|
535 // Data descriptor reported with the event. |
|
536 TDesC8* iData; |
|
537 // number of listeners that need this event |
|
538 TInt iListenerCount; |
|
539 }; |
|
540 |
|
541 |
|
542 // CLASS DECLARATION |
|
543 |
|
544 /** |
|
545 * Container for one reported event from which it can be read by all listening sessions |
|
546 */ |
|
547 class CListenerContainer : public CBase |
|
548 { |
|
549 public: //Methods |
|
550 // Constructors and destructor |
|
551 CListenerContainer(const RMessage2& aMessage, TDesC8* aSpec, |
|
552 CEventMediatorServer* aServer); |
|
553 ~CListenerContainer(); |
|
554 |
|
555 inline TEventType Type() {return (TEventType) iMessage.Int0();} |
|
556 inline RMessage2& Message() {return iMessage;} |
|
557 inline TDesC8* Specification() {return iSpec;} |
|
558 void Complete(TInt status); |
|
559 |
|
560 void AnalyzeRequestL(); |
|
561 TBool WaitingForFulfilling(); |
|
562 void MarkAsBeingFulfilled(); |
|
563 TBool BeingFulfilled(); |
|
564 |
|
565 TBool HandlesEvent(TEventType aEventType, const TDesC8* aEventSpec); |
|
566 |
|
567 private: //Data |
|
568 // Data descriptor reported with the event. |
|
569 TDesC8* iSpec; |
|
570 RMessage2 iMessage; |
|
571 TEventType iEventType; |
|
572 // Pointer to the event mediator server |
|
573 CEventMediatorServer* iServer; |
|
574 // A flag that tells whether the request |
|
575 // is being fulfilled by the SIT or not |
|
576 TBool iBeingFulfilledBySit; |
|
577 }; |
|
578 |
|
579 #endif |