|
1 /* |
|
2 * Copyright (c) 2008-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: Definition of CListener class. Observers RProperty changes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef LISTENER_H |
|
20 #define LISTENER_H |
|
21 |
|
22 // SYSTEM INCLUDES |
|
23 #include <aknappui.h> |
|
24 #include <aknViewAppUi.h> |
|
25 #include <e32property.h> |
|
26 #include <e32def.h> |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 class MKeyObserver; |
|
30 class MKeyAndStatusObserver; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 /** |
|
34 * Property listener class. |
|
35 * Observes property keys for key values and status changes. |
|
36 * |
|
37 * @code |
|
38 * // Create new listener. |
|
39 * CListener* listener = CListener::NewL( |
|
40 * aPropertyCategory, |
|
41 * aKey |
|
42 * ); |
|
43 * |
|
44 * listener->RegisterNewClientForKeyValueL( aKeyObserver ); |
|
45 * @endcode |
|
46 * |
|
47 * @lib common.lib |
|
48 * @since - |
|
49 */ |
|
50 NONSHARABLE_CLASS( CListener ) : public CActive |
|
51 { |
|
52 public: |
|
53 |
|
54 /** |
|
55 * Factory method NewL |
|
56 * @param aPropertyCategory The property's category. |
|
57 * @param aKey The P&S key to be watched. |
|
58 * @return The new watcher object. |
|
59 */ |
|
60 static CListener* NewL( const TUid aPropertyCategory, |
|
61 const TUint aKey ); |
|
62 |
|
63 /** |
|
64 * Factory method NewLC |
|
65 * @param aPropertyCategory The property's category. |
|
66 * @param aKey The P&S key to be watched. |
|
67 * @return The new watcher object on the cleanupstack. |
|
68 */ |
|
69 static CListener* NewLC( const TUid aPropertyCategory, |
|
70 const TUint aKey ); |
|
71 |
|
72 /** |
|
73 * Destructor. Make public to clean it via CPropertyWatcher. |
|
74 */ |
|
75 virtual ~CListener(); |
|
76 |
|
77 public: // New functions |
|
78 |
|
79 /** |
|
80 * Returns observed key. |
|
81 * @return The key value. |
|
82 */ |
|
83 TUint ObservedKey () const; |
|
84 |
|
85 /** |
|
86 * Returns observed category. |
|
87 * @return The category's uid. |
|
88 */ |
|
89 TUid ObservedCategory () const; |
|
90 |
|
91 /** |
|
92 * Removes watcher client. |
|
93 * @param aKeyObserver Pointer to caller's adress. |
|
94 */ |
|
95 void RegisterNewClientForKeyValueL ( const MKeyObserver* aKeyObserver ); |
|
96 |
|
97 /** |
|
98 * Adds new watcher client. Listens key and status changes. |
|
99 * @param aKeyAndStatusObserver Pointer to caller's adress. |
|
100 */ |
|
101 void RegisterNewClientForKeyAndStatusL ( const MKeyAndStatusObserver* aKeyAndStatusObserver ); |
|
102 |
|
103 /** |
|
104 * Removes watcher client. |
|
105 * @param aKeyObserver Pointer to caller's adress. |
|
106 */ |
|
107 void UnregisterKeyClient( const MKeyObserver* aKeyObserver ); |
|
108 |
|
109 /** |
|
110 * Removes watcher client. |
|
111 * @param aKeyAndStatusObserver Pointer to caller's adress. |
|
112 */ |
|
113 void UnregisterKeyAndStatusClient( |
|
114 const MKeyAndStatusObserver* aKeyAndStatusObserver ); |
|
115 |
|
116 private: // Construction and destruction. |
|
117 |
|
118 /** |
|
119 * Constructor. |
|
120 * @param aPropertyCategory The property's category. |
|
121 * @param aKey The P&S key to be watched. |
|
122 */ |
|
123 CListener::CListener( const TUid aPropertyCategory, |
|
124 const TUint aKey ); |
|
125 |
|
126 /** |
|
127 * Symbian 2nd phase constructor. |
|
128 */ |
|
129 void ConstructL(); |
|
130 |
|
131 private: // Functions from CActive |
|
132 /** |
|
133 * Implements CActive |
|
134 */ |
|
135 void RunL(); |
|
136 |
|
137 /** |
|
138 * Implements CActive |
|
139 * @param aError the error returned |
|
140 * @return error |
|
141 */ |
|
142 TInt RunError( TInt aError ); |
|
143 |
|
144 /** |
|
145 * Implements CActive |
|
146 */ |
|
147 void DoCancel(); |
|
148 |
|
149 private: |
|
150 |
|
151 /** |
|
152 * Starts active object - listen key changes. |
|
153 */ |
|
154 void StartListening(); |
|
155 |
|
156 /** |
|
157 * Send notifications to registered clients. |
|
158 * @param aKeyValue - observed key's value. |
|
159 * @return aStatus - reference to iStatus. |
|
160 */ |
|
161 void SendNotificationsL( const TUint aKeyValue, |
|
162 TRequestStatus& aStatus ) const; |
|
163 |
|
164 private: // Data |
|
165 |
|
166 /*iArrayForKeyValue - all registered clients for value |
|
167 * owned by this class.*/ |
|
168 RPointerArray<MKeyObserver> iArrayForKeyValue; |
|
169 |
|
170 /*iArrayForKeyAndStatus - all registered clients for status |
|
171 * owned by this class*/ |
|
172 RPointerArray<MKeyAndStatusObserver> iArrayForKeyAndStatus; |
|
173 |
|
174 /*iPropertyCategory; - property's gategory. |
|
175 * owned by this class*/ |
|
176 TUid iPropertyCategory; |
|
177 |
|
178 /*iKey - observed key, owned by this class*/ |
|
179 TUint iKey; |
|
180 |
|
181 /*iProperty - owned by this class*/ |
|
182 RProperty iProperty; |
|
183 }; |
|
184 |
|
185 #endif // LISTENER_H |
|
186 |
|
187 // End of File. |