williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
3 |
* All rights reserved.
|
williamr@2
|
4 |
* This component and the accompanying materials are made available
|
williamr@4
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
williamr@2
|
6 |
* which accompanies this distribution, and is available
|
williamr@4
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Initial Contributors:
|
williamr@2
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Contributors:
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* Description:
|
williamr@2
|
15 |
*
|
williamr@2
|
16 |
*/
|
williamr@2
|
17 |
|
williamr@2
|
18 |
|
williamr@2
|
19 |
|
williamr@2
|
20 |
#ifndef CENREPNOTIFYHANDLER_H
|
williamr@2
|
21 |
#define CENREPNOTIFYHANDLER_H
|
williamr@2
|
22 |
|
williamr@2
|
23 |
// INCLUDES
|
williamr@2
|
24 |
#include <e32std.h>
|
williamr@2
|
25 |
#include <e32base.h>
|
williamr@2
|
26 |
|
williamr@2
|
27 |
// FORWARD DECLARATIONS
|
williamr@2
|
28 |
class MCenRepNotifyHandlerCallback;
|
williamr@2
|
29 |
class CRepository;
|
williamr@2
|
30 |
|
williamr@2
|
31 |
/**
|
williamr@2
|
32 |
* Active object wrapper for Central Repository one-shot notification handling.
|
williamr@2
|
33 |
* Central Repository Notification Handler API provides an easy-to-use
|
williamr@2
|
34 |
* implementation of a CActive-based wrapper for Central Repository single-shot
|
williamr@2
|
35 |
* notifications. In most cases Central Repository Notification Handler can
|
williamr@2
|
36 |
* automatically resubscribe to notifications and fetch the modified value from
|
williamr@2
|
37 |
* Central Repository.
|
williamr@2
|
38 |
* The API consists of the classes CCenRepNotifyHandler and
|
williamr@2
|
39 |
* MCenRepNotifyHandlerCallback. The user of this class needs to implement relevant
|
williamr@2
|
40 |
* MCenRepNotifyHandlerCallback interface methods to receive notifications.
|
williamr@2
|
41 |
* The user of Central Repository Notification Handler API needs access to
|
williamr@2
|
42 |
* Central Repository (centralrepository.h).
|
williamr@2
|
43 |
*
|
williamr@2
|
44 |
* Usage:
|
williamr@2
|
45 |
*
|
williamr@2
|
46 |
* Initialization example (from a class that implements MCenRepNotifyHandlerCallback interface):
|
williamr@2
|
47 |
* @code
|
williamr@2
|
48 |
* iSession = CRepository::NewL(KTestUid);
|
williamr@2
|
49 |
* iNotifyHandler = CCenRepNotifyHandler::NewL(*this, *iSession, CCenRepNotifyHandler::EStringKey, KKey1);
|
williamr@2
|
50 |
* iNotifyHandler->StartListeningL();
|
williamr@2
|
51 |
* @endcode
|
williamr@2
|
52 |
*
|
williamr@2
|
53 |
* Uninitialization example:
|
williamr@2
|
54 |
* @code
|
williamr@2
|
55 |
* iNotifyHandler->StopListening();
|
williamr@2
|
56 |
* delete iNotifyHandler;
|
williamr@2
|
57 |
* @endcode
|
williamr@2
|
58 |
*
|
williamr@2
|
59 |
* Handler method implementation example:
|
williamr@2
|
60 |
* @code
|
williamr@2
|
61 |
* void CMyCenRepNotifyTest::HandleNotifyString(TUint32 aId, const TDesC16& aNewValue)
|
williamr@2
|
62 |
* {
|
williamr@2
|
63 |
* // Print out the notified value
|
williamr@2
|
64 |
* RDebug::Print(_L("Key %d changed, new value: %S"), aId, &aNewValue);
|
williamr@2
|
65 |
* }
|
williamr@2
|
66 |
* @endcode
|
williamr@2
|
67 |
*
|
williamr@4
|
68 |
* @publishedAll
|
williamr@2
|
69 |
* @released
|
williamr@2
|
70 |
*/
|
williamr@2
|
71 |
class CCenRepNotifyHandler : public CActive
|
williamr@2
|
72 |
{
|
williamr@2
|
73 |
public:
|
williamr@2
|
74 |
/**
|
williamr@2
|
75 |
* Defines different key types. Enumeration is used to indicate the
|
williamr@2
|
76 |
* key type that is listened to.
|
williamr@2
|
77 |
*/
|
williamr@2
|
78 |
enum TCenRepKeyType
|
williamr@2
|
79 |
{
|
williamr@2
|
80 |
EIntKey, ///< Key holds a TInt value.
|
williamr@2
|
81 |
ERealKey, ///< Key holds a TReal value.
|
williamr@2
|
82 |
EStringKey, ///< Key holds a TDesC16 value.
|
williamr@2
|
83 |
EBinaryKey ///< Key holds a TDesC8 value.
|
williamr@2
|
84 |
};
|
williamr@2
|
85 |
|
williamr@2
|
86 |
IMPORT_C static CCenRepNotifyHandler* NewL( MCenRepNotifyHandlerCallback& aCallback,
|
williamr@2
|
87 |
CRepository& aSession,
|
williamr@2
|
88 |
TCenRepKeyType aKeyType,
|
williamr@2
|
89 |
TUint32 aId );
|
williamr@2
|
90 |
|
williamr@2
|
91 |
IMPORT_C static CCenRepNotifyHandler* NewL( MCenRepNotifyHandlerCallback& aCallback,
|
williamr@2
|
92 |
CRepository& aSession );
|
williamr@2
|
93 |
|
williamr@2
|
94 |
IMPORT_C static CCenRepNotifyHandler* NewLC( MCenRepNotifyHandlerCallback& aCallback,
|
williamr@2
|
95 |
CRepository& aSession,
|
williamr@2
|
96 |
TCenRepKeyType aKeyType,
|
williamr@2
|
97 |
TUint32 aId );
|
williamr@2
|
98 |
|
williamr@2
|
99 |
IMPORT_C static CCenRepNotifyHandler* NewLC( MCenRepNotifyHandlerCallback& aCallback,
|
williamr@2
|
100 |
CRepository& aSession );
|
williamr@2
|
101 |
IMPORT_C void StartListeningL();
|
williamr@2
|
102 |
|
williamr@2
|
103 |
IMPORT_C void StopListening();
|
williamr@2
|
104 |
|
williamr@2
|
105 |
|
williamr@2
|
106 |
/**
|
williamr@2
|
107 |
* Destructor.
|
williamr@2
|
108 |
*/
|
williamr@2
|
109 |
IMPORT_C virtual ~CCenRepNotifyHandler();
|
williamr@2
|
110 |
|
williamr@2
|
111 |
protected:
|
williamr@2
|
112 |
|
williamr@2
|
113 |
void RunL();
|
williamr@2
|
114 |
|
williamr@2
|
115 |
TInt RunError( TInt aError );
|
williamr@2
|
116 |
|
williamr@2
|
117 |
void DoCancel();
|
williamr@2
|
118 |
|
williamr@2
|
119 |
private:
|
williamr@2
|
120 |
|
williamr@2
|
121 |
CCenRepNotifyHandler( MCenRepNotifyHandlerCallback& aCallback,
|
williamr@2
|
122 |
CRepository& aSession,
|
williamr@2
|
123 |
TCenRepKeyType aKeyType,
|
williamr@2
|
124 |
TUint32 aId );
|
williamr@2
|
125 |
|
williamr@2
|
126 |
CCenRepNotifyHandler( MCenRepNotifyHandlerCallback& aCallback,
|
williamr@2
|
127 |
CRepository& aSession );
|
williamr@2
|
128 |
TInt OrderNotification();
|
williamr@2
|
129 |
|
williamr@2
|
130 |
private:
|
williamr@2
|
131 |
|
williamr@2
|
132 |
CRepository& iSession; // not owned by this class
|
williamr@2
|
133 |
MCenRepNotifyHandlerCallback& iCallback; // not owned by this class
|
williamr@2
|
134 |
TCenRepKeyType iKeyType;
|
williamr@2
|
135 |
TUint32 iId;
|
williamr@2
|
136 |
TBool iWholeRepository; // The flag to indicate if listening is for whole repository
|
williamr@2
|
137 |
};
|
williamr@2
|
138 |
|
williamr@2
|
139 |
|
williamr@2
|
140 |
/**
|
williamr@2
|
141 |
* Class provides a callback interface for handling the notifification
|
williamr@2
|
142 |
* events from the Central Repository. The Client derives a class
|
williamr@2
|
143 |
* from this interface and implements the HandleNotify-methods that
|
williamr@2
|
144 |
* interest it.
|
williamr@2
|
145 |
* An empty default implementation is provided for all of the methods.
|
williamr@2
|
146 |
* In debug build the default implementations print out a debug trace.
|
williamr@2
|
147 |
*
|
williamr@4
|
148 |
* @publishedAll
|
williamr@2
|
149 |
* @released
|
williamr@2
|
150 |
*/
|
williamr@2
|
151 |
class MCenRepNotifyHandlerCallback
|
williamr@2
|
152 |
{
|
williamr@2
|
153 |
|
williamr@2
|
154 |
public:
|
williamr@2
|
155 |
|
williamr@2
|
156 |
/**
|
williamr@2
|
157 |
* This callback method is used to notify the client about
|
williamr@2
|
158 |
* changes for integer value keys, i.e. key type is EIntKey.
|
williamr@2
|
159 |
*
|
williamr@2
|
160 |
* @param aId Id of the key that has changed.
|
williamr@2
|
161 |
* @param aNewValue The new value of the key.
|
williamr@2
|
162 |
* @capability Dependent Capability required depends on implementation of override.
|
williamr@2
|
163 |
*/
|
williamr@2
|
164 |
IMPORT_C virtual void HandleNotifyInt( TUint32 aId, TInt aNewValue );
|
williamr@2
|
165 |
|
williamr@2
|
166 |
/**
|
williamr@2
|
167 |
* This callback method is used to notify the client about
|
williamr@2
|
168 |
* changes for real value keys, i.e. key type is ERealKey.
|
williamr@2
|
169 |
*
|
williamr@2
|
170 |
* @param aId Id of the key that has changed.
|
williamr@2
|
171 |
* @param aNewValue The new value of the key.
|
williamr@2
|
172 |
* @capability Dependent Capability required depends on implementation of override.
|
williamr@2
|
173 |
*/
|
williamr@2
|
174 |
IMPORT_C virtual void HandleNotifyReal( TUint32 aId, TReal aNewValue );
|
williamr@2
|
175 |
|
williamr@2
|
176 |
/**
|
williamr@2
|
177 |
* This callback method is used to notify the client about
|
williamr@2
|
178 |
* changes for string value keys, i.e. key type is EStringKey.
|
williamr@2
|
179 |
*
|
williamr@2
|
180 |
* @param aId Id of the key that has changed.
|
williamr@2
|
181 |
* @param aNewValue The new value of the key.
|
williamr@2
|
182 |
* @capability Dependent Capability required depends on implementation of override.
|
williamr@2
|
183 |
*/
|
williamr@2
|
184 |
IMPORT_C virtual void HandleNotifyString( TUint32 aId, const TDesC16& aNewValue );
|
williamr@2
|
185 |
|
williamr@2
|
186 |
/**
|
williamr@2
|
187 |
* This callback method is used to notify the client about
|
williamr@2
|
188 |
* changes for binary value keys, i.e. key type is EBinaryKey.
|
williamr@2
|
189 |
*
|
williamr@2
|
190 |
* @param aId Id of the key that has changed.
|
williamr@2
|
191 |
* @param aNewValue The new value of the key.
|
williamr@2
|
192 |
* @capability Dependent Capability required depends on implementation of override.
|
williamr@2
|
193 |
*/
|
williamr@2
|
194 |
IMPORT_C virtual void HandleNotifyBinary( TUint32 aId, const TDesC8& aNewValue );
|
williamr@2
|
195 |
|
williamr@2
|
196 |
/**
|
williamr@2
|
197 |
* This callback method is used to notify the client about
|
williamr@2
|
198 |
* changes in keys when the whole repository is listened for.
|
williamr@2
|
199 |
*
|
williamr@2
|
200 |
* Note: It is not guaranteed that a notification will be received
|
williamr@2
|
201 |
* for all keys, if multiple keys are changed in rapid succession
|
williamr@2
|
202 |
* by multiple threads or when the whole repository is reset,
|
williamr@2
|
203 |
* therefore only listen for whole repository if this is not an issue.
|
williamr@2
|
204 |
*
|
williamr@2
|
205 |
* @param aId Id of the key that has changed. If multiple keys were changed by
|
williamr@2
|
206 |
* whole repository reset, value will be KInvalidNotificationId.
|
williamr@2
|
207 |
* @capability Dependent Capability required depends on implementation of override.
|
williamr@2
|
208 |
*/
|
williamr@2
|
209 |
IMPORT_C virtual void HandleNotifyGeneric( TUint32 aId );
|
williamr@2
|
210 |
|
williamr@2
|
211 |
/**
|
williamr@2
|
212 |
* This callback method is used to notify the client about errors
|
williamr@2
|
213 |
* in the handler. Any error in handling causes the handler to stop
|
williamr@2
|
214 |
* handling any more notifications. Handling can be restarted with
|
williamr@2
|
215 |
* a call to aHandler->StartListeningL(), if the error is non-fatal.
|
williamr@2
|
216 |
* However, be careful to trap any errors from this call if this is done.
|
williamr@2
|
217 |
*
|
williamr@2
|
218 |
* @param aId Id of the key this instance listens to or if notifications for
|
williamr@2
|
219 |
* whole repository are listened, could also be KInvalidNotificationId.
|
williamr@2
|
220 |
* @param aError Error code.
|
williamr@2
|
221 |
* @param aHandler Pointer to the handler instance.
|
williamr@2
|
222 |
* This pointer can be used to identify the handler or restart the listening.
|
williamr@2
|
223 |
* @capability Dependent Capability required depends on implementation of override.
|
williamr@2
|
224 |
*/
|
williamr@2
|
225 |
IMPORT_C virtual void HandleNotifyError( TUint32 aId, TInt aError,
|
williamr@2
|
226 |
CCenRepNotifyHandler* aHandler );
|
williamr@2
|
227 |
};
|
williamr@2
|
228 |
|
williamr@2
|
229 |
#endif // CENREPNOTIFYHANDLER_H
|
williamr@2
|
230 |
|
williamr@2
|
231 |
// End of File
|