predictivesearch/PcsAlgorithm/Algorithm2/src/CPsDataPluginInterface.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 09:41:07 +0300
branchRCL_3
changeset 18 d4f567ce2e7c
parent 0 e686773b3f54
permissions -rw-r--r--
Revision: 201031 Kit: 201033

/*
* 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<TDesC>& 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<TInt>& aDataFields)
{

    PRINT ( _L("Enter CPsDataPluginInterface::GetAllSupportedDataStoresL") );
   
    const TInt instancesCount = iPsDataPluginInstances.Count();
    for ( TInt idx = 0; idx < instancesCount; idx++ )
    {
       RPointerArray<TDesC> 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