phonebookengines_old/contactsmodel/cntplsql/src/clplproxyfactory.cpp
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 2007-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   
       
    23 #include "clplproxyfactory.h"
       
    24 #include "rcntmodel.h"
       
    25 #include <ecom/ecom.h>
       
    26 #include <cntsync.h>
       
    27 
       
    28 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    29 #include "cntsyncecom.h"
       
    30 #endif
       
    31 
       
    32 #include "cntviewprivate.h"
       
    33 
       
    34 
       
    35 // The name of the test phone book sync plugin.  This plugin will be used in the
       
    36 // first instance (i.e. if it exists then use it rather than any other plugin).
       
    37 _LIT(KTestPluginName,"Test phone book synchronizer Implementation");
       
    38 
       
    39 
       
    40 /**
       
    41 CContactSynchroniser object factory method.
       
    42 
       
    43 This class is copied from the Persistence Layer.  It should be refactored into
       
    44 a shared library if possible.
       
    45 
       
    46 @return CContactSynchroniser object.
       
    47 */
       
    48 CContactSynchroniser* CContactSynchroniser::NewL()
       
    49 	{
       
    50 	RImplInfoPtrArray implInfoArray;
       
    51 	CleanupResetAndDestroyPushL(implInfoArray);
       
    52 	REComSession::ListImplementationsL(KUidEcomCntPhBkSyncInterface, implInfoArray);
       
    53 	
       
    54 	const TInt count = implInfoArray.Count(); 
       
    55 	__ASSERT_ALWAYS(count > 0, User::Leave(KErrNotSupported));
       
    56 
       
    57 	TInt pluginToBeUsed = 0;
       
    58 	CImplementationInformation *info;
       
    59 
       
    60 	// Scan the list of plugins for the test plugin.
       
    61 	for (TInt plugIn = 0 ; plugIn < count ; ++plugIn)
       
    62 	{
       
    63 		info = implInfoArray[plugIn];
       
    64 		if(info->DisplayName() == KTestPluginName)
       
    65 		{
       
    66 			// We have found the test plugin so use it rather than any other
       
    67 			// plugin.
       
    68 			pluginToBeUsed = plugIn;
       
    69 			break;
       
    70 		}
       
    71 	}
       
    72 
       
    73 	// Create the implementation found for KUidEcomCntPhBkSyncInterface.
       
    74 	const TUid theImplementationID = implInfoArray[pluginToBeUsed]->ImplementationUid();
       
    75 	
       
    76 	TAny* ptr(NULL);
       
    77 	ptr = REComSession::CreateImplementationL(theImplementationID, _FOFF(CContactSynchroniser,iDtor_ID_Key));
       
    78 
       
    79 #ifdef __VERBOSE_DEBUG__
       
    80 	RDebug::Print(_L("[CNTMODEL] CContactSynchroniser::NewL(): Create sync plugin: %S\n"), &info->DisplayName());
       
    81 #endif
       
    82 
       
    83 	CleanupStack::PopAndDestroy(&implInfoArray);
       
    84 
       
    85 	return reinterpret_cast<CContactSynchroniser*>(ptr);
       
    86 	}
       
    87 
       
    88 
       
    89 /**
       
    90 CProxyFactory object factory method.
       
    91 
       
    92 @param aDb Contacts database used by the proxies this factory provides.
       
    93 
       
    94 @return CProxyFactory object.
       
    95 */
       
    96 CProxyFactory* CProxyFactory::NewL(const CContactDatabase& aDb)
       
    97 	{
       
    98 	CProxyFactory*	self = new (ELeave) CProxyFactory(aDb);
       
    99 	CleanupStack::PushL(self);
       
   100 	self->ConstructL();
       
   101 	CleanupStack::Pop(self);
       
   102 	return self;
       
   103 	}
       
   104 
       
   105 	
       
   106 /**
       
   107 CProxyFactory second phase constructor.
       
   108 */
       
   109 void CProxyFactory::ConstructL()
       
   110 	{
       
   111 	}
       
   112 
       
   113 
       
   114 /**
       
   115 CProxyFactory first phase constructor.
       
   116 
       
   117 @param aDb Contacts database used to access Contacts Model session handle.
       
   118 */
       
   119 CProxyFactory::CProxyFactory(const CContactDatabase& aDb)
       
   120 	:
       
   121 	iDb(aDb)
       
   122 	{
       
   123 	}
       
   124 
       
   125 
       
   126 /**
       
   127 CProxyFactory destructor.
       
   128 */
       
   129 CProxyFactory::~CProxyFactory()
       
   130 	{
       
   131 	if (iSynchroniser)
       
   132 		{
       
   133 		iSynchroniser->Release();  //calls delete this
       
   134 		iSynchroniser = NULL;
       
   135 		}	
       
   136 	delete iManager;
       
   137 	delete iCollection;
       
   138 	}
       
   139 
       
   140 
       
   141 /**
       
   142 Get the MLplViewItemManager proxy interface.  If the
       
   143 CViewIteratorProxyManager object does not yet exist then 
       
   144 create it.
       
   145 
       
   146 @return MLplViewIteratorManager proxy interface instance.
       
   147 */
       
   148 MLplViewIteratorManager& CProxyFactory::GetViewIteratorManagerL()
       
   149 	{
       
   150 	if(iManager == NULL)
       
   151 		{
       
   152 		iManager = CViewIteratorProxyManager::NewL(iDb);
       
   153 		}
       
   154 	return *iManager;
       
   155 	}
       
   156 
       
   157 
       
   158 /**
       
   159 Get the MContactSynchroniser interface.  If the CContactSynchroniser object does
       
   160 not yet exist then create it (lazy initialisation).
       
   161 
       
   162 @return MContactSynchroniser interface instance.
       
   163 */
       
   164 MContactSynchroniser& CProxyFactory::GetContactSynchroniserL(TUint)
       
   165 	{
       
   166 	if(iSynchroniser == NULL)
       
   167 		{
       
   168 		iSynchroniser = CContactSynchroniser::NewL();
       
   169 		}
       
   170 	return *iSynchroniser;
       
   171 	}
       
   172 
       
   173 
       
   174 /**
       
   175 Get the MLplCollection proxy interface.  If the CCollectionProxy proxy object
       
   176 does not yet exist then create it (lazy initialisation).
       
   177 
       
   178 @return MLplCollection proxy interface instance.
       
   179 */
       
   180 MLplCollection& CProxyFactory::GetCollectorL()
       
   181 	{
       
   182 	if(iCollection == NULL)
       
   183 		{
       
   184 		iCollection = new (ELeave) CCollectionProxy(iDb);
       
   185 		}
       
   186 	return *iCollection;
       
   187 	}
       
   188 
       
   189 
       
   190 /**
       
   191 CViewIteratorProxyManager object factory method.
       
   192 
       
   193 @param aDb Contacts database used to access Contacts Model session handle.
       
   194 
       
   195 @return CViewIteratorProxyManager object.
       
   196 */
       
   197 CViewIteratorProxyManager* CViewIteratorProxyManager::NewL(const CContactDatabase& aDb)
       
   198 	{
       
   199 	CViewIteratorProxyManager* self = new (ELeave) CViewIteratorProxyManager(aDb);
       
   200 	CleanupStack::PushL(self);
       
   201 	self->ConstructL();
       
   202 	CleanupStack::Pop(self);
       
   203 	return self;
       
   204 	}
       
   205 
       
   206 
       
   207 /**
       
   208 CViewIteratorProxyManager second phase constructor.
       
   209 */
       
   210 void CViewIteratorProxyManager::ConstructL()
       
   211 	{
       
   212 	}
       
   213 
       
   214 
       
   215 /**
       
   216 CViewIteratorProxyManager first phase constructor.
       
   217 
       
   218 @param aDb Contacts database used to access Contacts Model session handle.
       
   219 */
       
   220 CViewIteratorProxyManager::CViewIteratorProxyManager(const CContactDatabase& aDb)
       
   221 	:
       
   222 	iDb(aDb)
       
   223 	{
       
   224 	}
       
   225 
       
   226 
       
   227 /**
       
   228 CViewIteratorProxyManager destructor.
       
   229 */
       
   230 CViewIteratorProxyManager::~CViewIteratorProxyManager()
       
   231 	{
       
   232 	}
       
   233 
       
   234 
       
   235 /**
       
   236 Proxy implementation of pure virtual methods in MLplViewItemManager.
       
   237 
       
   238 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   239 Contacts Model session handle to access the Persistence Layer via the server.
       
   240 */
       
   241 CViewContact* CViewIteratorProxyManager::ItemAtL(TContactItemId aContactId, TInt aViewId)
       
   242 	{
       
   243 	return iDb.iCntSvr->ItemAtL(aContactId, aViewId);
       
   244 	}
       
   245 
       
   246 	
       
   247 /**
       
   248 Proxy implementation of pure virtual methods in MLplViewItemManager.
       
   249 
       
   250 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   251 Contacts Model session handle to access the Persistence Layer via the server.
       
   252 */
       
   253 TInt CViewIteratorProxyManager::OpenViewL(const CContactTextDef& aTextDef, TContactViewPreferences aViewPrefs)
       
   254 	{
       
   255 	return iDb.iCntSvr->OpenViewL(aTextDef, aViewPrefs);
       
   256 	}
       
   257 	
       
   258 
       
   259 /**
       
   260 Proxy implementation of pure virtual methods in MLplViewItemManager.
       
   261 
       
   262 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   263 Contacts Model session handle to access the Persistence Layer via the server.
       
   264 */
       
   265 void CViewIteratorProxyManager::CloseView(TInt aViewId)
       
   266 	{
       
   267 	iDb.iCntSvr->CloseView(aViewId);
       
   268 	}
       
   269 
       
   270 	
       
   271 /**
       
   272 Proxy implementation of pure virtual methods in MLplViewItemManager.
       
   273 
       
   274 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   275 Contacts Model session handle to access the Persistence Layer via the server.
       
   276 */
       
   277 void CViewIteratorProxyManager::ChangeSortOrderL(TInt aViewId, const CContactTextDef& aTextDef)
       
   278 	{
       
   279 	iDb.iCntSvr->ChangeSortOrderL(aViewId, aTextDef);
       
   280 	}
       
   281 
       
   282 	
       
   283 /**
       
   284 Proxy implementation of pure virtual methods in MLplViewItemManager.
       
   285 
       
   286 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   287 Contacts Model session handle to access the Persistence Layer via the server.
       
   288 */
       
   289 void CViewIteratorProxyManager::BeginIterateL(TInt aViewId)
       
   290 	{
       
   291 	iDb.iCntSvr->BeginIterateL(aViewId);
       
   292 	}
       
   293 	
       
   294 	
       
   295 /**
       
   296 Proxy implementation of pure virtual methods in MLplViewItemManager.
       
   297 
       
   298 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   299 Contacts Model session handle to access the Persistence Layer via the server.
       
   300 */
       
   301 void CViewIteratorProxyManager::EndIterateL(TInt aViewId)
       
   302 	{
       
   303 	iDb.iCntSvr->EndIterateL(aViewId);
       
   304 	}
       
   305 
       
   306 	
       
   307 /**
       
   308 Proxy implementation of pure virtual methods in MLplViewItemManager.
       
   309 
       
   310 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   311 Contacts Model session handle to access the Persistence Layer via the server.
       
   312 */
       
   313 CViewContact* CViewIteratorProxyManager::NextItemL(TInt aViewId, TContactViewPreferences aViewPrefs)
       
   314 	{
       
   315 	return iDb.iCntSvr->NextItemL(aViewId, aViewPrefs);
       
   316 	}
       
   317 
       
   318 
       
   319 /**
       
   320 Proxy implementation of pure virtual methods in MLplViewItemManager.
       
   321 
       
   322 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   323 Contacts Model session handle to access the Persistence Layer via the server.
       
   324 */
       
   325 TUid CViewIteratorProxyManager::ReadContactTextDefL(TContactItemId aContactId, TDes &aResult,const CContactTextDef& aTextDef)
       
   326     {
       
   327     iDb.iCntSvr->ReadContactTextDefL(aContactId, aResult, aTextDef);
       
   328     return TUid(KNullUid); //type uid is not used at client side.   
       
   329     }
       
   330 
       
   331 
       
   332 /**
       
   333 Proxy implementation of pure virtual methods in MLplViewItemManager.
       
   334 
       
   335 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   336 Contacts Model session handle to access the Persistence Layer via the server.
       
   337 */
       
   338 void CViewIteratorProxyManager::TextFieldL(TInt aCntItemId,TFieldType aFieldType, TDes& aText)
       
   339     {
       
   340     iDb.iCntSvr->TextFieldL(aCntItemId, aFieldType, aText);
       
   341     }
       
   342 
       
   343 
       
   344 /**
       
   345 CCollectionProxy first phase constructor.
       
   346 
       
   347 @param aDb Contacts database used to access Contacts Model session handle.
       
   348 */
       
   349 CCollectionProxy::CCollectionProxy(const CContactDatabase& aDb)
       
   350 	:
       
   351 	iDb(aDb)
       
   352 	{
       
   353 	}
       
   354 
       
   355 
       
   356 /**
       
   357 Proxy implementation of pure virtual method in MLplCollection.
       
   358 
       
   359 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   360 Contacts Model session handle to access the Persistence Layer via the server.
       
   361 */
       
   362 CContactIdArray* CCollectionProxy::CollectionL(TLplViewType aViewType,TTime aTime,const TDesC& aGuid)
       
   363 	{
       
   364 	return iDb.iCntSvr->CollectionL(aViewType,aTime,aGuid);
       
   365 	}
       
   366 
       
   367 /**
       
   368 Proxy implementation of pure virtual method in MLplCollection.
       
   369 
       
   370 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   371 Contacts Model session handle to access the Persistence Layer via the server.
       
   372 */
       
   373 TBool CCollectionProxy::SeekContactL(TContactItemId aReqId,TContactItemId& aId,TUid& aContactType, TBool& aDeleted)
       
   374 	{
       
   375 	return iDb.iCntSvr->SeekContactL(aReqId, aId, aContactType, aDeleted);		
       
   376 	}
       
   377 	
       
   378 /**
       
   379 Proxy implementation of pure virtual method in MLplCollection.
       
   380 
       
   381 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   382 Contacts Model session handle to access the Persistence Layer via the server.
       
   383 */
       
   384 TInt CCollectionProxy::ContactCountL()
       
   385 	{
       
   386 	return iDb.iCntSvr->ContactCountL();
       
   387 	}
       
   388 
       
   389 
       
   390 /**
       
   391 Dummy method - implemented in the Persistence Layer.
       
   392 */
       
   393 TBool CCollectionProxy::ContactMatchesHintFieldL (TInt /*aBitWiseFilter*/, TContactItemId /*aContactId*/)
       
   394 	{
       
   395 	return EFalse;		
       
   396 	}
       
   397 
       
   398 
       
   399 /**
       
   400 Dummy method - implemented in the Persistence Layer.
       
   401 */
       
   402 CContactIdArray* CCollectionProxy::MatchPhoneNumberL(const TDesC& /*aNumber*/, const TInt /*aMatchLengthFromRight*/)
       
   403 	{
       
   404 	return NULL;	
       
   405 	}
       
   406 
       
   407 
       
   408 /**
       
   409 Proxy implementation of pure virtual method in MLplCollection.
       
   410 
       
   411 The proxy does not access the Persistence Layer directly.  Instead it uses the
       
   412 Contacts Model session handle to access the Persistence Layer via the server.
       
   413 
       
   414 This method could be a dummy implementation since only CContactDatabase calls
       
   415 the client session FindL() method.
       
   416 */
       
   417 CContactIdArray* CCollectionProxy::FindL(const TDesC& aText, const CContactItemFieldDef* aFieldDef, TUint /*aSessionId*/)
       
   418 	{
       
   419 	return iDb.iCntSvr->FindL(aText,aFieldDef);
       
   420 	}
       
   421 
       
   422 	
       
   423 /**
       
   424 Dummy method - implemented in the Persistence Layer.
       
   425 */
       
   426 CContactIdArray* CCollectionProxy::FilterDatabaseL(CCntFilter& /*aFilter*/)
       
   427 	{
       
   428 	return NULL;
       
   429 	}
       
   430 
       
   431 
       
   432 /**
       
   433 Dummy method - implemented in the Persistence Layer.
       
   434 */
       
   435 void CCollectionProxy::Reset()
       
   436 	{
       
   437 	}
       
   438 
       
   439 
       
   440 /**
       
   441 Dummy method - implemented in the Persistence Layer.
       
   442 */
       
   443 void CCollectionProxy::FindAsyncInitL(const TDesC& /*aText*/,CContactItemFieldDef* /*aFieldDef*/)
       
   444 	{
       
   445 	}
       
   446 
       
   447 
       
   448 /**
       
   449 Dummy method - implemented in the Persistence Layer.
       
   450 */
       
   451 void CCollectionProxy::FindAsyncTextDefInitL(const CDesCArray& /*aWords*/,CContactTextDef* /*aTextDef*/)
       
   452 	{
       
   453 	}
       
   454 
       
   455 
       
   456 /**
       
   457 Dummy method - implemented in the Persistence Layer.
       
   458 */
       
   459 CContactIdArray* CCollectionProxy::FindAsyncL(TBool& /*aMoreToGo*/, TUint /*aSessionId*/)
       
   460 	{
       
   461 	return NULL;
       
   462 	}
       
   463 
       
   464 
       
   465 /**
       
   466 Dummy method - implemented in the Persistence Layer.
       
   467 */
       
   468 TBool CCollectionProxy::UsesIdentityFieldsOnly(TInt /*aFindFlags*/)
       
   469 	{
       
   470 	return EFalse;		
       
   471 	}
       
   472 
       
   473 
       
   474 /**
       
   475 Dummy method - implemented in the Persistence Layer.
       
   476 */
       
   477 void CCollectionProxy::ConstructBitwiseFlagsFromTextDef(TInt& /*aFindFlags*/, TInt& /*aIdentityColumnsCount*/, const CContactTextDef* /*aTextDef*/)	
       
   478 	{
       
   479 	}