37
|
1 |
/*
|
|
2 |
* Copyright (c) 2005 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: Publish & Subscribe proxy.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <e32base.h> // TPriority::EPriorityHigh=20
|
|
21 |
#include <PSVariables.h>
|
|
22 |
#include <telinternalpskeys.h>
|
|
23 |
#include <telephonydomainpstypes.h>
|
|
24 |
#include <btengdomainpskeys.h>
|
|
25 |
|
|
26 |
#include <startupdomainpskeys.h>
|
|
27 |
#include <coreapplicationuisdomainpskeys.h>
|
|
28 |
#include <hwrmdomainpskeys.h>
|
|
29 |
#include <UikonInternalPSKeys.h>
|
|
30 |
|
|
31 |
#include "phoneui.pan"
|
|
32 |
#include "phoneconstants.h"
|
|
33 |
#include "phonelogger.h"
|
|
34 |
|
|
35 |
#include "cphonepubsubproxy.h"
|
|
36 |
#include "cphonepublishsubscriberao.h"
|
|
37 |
|
|
38 |
// ================= MEMBER FUNCTIONS =======================
|
|
39 |
|
|
40 |
|
|
41 |
// ---------------------------------------------------------
|
|
42 |
// CPhonePubSubProxy::Instance
|
|
43 |
// Initializes the singleton object
|
|
44 |
// (other items were commented in a header).
|
|
45 |
// ---------------------------------------------------------
|
|
46 |
//
|
|
47 |
EXPORT_C CPhonePubSubProxy* CPhonePubSubProxy::Instance()
|
|
48 |
{
|
|
49 |
CPhonePubSubProxy* instance = static_cast<CPhonePubSubProxy*>
|
|
50 |
( CCoeEnv::Static ( KUidPubSubProxySingleton ) );
|
|
51 |
|
|
52 |
if ( !instance )
|
|
53 |
{
|
|
54 |
TRAPD( err, instance = CPhonePubSubProxy::NewL() );
|
|
55 |
if ( err )
|
|
56 |
{
|
|
57 |
Panic( EPhoneUtilsCouldNotCreateSingleton );
|
|
58 |
}
|
|
59 |
}
|
|
60 |
return instance;
|
|
61 |
}
|
|
62 |
|
|
63 |
// ---------------------------------------------------------
|
|
64 |
// CPhonePubSubProxy::CancelAllNotifications
|
|
65 |
// Cancel the notification if the singleton still exists.
|
|
66 |
// (other items were commented in a header).
|
|
67 |
// ---------------------------------------------------------
|
|
68 |
//
|
|
69 |
EXPORT_C void CPhonePubSubProxy::CancelAllNotifications(
|
|
70 |
MPhonePubSubObserver* aObserver )
|
|
71 |
{
|
|
72 |
CPhonePubSubProxy* instance = static_cast<CPhonePubSubProxy*>
|
|
73 |
( CCoeEnv::Static( KUidPubSubProxySingleton ) );
|
|
74 |
|
|
75 |
// Ignore the call since the singleton has already been destroyed and the
|
|
76 |
// notifications removed
|
|
77 |
if ( instance )
|
|
78 |
{
|
|
79 |
instance->CancelAllObserverNotifies( aObserver );
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
|
|
84 |
// ---------------------------------------------------------
|
|
85 |
// CPhonePubSubProxy::NewL
|
|
86 |
// ---------------------------------------------------------
|
|
87 |
//
|
|
88 |
CPhonePubSubProxy* CPhonePubSubProxy::NewL()
|
|
89 |
{
|
|
90 |
CPhonePubSubProxy* self = new (ELeave) CPhonePubSubProxy();
|
|
91 |
|
|
92 |
CleanupStack::PushL( self );
|
|
93 |
self->ConstructL();
|
|
94 |
CleanupStack::Pop( self );
|
|
95 |
|
|
96 |
return self;
|
|
97 |
}
|
|
98 |
|
|
99 |
// ---------------------------------------------------------
|
|
100 |
// CPhonePubSubProxy::~CPhonePubSubProxy
|
|
101 |
// ---------------------------------------------------------
|
|
102 |
//
|
|
103 |
EXPORT_C CPhonePubSubProxy::~CPhonePubSubProxy()
|
|
104 |
{
|
|
105 |
if ( iPublishSubscriberArray )
|
|
106 |
{
|
|
107 |
iPublishSubscriberArray->ResetAndDestroy();
|
|
108 |
}
|
|
109 |
delete iPublishSubscriberArray;
|
|
110 |
delete iObserverArray;
|
|
111 |
}
|
|
112 |
|
|
113 |
// ---------------------------------------------------------
|
|
114 |
// CPhonePubSubProxy::CPhonePubSubProxy
|
|
115 |
// ---------------------------------------------------------
|
|
116 |
//
|
|
117 |
CPhonePubSubProxy::CPhonePubSubProxy() :
|
|
118 |
CCoeStatic( KUidPubSubProxySingleton, EThread )
|
|
119 |
{
|
|
120 |
}
|
|
121 |
|
|
122 |
// ---------------------------------------------------------
|
|
123 |
// CPhonePubSubProxy::ConstructL
|
|
124 |
// ---------------------------------------------------------
|
|
125 |
//
|
|
126 |
void CPhonePubSubProxy::ConstructL()
|
|
127 |
{
|
|
128 |
iObserverArray = new ( ELeave ) CArrayFixFlat< TPubSubObserverTag >(
|
|
129 |
KPhonePubSubProxyObserverArrayGranularity );
|
|
130 |
|
|
131 |
iPublishSubscriberArray = new ( ELeave )
|
|
132 |
CArrayPtrFlat< CPhonePublishSubscriberAO >(
|
|
133 |
KPhonePubSubArrayGranularity );
|
|
134 |
}
|
|
135 |
|
|
136 |
// ---------------------------------------------------------
|
|
137 |
// CPhonePubSubProxy::Value
|
|
138 |
// ---------------------------------------------------------
|
|
139 |
//
|
|
140 |
EXPORT_C TInt CPhonePubSubProxy::Value(
|
|
141 |
const TUid& aCategory,
|
|
142 |
const TUint aKey )
|
|
143 |
{
|
|
144 |
TInt err( KErrNone );
|
|
145 |
TInt value( 0 );
|
|
146 |
|
|
147 |
err = RProperty::Get( aCategory, aKey, value );
|
|
148 |
if ( err != KErrNone )
|
|
149 |
{
|
|
150 |
value = err;
|
|
151 |
|
|
152 |
__PHONELOG1(
|
|
153 |
EBasic,
|
|
154 |
EPhonePhoneapp,
|
|
155 |
"CPhonePubSubProxy::GetValue error: %d",
|
|
156 |
err );
|
|
157 |
}
|
|
158 |
|
|
159 |
return value;
|
|
160 |
}
|
|
161 |
|
|
162 |
// ---------------------------------------------------------
|
|
163 |
// CPhonePubSubProxy::NotifyChangeL
|
|
164 |
// ---------------------------------------------------------
|
|
165 |
//
|
|
166 |
EXPORT_C void CPhonePubSubProxy::NotifyChangeL(
|
|
167 |
const TUid& aCategory,
|
|
168 |
const TUint aKey,
|
|
169 |
MPhonePubSubObserver* aObserver )
|
|
170 |
{
|
|
171 |
__ASSERT_DEBUG( aObserver, Panic( EPhoneUtilsParameterNotInitialized ) );
|
|
172 |
__LOGMETHODSTARTEND(EPhoneUIUtils, "CPhonePubSubProxy::NotifyChangeL() ");
|
|
173 |
|
|
174 |
// make sure this a new item in iObserverArray
|
|
175 |
TBool requestIssued = EFalse;
|
|
176 |
TBool sameRequestIssuedByObserver = EFalse;
|
|
177 |
TInt count = iObserverArray->Count();
|
|
178 |
|
|
179 |
// check if the request has already been issued
|
|
180 |
for ( TInt i = 0; i < count && !requestIssued; i++ )
|
|
181 |
{
|
|
182 |
const TPubSubObserverTag& observerTag = iObserverArray->At( i );
|
|
183 |
if ( ( observerTag.iCategory == aCategory ) &&
|
|
184 |
( observerTag.iKey == aKey ) )
|
|
185 |
{
|
|
186 |
requestIssued = ETrue;
|
|
187 |
if ( observerTag.iObserver == aObserver )
|
|
188 |
{
|
|
189 |
sameRequestIssuedByObserver = ETrue;
|
|
190 |
}
|
|
191 |
}
|
|
192 |
}
|
|
193 |
|
|
194 |
// make sure the same request hasn't been issued by this observer
|
|
195 |
if ( !sameRequestIssuedByObserver )
|
|
196 |
{
|
|
197 |
//add new observer to the array
|
|
198 |
TPubSubObserverTag newObserver;
|
|
199 |
newObserver.iCategory = aCategory;
|
|
200 |
newObserver.iKey = aKey;
|
|
201 |
newObserver.iObserver = aObserver;
|
|
202 |
iObserverArray->AppendL( newObserver );
|
|
203 |
}
|
|
204 |
|
|
205 |
//make sure the request hasn't been issued before
|
|
206 |
if ( !requestIssued )
|
|
207 |
{
|
|
208 |
//issue a new request
|
|
209 |
CPhonePublishSubscriberAO* publishSubscriber =
|
|
210 |
CPhonePublishSubscriberAO::NewL( this, aCategory, aKey );
|
|
211 |
|
|
212 |
CleanupStack::PushL( publishSubscriber );
|
|
213 |
iPublishSubscriberArray->AppendL( publishSubscriber );
|
|
214 |
CleanupStack::Pop( publishSubscriber );
|
|
215 |
|
|
216 |
//subscribe for property change notications
|
|
217 |
publishSubscriber->Subscribe();
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
// ---------------------------------------------------------
|
|
222 |
// CPhonePubSubProxy::ChangePropertyValue
|
|
223 |
// ---------------------------------------------------------
|
|
224 |
//
|
|
225 |
EXPORT_C void CPhonePubSubProxy::ChangePropertyValue(
|
|
226 |
const TUid& aCategory,
|
|
227 |
const TUint aKey,
|
|
228 |
const TInt aValue )
|
|
229 |
{
|
|
230 |
TInt err( KErrNone );
|
|
231 |
|
|
232 |
err = RProperty::Set( aCategory, aKey, aValue );
|
|
233 |
if ( err != KErrNone )
|
|
234 |
{
|
|
235 |
__PHONELOG1(
|
|
236 |
EBasic,
|
|
237 |
EPhonePhoneapp,
|
|
238 |
"CPhonePubSubProxy::ChangePropertyValue error: %d",
|
|
239 |
err );
|
|
240 |
}
|
|
241 |
}
|
|
242 |
|
|
243 |
// ---------------------------------------------------------
|
|
244 |
// CPhonePubSubProxy::HandlePropertyChangedL
|
|
245 |
// ---------------------------------------------------------
|
|
246 |
//
|
|
247 |
void CPhonePubSubProxy::HandlePropertyChangedL(
|
|
248 |
const TUid& aCategory,
|
|
249 |
const TUint aKey,
|
|
250 |
const TInt aValue )
|
|
251 |
{
|
|
252 |
TInt count = iObserverArray->Count();
|
|
253 |
for ( TInt i = 0; i < count; )
|
|
254 |
{
|
|
255 |
// Take observer information.
|
|
256 |
TPubSubObserverTag observerTag = iObserverArray->At( i );
|
|
257 |
|
|
258 |
if ( ( observerTag.iCategory == aCategory ) &&
|
|
259 |
( observerTag.iKey == aKey ) )
|
|
260 |
{
|
|
261 |
observerTag.iObserver->HandlePropertyChangedL(
|
|
262 |
aCategory, aKey, aValue );
|
|
263 |
}
|
|
264 |
|
|
265 |
// Update count variable - might have been modified by the
|
|
266 |
// HandlePropertyChangedL call.
|
|
267 |
count = iObserverArray->Count();
|
|
268 |
|
|
269 |
// If still in bounds, check if nothing changed. If so, then
|
|
270 |
// we can move to next observer.
|
|
271 |
if ( i < count )
|
|
272 |
{
|
|
273 |
const TPubSubObserverTag& obs = iObserverArray->At( i );
|
|
274 |
|
|
275 |
if ( ( obs.iObserver == observerTag.iObserver ) &&
|
|
276 |
( obs.iCategory == observerTag.iCategory ) &&
|
|
277 |
( obs.iKey == observerTag.iKey ) )
|
|
278 |
{
|
|
279 |
i++;
|
|
280 |
}
|
|
281 |
}
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
// ---------------------------------------------------------
|
|
286 |
// CPhonePubSubProxy::CancelAllObserverNotifies
|
|
287 |
// ---------------------------------------------------------
|
|
288 |
//
|
|
289 |
void CPhonePubSubProxy::CancelAllObserverNotifies(
|
|
290 |
MPhonePubSubObserver* aObserver )
|
|
291 |
{
|
|
292 |
TInt count = iObserverArray->Count();
|
|
293 |
|
|
294 |
// Remove the observer and its subscriptions
|
|
295 |
TBool observerRemoved = EFalse;
|
|
296 |
for( TInt i = count - 1; i >= 0 && !observerRemoved; i-- )
|
|
297 |
{
|
|
298 |
const TPubSubObserverTag& observerTag = iObserverArray->At( i );
|
|
299 |
if ( observerTag.iObserver == aObserver )
|
|
300 |
{
|
|
301 |
// Remove observer
|
|
302 |
observerRemoved = ETrue;
|
|
303 |
iObserverArray->Delete( i );
|
|
304 |
|
|
305 |
// Remove this observers' subscriptions
|
|
306 |
TInt pubSubCount = iPublishSubscriberArray->Count();
|
|
307 |
|
|
308 |
for ( TInt j = pubSubCount - 1; j >= 0; j++ )
|
|
309 |
{
|
|
310 |
CPhonePublishSubscriberAO* publishSubscriber =
|
|
311 |
iPublishSubscriberArray->At( j );
|
|
312 |
|
|
313 |
if ( publishSubscriber->Category() == observerTag.iCategory &&
|
|
314 |
publishSubscriber->Key() == observerTag.iKey )
|
|
315 |
{
|
|
316 |
iPublishSubscriberArray->Delete( i );
|
|
317 |
delete publishSubscriber;
|
|
318 |
}
|
|
319 |
}
|
|
320 |
}
|
|
321 |
}
|
|
322 |
}
|
|
323 |
|
|
324 |
// End of File
|
|
325 |
|