diff -r 5b6f26637ad3 -r f4a778e096c2 predictivesearch/PcsAlgorithm/Algorithm2/src/CPsDataPluginInterface.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/predictivesearch/PcsAlgorithm/Algorithm2/src/CPsDataPluginInterface.cpp Wed Sep 01 12:29:52 2010 +0100 @@ -0,0 +1,246 @@ +/* +* Copyright (c) 2007 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: +* +*/ + + +// INCLUDE FILES +#include "CPsDataPluginInterface.h" +#include "CPsDataPlugin.h" +#include "CPcsDebug.h" + +// ============================== MEMBER FUNCTIONS ============================ + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::NewL +// Two Phase Construction +// ---------------------------------------------------------------------------- +CPsDataPluginInterface* CPsDataPluginInterface::NewL(MDataStoreObserver* aObserverForDataStore, + MStoreListObserver* aStoreListObserver) +{ + PRINT ( _L("Enter CPsDataPluginInterface::NewL") ); + + CPsDataPluginInterface* self = CPsDataPluginInterface::NewLC(aObserverForDataStore, aStoreListObserver); + CleanupStack::Pop( self ); + + PRINT ( _L("End CPsDataPluginInterface::NewL") ); + + return self; +} + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::NewLC +// Two Phase Construction +// ---------------------------------------------------------------------------- +CPsDataPluginInterface* CPsDataPluginInterface::NewLC(MDataStoreObserver* aObserverForDataStore, + MStoreListObserver* aStoreListObserver) +{ + PRINT ( _L("Enter CPsDataPluginInterface::NewLC") ); + + CPsDataPluginInterface* self = new( ELeave ) CPsDataPluginInterface(); + CleanupStack::PushL( self ); + self->ConstructL(aObserverForDataStore, aStoreListObserver); + + PRINT ( _L("End CPsDataPluginInterface::NewLC") ); + + return self; +} + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::CPsDataPluginInterface +// Constructor +// ---------------------------------------------------------------------------- +CPsDataPluginInterface::CPsDataPluginInterface() +{ + PRINT ( _L("Enter CPsDataPluginInterface::CPsDataPluginInterface") ); + PRINT ( _L("End CPsDataPluginInterface::CPsDataPluginInterface") ); +} + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::ConstructL +// 2nd phase constructor +// ---------------------------------------------------------------------------- +void CPsDataPluginInterface::ConstructL(MDataStoreObserver* aObserverForDataStore, + MStoreListObserver* aStoreListObserver) +{ + PRINT ( _L("Enter CPsDataPluginInterface::ConstructL") ); + iObserverForDataStore = aObserverForDataStore; + iStoreListObserver = aStoreListObserver; + PRINT ( _L("End CPsDataPluginInterface::ConstructL") ); +} + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::~CPsDataPluginInterface +// Constructor +// ---------------------------------------------------------------------------- +CPsDataPluginInterface::~CPsDataPluginInterface( ) +{ + PRINT ( _L("Enter CPsDataPluginInterface::~CPsDataPluginInterface") ); + + UnloadPlugIns(); + iPsDataPluginInstances.ResetAndDestroy(); + + PRINT ( _L("End CPsDataPluginInterface::~CPsDataPluginInterface") ); +} + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::InstantiateAllPlugInsL +// Instantiates all plugins +// ---------------------------------------------------------------------------- +void CPsDataPluginInterface::InstantiateAllPlugInsL( ) +{ + PRINT ( _L("Enter CPsDataPluginInterface::InstantiateAllPlugInsL") ); + + RImplInfoPtrArray infoArray; + + // Get list of all implementations + ListAllImplementationsL( infoArray ); + + // Instantiate plugins for all impUIds by calling + // InstantiatePlugInFromImpUidL + const TInt infoArrayCount = infoArray.Count(); + for ( TInt i=0; i < infoArrayCount; i++ ) + { + // Get imp info + CImplementationInformation& info( *infoArray[i] ); + + // Get imp UID + TUid impUid ( info.ImplementationUid() ); + + PRINT ( _L("------------- PS Data Store Details -----------")); + PRINT1 ( _L("Name: %S"), &(info.DisplayName()) ); + PRINT1 ( _L("UID: %X"), impUid.iUid ); + PRINT ( _L("-----------------------------------------------")); + + CPsDataPlugin* plugin = NULL; + + //instantiate plugin for impUid + plugin = InstantiatePlugInFromImpUidL( impUid, iObserverForDataStore, iStoreListObserver ) ; + if ( plugin ) + { + + iPsDataPluginInstances.AppendL( plugin ); + + } + } + + infoArray.ResetAndDestroy(); + + PRINT ( _L("End CPsDataPluginInterface::InstantiateAllPlugInsL") ); +} + +// ----------------------------------------------------------------------------- +// CPsDataPluginInterface::UnloadPlugIns +// Unloads plugins +// ----------------------------------------------------------------------------- +void CPsDataPluginInterface::UnloadPlugIns() +{ + PRINT ( _L("Enter CPsDataPluginInterface::UnloadPlugIns") ); + + REComSession::FinalClose(); + + PRINT ( _L("End CPsDataPluginInterface::UnloadPlugIns") ); +} + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::InstantiatePlugInFromImpUidL +// Instantiates plugin +// ---------------------------------------------------------------------------- +CPsDataPlugin* CPsDataPluginInterface::InstantiatePlugInFromImpUidL( const TUid& aImpUid, + MDataStoreObserver* aObserverForDataStore, + MStoreListObserver* aStoreListObserver ) +{ + PRINT ( _L("Enter CPsDataPluginInterface::InstantiatePlugInFromImpUidL") ); + + CPsDataPlugin* plugin = CPsDataPlugin::NewL(aImpUid, aObserverForDataStore, aStoreListObserver); + + PRINT ( _L("End CPsDataPluginInterface::InstantiatePlugInFromImpUidL") ); + + return plugin; +} + + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::RequestForDataL +// Requests for data from the data store +// ---------------------------------------------------------------------------- +void CPsDataPluginInterface::RequestForDataL(TDesC& aDataStore) +{ + + PRINT ( _L("Enter CPsDataPluginInterface::RequestForDataL") ); + const TInt instancesCount = iPsDataPluginInstances.Count(); + for ( TInt idx = 0; idx < instancesCount; idx++ ) + { + if(iPsDataPluginInstances[idx]->IsDataStoresSupportedL(aDataStore)) + { + iPsDataPluginInstances[idx]->RequestForDataL(aDataStore); + break; + } + } + + PRINT ( _L("End CPsDataPluginInterface::RequestForDataL") ); + +} + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::GetAllSupportedDataStoresL +// Requests all the supported data stores from data adapters +// ---------------------------------------------------------------------------- +void CPsDataPluginInterface::GetAllSupportedDataStoresL(RPointerArray& aDataStores) +{ + + PRINT ( _L("Enter CPsDataPluginInterface::GetAllSupportedDataStoresL") ); + const TInt instancesCount = iPsDataPluginInstances.Count(); + for ( TInt idx = 0; idx < instancesCount; idx++ ) + { + iPsDataPluginInstances[idx]->GetSupportedDataStoresL(aDataStores); + } + + PRINT ( _L("End CPsDataPluginInterface::GetAllSupportedDataStoresL") ); + +} + +// ---------------------------------------------------------------------------- +// CPsDataPluginInterface::GetAllSupportedDataFieldsL +// Requests all the supported data fields from from data adapters +// ---------------------------------------------------------------------------- +void CPsDataPluginInterface::GetSupportedDataFieldsL(TDesC& aUri, RArray& aDataFields) +{ + + PRINT ( _L("Enter CPsDataPluginInterface::GetAllSupportedDataStoresL") ); + + const TInt instancesCount = iPsDataPluginInstances.Count(); + for ( TInt idx = 0; idx < instancesCount; idx++ ) + { + RPointerArray dataStores; + CleanupClosePushL( dataStores ); + iPsDataPluginInstances[idx]->GetSupportedDataStoresL(dataStores); + + const TInt dataStoresCount = dataStores.Count(); + for ( TInt i(0); i < dataStoresCount; i++) + { + if ( dataStores[i]->Compare(aUri) == 0) + { + iPsDataPluginInstances[idx]->GetSupportedDataFieldsL(aDataFields); + break; + } + } + CleanupStack::PopAndDestroy( &dataStores ); // Close + } + + PRINT ( _L("End CPsDataPluginInterface::GetAllSupportedDataStoresL") ); + +} +// End of file