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