phonebookengines/contactsmodel/cntplsql/src/cplplugins.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19  @released
       
    20 */
       
    21 
       
    22 #include "plplugins.h"
       
    23 #include "cntviewprivate.h"
       
    24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    25 #include <cntphonenumparser.h>
       
    26 #include "cntdb_internal.h"
       
    27 #include "cntsyncecom.h"
       
    28 #endif
       
    29 
       
    30 
       
    31 // The name of the test phone book sync plugin.  This plugin will be used in the
       
    32 // first instance (i.e. if it exists then use it rather than any other plugin).
       
    33 _LIT(KTestPluginName,"Test phone book synchronizer Implementation");
       
    34 
       
    35 
       
    36 CContactPlugin::CContactPlugin()
       
    37 	{
       
    38 	}
       
    39 
       
    40 
       
    41 CContactPlugin::~CContactPlugin()
       
    42 	{
       
    43 	iDll.Close();
       
    44 	}
       
    45 
       
    46 
       
    47 CContactPhoneParser* CContactPhoneParser::NewL()
       
    48 	{
       
    49 	CContactPhoneParser* self=new(ELeave) CContactPhoneParser;
       
    50 	CleanupStack::PushL(self);
       
    51 	self->LoadEComPluginL();
       
    52 	CleanupStack::Pop(self); 
       
    53 	return self;
       
    54 	}
       
    55 
       
    56 
       
    57 CContactPhoneParser::~CContactPhoneParser()
       
    58 	{
       
    59 	delete iParser;
       
    60 	}
       
    61 
       
    62 
       
    63 void CContactPhoneParser::SetPluginL(TLibraryFunction aGateFunction)
       
    64 	{
       
    65 	iParser=REINTERPRET_CAST(CContactPhoneNumberParser*,(*aGateFunction)());
       
    66 	User::LeaveIfNull(iParser);
       
    67 	}
       
    68 
       
    69 
       
    70 void CContactPhoneParser::LoadEComPluginL()
       
    71 	{
       
    72 #ifdef __PROFILE__
       
    73 	RDebug::Print(_L("[CNTMODEL] Entering CContactPhoneParser::LoadEComPluginL\n"));
       
    74 	TTime now;
       
    75 	now.UniversalTime();
       
    76 #endif
       
    77 	
       
    78 	RImplInfoPtrArray	implInfoArray;
       
    79 	CleanupResetAndDestroyPushL(implInfoArray);
       
    80 
       
    81 	// Use default resolver parameters.
       
    82 	TEComResolverParams resolverParams;
       
    83 	
       
    84 	// List implementations, searching only in ROM for the plugin.
       
    85 	REComSession::ListImplementationsL(KUidEcomCntPhoneNumberParserInterface,
       
    86 		resolverParams,	KRomOnlyResolverUid, implInfoArray);
       
    87 
       
    88 	const TInt count = implInfoArray.Count();
       
    89 	__ASSERT_ALWAYS( count > 0, User::Leave(KErrNotFound));
       
    90 
       
    91 	// Create the first implementation found for
       
    92 	// KUidEcomCntPhoneNumberParserInterface.
       
    93 	const TUid firstImplementationFound = implInfoArray[0]->ImplementationUid();
       
    94 	iParser = CContactEcomPhoneNumberParser::NewL(firstImplementationFound);
       
    95 	CleanupStack::PopAndDestroy(&implInfoArray);
       
    96 
       
    97 #ifdef __PROFILE__
       
    98 	TTime now2;
       
    99 	now2.UniversalTime();
       
   100 	RDebug::Print(_L("[CNTMODEL] Spend %d microseconds in CContactPhoneParser::LoadEComPluginL\n"), now2.MicroSecondsFrom(now).Int64());
       
   101 #endif
       
   102 	}
       
   103 
       
   104 
       
   105 EXPORT_C CContactSynchroniser::~CContactSynchroniser()
       
   106 	{
       
   107 	REComSession::DestroyedImplementation(iDtor_ID_Key);
       
   108 	}
       
   109 
       
   110 
       
   111 CContactSynchroniser* CContactSynchroniser::NewL()
       
   112 	{
       
   113 #ifdef __PROFILE__
       
   114 	RDebug::Print(_L("[CNTMODEL] Entering CContactSynchroniser::NewL\n"));
       
   115 	TTime now;
       
   116 	now.UniversalTime();
       
   117 #endif
       
   118 
       
   119 	RImplInfoPtrArray implInfoArray;
       
   120 	CleanupResetAndDestroyPushL(implInfoArray);
       
   121 	REComSession::ListImplementationsL(KUidEcomCntPhBkSyncInterface, implInfoArray);
       
   122 	// Load the implementation found for KUidEcomCntPhBkSyncInterface, prefer the test plugin
       
   123 	const TInt count = implInfoArray.Count(); 
       
   124 	__ASSERT_ALWAYS(count > 0, User::Leave(KErrNotSupported));
       
   125 	
       
   126 	TInt pluginToBeUsed = 0;
       
   127 	CImplementationInformation *info;
       
   128 	
       
   129 	// Scan the list of plugins for the test plugin.
       
   130 	for (TInt plugIn = 0 ; plugIn < count ; ++plugIn)
       
   131 	{
       
   132 		info = implInfoArray[plugIn];
       
   133 		if(info->DisplayName() == KTestPluginName)
       
   134 		{
       
   135 			// We have found the test plugin so use it rather than any other
       
   136 			// plugin.
       
   137 			pluginToBeUsed = plugIn;
       
   138 			break;
       
   139 		}
       
   140 	}
       
   141 #ifdef __VERBOSE_DEBUG__
       
   142 	RDebug::Print(_L("[CNTMODEL] CntServer has loaded syncplugin: %S\n"), &info->DisplayName());
       
   143 #endif
       
   144 
       
   145 	// Create the implementation found for KUidEcomCntPhBkSyncInterface.
       
   146 	const TUid theImplementationID = implInfoArray[pluginToBeUsed]->ImplementationUid();
       
   147 	TAny* ptr = REComSession::CreateImplementationL(theImplementationID,
       
   148 		_FOFF(CContactSynchroniser,iDtor_ID_Key));
       
   149 
       
   150 	CleanupStack::PopAndDestroy(&implInfoArray);
       
   151 
       
   152 #ifdef __PROFILE__
       
   153 	TTime now2;
       
   154 	now2.UniversalTime();
       
   155 	RDebug::Print(_L("[CNTMODEL] Spend %d microseconds in CContactSynchroniser::NewL()\n"), now2.MicroSecondsFrom(now).Int64());
       
   156 #endif
       
   157 
       
   158 	return reinterpret_cast<CContactSynchroniser*>(ptr);
       
   159 	}
       
   160 
       
   161 
       
   162 /**
       
   163 Reserved (private) virtual function to allow further extension of the
       
   164 MContactSynchroniser interface without requiring changes to all derived classes.
       
   165 This can be used to return a pointer to an additional extension class.
       
   166 */
       
   167 EXPORT_C void MContactSynchroniser::MContactSynchroniser_Reserved_1()
       
   168 	{
       
   169 	}