predictivesearch/PcsAlgorithm/Algorithm2/src/CPsDataPluginInterface.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 85 38bb213f60ba
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2007 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPsDataPluginInterface.h"
       
    21 #include "CPsDataPlugin.h"
       
    22 #include "CPcsDebug.h"
       
    23 
       
    24 // ============================== MEMBER FUNCTIONS ============================
       
    25 
       
    26 // ----------------------------------------------------------------------------
       
    27 // CPsDataPluginInterface::NewL
       
    28 // Two Phase Construction
       
    29 // ----------------------------------------------------------------------------
       
    30 CPsDataPluginInterface* CPsDataPluginInterface::NewL(MDataStoreObserver* aObserverForDataStore,
       
    31 													MStoreListObserver* aStoreListObserver)
       
    32 {
       
    33     PRINT ( _L("Enter CPsDataPluginInterface::NewL") );
       
    34     
       
    35     CPsDataPluginInterface* self = CPsDataPluginInterface::NewLC(aObserverForDataStore, aStoreListObserver);
       
    36     CleanupStack::Pop( self );
       
    37     
       
    38     PRINT ( _L("End CPsDataPluginInterface::NewL") );
       
    39     
       
    40     return self;
       
    41 }
       
    42 
       
    43 // ----------------------------------------------------------------------------
       
    44 // CPsDataPluginInterface::NewLC
       
    45 // Two Phase Construction
       
    46 // ---------------------------------------------------------------------------- 
       
    47 CPsDataPluginInterface* CPsDataPluginInterface::NewLC(MDataStoreObserver* aObserverForDataStore,
       
    48 													MStoreListObserver* aStoreListObserver)
       
    49 {
       
    50     PRINT ( _L("Enter CPsDataPluginInterface::NewLC") );
       
    51     
       
    52     CPsDataPluginInterface* self = new( ELeave ) CPsDataPluginInterface();
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL(aObserverForDataStore, aStoreListObserver);
       
    55     
       
    56     PRINT ( _L("End CPsDataPluginInterface::NewLC") );
       
    57     
       
    58     return self;
       
    59 }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CPsDataPluginInterface::CPsDataPluginInterface
       
    63 // Constructor
       
    64 // ----------------------------------------------------------------------------    
       
    65 CPsDataPluginInterface::CPsDataPluginInterface()
       
    66 {
       
    67     PRINT ( _L("Enter CPsDataPluginInterface::CPsDataPluginInterface") );
       
    68     PRINT ( _L("End CPsDataPluginInterface::CPsDataPluginInterface") );
       
    69 }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CPsDataPluginInterface::ConstructL
       
    73 // 2nd phase constructor
       
    74 // ---------------------------------------------------------------------------- 
       
    75 void CPsDataPluginInterface::ConstructL(MDataStoreObserver* aObserverForDataStore,
       
    76 										MStoreListObserver* aStoreListObserver)
       
    77 {
       
    78     PRINT ( _L("Enter CPsDataPluginInterface::ConstructL") );
       
    79     iObserverForDataStore = aObserverForDataStore;
       
    80     iStoreListObserver = aStoreListObserver;
       
    81     PRINT ( _L("End CPsDataPluginInterface::ConstructL") );
       
    82 }
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // CPsDataPluginInterface::~CPsDataPluginInterface
       
    86 // Constructor
       
    87 // ---------------------------------------------------------------------------- 
       
    88 CPsDataPluginInterface::~CPsDataPluginInterface( ) 
       
    89 {
       
    90     PRINT ( _L("Enter CPsDataPluginInterface::~CPsDataPluginInterface") );
       
    91     
       
    92     UnloadPlugIns();
       
    93     iPsDataPluginInstances.ResetAndDestroy();
       
    94     
       
    95     PRINT ( _L("End CPsDataPluginInterface::~CPsDataPluginInterface") );
       
    96 }
       
    97         
       
    98 // ----------------------------------------------------------------------------
       
    99 // CPsDataPluginInterface::InstantiateAllPlugInsL
       
   100 // Instantiates all plugins
       
   101 // ----------------------------------------------------------------------------     
       
   102 void CPsDataPluginInterface::InstantiateAllPlugInsL( )
       
   103 {
       
   104     PRINT ( _L("Enter CPsDataPluginInterface::InstantiateAllPlugInsL") );
       
   105 
       
   106     RImplInfoPtrArray infoArray;
       
   107     
       
   108     // Get list of all implementations
       
   109     ListAllImplementationsL( infoArray );
       
   110     
       
   111     // Instantiate plugins for all impUIds by calling 
       
   112     // InstantiatePlugInFromImpUidL
       
   113     const TInt infoArrayCount = infoArray.Count();
       
   114     for ( TInt i=0; i < infoArrayCount; i++ )
       
   115     {
       
   116         // Get imp info
       
   117         CImplementationInformation& info( *infoArray[i] );
       
   118         
       
   119         // Get imp UID
       
   120         TUid impUid ( info.ImplementationUid() );
       
   121         
       
   122         PRINT ( _L("------------- PS Data Store Details -----------"));
       
   123         PRINT1 ( _L("Name: %S"), &(info.DisplayName()) );
       
   124         PRINT1 ( _L("UID: %X"), impUid.iUid );
       
   125         PRINT ( _L("-----------------------------------------------"));
       
   126         
       
   127         CPsDataPlugin* plugin = NULL;
       
   128         
       
   129         //instantiate plugin for impUid
       
   130         plugin = InstantiatePlugInFromImpUidL( impUid, iObserverForDataStore, iStoreListObserver ) ;
       
   131         if ( plugin )
       
   132         {
       
   133             
       
   134             iPsDataPluginInstances.AppendL( plugin );
       
   135                    
       
   136         }    	        	     
       
   137     }
       
   138     
       
   139     infoArray.ResetAndDestroy();
       
   140     
       
   141     PRINT ( _L("End CPsDataPluginInterface::InstantiateAllPlugInsL") );
       
   142 }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CPsDataPluginInterface::UnloadPlugIns
       
   146 // Unloads plugins
       
   147 // -----------------------------------------------------------------------------
       
   148 void CPsDataPluginInterface::UnloadPlugIns()
       
   149 {
       
   150     PRINT ( _L("Enter CPsDataPluginInterface::UnloadPlugIns") );
       
   151     
       
   152     REComSession::FinalClose();
       
   153     
       
   154     PRINT ( _L("End CPsDataPluginInterface::UnloadPlugIns") );
       
   155 }
       
   156 
       
   157 // ----------------------------------------------------------------------------
       
   158 // CPsDataPluginInterface::InstantiatePlugInFromImpUidL
       
   159 // Instantiates plugin
       
   160 // ---------------------------------------------------------------------------- 
       
   161 CPsDataPlugin* CPsDataPluginInterface::InstantiatePlugInFromImpUidL( const TUid& aImpUid, 
       
   162 																	 MDataStoreObserver* aObserverForDataStore,
       
   163 																	 MStoreListObserver* aStoreListObserver )
       
   164 {
       
   165     PRINT ( _L("Enter CPsDataPluginInterface::InstantiatePlugInFromImpUidL") );
       
   166     
       
   167     CPsDataPlugin* plugin = CPsDataPlugin::NewL(aImpUid, aObserverForDataStore, aStoreListObserver);
       
   168     
       
   169     PRINT ( _L("End CPsDataPluginInterface::InstantiatePlugInFromImpUidL") );
       
   170     
       
   171     return plugin;
       
   172 }
       
   173     
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CPsDataPluginInterface::RequestForDataL
       
   177 // Requests for data from the data store
       
   178 // ---------------------------------------------------------------------------- 
       
   179 void  CPsDataPluginInterface::RequestForDataL(TDesC& aDataStore)
       
   180 {
       
   181 
       
   182     PRINT ( _L("Enter CPsDataPluginInterface::RequestForDataL") );
       
   183    const TInt instancesCount = iPsDataPluginInstances.Count();
       
   184     for ( TInt idx = 0; idx < instancesCount; idx++ )
       
   185     {
       
   186         if(iPsDataPluginInstances[idx]->IsDataStoresSupportedL(aDataStore))
       
   187         {
       
   188        		iPsDataPluginInstances[idx]->RequestForDataL(aDataStore);
       
   189     		break; 
       
   190         }
       
   191     }
       
   192     
       
   193     PRINT ( _L("End CPsDataPluginInterface::RequestForDataL") );
       
   194 
       
   195 }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // CPsDataPluginInterface::GetAllSupportedDataStoresL
       
   199 // Requests all the supported data stores from data adapters
       
   200 // ---------------------------------------------------------------------------- 
       
   201 void  CPsDataPluginInterface::GetAllSupportedDataStoresL(RPointerArray<TDesC>& aDataStores)
       
   202 {
       
   203 
       
   204     PRINT ( _L("Enter CPsDataPluginInterface::GetAllSupportedDataStoresL") );
       
   205     const TInt instancesCount = iPsDataPluginInstances.Count();
       
   206     for ( TInt idx = 0; idx < instancesCount; idx++ )
       
   207     {       
       
   208        iPsDataPluginInstances[idx]->GetSupportedDataStoresL(aDataStores);
       
   209     }
       
   210     
       
   211     PRINT ( _L("End CPsDataPluginInterface::GetAllSupportedDataStoresL") );
       
   212 
       
   213 }
       
   214 
       
   215 // ----------------------------------------------------------------------------
       
   216 // CPsDataPluginInterface::GetAllSupportedDataFieldsL
       
   217 // Requests all the supported data fields from from data adapters
       
   218 // ---------------------------------------------------------------------------- 
       
   219 void  CPsDataPluginInterface::GetSupportedDataFieldsL(TDesC& aUri, RArray<TInt>& aDataFields)
       
   220 {
       
   221 
       
   222     PRINT ( _L("Enter CPsDataPluginInterface::GetAllSupportedDataStoresL") );
       
   223    
       
   224     const TInt instancesCount = iPsDataPluginInstances.Count();
       
   225     for ( TInt idx = 0; idx < instancesCount; idx++ )
       
   226     {
       
   227        RPointerArray<TDesC> dataStores;
       
   228        CleanupClosePushL( dataStores );
       
   229        iPsDataPluginInstances[idx]->GetSupportedDataStoresL(dataStores);
       
   230        
       
   231        const TInt dataStoresCount = dataStores.Count();
       
   232        for ( TInt i(0); i < dataStoresCount; i++)
       
   233        {
       
   234 	       	if ( dataStores[i]->Compare(aUri) == 0)
       
   235 	       	{
       
   236 	       		iPsDataPluginInstances[idx]->GetSupportedDataFieldsL(aDataFields);
       
   237 	       		break;
       
   238 	       	}
       
   239        }
       
   240        CleanupStack::PopAndDestroy( &dataStores ); // Close
       
   241     }
       
   242     
       
   243     PRINT ( _L("End CPsDataPluginInterface::GetAllSupportedDataStoresL") );
       
   244 
       
   245 }
       
   246 // End of file