predictivesearch/PcsAlgorithm/Algorithm1/src/CPsDataPluginInterface.cpp
changeset 0 e686773b3f54
child 6 e8e3147d53eb
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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     for ( TInt i=0; i<infoArray.Count(); i++ )
       
   114     {
       
   115         // Get imp info
       
   116         CImplementationInformation& info( *infoArray[i] );
       
   117         
       
   118         // Get imp UID
       
   119         TUid impUid ( info.ImplementationUid() );
       
   120         
       
   121         PRINT ( _L("------------- PS Data Store Details -----------"));
       
   122         PRINT1 ( _L("Name: %S"), &(info.DisplayName()) );
       
   123         PRINT1 ( _L("UID: %X"), impUid.iUid );
       
   124         PRINT ( _L("-----------------------------------------------"));
       
   125         
       
   126         CPsDataPlugin* plugin = NULL;
       
   127         
       
   128         //instantiate plugin for impUid
       
   129         plugin = InstantiatePlugInFromImpUidL( impUid, iObserverForDataStore, iStoreListObserver ) ;
       
   130         if ( plugin )
       
   131         {
       
   132             
       
   133             iPsDataPluginInstances.AppendL( plugin );
       
   134                    
       
   135         }    	        	     
       
   136     }
       
   137     
       
   138     infoArray.ResetAndDestroy();
       
   139     
       
   140     PRINT ( _L("End CPsDataPluginInterface::InstantiateAllPlugInsL") );
       
   141 }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CPsDataPluginInterface::UnloadPlugIns
       
   145 // Unloads plugins
       
   146 // -----------------------------------------------------------------------------
       
   147 void CPsDataPluginInterface::UnloadPlugIns()
       
   148 {
       
   149     PRINT ( _L("Enter CPsDataPluginInterface::UnloadPlugIns") );
       
   150     
       
   151     REComSession::FinalClose();
       
   152     
       
   153     PRINT ( _L("End CPsDataPluginInterface::UnloadPlugIns") );
       
   154 }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // CPsDataPluginInterface::InstantiatePlugInFromImpUidL
       
   158 // Instantiates plugin
       
   159 // ---------------------------------------------------------------------------- 
       
   160 CPsDataPlugin* CPsDataPluginInterface::InstantiatePlugInFromImpUidL( const TUid& aImpUid, 
       
   161 																	 MDataStoreObserver* aObserverForDataStore,
       
   162 																	 MStoreListObserver* aStoreListObserver )
       
   163 {
       
   164     PRINT ( _L("Enter CPsDataPluginInterface::InstantiatePlugInFromImpUidL") );
       
   165     
       
   166     CPsDataPlugin* plugin = CPsDataPlugin::NewL(aImpUid, aObserverForDataStore, aStoreListObserver);
       
   167     
       
   168     PRINT ( _L("End CPsDataPluginInterface::InstantiatePlugInFromImpUidL") );
       
   169     
       
   170     return plugin;
       
   171 }
       
   172     
       
   173 
       
   174 // ----------------------------------------------------------------------------
       
   175 // CPsDataPluginInterface::RequestForDataL
       
   176 // Requests for data from the data store
       
   177 // ---------------------------------------------------------------------------- 
       
   178 void  CPsDataPluginInterface::RequestForDataL(TDesC& aDataStore)
       
   179 {
       
   180 
       
   181     PRINT ( _L("Enter CPsDataPluginInterface::RequestForDataL") );
       
   182    
       
   183     for ( TInt idx = 0; idx < iPsDataPluginInstances.Count(); idx++ )
       
   184     {
       
   185         if(iPsDataPluginInstances[idx]->IsDataStoresSupportedL(aDataStore))
       
   186         {
       
   187        		iPsDataPluginInstances[idx]->RequestForDataL(aDataStore);
       
   188     		break; 
       
   189         }
       
   190     }
       
   191     
       
   192     PRINT ( _L("End CPsDataPluginInterface::RequestForDataL") );
       
   193 
       
   194 }
       
   195 
       
   196 // ----------------------------------------------------------------------------
       
   197 // CPsDataPluginInterface::GetAllSupportedDataStoresL
       
   198 // Requests all the supported data stores from data adapters
       
   199 // ---------------------------------------------------------------------------- 
       
   200 void  CPsDataPluginInterface::GetAllSupportedDataStoresL(RPointerArray<TDesC>& aDataStores)
       
   201 {
       
   202 
       
   203     PRINT ( _L("Enter CPsDataPluginInterface::GetAllSupportedDataStoresL") );
       
   204    
       
   205     for ( TInt idx = 0; idx < iPsDataPluginInstances.Count(); idx++ )
       
   206     {       
       
   207        iPsDataPluginInstances[idx]->GetSupportedDataStoresL(aDataStores);
       
   208     }
       
   209     
       
   210     PRINT ( _L("End CPsDataPluginInterface::GetAllSupportedDataStoresL") );
       
   211 
       
   212 }
       
   213 
       
   214 // ----------------------------------------------------------------------------
       
   215 // CPsDataPluginInterface::GetAllSupportedDataFieldsL
       
   216 // Requests all the supported data fields from from data adapters
       
   217 // ---------------------------------------------------------------------------- 
       
   218 void  CPsDataPluginInterface::GetSupportedDataFieldsL(TDesC& aUri, RArray<TInt>& aDataFields)
       
   219 {
       
   220 
       
   221     PRINT ( _L("Enter CPsDataPluginInterface::GetAllSupportedDataStoresL") );
       
   222    
       
   223     for ( TInt idx = 0; idx < iPsDataPluginInstances.Count(); idx++ )
       
   224     {   
       
   225        RPointerArray<TDesC> aDataStores;    
       
   226        iPsDataPluginInstances[idx]->GetSupportedDataStoresL(aDataStores);
       
   227        
       
   228        for( TInt i(0); i<aDataStores.Count(); i++)
       
   229        {       	
       
   230 	       	if( aDataStores[i]->Compare(aUri) == 0)
       
   231 	       	{
       
   232 	       		iPsDataPluginInstances[idx]->GetSupportedDataFieldsL(aDataFields);
       
   233 	       		break;
       
   234 	       	}    	
       
   235        }
       
   236        aDataStores.Reset();
       
   237     }
       
   238     
       
   239     PRINT ( _L("End CPsDataPluginInterface::GetAllSupportedDataStoresL") );
       
   240 
       
   241 }
       
   242 // End of file