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