syncmlfw/syncmlnotifier/src/SyncMLPreSyncPluginInterface.cpp
changeset 22 19fb38abab1d
parent 5 3f7d9dbe57c8
child 24 bf47f3b79154
equal deleted inserted replaced
5:3f7d9dbe57c8 22:19fb38abab1d
     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:  Finds the correct plugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "SyncMLPreSyncPluginInterface.h"
       
    21 #include "CPreSyncPlugin.h"
       
    22 
       
    23 _LIT(kDefault,"DEFAULT");
       
    24 
       
    25 // ============================== MEMBER FUNCTIONS ============================
       
    26 
       
    27 // ----------------------------------------------------------------------------
       
    28 // CPreSyncPluginInterface::NewL
       
    29 // Two Phase Construction
       
    30 // ----------------------------------------------------------------------------
       
    31 CPreSyncPluginInterface* CPreSyncPluginInterface::NewL()
       
    32 {    
       
    33     CPreSyncPluginInterface* self = CPreSyncPluginInterface::NewLC();
       
    34     CleanupStack::Pop( self );
       
    35       
       
    36     return self;
       
    37 }
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // CPreSyncPluginInterface::NewLC
       
    41 // Two Phase Construction
       
    42 // ---------------------------------------------------------------------------- 
       
    43 CPreSyncPluginInterface* CPreSyncPluginInterface::NewLC()
       
    44 {   
       
    45     CPreSyncPluginInterface* self = new( ELeave ) CPreSyncPluginInterface();
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     
       
    49     return self;
       
    50 }
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CPreSyncPluginInterface::CPreSyncPluginInterface
       
    54 // Constructor
       
    55 // ----------------------------------------------------------------------------    
       
    56 CPreSyncPluginInterface::CPreSyncPluginInterface()
       
    57 {
       
    58 }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // CPreSyncPluginInterface::ConstructL
       
    62 // 2nd phase constructor
       
    63 // ---------------------------------------------------------------------------- 
       
    64 void CPreSyncPluginInterface::ConstructL()
       
    65 {
       
    66 }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CPreSyncPluginInterface::~CPreSyncPluginInterface
       
    70 // Constructor
       
    71 // ---------------------------------------------------------------------------- 
       
    72 CPreSyncPluginInterface::~CPreSyncPluginInterface( ) 
       
    73 {
       
    74     UnloadPlugIns();
       
    75     //iPcsPluginInstances.ResetAndDestroy();
       
    76 }
       
    77         
       
    78 /**
       
    79 * Lists all implementations which satisfy this ecom interface
       
    80 *
       
    81 * @param aImplInfoArray On return, contains the list of available implementations
       
    82 * 
       
    83 */   
       
    84 inline void CPreSyncPluginInterface::ListAllImplementationsL( RImplInfoPtrArray& aImplInfoArray )
       
    85 {
       
    86     REComSession::ListImplementationsL( KPreSyncPluginInterfaceUid, aImplInfoArray );
       
    87 }
       
    88         
       
    89 // ----------------------------------------------------------------------------
       
    90 // CPreSyncPluginInterface::InstantiateAllPlugInsL
       
    91 // Instantiates all plugins
       
    92 // ----------------------------------------------------------------------------     
       
    93 CPreSyncPlugin* CPreSyncPluginInterface::InstantiateRoamingPluginLC( TSmlProfileId aProfileId )
       
    94 {
       
    95     RImplInfoPtrArray infoArray;
       
    96     TBool bHandleSync = false;
       
    97     CPreSyncPlugin* syncPlugin = NULL;
       
    98     CPreSyncPlugin* defaultSyncPlugin = NULL;
       
    99 
       
   100     // Get list of all implementations
       
   101     TRAPD(error, ListAllImplementationsL( infoArray ));
       
   102     
       
   103     if (error != KErrNone)
       
   104         {
       
   105         return NULL;
       
   106         }
       
   107 
       
   108     // Instantiate plugins for all impUIds by calling 
       
   109     // InstantiatePlugInFromImpUidL
       
   110     for ( TInt i=0; i<infoArray.Count(); i++ )
       
   111     {
       
   112         // Get imp info
       
   113         CImplementationInformation& info( *infoArray[i] );
       
   114 
       
   115 		TUid impUid ( info.ImplementationUid() );	        
       
   116 	    
       
   117 
       
   118         if ( info.DisplayName().Compare(kDefault) == 0 )
       
   119         {			
       
   120 	        //instantiate plugin for impUid
       
   121 	        defaultSyncPlugin = InstantiatePlugInFromImpUidL( impUid );
       
   122 	        defaultSyncPlugin->SetProfile(aProfileId);
       
   123         }
       
   124 		else
       
   125 		{
       
   126 			syncPlugin = InstantiatePlugInFromImpUidL( impUid );
       
   127 			syncPlugin->SetProfile(aProfileId);
       
   128 			if(syncPlugin->IsSupported() == true)
       
   129 			{
       
   130 				bHandleSync = true;
       
   131 				break;
       
   132 			}
       
   133 			else
       
   134 			{
       
   135 				delete syncPlugin;
       
   136 			}
       
   137 		}
       
   138     }
       
   139 
       
   140     infoArray.ResetAndDestroy();
       
   141 	if(bHandleSync == true)
       
   142 	{		
       
   143 		//delete defaultSyncPlugin;
       
   144 	    if(defaultSyncPlugin != NULL)
       
   145 	    {
       
   146 	    CleanupStack::PopAndDestroy(defaultSyncPlugin);
       
   147 	    }
       
   148 		return syncPlugin;
       
   149 	}
       
   150 	else
       
   151 	{
       
   152 		return defaultSyncPlugin;
       
   153 	}    
       
   154  }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CPreSyncPluginInterface::UnloadPlugIns
       
   158 // Unloads plugins
       
   159 // -----------------------------------------------------------------------------
       
   160 void CPreSyncPluginInterface::UnloadPlugIns()
       
   161 {    
       
   162     REComSession::FinalClose();
       
   163 }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CPreSyncPluginInterface::InstantiatePlugInFromImpUidL
       
   167 // Instantiates plugin
       
   168 // ---------------------------------------------------------------------------- 
       
   169 CPreSyncPlugin* CPreSyncPluginInterface::InstantiatePlugInFromImpUidL( const TUid& aImpUid )
       
   170 {    
       
   171    // REComSession
       
   172     CPreSyncPlugin *preSyncPlugin= NULL;
       
   173     preSyncPlugin = CPreSyncPlugin::NewL(aImpUid);
       
   174     CleanupStack::PushL(preSyncPlugin);
       
   175     return preSyncPlugin;
       
   176 /*
       
   177    TAny* implementation = REComSession::CreateImplementationL ( aImpUid, 
       
   178                 _FOFF( CPreSyncPlugin , iDtor_ID_Key) );
       
   179    CPreSyncPlugin* self = REINTERPRET_CAST( CPreSyncPlugin*, implementation );
       
   180    CleanupStack::PushL( self );
       
   181         
       
   182    return self;
       
   183    */
       
   184 }
       
   185     
       
   186