|
1 /* |
|
2 * Copyright (c) 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: header of EventNotifier class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef EVENTNOTIFIER_H |
|
21 #define EVENTNOTIFIER_H |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <Events.h> |
|
25 |
|
26 namespace multimedia |
|
27 { |
|
28 class MControlObserver; |
|
29 class CEventBase; |
|
30 class MControl; |
|
31 |
|
32 class CObserverManager : public CBase |
|
33 { |
|
34 public: |
|
35 static CObserverManager* NewL(); |
|
36 ~CObserverManager(); |
|
37 |
|
38 // Adds observer to list |
|
39 TInt AddObserver( const MControlObserver& aObserver ); |
|
40 // Marks observer as inactive in the list |
|
41 TInt RemoveObserver( const MControlObserver& aObserver ); |
|
42 |
|
43 // Moves the pointer to element before the first in list |
|
44 void Init(); |
|
45 // Returns true and moves pointer to next active observer. |
|
46 TBool Next(); |
|
47 // aObserver will contain pointer to current observer |
|
48 void Observer( MControlObserver*& aObserver ); |
|
49 |
|
50 // Returns the count of active observers |
|
51 TInt Count(); |
|
52 // Purge inactive observers in the list |
|
53 void Purge(); |
|
54 // Resets the list |
|
55 void Reset(); |
|
56 |
|
57 private: |
|
58 CObserverManager(); |
|
59 void ConstructL(); |
|
60 |
|
61 private: |
|
62 TInt iObserverCount; |
|
63 TInt iCurrentObserverIndex; |
|
64 // For now we maintain 2 RPointerArray lists |
|
65 // better option is to merge into one data structure |
|
66 RPointerArray<MControlObserver> iObserversList; |
|
67 RArray<TInt> iActiveList; |
|
68 }; |
|
69 |
|
70 class CEventQueueItem : public CBase |
|
71 { |
|
72 public: |
|
73 static CEventQueueItem* NewL( MControl* aControl, TUint aEvent, CEventBase* aEventObject ); |
|
74 ~CEventQueueItem(); |
|
75 |
|
76 TUint EventType(); |
|
77 CEventBase* EventObject(); |
|
78 MControl* ControlObject(); |
|
79 TAny* GetInterface(); |
|
80 |
|
81 private: |
|
82 CEventQueueItem( MControl* aControl,TUint aEvent, CEventBase* aEventObject ); |
|
83 void ConstructL(); |
|
84 |
|
85 public: |
|
86 // next item |
|
87 TSglQueLink* iLink; |
|
88 |
|
89 private: |
|
90 TUint iEvent; |
|
91 CEventBase* iEventObject; |
|
92 MControl* iControl; |
|
93 }; |
|
94 |
|
95 class CEventNotifier : public CActive |
|
96 { |
|
97 public: |
|
98 static CEventNotifier* NewL(); |
|
99 ~CEventNotifier(); |
|
100 |
|
101 // Adds observer |
|
102 TInt AddObserver( const MControlObserver& aObserver ); |
|
103 // Remove observer |
|
104 TInt RemoveObserver( const MControlObserver& aObserver ); |
|
105 // Send notification to observers. If another event is |
|
106 // being processed, this will add event to pending events |
|
107 // and observers will be notified later. |
|
108 // Takes ownership of aEventObject |
|
109 TInt Event( MControl* aControl, TUint aEvent, CEventBase* aEventObject ); |
|
110 |
|
111 // From CActive |
|
112 void RunL(); |
|
113 void DoCancel(); |
|
114 TInt RunError(TInt aError); |
|
115 |
|
116 private: |
|
117 CEventNotifier(); |
|
118 void ConstructL(); |
|
119 |
|
120 // Signals to continue processing. |
|
121 void KickSignal(); |
|
122 // Signals the event has been notified to all observers |
|
123 void EventNotified(); |
|
124 |
|
125 void EmptyQueue(); |
|
126 |
|
127 private: |
|
128 // Pointer to observer manager |
|
129 CObserverManager* iObserverManager; |
|
130 // List holding events to be notified |
|
131 TSglQue<CEventQueueItem>* iEventQueue; |
|
132 }; |
|
133 } // namespace multimedia |
|
134 |
|
135 #endif // EVENTNOTIFIER_H |
|
136 |
|
137 // End of file |