66
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: The source file of the CClockEcomListener class.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <ecom/ecom.h>
|
|
20 |
|
|
21 |
// User includes
|
|
22 |
#include "clockecomlistener.h"
|
|
23 |
#include "clockecomobserver.h"
|
|
24 |
#include "clock_debug.h"
|
|
25 |
|
|
26 |
// Constants
|
|
27 |
const TUid KTimeSourceInterfaceUID = { 0x200159A7 };
|
|
28 |
|
|
29 |
// ---------------------------------------------------------
|
|
30 |
// ReleaseOnCleanup
|
|
31 |
// Used for cleanup of objects on stack if a function leaves.
|
|
32 |
// ---------------------------------------------------------
|
|
33 |
//
|
|
34 |
LOCAL_C void ReleaseOnCleanup( TAny* aObject )
|
|
35 |
{
|
|
36 |
__PRINTS( "ReleaseOnCleanup - Entry" );
|
|
37 |
|
|
38 |
REINTERPRET_CAST( RImplInfoPtrArray*, ( aObject ) )->ResetAndDestroy();
|
|
39 |
REINTERPRET_CAST( RImplInfoPtrArray*, ( aObject ) )->Close();
|
|
40 |
|
|
41 |
__PRINTS( "ReleaseOnCleanup - Exit" );
|
|
42 |
}
|
|
43 |
|
|
44 |
// ---------------------------------------------------------
|
|
45 |
// CClockEComListener::NewL
|
|
46 |
// rest of the details are commented in the header
|
|
47 |
// ---------------------------------------------------------
|
|
48 |
//
|
|
49 |
EXPORT_C CClockEComListener* CClockEComListener::NewL( MClockEComObserver& aClockEComObserver )
|
|
50 |
{
|
|
51 |
__PRINTS( "CClockEComListener::NewL - Entry" );
|
|
52 |
|
|
53 |
CClockEComListener* self = new ( ELeave ) CClockEComListener( aClockEComObserver );
|
|
54 |
CleanupStack::PushL( self );
|
|
55 |
|
|
56 |
self->ConstructL();
|
|
57 |
|
|
58 |
CleanupStack::Pop();
|
|
59 |
|
|
60 |
__PRINTS( "CClockEComListener::NewL - Exit" );
|
|
61 |
|
|
62 |
return self;
|
|
63 |
}
|
|
64 |
|
|
65 |
// ---------------------------------------------------------
|
|
66 |
// CClockEComListener::~CClockEComListener
|
|
67 |
// rest of the details are commented in the header
|
|
68 |
// ---------------------------------------------------------
|
|
69 |
//
|
|
70 |
EXPORT_C CClockEComListener::~CClockEComListener()
|
|
71 |
{
|
|
72 |
__PRINTS( "CClockEComListener::~CClockEComListener - Entry" );
|
|
73 |
|
|
74 |
// Cancel any outstanding requests.
|
|
75 |
Stop();
|
|
76 |
if( iEComSession )
|
|
77 |
{
|
|
78 |
iEComSession->Close();
|
|
79 |
}
|
|
80 |
|
|
81 |
iImplArray.ResetAndDestroy();
|
|
82 |
iImplArray.Close();
|
|
83 |
|
|
84 |
__PRINTS( "CClockEComListener::~CClockEComListener - Exit" );
|
|
85 |
}
|
|
86 |
|
|
87 |
// ---------------------------------------------------------
|
|
88 |
// CClockEComListener::NotifyEComObserverL
|
|
89 |
// rest of the details are commented in the header
|
|
90 |
// ---------------------------------------------------------
|
|
91 |
//
|
|
92 |
void CClockEComListener::NotifyEComObserverL( CImplementationInformation* aImplInfo, TBool aInstalled )
|
|
93 |
{
|
|
94 |
__PRINTS( "CClockEComListener::NotifyEComObserverL - Entry" );
|
|
95 |
|
|
96 |
// Notify the observer about changes in the registry.
|
|
97 |
iClockEComObserver.NotifyPluginInstallUninstallL( *aImplInfo, aInstalled );
|
|
98 |
|
|
99 |
__PRINTS( "CClockEComListener::NotifyEComObserverL - Exit" );
|
|
100 |
}
|
|
101 |
|
|
102 |
// ---------------------------------------------------------
|
|
103 |
// CClockEComListener::RunL
|
|
104 |
// rest of the details are commented in the header
|
|
105 |
// ---------------------------------------------------------
|
|
106 |
//
|
|
107 |
void CClockEComListener::RunL()
|
|
108 |
{
|
|
109 |
__PRINTS( "CClockEComListener::RunL - Entry" );
|
|
110 |
|
|
111 |
// Check whether a plugin was installed or removed.
|
|
112 |
CheckForEcomPluginInstallUninstallL();
|
|
113 |
|
|
114 |
//Restart the active Object
|
|
115 |
Start();
|
|
116 |
|
|
117 |
__PRINTS( "CClockEComListener::RunL - Exit" );
|
|
118 |
}
|
|
119 |
|
|
120 |
// ---------------------------------------------------------
|
|
121 |
// CClockEComListener::DoCancel
|
|
122 |
// rest of the details are commented in the header
|
|
123 |
// ---------------------------------------------------------
|
|
124 |
//
|
|
125 |
void CClockEComListener::DoCancel()
|
|
126 |
{
|
|
127 |
__PRINTS( "CClockEComListener::DoCancel - Entry" );
|
|
128 |
|
|
129 |
// Cancel any outstanding requests.
|
|
130 |
iEComSession->CancelNotifyOnChange( iStatus );
|
|
131 |
|
|
132 |
__PRINTS( "CClockEComListener::DoCancel - Exit" );
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------
|
|
136 |
// CClockEComListener::CClockEComListener
|
|
137 |
// rest of the details are commented in the header
|
|
138 |
// ---------------------------------------------------------
|
|
139 |
//
|
|
140 |
CClockEComListener::CClockEComListener( MClockEComObserver& aClockEComObserver ) : CActive( CActive::EPriorityStandard ), iClockEComObserver( aClockEComObserver )
|
|
141 |
{
|
|
142 |
__PRINTS( "CClockEComListener::CClockEComListener - Entry" );
|
|
143 |
|
|
144 |
// No implementation yet.
|
|
145 |
|
|
146 |
__PRINTS( "CClockEComListener::CClockEComListener - Exit" );
|
|
147 |
}
|
|
148 |
|
|
149 |
// ---------------------------------------------------------
|
|
150 |
// CClockEComListener::ConstructL
|
|
151 |
// rest of the details are commented in the header
|
|
152 |
// ---------------------------------------------------------
|
|
153 |
//
|
|
154 |
void CClockEComListener::ConstructL()
|
|
155 |
{
|
|
156 |
__PRINTS( "CClockEComListener::ConstructL - Entry" );
|
|
157 |
|
|
158 |
// Connect to the ECOM session server.
|
|
159 |
iEComSession = &REComSession::OpenL();
|
|
160 |
|
|
161 |
// Get the list of all plugins which are present.
|
|
162 |
TRAP_IGNORE( REComSession::ListImplementationsL( KTimeSourceInterfaceUID, iImplArray ) );
|
|
163 |
|
|
164 |
// Queue the active object in the scheduler
|
|
165 |
CActiveScheduler::Add( this );
|
|
166 |
|
|
167 |
// Start the listener.
|
|
168 |
Start();
|
|
169 |
|
|
170 |
__PRINTS( "CClockEComListener::ConstructL - Exit" );
|
|
171 |
}
|
|
172 |
|
|
173 |
// ---------------------------------------------------------
|
|
174 |
// CClockEComListener::Start
|
|
175 |
// rest of the details are commented in the header
|
|
176 |
// ---------------------------------------------------------
|
|
177 |
//
|
|
178 |
void CClockEComListener::Start()
|
|
179 |
{
|
|
180 |
__PRINTS( "CClockEComListener::Start - Entry" );
|
|
181 |
|
|
182 |
if (!IsActive())
|
|
183 |
{
|
|
184 |
// Start the active object and listen for changes in the ECOM registry.
|
|
185 |
if( iEComSession )
|
|
186 |
{
|
|
187 |
iEComSession->NotifyOnChange( iStatus );
|
|
188 |
SetActive();
|
|
189 |
}
|
|
190 |
}
|
|
191 |
|
|
192 |
|
|
193 |
__PRINTS( "CClockEComListener::Start - Exit" );
|
|
194 |
}
|
|
195 |
|
|
196 |
// ---------------------------------------------------------
|
|
197 |
// CClockEComListener::Stop
|
|
198 |
// rest of the details are commented in the header
|
|
199 |
// ---------------------------------------------------------
|
|
200 |
//
|
|
201 |
void CClockEComListener::Stop()
|
|
202 |
{
|
|
203 |
__PRINTS( "CClockEComListener::Stop - Entry" );
|
|
204 |
|
|
205 |
Cancel();
|
|
206 |
|
|
207 |
__PRINTS( "CClockEComListener::Stop - Exit" );
|
|
208 |
}
|
|
209 |
|
|
210 |
// ---------------------------------------------------------
|
|
211 |
// CClockEComListener::CheckForEcomPluginInstallUninstallL
|
|
212 |
// rest of the details are commented in the header
|
|
213 |
// ---------------------------------------------------------
|
|
214 |
//
|
|
215 |
void CClockEComListener::CheckForEcomPluginInstallUninstallL()
|
|
216 |
{
|
|
217 |
__PRINTS( "CClockEComListener::CheckForEcomPluginInstallUninstallL - Entry" );
|
|
218 |
|
|
219 |
// Array to return all implementations in an interface
|
|
220 |
RImplInfoPtrArray plugInArray;
|
|
221 |
|
|
222 |
// Get the list of all implementations.
|
|
223 |
TRAPD( errorVal, REComSession::ListImplementationsL( KTimeSourceInterfaceUID, plugInArray ) );
|
|
224 |
CleanupStack::PushL( TCleanupItem( ReleaseOnCleanup, &plugInArray ) );
|
|
225 |
|
|
226 |
TBool implAdded( EFalse );
|
|
227 |
TBool implRemoved( EFalse );
|
|
228 |
|
|
229 |
// If an implementation is not present in the iPluginUidList then its added.
|
|
230 |
for( TInt index( plugInArray.Count() - 1 ); index >= 0; --index )
|
|
231 |
{
|
|
232 |
TUid uId( plugInArray[ index ]->ImplementationUid() );
|
|
233 |
if( IsPluginInstalled( uId ) )
|
|
234 |
{
|
|
235 |
// Add the implementation which is not present in the plugin array.
|
|
236 |
// Notify the observer about the plugin addition.
|
|
237 |
__PRINT( "UID: %x", uId );
|
|
238 |
__PRINT( "Version: %d", plugInArray[ index ]->Version() );
|
|
239 |
|
|
240 |
NotifyEComObserverL( plugInArray[ index ], ETrue );
|
|
241 |
|
|
242 |
implAdded = ETrue;
|
|
243 |
|
|
244 |
break;
|
|
245 |
}
|
|
246 |
}
|
|
247 |
|
|
248 |
if( !implAdded )
|
|
249 |
{
|
|
250 |
// If an implementation is not present in present in the plugInArray then its removed.
|
|
251 |
for( TInt index( iImplArray.Count() - 1 ); index >= 0; --index )
|
|
252 |
{
|
|
253 |
TUid uId( iImplArray[ index ]->ImplementationUid() );
|
|
254 |
if( IsPluginUninstalled( uId, plugInArray ) )
|
|
255 |
{
|
|
256 |
// Remove the implementation in the plugin array.
|
|
257 |
// Notify the observer about the plugin removal.
|
|
258 |
__PRINT( "UID: %x", uId );
|
|
259 |
__PRINT( "Version: %d", iImplArray[ index ]->Version() );
|
|
260 |
|
|
261 |
NotifyEComObserverL( iImplArray[ index ], EFalse );
|
|
262 |
|
|
263 |
implRemoved = ETrue;
|
|
264 |
|
|
265 |
break;
|
|
266 |
}
|
|
267 |
}
|
|
268 |
}
|
|
269 |
|
|
270 |
if( !implAdded && !implRemoved )
|
|
271 |
{
|
|
272 |
// Check if a plugin was upgraded by installation OR downgraded by uninstallation.
|
|
273 |
CheckForPluginUpgradeDowngradeL( plugInArray );
|
|
274 |
}
|
|
275 |
|
|
276 |
// Reset the array and refresh the plugin list.
|
|
277 |
iImplArray.ResetAndDestroy();
|
|
278 |
iImplArray.Close();
|
|
279 |
|
|
280 |
TRAP( errorVal, REComSession::ListImplementationsL( KTimeSourceInterfaceUID, iImplArray ) );
|
|
281 |
|
|
282 |
// Cleanup.
|
|
283 |
CleanupStack::Pop( &plugInArray );
|
|
284 |
plugInArray.ResetAndDestroy();
|
|
285 |
plugInArray.Close();
|
|
286 |
|
|
287 |
__PRINTS( "CClockEComListener::CheckForEcomPluginInstallUninstallL - Exit" );
|
|
288 |
}
|
|
289 |
|
|
290 |
// ---------------------------------------------------------
|
|
291 |
// CClockEComListener::IsPluginInstalled
|
|
292 |
// rest of the details are commented in the header
|
|
293 |
// ---------------------------------------------------------
|
|
294 |
//
|
|
295 |
TBool CClockEComListener::IsPluginInstalled( const TUid aUid )
|
|
296 |
{
|
|
297 |
__PRINTS( "CClockEComListener::IsPluginInstalled - Entry" );
|
|
298 |
|
|
299 |
for( TInt index( iImplArray.Count() - 1 ); index >= 0; --index )
|
|
300 |
{
|
|
301 |
if( aUid == ( iImplArray[ index ] )->ImplementationUid() )
|
|
302 |
{
|
|
303 |
__PRINTS( "CClockEComListener::IsPluginInstalled - Exit" );
|
|
304 |
|
|
305 |
return EFalse;
|
|
306 |
}
|
|
307 |
}
|
|
308 |
__PRINT( "Plugin added: %x", aUid );
|
|
309 |
|
|
310 |
__PRINTS( "CClockEComListener::IsPluginInstalled - Exit" );
|
|
311 |
|
|
312 |
return ETrue;
|
|
313 |
}
|
|
314 |
|
|
315 |
// ---------------------------------------------------------
|
|
316 |
// CClockEComListener::IsPluginUninstalled
|
|
317 |
// rest of the details are commented in the header
|
|
318 |
// ---------------------------------------------------------
|
|
319 |
//
|
|
320 |
TBool CClockEComListener::IsPluginUninstalled( const TUid aUid, RImplInfoPtrArray aPlugInArray )
|
|
321 |
{
|
|
322 |
__PRINTS( "CClockEComListener::IsPluginUninstalled - Entry" );
|
|
323 |
|
|
324 |
for( TInt index( aPlugInArray.Count() - 1 ); index >= 0; --index )
|
|
325 |
{
|
|
326 |
if( aUid == aPlugInArray[ index ]->ImplementationUid() )
|
|
327 |
{
|
|
328 |
__PRINTS( "CClockEComListener::IsPluginUninstalled - Exit" );
|
|
329 |
|
|
330 |
return EFalse;
|
|
331 |
}
|
|
332 |
}
|
|
333 |
__PRINT( "Plugin removed: %x", aUid );
|
|
334 |
|
|
335 |
__PRINTS( "CClockEComListener::IsPluginUninstalled - Exit" );
|
|
336 |
|
|
337 |
return ETrue;
|
|
338 |
}
|
|
339 |
|
|
340 |
// ---------------------------------------------------------
|
|
341 |
// CClockEComListener::CheckForPluginUpgradeDowngradeL
|
|
342 |
// rest of the details are commented in the header
|
|
343 |
// ---------------------------------------------------------
|
|
344 |
//
|
|
345 |
void CClockEComListener::CheckForPluginUpgradeDowngradeL( const RImplInfoPtrArray& aPlugInArray )
|
|
346 |
{
|
|
347 |
__PRINTS( "CClockEComListener::CheckForPluginUpgradeDowngradeL - Entry" );
|
|
348 |
|
|
349 |
// Check for each plugin in the array if the version matches with the plugin we have
|
|
350 |
for( TInt outerIndex( aPlugInArray.Count() - 1 ); outerIndex >= 0; --outerIndex )
|
|
351 |
{
|
|
352 |
TUid uId( aPlugInArray[ outerIndex ]->ImplementationUid() );
|
|
353 |
for( TInt innerIndex( iImplArray.Count() - 1 ); innerIndex >= 0; --innerIndex )
|
|
354 |
{
|
|
355 |
if( uId == iImplArray[ innerIndex ]->ImplementationUid() )
|
|
356 |
{
|
|
357 |
if( aPlugInArray[ outerIndex ]->Version() != iImplArray[ innerIndex ]->Version() )
|
|
358 |
{
|
|
359 |
__PRINTS( "Plugin upgraded / degraded" );
|
|
360 |
__PRINT( "UID: %x", uId );
|
|
361 |
__PRINT( "Version: %d", aPlugInArray[ outerIndex ]->Version() );
|
|
362 |
|
|
363 |
// If control reaches here, it means we either have an upgrade or downgrade.
|
|
364 |
NotifyEComObserverL( aPlugInArray[ outerIndex ], ETrue );
|
|
365 |
|
|
366 |
break;
|
|
367 |
}
|
|
368 |
}
|
|
369 |
}
|
|
370 |
}
|
|
371 |
|
|
372 |
__PRINTS( "CClockEComListener::CheckForPluginUpgradeDowngradeL - Exit" );
|
|
373 |
}
|
|
374 |
|
|
375 |
// End of file
|