diff -r 000000000000 -r ff3acec5bc43 musichomescreen/musiccontentpublisher/src/pluginmanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/musichomescreen/musiccontentpublisher/src/pluginmanager.cpp Thu Dec 17 08:45:05 2009 +0200 @@ -0,0 +1,250 @@ +/* +* Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Plugin manager, responsible to load the plugins. +* +*/ + +#include // MPX_DEBUG +#include +// for CeanupResetAndDestroyPushL +#include + +#include "musiccontentpublisher.h" +#include "pluginmanager.h" + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// Constructor +// --------------------------------------------------------------------------- +// +CPluginManager::CPluginManager( TUid aUid, + TAny* aParameter, + CMusicContentPublisher* aContentPublisher) : + CActive( EPriorityStandard ), + iUid( aUid ), + iParameter( aParameter ), + iContentPublisher(aContentPublisher) + { + } + +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CPluginManager::ConstructL() + { + MPX_DEBUG1("CPluginManager::ConstructL <---"); + iSession = &REComSession::OpenL(); + LoadPluginsL(); + iSession->NotifyOnChange( iStatus ); + CActiveScheduler::Add( this ); + SetActive(); + MPX_DEBUG1("CPluginManager::ConstructL --->"); + } + +// --------------------------------------------------------------------------- +// Two-phased constructor. +// --------------------------------------------------------------------------- +// +CPluginManager* CPluginManager::NewL( TUid aUid, + TAny *aParameter, + CMusicContentPublisher* aContentPublisher ) + { + CPluginManager* self = CPluginManager::NewLC( aUid, + aParameter, + aContentPublisher ); + CleanupStack::Pop( self ); + return self; + } + +// --------------------------------------------------------------------------- +// Two-phased constructor. +// --------------------------------------------------------------------------- +// +CPluginManager* CPluginManager::NewLC( TUid aUid, + TAny *aParameter, + CMusicContentPublisher* aContentPublisher ) + { + CPluginManager* self = new( ELeave ) CPluginManager( aUid, + aParameter, + aContentPublisher ); + CleanupStack::PushL( self ); + self->ConstructL(); + return self; + } + +// --------------------------------------------------------------------------- +// destructor +// --------------------------------------------------------------------------- +CPluginManager::~CPluginManager() + { + MPX_DEBUG1("CPluginManager::~CPluginManager <---"); + Cancel(); + CleanPluginsTable(); + iPluginMap.Close(); + if ( iSession ) + { + iSession->Close(); + } + REComSession::FinalClose(); + MPX_DEBUG1("CPluginManager::~CPluginManager --->"); + } + +// --------------------------------------------------------------------------- +// Retuns a plugin by UID +// --------------------------------------------------------------------------- +// +TAny* CPluginManager::GetImplementation( TUid aUid ) + { + TInt32 key = aUid.iUid; + TAny* ret= NULL; + TAny** imp= NULL; + imp = iPluginMap.Find( key ); + if ( imp ) + { + ret = *imp; + } + return ret; + } + +// --------------------------------------------------------------------------- +// Retuns a plugin by index +// --------------------------------------------------------------------------- +// +TAny* CPluginManager::GetImplementation( TInt aIndex ) + { + TAny* ret= NULL; + THashMapIter iter( iPluginMap ); + TAny*const* ptr = iter.NextValue(); + for ( TInt i( 0 ); ptr; i++ ) + { + if ( i == aIndex ) + { + ret = *ptr; + break; + } + ptr = iter.NextValue(); + } + return ret; + } + +// --------------------------------------------------------------------------- +// Returns the count of the plug-ins. +// --------------------------------------------------------------------------- +// +TInt CPluginManager::GetCount() + { + return iPluginMap.Count(); + } + +// --------------------------------------------------------------------------- +// Loads the plugins. +// --------------------------------------------------------------------------- +// +void CPluginManager::LoadPluginsL() + { + MPX_DEBUG1("CPluginManager::LoadPluginsL <---"); + // Read info about all implementations into infoArray + RImplInfoPtrArray infoArray; + CleanupResetAndDestroyPushL( infoArray ); + + REComSession::ListImplementationsL( iUid, infoArray ); + for ( TInt i = 0; i < infoArray.Count(); i++ ) + { + TUid current_plugin = infoArray[i]->ImplementationUid(); + TAny* plug( NULL ); + TUid temp; + TInt err( KErrNone ); + TRAP( err, plug = REComSession::CreateImplementationL( + current_plugin, + temp, + iParameter ) ); + if ( err == KErrNone && plug ) + { + CleanupStack::PushL( plug ); + TInt32 key = current_plugin.iUid; + iPluginMap.InsertL( key, plug ); + CleanupStack::Pop( plug ); + } + } + + CleanupStack::PopAndDestroy( &infoArray ); + MPX_DEBUG1("CPluginManager::LoadPluginsL --->"); + } + +// --------------------------------------------------------------------------- +// Unloads the plgugins. +// --------------------------------------------------------------------------- +// +void CPluginManager::CleanPluginsTable() + { + MPX_DEBUG1("CPluginManager::CleanPluginsTable <---"); + THashMapIter iter( iPluginMap ); + TAny*const* ptr = iter.NextValue(); + CBase* plug( NULL ); + const TInt32* pluginUid( NULL ); + while ( ptr ) + { + plug = static_cast( *ptr ); + delete plug; + plug = NULL; + pluginUid = iter.CurrentKey(); + REComSession::DestroyedImplementation( TUid::Uid( *pluginUid ) ); + ptr = iter.NextValue(); + pluginUid = NULL; + } + MPX_DEBUG1("CPluginManager::CleanPluginsTable --->"); + } + +// --------------------------------------------------------------------------- +//From CActive +// --------------------------------------------------------------------------- +// +void CPluginManager::RunL() + { + MPX_DEBUG1("CPluginManager::RunL <---"); + CleanPluginsTable(); + iPluginMap.Close(); + iContentPublisher->ResetL(); + LoadPluginsL(); + iSession->NotifyOnChange( iStatus ); + SetActive(); + MPX_DEBUG1("CPluginManager::RunL --->"); + } + +// --------------------------------------------------------------------------- +//From CActive +// --------------------------------------------------------------------------- +// +void CPluginManager::DoCancel() + { + MPX_DEBUG1("CPluginManager::DoCancel <---"); + iSession->CancelNotifyOnChange( iStatus ); + MPX_DEBUG1("CPluginManager::DoCancel --->"); + } + +// --------------------------------------------------------------------------- +//From CActive +// --------------------------------------------------------------------------- +// +TInt CPluginManager::RunError( TInt /*aError*/ ) + { + MPX_DEBUG1("CPluginManager::RunError <---"); + MPX_DEBUG1("CPluginManager::RunError --->"); + return KErrNone; + } + +// End of File +