uiservicetab/vimpstengine/src/cvimpstengine.cpp
branchRCL_3
changeset 23 9a48e301e94b
equal deleted inserted replaced
22:3104fc151679 23:9a48e301e94b
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Class that capsulates single service data members
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDES
       
    20 #include "cvimpstengine.h"
       
    21 
       
    22 #include "cvimpstengineservicetablefetcher.h"
       
    23 #include <e32std.h>
       
    24 #include <barsc.h>
       
    25 #include <gulutil.h>
       
    26 #include <coemain.h>
       
    27 #include <e32base.h>
       
    28 
       
    29 #include "tvimpstconsts.h"
       
    30 #include "cvimpstenginevoipsubservice.h"
       
    31 #include "cvimpstengineimsubservice.h"
       
    32 #include "cvimpstenginepresencesubservice.h"
       
    33 #include "cvimpstenginecchhandler.h"
       
    34 //storage
       
    35 #include "cvimpststoragemanagerfactory.h"
       
    36 #include "cvimpstenginesessioncntxtobserver.h"
       
    37 #include "mvimpststorageserviceview.h"
       
    38 #include "mvimpststoragevpbkstorehandler.h"
       
    39 
       
    40 #include "tvimpstenums.h" 
       
    41 
       
    42 #include "mvimpstengineextentionfeatures.h"
       
    43 #include "mvimpstengineservicestateeventobserver.h"
       
    44 
       
    45 //extention features
       
    46 #include "cvimpstenginesearchmgrextention.h"
       
    47 #include "cvimpstenginecontactmgmtextention.h"
       
    48 #include "cvimpstblockedlistmanager.h"
       
    49 
       
    50 #include "mvimpststoragecontactlist.h"
       
    51 #include <cvimpstsettingsstore.h>
       
    52 
       
    53 #include "uiservicetabtracer.h"
       
    54 
       
    55 // Constants
       
    56 _LIT( KListNameAllBuddy ,"buddylist" );
       
    57 
       
    58 // ================= MEMBER FUNCTIONS =======================
       
    59 // ---------------------------------------------------------
       
    60 // CVIMPSTEngine::NewL
       
    61 // 
       
    62 // ---------------------------------------------------------
       
    63 CVIMPSTEngine* CVIMPSTEngine::NewL(
       
    64 								TUint32 aServiceId,
       
    65 								CVIMPSTEngineServiceTableFetcher& aTableFetcher )
       
    66     {
       
    67 	TRACER_AUTO; 
       
    68 	TRACE("ServiceId: %d", aServiceId);
       
    69     
       
    70     
       
    71     CVIMPSTEngine* self = CVIMPSTEngine::NewLC(	aServiceId,
       
    72     											aTableFetcher );
       
    73     CleanupStack::Pop( self );
       
    74  
       
    75     return self;
       
    76     }
       
    77 
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CVIMPSTEngine::NewLC
       
    81 // 
       
    82 // ---------------------------------------------------------
       
    83     
       
    84 CVIMPSTEngine* CVIMPSTEngine::NewLC(
       
    85 								TUint32 aServiceId,
       
    86 								CVIMPSTEngineServiceTableFetcher& aTableFetcher )
       
    87 	{  
       
    88 	TRACER_AUTO;
       
    89     TRACE( "ServiceId: %d", aServiceId );
       
    90 	
       
    91     CVIMPSTEngine* self = new (ELeave) CVIMPSTEngine(
       
    92     												aServiceId, 
       
    93     												aTableFetcher );
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL( aServiceId );    
       
    96   
       
    97     return self;
       
    98 	}
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CVIMPSTEngine::~CVIMPSTEngine
       
   102 // 
       
   103 // ---------------------------------------------------------
       
   104 
       
   105 CVIMPSTEngine::~CVIMPSTEngine()
       
   106 	{
       
   107 	TRACER_AUTO;
       
   108 	
       
   109 	iObserverArray.Reset();
       
   110     iObserverArray.Close();
       
   111     
       
   112 	iSubService.ResetAndDestroy();	
       
   113 	iSubService.Close();
       
   114 	// Delete this after sub services, those might use it in destructor!
       
   115 	delete iSessionCntxtObserver;
       
   116     delete iServiceName;
       
   117 	
       
   118 	iExtentionFeatures.ResetAndDestroy();
       
   119 	iExtentionFeatures.Close();
       
   120 	
       
   121 	delete iCchHandler;
       
   122     iCchHandler = NULL;       
       
   123 
       
   124  
       
   125  	}
       
   126 
       
   127 
       
   128 // ---------------------------------------------------------
       
   129 // CVIMPSTEngine::ConstructL
       
   130 // 
       
   131 // ---------------------------------------------------------
       
   132 
       
   133 void CVIMPSTEngine::ConstructL( TUint32 aServiceId )
       
   134 	{
       
   135 	TRACER_AUTO;
       
   136     TRACE( "ServiceId: %d", aServiceId );
       
   137 
       
   138 	iServiceName = HBufC::NewL( KVIMPSTUISPSMaxPropertyLength );
       
   139 	
       
   140 	// construct the service state by passing the array of subservices.
       
   141 	iCchHandler = CVIMPSTEngineCchHandler::NewL(iServiceId,*this);
       
   142 	
       
   143 	//construct eventobserver only if there are any adaptations.
       
   144 	TInt ximpAdapterUid = iTableFetcher.XimpAdapterUidL(aServiceId);
       
   145 	
       
   146 	
       
   147 	TBool requireXimp = EFalse;		
       
   148 	TBool presenceSupported = IsSubServiceSupportedInternal(TVIMPSTEnums::EPresence);
       
   149 	TBool imSupported = IsSubServiceSupportedInternal(TVIMPSTEnums::EIM);
       
   150 	
       
   151 	requireXimp |= presenceSupported;
       
   152     requireXimp |= imSupported;
       
   153 
       
   154     TPtr serviceIdPtr(iServiceName->Des());
       
   155     iTableFetcher.GetServiceNameL(aServiceId, serviceIdPtr);
       
   156 
       
   157 	//if either of Presence/IM Subservice supported then we need
       
   158 	//to bind to XIMP context. 
       
   159 	if ( KErrNotFound != ximpAdapterUid && requireXimp )
       
   160 	    {
       
   161         TRAPD( err, (iSessionCntxtObserver = CVIMPSTEngineSessionCntxtObserver::NewL(aServiceId)));
       
   162         TRACE( "1st Creating session context observer: %d", err );	
       
   163         if (KErrNotFound == err)
       
   164             {
       
   165 						TRACE( "Ximp impl not found. Calling Logout" );            	
       
   166             iUnInstall = ETrue;
       
   167             LogoutL();
       
   168             TRACE( "Logout Called on account of uninstall" );
       
   169             return;
       
   170             }
       
   171 	    }
       
   172 	
       
   173 	// iterate the service array
       
   174     for ( TInt index = TVIMPSTEnums::EVoip; index < TVIMPSTEnums::ELast ; index++ )        
       
   175         {
       
   176 	    //create the subservice
       
   177 	    switch(index)
       
   178 	        {
       
   179 	        case TVIMPSTEnums::EVoip:
       
   180 	            {
       
   181 	            if(IsSubServiceSupportedInternal(TVIMPSTEnums::EVoip))
       
   182 	                {
       
   183 	                CVIMPSTEngineVOIPSubService* item = 
       
   184 	                CVIMPSTEngineVOIPSubService::NewL(aServiceId, *iCchHandler,
       
   185 	                        iTableFetcher, *this);
       
   186 	                iSubService.Append(item);
       
   187 	                }
       
   188 	            break;				
       
   189 	            }
       
   190 	        case TVIMPSTEnums::EPresence:
       
   191 	            {
       
   192 	            if(presenceSupported)
       
   193 	                {
       
   194 	                if (iSessionCntxtObserver)
       
   195 	                    {
       
   196 	                    CVIMPSTEnginePresenceSubService* item = CVIMPSTEnginePresenceSubService::NewL(
       
   197 	                            aServiceId,*iCchHandler,iTableFetcher,
       
   198 	                            *iSessionCntxtObserver,*this
       
   199 	                    );
       
   200 	                    iSubService.Append(item);
       
   201 	                    iSessionCntxtObserver->RegisterObserver(item);					
       
   202 	                    }
       
   203 	                }
       
   204 	            break;
       
   205 	            }
       
   206 	        case TVIMPSTEnums::EIM:
       
   207 	            {
       
   208 	            if(imSupported)
       
   209 	                {
       
   210 	                CVIMPSTEngineIMSubService* item = 
       
   211 	                CVIMPSTEngineIMSubService::NewL(aServiceId, *iCchHandler, 
       
   212 	                        iTableFetcher,*this);
       
   213 	                iSubService.Append(item);
       
   214 	                }
       
   215 	            break;
       
   216 	            }
       
   217 	        default:		
       
   218 	            {
       
   219 	            break;
       
   220 	            }
       
   221 
       
   222 	        }				
       
   223 	    }
       
   224 		
       
   225     //Create the required extention mgrs
       
   226     CreateExtentionFeaturesL(); 		
       
   227     iState = ParseGetServiceState();
       
   228     //if cch is already logged in, and the callback's servicestatuschanged() stopped
       
   229     RetriveContextIfCChEnabledL();
       
   230     }
       
   231 
       
   232 
       
   233 // ---------------------------------------------------------
       
   234 // CVIMPSTEngine::CVIMPSTEngine
       
   235 // 
       
   236 // ---------------------------------------------------------
       
   237 
       
   238 CVIMPSTEngine::CVIMPSTEngine( TUint32 aServiceId,
       
   239 								CVIMPSTEngineServiceTableFetcher& aTableFetcher ) :
       
   240 iServiceId(aServiceId),
       
   241 iTableFetcher(aTableFetcher)								
       
   242 	{
       
   243     iUnInstall = EFalse;
       
   244 	}
       
   245 
       
   246 // ---------------------------------------------------------
       
   247 // CVIMPSTEngine::RetriveContextIfCChEnabledL
       
   248 // 
       
   249 // ---------------------------------------------------------
       
   250 void CVIMPSTEngine::RetriveContextIfCChEnabledL()
       
   251 	{
       
   252 	TRACER_AUTO; 
       
   253     if ( (iSessionCntxtObserver) && 
       
   254          (TVIMPSTEnums::ESVCEUpdatingContacts == iState || TVIMPSTEnums::ESVCERegistered == iState ) 
       
   255    		 && ( TVIMPSTEnums::EVIMPSTBindNotDone == iSessionCntxtObserver->ContextBindStatus()  ) )
       
   256 		{
       
   257 		TInt ximpAdapterUid = iTableFetcher.XimpAdapterUidL(iServiceId);
       
   258 		TInt err = iSessionCntxtObserver->ServerBindL(TUid::Uid( ximpAdapterUid ));	      
       
   259         if(KErrNone != err)
       
   260             {
       
   261             //should never reache here;
       
   262             iCchHandler->DisableService();
       
   263             User::LeaveIfError(err);
       
   264             }
       
   265         SetExtentionFeaturesSupportedL();
       
   266 		}
       
   267 
       
   268 	}
       
   269 
       
   270 // ---------------------------------------------------------
       
   271 // CVIMPSTEngine::LoginL
       
   272 // 
       
   273 // ---------------------------------------------------------
       
   274 TInt CVIMPSTEngine::Login()
       
   275 	{
       
   276 	TRACER_AUTO; 
       
   277     TRACE( "ServiceId: %d", iServiceId );
       
   278 	
       
   279 	TInt error = KErrNotFound;
       
   280 	if(iCchHandler)
       
   281 		{
       
   282 	TRACE( "EnableService Called");
       
   283 		error =  iCchHandler->EnableService(); 		
       
   284 		}
       
   285 	
       
   286 	TRACE( "error: %d", error );
       
   287 		
       
   288 	return error;
       
   289 	}
       
   290 
       
   291 
       
   292 // ---------------------------------------------------------
       
   293 // CVIMPSTEngine::Logout
       
   294 // 
       
   295 // ---------------------------------------------------------
       
   296 void CVIMPSTEngine::LogoutL()
       
   297 	{
       
   298 	TRACER_AUTO;
       
   299 	TRACE( "ServiceId: %d", iServiceId );
       
   300 	
       
   301 	if(iCchHandler)
       
   302 		{
       
   303 		MVIMPSTEngineSubService* subService = SubService(TVIMPSTEnums::EPresence);
       
   304 		if (subService)
       
   305 		    {
       
   306 		    //Get Presence SubService     
       
   307 		    MVIMPSTEnginePresenceSubService& presenceSubService = 
       
   308 		                    MVIMPSTEnginePresenceSubService::Cast(*subService);
       
   309 		    if (TVIMPSTEnums::ESVCERegistered == subService->SubServiceState() ||
       
   310 		            TVIMPSTEnums::ESVCEUpdatingContacts == subService->SubServiceState() ) 
       
   311 		        {
       
   312 		        // Unsubscribe all lists here to get whole list contents when doing a new bind.
       
   313                 // Trap here to avoid unbind not being done if list operations should leave
       
   314                 TRAP_IGNORE( presenceSubService.UnsubscribeListsL() ); 
       
   315 		        }		    
       
   316 		    }
       
   317  			//if either of Presence/IM Subservice supported then we need
       
   318       //to unbind to XIMP context. 
       
   319       if( iSessionCntxtObserver )
       
   320           {
       
   321           TRACE( "ServerUnBindL Called");
       
   322           iSessionCntxtObserver->ServerUnBindL(ETrue);    
       
   323           }		
       
   324 		TRACE(" DisableService Called");
       
   325 		iCchHandler->DisableService();  
       
   326 		}	
       
   327 	
       
   328 	}
       
   329 
       
   330 
       
   331 // ---------------------------------------------------------
       
   332 // CVIMPSTEngine::ServiceId
       
   333 // 
       
   334 // ---------------------------------------------------------
       
   335 TUint32 CVIMPSTEngine::ServiceId() const
       
   336 	{
       
   337 	TRACER_AUTO;
       
   338 	TRACE( "ServiceId: %d", iServiceId );
       
   339 	return iServiceId;	
       
   340 	}
       
   341 
       
   342 
       
   343 // ---------------------------------------------------------
       
   344 // CVIMPSTEngine::ServiceName
       
   345 // 
       
   346 // ---------------------------------------------------------
       
   347 const TDesC& CVIMPSTEngine::ServiceName() const
       
   348 	{
       
   349 	TRACER_AUTO;
       
   350 	TPtr serviceNamePtr = iServiceName->Des();
       
   351 	TRACE( "ServiceName: '%S'", &serviceNamePtr );
       
   352 	return *iServiceName;	
       
   353 	}
       
   354 
       
   355 // ---------------------------------------------------------
       
   356 // CVIMPSTEngine::ServiceState
       
   357 // 
       
   358 // ---------------------------------------------------------
       
   359 TVIMPSTEnums::TVIMPSTRegistrationState CVIMPSTEngine::ServiceState() const
       
   360 	{
       
   361 	TRACER_AUTO;
       
   362 	TRACE( "ServiceState: %d", iState  );
       
   363 	return iState;
       
   364 	}
       
   365 
       
   366 
       
   367 // ---------------------------------------------------------
       
   368 // CVIMPSTEngine::GetBrandInfo
       
   369 // 
       
   370 // ---------------------------------------------------------
       
   371 TInt CVIMPSTEngine::GetBrandInfoL(TLanguage& aBrandLanguage, 
       
   372 				TInt &aBrandVersion, TDes8& aBrandId) const
       
   373 
       
   374 	{
       
   375 	TRACER_AUTO;	
       
   376 	TRACE("ServiceId: %d", iServiceId );
       
   377 	
       
   378 	iTableFetcher.GetBrandIdL(iServiceId, aBrandId);
       
   379 	aBrandLanguage = iTableFetcher.PropertyBrandLanguageL(iServiceId);
       
   380 	aBrandVersion = iTableFetcher.PropertyBrandVersionL(iServiceId);	
       
   381 	return KErrNone;
       
   382 	}
       
   383 	
       
   384 
       
   385 // ---------------------------------------------------------
       
   386 // CVIMPSTEngine::IsSubServiceSupportedL
       
   387 // 
       
   388 // ---------------------------------------------------------
       
   389 TBool CVIMPSTEngine::IsSubServiceSupportedL(TVIMPSTEnums::SubServiceType aType) const 
       
   390 	{
       
   391 	TRACER_AUTO;	
       
   392 	TRACE("ServiceId: %d", iServiceId);
       
   393 	TRACE("SubServiceType: %d", aType);
       
   394 	
       
   395 	TBool support = EFalse;
       
   396 	
       
   397 	MVIMPSTEngineSubService* subService = SubService(aType);
       
   398 	if (subService)
       
   399 		{
       
   400 		support = ETrue;
       
   401 		}
       
   402 	
       
   403 	TRACE( "support: %d", support );		
       
   404 	return support;
       
   405 	
       
   406 	}
       
   407 					
       
   408 
       
   409 // ---------------------------------------------------------
       
   410 // CVIMPSTEngine::IsSubServiceEnabled
       
   411 // 
       
   412 // ---------------------------------------------------------		
       
   413 TBool CVIMPSTEngine::IsSubServiceEnabled(TVIMPSTEnums::SubServiceType aType) const 
       
   414 	{
       
   415 	
       
   416 
       
   417 	TRACER_AUTO;
       
   418     TRACE( "ServiceId: %d", iServiceId );
       
   419     TRACE( "SubServiceType: %d", aType );
       
   420 
       
   421 	MVIMPSTEngineSubService* subService = SubService(aType);
       
   422 	TBool enabled = EFalse;
       
   423 	
       
   424 	if (subService)
       
   425 		{			
       
   426 		if ( TVIMPSTEnums::ESVCERegistered == subService->SubServiceState() )
       
   427 			{			
       
   428 			enabled = ETrue;
       
   429 			}
       
   430 		}	
       
   431 	TRACE( "enabled: %d", enabled );
       
   432 	return enabled;	
       
   433 	}
       
   434 			
       
   435 // ---------------------------------------------------------
       
   436 // CVIMPSTEngine::GetContactStoreIdL
       
   437 // 
       
   438 // ---------------------------------------------------------	
       
   439 void CVIMPSTEngine::ContactStoreIdL (TDes& aContactStoreId ) const
       
   440 	{
       
   441 	TRACER_AUTO;
       
   442 	TRACE("ServiceId: %d", iServiceId );	
       
   443 	iTableFetcher.GetContactStoreIdL(iServiceId, aContactStoreId);	
       
   444 
       
   445 	}
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // CVIMPSTEngine::RegisterServiceSessionObserver()
       
   449 // ---------------------------------------------------------------------------
       
   450 // 
       
   451 void CVIMPSTEngine::RegisterServiceSessionObserverL
       
   452 							(MVIMPSTEngineServiceStateEventObserver* aObserver)
       
   453 	{
       
   454 	TRACER_AUTO;
       
   455 	__ASSERT_ALWAYS(aObserver,User::Leave(KErrArgument));	
       
   456 	TInt index = iObserverArray.Find(aObserver);
       
   457 	        if( index == KErrNotFound )
       
   458 	            {
       
   459 	            iObserverArray.Append( aObserver );   
       
   460 	            } 
       
   461 
       
   462 	}
       
   463 	
       
   464 // ---------------------------------------------------------------------------
       
   465 // CVIMPSTEngine::UnRegisterServiceSessionObserver()
       
   466 // ---------------------------------------------------------------------------
       
   467 //     
       
   468 void CVIMPSTEngine::UnRegisterServiceSessionObserver
       
   469 							(MVIMPSTEngineServiceStateEventObserver* aObserver)
       
   470 	{
       
   471 
       
   472 	TRACER_AUTO;
       
   473     if(aObserver)
       
   474         {
       
   475         TInt index = iObserverArray.Find(aObserver);
       
   476         if( index >=0 )
       
   477             {
       
   478             iObserverArray.Remove( index );
       
   479             iObserverArray.Compress();
       
   480             }
       
   481         }
       
   482 
       
   483 	}
       
   484 // ---------------------------------------------------------
       
   485 // CVIMPSTEngine::IntializeStorage
       
   486 // 
       
   487 // ---------------------------------------------------------	
       
   488 void CVIMPSTEngine::IntializeStorageL()
       
   489 	{
       
   490 	TRACER_AUTO;
       
   491     TRACE( "ServiceId: %d", iServiceId );	
       
   492  	iContactInterface = CVIMPSTStorageManagerFactory::ContactListInterfaceL(iServiceId);
       
   493  	if(iContactInterface)
       
   494 		{
       
   495 		iContactInterface->AddObserverL( this );   
       
   496 		MVIMPSTSettingsStore* store = CVIMPSTSettingsStore::NewLC(); 
       
   497 		RBuf lastUserName;
       
   498 		lastUserName.CreateL( KPropertyMaxLength );
       
   499 		CleanupClosePushL( lastUserName );
       
   500 		store->GetL( iServiceId, EServiceLastUserName, lastUserName );
       
   501 		if( lastUserName.Length() == 0 )
       
   502 			{
       
   503 			HBufC* userId = GetOwnUserIdFromCChOrStorageL();
       
   504 			CleanupStack::PushL( userId );
       
   505 			store->SetL(iServiceId, EServiceLastUserName,*userId);
       
   506 			iContactInterface->SetOwnUserIdL(*userId );  
       
   507 			CleanupStack::PopAndDestroy(); //userId   
       
   508 			}
       
   509 		else
       
   510 			{
       
   511 			iContactInterface->SetOwnUserIdL(lastUserName );	
       
   512 			}
       
   513 		CleanupStack::PopAndDestroy(&lastUserName); //lastUserName  
       
   514 		CleanupStack::PopAndDestroy(); //store     
       
   515 		}
       
   516  
       
   517 	}
       
   518 // ---------------------------------------------------------
       
   519 // CVIMPSTEngine::UnIntializeStorage
       
   520 // 
       
   521 // ---------------------------------------------------------	
       
   522 void CVIMPSTEngine::UnIntializeStorage()
       
   523 	{
       
   524 	TRACER_AUTO;
       
   525 	TRACE( "ServiceId: %d", iServiceId );
       
   526 	if(iContactInterface)
       
   527 		{
       
   528 		iContactInterface->RemoveObserver( this );
       
   529 		} 
       
   530 
       
   531 	}
       
   532 	
       
   533 //-----------------------------------------------------------------------------
       
   534 // CVIMPSTEngine::SetOwnUserIdIfChangedL
       
   535 // ( Other items commented in header )
       
   536 //----------------------------------------------------------------------------- 
       
   537 void CVIMPSTEngine::SetOwnUserIdIfChangedL(const TDesC& aUserId)
       
   538 	{
       
   539 
       
   540 	TRACER_AUTO;
       
   541 	MVIMPSTSettingsStore* store = CVIMPSTSettingsStore::NewLC();
       
   542 	RBuf lastUserName;
       
   543 	lastUserName.CreateL( KPropertyMaxLength );
       
   544 	CleanupClosePushL( lastUserName );
       
   545 	store->GetL( iServiceId, EServiceLastUserName, lastUserName );
       
   546 	//first time when cenrep is not set with any value. set current as lastusername
       
   547 	if( lastUserName.Compare( aUserId ) != 0  )
       
   548 		{ 
       
   549 		store->SetL(iServiceId, EServiceLastUserName,aUserId);
       
   550 		iContactInterface->SetOwnUserIdL(aUserId );  
       
   551 		} 
       
   552 	CleanupStack::PopAndDestroy(&lastUserName); //lastUserName         
       
   553 	CleanupStack::PopAndDestroy(); //store 
       
   554 
       
   555 	}
       
   556 
       
   557 //-----------------------------------------------------------------------------
       
   558 // CVIMPSTEngine::GetOwnUserIdFromCChOrStorageL
       
   559 // ( Other items commented in header )
       
   560 //----------------------------------------------------------------------------- 
       
   561 HBufC* CVIMPSTEngine::GetOwnUserIdFromCChOrStorageL() const
       
   562 	{
       
   563 
       
   564 	TRACER_AUTO;
       
   565 	TRACE( "ServiceId: %d", iServiceId );
       
   566 	HBufC* buffer = NULL;
       
   567 	if(iCchHandler)
       
   568 		{
       
   569 		// Set userid
       
   570 		buffer = iCchHandler->GetConParametersL(ECchUsername);      
       
   571 		CleanupStack::PushL( buffer );
       
   572 		}
       
   573 	if (!buffer)
       
   574 	    {
       
   575 	    buffer = KNullDesC().AllocLC();
       
   576 	    }
       
   577 	CleanupStack::Pop();//buffer 
       
   578 	return buffer;
       
   579 	}
       
   580 
       
   581 //-----------------------------------------------------------------------------
       
   582 // CVIMPSTEngine::SubService
       
   583 // ( Other items commented in header )
       
   584 //----------------------------------------------------------------------------- 
       
   585 MVIMPSTEngineSubService* CVIMPSTEngine::SubService(TVIMPSTEnums::SubServiceType aType) const 
       
   586 	{
       
   587 	TRACER_AUTO;
       
   588 	TRACE("ServiceId: %d", iServiceId );
       
   589 	TRACE( "SubServiceType: %d", aType );
       
   590 	TInt subServiceCount = iSubService.Count();
       
   591 	MVIMPSTEngineSubService* subService = NULL;	
       
   592 	
       
   593 	// iterate the service array
       
   594     for ( TInt index = 0; index < subServiceCount ; index++ )        
       
   595         {
       
   596         
       
   597         if (aType == iSubService[index]->Type())
       
   598 	        {
       
   599 	        subService = iSubService[index];	  
       
   600 	        TRACE("SubService Found");
       
   601 	        break;
       
   602 	        }       			
       
   603 		}	
       
   604 	
       
   605 
       
   606     
       
   607 	return subService;	
       
   608 	}
       
   609 	
       
   610 
       
   611 //-----------------------------------------------------------------------------
       
   612 // CVIMPSTEngine::ExtentionFeatures
       
   613 // ( Other items commented in header )
       
   614 //----------------------------------------------------------------------------- 
       
   615 MVIMPSTEngineExtentionFeatures* CVIMPSTEngine::ExtentionFeatures(TVIMPSTEnums::ExtentionType aType) const 
       
   616 	{
       
   617 	TRACER_AUTO;
       
   618 	TRACE("ServiceId: %d", iServiceId);
       
   619 	TRACE("ExtentionType: %d", aType);
       
   620 	TInt fetaureCount = iExtentionFeatures.Count();
       
   621 	MVIMPSTEngineExtentionFeatures* feature = NULL;	
       
   622 	
       
   623 	// iterate the service array
       
   624     for ( TInt index = 0; index < fetaureCount ; index++ )        
       
   625         {
       
   626         
       
   627         if (aType == iExtentionFeatures[index]->Type())
       
   628 	        {
       
   629 	        feature = iExtentionFeatures[index];	   
       
   630 	        TRACE("ExtentionFeatures Found");	
       
   631 	        break;
       
   632 	        }       			
       
   633 		}	
       
   634 	
       
   635 
       
   636 	return feature;	
       
   637 	}
       
   638 
       
   639 
       
   640 
       
   641 //-----------------------------------------------------------------------------
       
   642 // CVIMPSTEngine::AddExtentionFeaturesL
       
   643 // ( Other items commented in header )
       
   644 //----------------------------------------------------------------------------- 
       
   645 void CVIMPSTEngine::AddExtentionFeaturesL(MVIMPSTEngineExtentionFeatures* aFeature) 
       
   646 	{
       
   647 	__ASSERT_ALWAYS(aFeature,User::Leave(KErrArgument));	
       
   648 
       
   649 	TRACER_AUTO;
       
   650 	TRACE( "ServiceId: %d", iServiceId );
       
   651 	if (aFeature)
       
   652 		{		
       
   653 	    TRACE( "ExtentionType: %d", aFeature->Type() );
       
   654 		iExtentionFeatures.Append(aFeature);		
       
   655 		TRACE( "Append Done" );
       
   656 		}	
       
   657 	
       
   658 
       
   659 	
       
   660 	}
       
   661 	
       
   662 	
       
   663 //-----------------------------------------------------------------------------
       
   664 // CVIMPSTEngine::RemoveExtentionFeatures
       
   665 // ( Other items commented in header )
       
   666 //----------------------------------------------------------------------------- 
       
   667 void CVIMPSTEngine::RemoveExtentionFeatures(TVIMPSTEnums::ExtentionType aType) 
       
   668 	{
       
   669 	TRACER_AUTO;	
       
   670 
       
   671 	TRACE( "ServiceId: %d", iServiceId );
       
   672 	TInt fetaureCount = iExtentionFeatures.Count();
       
   673 	
       
   674 	// iterate the service array
       
   675     for ( TInt index = 0; index < fetaureCount ; index++ )        
       
   676         {
       
   677         
       
   678         if (aType == iExtentionFeatures[index]->Type())
       
   679 	        {
       
   680 	        TRACE( "ExtentionType: %d", aType );
       
   681 	        iExtentionFeatures.Remove(index);
       
   682 	        iExtentionFeatures.Compress();
       
   683 	        TRACE( "Remove Done" );
       
   684 	        break;
       
   685 	        }       			
       
   686 		}	
       
   687 	
       
   688 
       
   689 		
       
   690 	}	
       
   691 	
       
   692 
       
   693 
       
   694 //-----------------------------------------------------------------------------
       
   695 // CVIMPSTEngine::HandleServceConnectionEventL
       
   696 // ( Other items commented in header )
       
   697 //-----------------------------------------------------------------------------
       
   698 void  CVIMPSTEngine::HandleServceConnectionEventL()
       
   699 	{
       
   700 	TRACER_AUTO;
       
   701 	TRACE( "ServiceId: %d", iServiceId );	
       
   702 
       
   703 	TVIMPSTEnums::TVIMPSTRegistrationState previousState = iState;
       
   704 	iState = ParseGetServiceState();	
       
   705 
       
   706 	if(TVIMPSTEnums::ESVCENotRegistered == iState)
       
   707 		{
       
   708 		CVIMPSTEnginePresenceSubService* presSubService = 
       
   709 		dynamic_cast<CVIMPSTEnginePresenceSubService*> 
       
   710 		(SubService(TVIMPSTEnums::EPresence));   
       
   711 		if(presSubService)
       
   712 			{
       
   713 			presSubService->ResetBlockedListManagerL();
       
   714 			}
       
   715 		}
       
   716 	TRACE( "PreviousState: %d, CurrentState:%d", previousState, iState );
       
   717 	//Only send observer notifications if there is any change in the Service State
       
   718 	//Otherwise not required
       
   719 	if (previousState != iState)
       
   720 		{
       
   721 		//Presence Service needs to Register for the XIMP Events once when
       
   722 		//the context gets binded
       
   723 		//Get Presence SubService   
       
   724 		CVIMPSTEnginePresenceSubService* presSubService = 
       
   725 									dynamic_cast<CVIMPSTEnginePresenceSubService*>(SubService(TVIMPSTEnums::EPresence));     
       
   726 		// in case of roaming(moving from one network to another)
       
   727 		// servicetab goes from registered to connecting state, hence the unbind is done here.
       
   728     if (  presSubService && TVIMPSTEnums::ESVCERegistered == previousState &&
       
   729           TVIMPSTEnums::ESVCENetworkConnecting == iState )
       
   730           {
       
   731           TRACE( "UnsubscribeLists"  );
       
   732           
       
   733           TRAPD( err, presSubService->UnsubscribeListsL() );
       
   734 	  
       
   735           TRACE( "UnsubscribeLists -err: %d" , err );
       
   736 	  
       
   737           if ( iSessionCntxtObserver )
       
   738               {
       
   739               iSessionCntxtObserver->ServerUnBindL( ETrue );
       
   740               }
       
   741           }          
       
   742 		TInt count = iObserverArray.Count();
       
   743 		for (TInt index=0; index<count; index++)		
       
   744 			{
       
   745 			TRACE( "calling HandleServiceEventL" );
       
   746 			iObserverArray[index]->HandleServiceEventL(iState, KErrNone);
       
   747 			}		
       
   748 		TInt ximpAdapterUid = iTableFetcher.XimpAdapterUidL(iServiceId);
       
   749 		if ( (iSessionCntxtObserver) && (KErrNotFound != ximpAdapterUid ) )
       
   750 			{
       
   751 
       
   752 			if ( ( TVIMPSTEnums::ESVCEUpdatingContacts == iState || 
       
   753 			     TVIMPSTEnums::ESVCERegistered == iState ) &&
       
   754 			     TVIMPSTEnums::EVIMPSTBindNotDone == iSessionCntxtObserver->ContextBindStatus() )
       
   755 				{				
       
   756 				TInt error = iSessionCntxtObserver->ServerBindL(TUid::Uid( ximpAdapterUid ));
       
   757 				if(KErrNone != error)
       
   758 					{
       
   759 					//should never reache here;
       
   760 					iCchHandler->DisableService();
       
   761 					User::LeaveIfError(error);
       
   762 					}
       
   763 				SetExtentionFeaturesSupportedL();
       
   764 				}
       
   765 			else if (TVIMPSTEnums::ESVCENotRegistered == iState )
       
   766 				{
       
   767 				MVIMPSTStorageServiceView* storage =  CVIMPSTStorageManagerFactory::ContactListInterfaceL(iServiceId);
       
   768 				if( storage )
       
   769 					{
       
   770 					 MVIMPSTStorageContact& ownContact = storage->OwnContactL();
       
   771                      TPtrC ownUserId = ownContact.UserId();
       
   772                      if( ownUserId.Length() &&  presSubService )
       
   773                         {
       
   774                         presSubService->UnSubscribePresenceOfSingleContactL( ownUserId );
       
   775                         }
       
   776 					 MVIMPSTStorageContactList* list = storage->FindContactList(KIMContactListId) ;      
       
   777 					if ( list )                     
       
   778 						{
       
   779 						TInt count = list->Count();
       
   780 						for(TInt i = 0;i < count; i++)
       
   781 							{
       
   782 							MVIMPSTStorageContact* contact = &(list->operator[](i));
       
   783 							if(contact)
       
   784 								{
       
   785 								if(presSubService)
       
   786 									{
       
   787 									if( contact->UserId().Length() )
       
   788 										{
       
   789 										TRAP_IGNORE( presSubService->UnSubscribePresenceOfSingleContactL( contact->UserId() ) );	
       
   790 										}
       
   791 									if(!(contact->UserId().Length())) // if no XspId
       
   792 									    {
       
   793 									    contact->SetOnlineStatus(TVIMPSTEnums::EUnknown);
       
   794 									    }
       
   795 									else if(TVIMPSTEnums::EPending != contact->OnlineStatus())
       
   796 										{
       
   797 										contact->SetOnlineStatus(TVIMPSTEnums::EOffline);
       
   798 										}// end of if
       
   799 									}// end of for
       
   800 								} // end of if(contact)
       
   801 							}// end of for
       
   802 						storage->Sort(KIMContactListId);						
       
   803 						// Inform service state changes to UI service tab
       
   804 						// and further to update the buddy list after sort. 
       
   805 						TInt obsvrArrayCount = iObserverArray.Count();
       
   806 						for (TInt index=0; index<obsvrArrayCount; index++)		
       
   807 							{
       
   808 							iObserverArray[index]->HandleServiceEventL(iState, KErrNone);
       
   809 							}	
       
   810 						}
       
   811 					}
       
   812 				ReSetExtentionFeaturesSupportedL();
       
   813 				} //end of else if
       
   814 			}// end of isessioncontextobserver and ximpadapteruid.
       
   815 			}// end of if(previousstate != iState)	
       
   816 
       
   817 	}
       
   818 	
       
   819 //-----------------------------------------------------------------------------
       
   820 // CVIMPSTEngine::ParseGetServiceState
       
   821 // ( Other items commented in header )
       
   822 //-----------------------------------------------------------------------------
       
   823 TVIMPSTEnums::TVIMPSTRegistrationState CVIMPSTEngine::ParseGetServiceState()
       
   824 	{
       
   825 	TRACER_AUTO;
       
   826 	TInt subServiceCount = iSubService.Count();
       
   827 	TInt serviceState = 0;
       
   828 		
       
   829 	//Find the cumulative of the ServiceStates of all subservices
       
   830 	// iterate the service array
       
   831     for ( TInt index = 0; index < subServiceCount ; index++ )        
       
   832         {           
       
   833         serviceState |= iSubService[index]->SubServiceState();
       
   834 		}
       
   835 	
       
   836 	//ServiceState
       
   837     TVIMPSTEnums::TVIMPSTRegistrationState state = TVIMPSTEnums::ESVCENotRegistered;
       
   838     
       
   839     //The logic below is that, if any one subservice not enabled for us the service is not enabled
       
   840     //So to do this we assign priority for each service state
       
   841     //Connecting gets the High Priority, when copmared to Waiting for Connection,
       
   842     //Disconnecting, Registered, UnRegistered.
       
   843     //By this way the Sevice Tab will be more usable and atleast we can perform operations
       
   844     //related to the the logged in subservice
       
   845     //its upto the connection handlers to do the job properly, whether to provide connectivity to all
       
   846     //sub services or not.. 
       
   847     
       
   848     //Start parsing and decide the state of the ServiceTab   
       
   849     if ( serviceState & TVIMPSTEnums::ESVCENetworkConnecting )
       
   850 	    {
       
   851 	    //Connecting	
       
   852 	    state = TVIMPSTEnums::ESVCENetworkConnecting;
       
   853 	    }
       
   854 	else if ( serviceState & TVIMPSTEnums::ESVCEWaitingForNetwork )
       
   855 	    {
       
   856 	    //Waiting for Connection	
       
   857 	    state = TVIMPSTEnums::ESVCEWaitingForNetwork;
       
   858 	    }
       
   859 	else if ( serviceState & TVIMPSTEnums::ESVCEUpdatingContacts )
       
   860 	    {
       
   861 	    //Waiting for Connection	
       
   862 	    state = TVIMPSTEnums::ESVCEUpdatingContacts;
       
   863 	    }	    	    
       
   864     else if ( serviceState & TVIMPSTEnums::ESVCENetworkDisConnecting )
       
   865 	    {
       
   866 	    //disconnecting	
       
   867 	    state = TVIMPSTEnums::ESVCENetworkDisConnecting;
       
   868 	    }   
       
   869 	else if ( serviceState & TVIMPSTEnums::ESVCERegistered ) 
       
   870 	    {
       
   871 	    //Enabled	
       
   872 	    state = TVIMPSTEnums::ESVCERegistered;
       
   873 	    }	     	
       
   874 	
       
   875 	return state;	
       
   876 	}	
       
   877 
       
   878 //-----------------------------------------------------------------------------
       
   879 // CVIMPSTEngine::HandleContactFetchedL
       
   880 // ( Other items commented in header )
       
   881 //-----------------------------------------------------------------------------
       
   882 void  CVIMPSTEngine::HandleContactFetchedL()
       
   883     {
       
   884   
       
   885 	TRACER_AUTO;
       
   886     
       
   887     if (TVIMPSTEnums::ESVCERegistered == iState ||
       
   888 	    	TVIMPSTEnums::ESVCEUpdatingContacts == iState ) 
       
   889 		{
       
   890 		MVIMPSTEngineSubService* subService = SubService(TVIMPSTEnums::EPresence);
       
   891 		if (subService)
       
   892 			{
       
   893 			//Get Presence SubService     
       
   894 			MVIMPSTEnginePresenceSubService& presenceSubService = 
       
   895 			        MVIMPSTEnginePresenceSubService::Cast(*subService);
       
   896 
       
   897 			if (TVIMPSTEnums::ESVCERegistered == subService->SubServiceState() ||
       
   898 				TVIMPSTEnums::ESVCEUpdatingContacts == subService->SubServiceState() ) 
       
   899 				{
       
   900 				presenceSubService.FetchPresenceFromCache();
       
   901 				}	    
       
   902 			presenceSubService.UpdatePresenceStateL();
       
   903 			}
       
   904 		// this is added here as for xmpp subscribeforsearchkeys needs to be done only 
       
   905 		// after the contactts are fetched from the server,
       
   906 		// SetExtensionFeaturesSupported is moved to immediately after login.
       
   907 		// as for sip case it would never come to this line if there are not contacts in it.   
       
   908 		MVIMPSTEngineExtentionFeatures* feature = ExtentionFeatures(
       
   909 		                    TVIMPSTEnums::ESearch);
       
   910 		if (feature)
       
   911 			{
       
   912 			MVIMPSTEngineSearchMgrExtention& searchFeature = 
       
   913 							MVIMPSTEngineSearchMgrExtention::Cast(*feature);                				
       
   914 			//subscribe for search keys, since this is a server feature            				               				
       
   915 			if(TVIMPSTEnums::ESupportUnKnown == searchFeature.IsSupported())
       
   916 			    {
       
   917 			    searchFeature.SubscribeForSearchKeysL();                
       
   918 			    }
       
   919 			}                
       
   920 		}                
       
   921   
       
   922     }
       
   923     
       
   924 // --------------------------------------------------------------------------
       
   925 // CVIMPSTEngine::HandleStorageChangeL
       
   926 // --------------------------------------------------------------------------
       
   927 //
       
   928 void CVIMPSTEngine::HandleStorageChangeL( TVIMPSTEnums::TVIMPSTStorgaeEventType aEventType,
       
   929 		         							MVIMPSTStorageContactList* /*aList*/, 
       
   930 			        						MVIMPSTStorageContact* aContact,
       
   931 			        						TInt /*aContactIndex*/ )
       
   932     {
       
   933   
       
   934 	TRACER_AUTO;  
       
   935 	TRACE(" iState = %d", iState);
       
   936     if (TVIMPSTEnums::ESVCERegistered == iState ||	TVIMPSTEnums::ESVCEUpdatingContacts == iState ) 
       
   937 		{	
       
   938         TRACE( "Inside IF");	
       
   939         TRACE( "aEventType : %d", aEventType);
       
   940 		switch( aEventType )
       
   941 		    {
       
   942 		    case TVIMPSTEnums::EStorageContactReadComplete:
       
   943 		    case TVIMPSTEnums::EStorageContactFetchComplete:
       
   944 		        {
       
   945 		        TRACE( "aEventType EStorageContactFetchComplete");
       
   946 		        MVIMPSTEngineSubService* subService =  SubService(TVIMPSTEnums::EPresence); 
       
   947 		        if( subService )   
       
   948 		            {
       
   949 		       
       
   950 		           TRACE( "Inside IF subService");
       
   951 		            MVIMPSTEnginePresenceSubService& presenceSubService = MVIMPSTEnginePresenceSubService::Cast(*subService);
       
   952 		            
       
   953 		            MVIMPSTStorageServiceView* storage =  CVIMPSTStorageManagerFactory::ContactListInterfaceL(iServiceId);
       
   954 		            if( storage )
       
   955 		                {
       
   956 		                MVIMPSTStorageContact& ownContact = storage->OwnContactL();
       
   957                         TPtrC ownUserId = ownContact.UserId();
       
   958                         if( ownUserId.Length() )
       
   959                             {
       
   960                             presenceSubService.SubscribePresenceOfSingleContactL( ownUserId );
       
   961                             }
       
   962 		          
       
   963 		                TRACE( "inside  if storage");
       
   964 		                MVIMPSTStorageContactList* list = storage->FindContactList(KIMContactListId) ;      
       
   965 		                if ( list )                     
       
   966 		                    {
       
   967 		               
       
   968 		                     TRACE( "inside  if list");
       
   969 		                    TInt count = list->Count();		                 
       
   970 		                    TRACE( "inside  count = %d", count);
       
   971 		                    for(TInt i = 0;i < count; i++)
       
   972 		                        {
       
   973 		                        MVIMPSTStorageContact* contact = &(list->operator[](i));
       
   974 		                        if(contact)
       
   975 		                            {
       
   976                                     if( contact->UserId().Length() )
       
   977                                         {
       
   978                                         TPtrC userId = contact->UserId();                                   
       
   979                                         TRACE("inside userId = %S", &userId);
       
   980                                         presenceSubService.SubscribePresenceOfSingleContactL( contact->UserId() );    
       
   981                                         }
       
   982 		                            } // end of if(contact)
       
   983 		                        }// end of for
       
   984 		                    }
       
   985 		                }
       
   986 
       
   987 		            }
       
   988 		        HandleContactFetchedL();
       
   989 
       
   990 		        break;	
       
   991 		        }
       
   992 		    case TVIMPSTEnums::EStorageEventOwnUserChanged:
       
   993 		    case TVIMPSTEnums::EStorageEventContactAddition:
       
   994 		    case TVIMPSTEnums::EStorageContactSynchronizing:
       
   995 		    case TVIMPSTEnums::EStorageContactReading:
       
   996 		    case TVIMPSTEnums::EStorageContactFetchExistInStore:
       
   997 		        {		    
       
   998 		        TRACE( "aEventType : %d", aEventType);
       
   999 		        MVIMPSTEngineSubService* subService =  SubService(TVIMPSTEnums::EPresence); 
       
  1000 		        if( subService && aContact && 
       
  1001 		                aContact->UserId().Length() && 
       
  1002 		                TVIMPSTEnums::ESVCERegistered == iState )   
       
  1003 		            {
       
  1004 		            MVIMPSTEnginePresenceSubService& presenceSubService = MVIMPSTEnginePresenceSubService::Cast(*subService);
       
  1005 		            presenceSubService.SubscribePresenceOfSingleContactL( aContact->UserId() );	
       
  1006 		            presenceSubService.FetchPresenceOfSingleContactL(aContact->UserId());
       
  1007 		            }
       
  1008 		        break;
       
  1009 		        }
       
  1010 		    case TVIMPSTEnums::EStorageEventUserIdPreChange:
       
  1011 		    case TVIMPSTEnums::EStorageEventDeleteFromPbk:
       
  1012 		        {
       
  1013 		     
       
  1014 		        TRACE("EStorageEventUserIdPreChange/EStorageEventDeleteFromPbk");
       
  1015 		        if( aContact && aContact->UserId().Length() ) 
       
  1016 		            {
       
  1017 		            TPtrC userId = aContact->UserId();
       
  1018 		            MVIMPSTEngineSubService* subService =  SubService(TVIMPSTEnums::EPresence);	
       
  1019 		            // incase of delete from phonebook delete from server and close conversation if exist
       
  1020 		            // mostly applicable for local store cases
       
  1021 		            if( subService )
       
  1022 		                {
       
  1023 		                MVIMPSTEnginePresenceSubService& presenceSubService = MVIMPSTEnginePresenceSubService::Cast(*subService);
       
  1024 		                presenceSubService.UnSubscribePresenceOfSingleContactL( userId ) ;	
       
  1025 		                }
       
  1026 		            MVIMPSTEngineExtentionFeatures* feature = ExtentionFeatures(TVIMPSTEnums::EContactManagement);
       
  1027 		            if (feature )	
       
  1028 		                {
       
  1029 		                MVIMPSTEngineContactMgmtExtention& contactMgr = MVIMPSTEngineContactMgmtExtention::Cast(*feature);
       
  1030 		                contactMgr.DeleteServerContactL(KNullDesC,userId) ;
       
  1031 		                }
       
  1032 		            MVIMPSTEngineSubService* imService = SubService(TVIMPSTEnums::EIM) ;    
       
  1033 		            if(imService)
       
  1034 		                {
       
  1035 		                MVIMPSTEngineIMSubService& imSubService = MVIMPSTEngineIMSubService::Cast (*imService);
       
  1036 		                imSubService.CloseConversationL( userId );
       
  1037 		                }
       
  1038 		            }
       
  1039 		        break;
       
  1040 		        }
       
  1041 		    case TVIMPSTEnums::EStorageEventUserIdPostChange:
       
  1042 		        {
       
  1043 		     
       
  1044 		        TRACE("EStorageEventUserIdPostChange");
       
  1045 		        if( aContact && aContact->UserId().Length() ) 
       
  1046 		            {
       
  1047 		            TPtrC userId = aContact->UserId();
       
  1048 		            // incase of delete from phonebook delete from server and close conversation if exist
       
  1049 		            // mostly applicable for local store cases
       
  1050 		            MVIMPSTEngineSubService* subService =  SubService(TVIMPSTEnums::EPresence);
       
  1051 		            if( subService )
       
  1052 		                {
       
  1053 		                MVIMPSTEnginePresenceSubService& presenceSubService = MVIMPSTEnginePresenceSubService::Cast(*subService);
       
  1054 		                presenceSubService.SubscribePresenceOfSingleContactL( userId );	
       
  1055 		                }
       
  1056 		            MVIMPSTEngineExtentionFeatures* feature = ExtentionFeatures(TVIMPSTEnums::EContactManagement);
       
  1057 		            if (feature )   
       
  1058 		                {
       
  1059 		                MVIMPSTEngineContactMgmtExtention& contactMgr = MVIMPSTEngineContactMgmtExtention::Cast(*feature);
       
  1060 		                contactMgr.AddServerContactL(KListNameAllBuddy,userId, aContact->Name(), EFalse );
       
  1061 		                }
       
  1062 		            }
       
  1063 		        break;
       
  1064 		        } 
       
  1065 		    default:
       
  1066 		        {
       
  1067 		        break;
       
  1068 		        }
       
  1069 		    }
       
  1070 		}
       
  1071     }
       
  1072     
       
  1073 //-----------------------------------------------------------------------------
       
  1074 // CVIMPSTEngine::CreateExtentionFeaturesL
       
  1075 // ( Other items commented in header )
       
  1076 //-----------------------------------------------------------------------------    
       
  1077 void CVIMPSTEngine::CreateExtentionFeaturesL()
       
  1078     {
       
  1079 	TRACER_AUTO;
       
  1080     if (!iSessionCntxtObserver)
       
  1081         {
       
  1082         return;	
       
  1083         }
       
  1084 
       
  1085     //create all the features
       
  1086     //first find whether we have the extention already created
       
  1087     //in the extention manager list 
       
  1088     
       
  1089     //first find whether we have the extention already created
       
  1090     //in the extention manager list
       
  1091     MVIMPSTEngineExtentionFeatures* contactMgtFeature = ExtentionFeatures(
       
  1092                             TVIMPSTEnums::EContactManagement);
       
  1093     
       
  1094     if (!contactMgtFeature)
       
  1095         {
       
  1096         CVIMPSTEngineContactMgmtExtention* contactItem = 
       
  1097                         CVIMPSTEngineContactMgmtExtention::NewL(
       
  1098                         iSessionCntxtObserver->XimpPresenceContextL(),
       
  1099                         iSessionCntxtObserver->XimpPresentityGroupsL(),
       
  1100                         *iSessionCntxtObserver->GetRequestMapper());
       
  1101 
       
  1102         AddExtentionFeaturesL(contactItem);
       
  1103         //Unregister is done by session context when the presence context gets
       
  1104         //unbinded
       
  1105         iSessionCntxtObserver->RegisterObserver(contactItem);   
       
  1106         }
       
  1107     
       
  1108     
       
  1109     //first find whether we have the extention already created
       
  1110     //in the extention manager list
       
  1111     MVIMPSTEngineExtentionFeatures* searchFeature = ExtentionFeatures(
       
  1112                             TVIMPSTEnums::ESearch);
       
  1113     if (!searchFeature)
       
  1114         {                   
       
  1115         CVIMPSTEngineSearchMgrExtention* searchitem = 
       
  1116                 CVIMPSTEngineSearchMgrExtention::NewL(
       
  1117                             iSessionCntxtObserver->XimpPresenceContextL(),
       
  1118                             *iSessionCntxtObserver->GetRequestMapper());
       
  1119                             
       
  1120         AddExtentionFeaturesL(searchitem);                  
       
  1121         
       
  1122         //Unregister is done by session context when the presence context gets
       
  1123         //unbinded
       
  1124         iSessionCntxtObserver->RegisterObserver(searchitem);
       
  1125         }
       
  1126     
       
  1127     }
       
  1128 
       
  1129 //-----------------------------------------------------------------------------
       
  1130 // CVIMPSTEngine::SetExtentionFeaturesSupportedL
       
  1131 // ( Other items commented in header )
       
  1132 //-----------------------------------------------------------------------------    
       
  1133 void CVIMPSTEngine::SetExtentionFeaturesSupportedL()
       
  1134     {
       
  1135 	TRACER_AUTO;
       
  1136     if (!iSessionCntxtObserver)
       
  1137 		{
       
  1138 		return;	
       
  1139 		}
       
  1140 		
       
  1141     //We would have got the supported features 
       
  1142     //iterate and create the required extentionmgr
       
  1143     TInt supportedFeatures = iSessionCntxtObserver->GetSupportedFeatures();
       
  1144 
       
  1145     if ( !(EVIMPSTFeatureSearch & supportedFeatures) )
       
  1146         {
       
  1147         //first find whether we have the extention already created
       
  1148         //in the extention manager list
       
  1149         MVIMPSTEngineExtentionFeatures* feature = ExtentionFeatures(
       
  1150                                 TVIMPSTEnums::ESearch);
       
  1151         if (feature)
       
  1152             {
       
  1153             MVIMPSTEngineSearchMgrExtention& searchFeature = 
       
  1154             				MVIMPSTEngineSearchMgrExtention::Cast(*feature);                				
       
  1155             searchFeature.SetSupported(TVIMPSTEnums::ENotSupported); 
       
  1156             //subscribe for search keys is done once the contacts are fetched from the server.
       
  1157             //check HandleContactFetchCOmpletedL().
       
  1158             }                
       
  1159         }
       
  1160         
       
  1161     if (( EVIMPSTFeatureAddContact & supportedFeatures ) || 
       
  1162     			( EVIMPSTFeatureDeleteContact & supportedFeatures ))
       
  1163         { 
       
  1164         //first find whether we have the extention already created
       
  1165         //in the extention manager list
       
  1166         MVIMPSTEngineExtentionFeatures* feature = ExtentionFeatures(
       
  1167                                 TVIMPSTEnums::EContactManagement);
       
  1168         if (feature)
       
  1169             {
       
  1170             MVIMPSTEngineContactMgmtExtention& contactMgmtFeature = 
       
  1171             				CVIMPSTEngineContactMgmtExtention::Cast(*feature);                				
       
  1172             contactMgmtFeature.SetSupported(TVIMPSTEnums::ESupported);                
       
  1173             }
       
  1174 
       
  1175         }
       
  1176     
       
  1177     if ( EVIMPSTFeatureAvatar & supportedFeatures )
       
  1178     	{
       
  1179         //first find whether we have the extention already created
       
  1180         //in the extention manager list
       
  1181         MVIMPSTEngineSubService* subService = SubService(
       
  1182                                 TVIMPSTEnums::EPresence);
       
  1183         if (subService)
       
  1184             {
       
  1185             MVIMPSTEnginePresenceSubService& avatarFeature = 
       
  1186             				CVIMPSTEnginePresenceSubService::Cast(*subService);                				
       
  1187             avatarFeature.SetAvatarSupported(ETrue);                
       
  1188             }
       
  1189         }
       
  1190     }
       
  1191 
       
  1192 
       
  1193 //-----------------------------------------------------------------------------
       
  1194 // CVIMPSTEngine::ReSetExtentionFeaturesSupportedL
       
  1195 // ( Other items commented in header )
       
  1196 //-----------------------------------------------------------------------------    
       
  1197 void CVIMPSTEngine::ReSetExtentionFeaturesSupportedL()
       
  1198     {
       
  1199 	TRACER_AUTO;
       
  1200     //first find whether we have the extention already created
       
  1201     //in the extention manager list
       
  1202     MVIMPSTEngineExtentionFeatures* feature = ExtentionFeatures(
       
  1203                             TVIMPSTEnums::ESearch);
       
  1204     if (feature)
       
  1205         {
       
  1206         MVIMPSTEngineSearchMgrExtention& searchFeature = 
       
  1207         				MVIMPSTEngineSearchMgrExtention::Cast(*feature);                				
       
  1208         searchFeature.SetSupported(TVIMPSTEnums::ESupportUnKnown);                    
       
  1209         }                
       
  1210 
       
  1211     //first find whether we have the extention already created
       
  1212     //in the extention manager list
       
  1213     MVIMPSTEngineExtentionFeatures* feature1 = ExtentionFeatures(
       
  1214                             TVIMPSTEnums::EContactManagement);
       
  1215     if (feature1)
       
  1216         {
       
  1217         MVIMPSTEngineContactMgmtExtention& contactMgmtFeature = 
       
  1218         				CVIMPSTEngineContactMgmtExtention::Cast(*feature1);                				
       
  1219         contactMgmtFeature.SetSupported(TVIMPSTEnums::ESupportUnKnown);                
       
  1220         }
       
  1221 
       
  1222     //first find whether we have the extention already created
       
  1223     //in the extention manager list
       
  1224     MVIMPSTEngineSubService* subService = SubService(
       
  1225                                 TVIMPSTEnums::EPresence );
       
  1226     if (subService)
       
  1227         {
       
  1228         MVIMPSTEnginePresenceSubService& avatarFeature = 
       
  1229         				CVIMPSTEnginePresenceSubService::Cast(*subService);                				
       
  1230         avatarFeature.SetAvatarSupported(EFalse);                
       
  1231         }
       
  1232     
       
  1233     }
       
  1234 
       
  1235 
       
  1236 // ---------------------------------------------------------
       
  1237 // CVIMPSTEngine::DefaultDomainNameL
       
  1238 // 
       
  1239 // ---------------------------------------------------------
       
  1240 void CVIMPSTEngine::DefaultDomainNameL( TDes& aDefaultDomainName ) const
       
  1241 	{
       
  1242 	TRACER_AUTO;	
       
  1243 	TRACE( "ServiceId: %d", iServiceId );
       
  1244 	iTableFetcher.GetDefaultDomainNameL(iServiceId, aDefaultDomainName);	
       
  1245 
       
  1246 	}
       
  1247 	
       
  1248 
       
  1249 // ---------------------------------------------------------
       
  1250 // CVIMPSTEngine::IsSubServiceSupportedInternal
       
  1251 // 
       
  1252 // ---------------------------------------------------------
       
  1253 TBool CVIMPSTEngine::IsSubServiceSupportedInternal(TVIMPSTEnums::SubServiceType aType) const 
       
  1254 	{
       
  1255 	TRACER_AUTO;
       
  1256 	TRACE( "ServiceId: %d", iServiceId );
       
  1257 	TRACE( "SubServiceType: %d", aType );
       
  1258 	TInt err = KErrNotFound;
       
  1259 	TBool support = EFalse;
       
  1260 	TCCHSubserviceState aCCHState(ECCHUninitialized);	
       
  1261 
       
  1262 	switch(aType)
       
  1263 		{
       
  1264 		case TVIMPSTEnums::EVoip:
       
  1265 			{
       
  1266 			err = iCchHandler->GetServiceState(iServiceId, ECCHVoIPSub, aCCHState);				
       
  1267 			break;				
       
  1268 			}
       
  1269 		case TVIMPSTEnums::EPresence:
       
  1270 			{
       
  1271 			err = iCchHandler->GetServiceState(iServiceId, ECCHPresenceSub, aCCHState);							
       
  1272 			break;
       
  1273 			}
       
  1274 		case TVIMPSTEnums::EIM:
       
  1275 			{
       
  1276 			err = iCchHandler->GetServiceState(iServiceId, ECCHIMSub, aCCHState);	
       
  1277 			break;
       
  1278 			}
       
  1279 		default:		
       
  1280 			{
       
  1281 			break;
       
  1282 			}
       
  1283 		
       
  1284 		}
       
  1285 	
       
  1286 	if (KErrNone == err)
       
  1287 		{
       
  1288 		support = ETrue;		
       
  1289 		}
       
  1290 		
       
  1291 
       
  1292 	TRACE("support: %d", support );
       
  1293 	return support;
       
  1294 	}
       
  1295 	
       
  1296 
       
  1297 // ---------------------------------------------------------
       
  1298 // CVIMPSTEngine::ChangeConnectionL
       
  1299 // 
       
  1300 // ---------------------------------------------------------
       
  1301 TInt CVIMPSTEngine::ChangeConnectionL()
       
  1302 	{
       
  1303 	TRACER_AUTO;
       
  1304 	TRACE( "ServiceId: %d", iServiceId );
       
  1305 	TInt error = KErrNotFound;
       
  1306 	if(iCchHandler)
       
  1307 		{
       
  1308 	
       
  1309 	   TRACE( "ChangeConnectionL() Called" );
       
  1310 		error =  iCchHandler->ChangeConnectionL(); 		
       
  1311 		}
       
  1312 	
       
  1313 
       
  1314 	TRACE("error: %d", error );
       
  1315 
       
  1316 	return error;
       
  1317 	}		
       
  1318 
       
  1319 // ---------------------------------------------------------
       
  1320 // CVIMPSTEngine::IsBlockSupportedL
       
  1321 // 
       
  1322 // ---------------------------------------------------------
       
  1323 
       
  1324 TBool CVIMPSTEngine::IsBlockSupportedL()
       
  1325     {
       
  1326 	TRACER_AUTO;
       
  1327     TBool isBlockSupported = EFalse;
       
  1328     //We would have got the supported features 
       
  1329     if(iSessionCntxtObserver && (TVIMPSTEnums::ESVCERegistered == ParseGetServiceState()))
       
  1330         {
       
  1331         TInt supportedFeatures = iSessionCntxtObserver->GetSupportedFeatures();
       
  1332         if ( (EVIMPSTFeatureBlock & supportedFeatures) && (EVIMPSTFeatureUnBlock & supportedFeatures) )
       
  1333             {
       
  1334             isBlockSupported = ETrue;
       
  1335             }
       
  1336         }
       
  1337     return isBlockSupported;
       
  1338     }
       
  1339 
       
  1340 // ---------------------------------------------------------
       
  1341 // CVIMPSTEngine::IsPasswordAvailable
       
  1342 // returns True if password is present in the settings else returns false
       
  1343 // ---------------------------------------------------------
       
  1344 TBool CVIMPSTEngine::IsPasswordAvailableL()
       
  1345     {
       
  1346 	TRACER_AUTO;
       
  1347  
       
  1348     return(iCchHandler->IsPasswordAvailable(ECchPasswordSet));    
       
  1349     }
       
  1350     
       
  1351 // ---------------------------------------------------------
       
  1352 // CVIMPSTEngine::DeleteDataBase
       
  1353 // ---------------------------------------------------------
       
  1354 void CVIMPSTEngine::DeleteDataBaseL() 
       
  1355 	{
       
  1356 	TRACER_AUTO;
       
  1357 	MVIMPSTStorageServiceView* storage = 
       
  1358 	CVIMPSTStorageManagerFactory::ContactListInterfaceL(iServiceId);
       
  1359 	if( storage )
       
  1360 		{
       
  1361 		//delete cdb file.
       
  1362 		storage->DeleteDatabaseL();
       
  1363 		}
       
  1364 	}
       
  1365 	
       
  1366 // ---------------------------------------------------------------------------
       
  1367 // CVIMPSTEnginePresenceSubService::GetPreseceSubService
       
  1368 // ---------------------------------------------------------------------------
       
  1369 //
       
  1370 MVIMPSTEnginePresenceSubService* CVIMPSTEngine::GetPreseceSubService()
       
  1371 	{
       
  1372 	TRACER_AUTO;
       
  1373 	MVIMPSTEngineSubService* subService = SubService(TVIMPSTEnums::EPresence);
       
  1374 	if (subService)
       
  1375 		{
       
  1376 		//Get Presence SubService     
       
  1377 		MVIMPSTEnginePresenceSubService& presenceSubService = 
       
  1378 									MVIMPSTEnginePresenceSubService::Cast(*subService);
       
  1379 		return &presenceSubService ;
       
  1380 		}
       
  1381 	return NULL;	
       
  1382 	}
       
  1383 
       
  1384 // ---------------------------------------------------------------------------
       
  1385 // CVIMPSTEngine::FetchBlockedList
       
  1386 // ---------------------------------------------------------------------------
       
  1387 //
       
  1388 void CVIMPSTEngine::FetchBlockedListL()
       
  1389 	{
       
  1390 	MVIMPSTEnginePresenceSubService* subService = GetPreseceSubService();
       
  1391 	if( subService )
       
  1392 		{
       
  1393 		//fetch the blocked list from server
       
  1394 		subService->FetchBlockedListFromServerL(iBlockListObs);
       
  1395 		}
       
  1396 	}
       
  1397 
       
  1398 // ---------------------------------------------------------------------------
       
  1399 // CVIMPSTEngine::RegisterBlockedListObserver
       
  1400 // ---------------------------------------------------------------------------
       
  1401 //
       
  1402 void CVIMPSTEngine::RegisterBlockedListObserver(
       
  1403 				MVIMPSTEngineBlockedListFetchEventObserver* aOb)
       
  1404 	{
       
  1405 	iBlockListObs = aOb;
       
  1406 	}
       
  1407 
       
  1408 // ---------------------------------------------------------------------------
       
  1409 // CVIMPSTEngine::HandleChangeConnectionEventL
       
  1410 // ---------------------------------------------------------------------------
       
  1411 //
       
  1412 void CVIMPSTEngine::HandleChangeConnectionEventL()
       
  1413     {
       
  1414 	TRACER_AUTO;
       
  1415     MVIMPSTEngineSubService* subService = SubService(TVIMPSTEnums::EPresence);
       
  1416     if (subService)
       
  1417         {
       
  1418         //Get Presence SubService     
       
  1419         MVIMPSTEnginePresenceSubService& presenceSubService = 
       
  1420         MVIMPSTEnginePresenceSubService::Cast(*subService);
       
  1421         if (TVIMPSTEnums::ESVCERegistered == subService->SubServiceState() ||
       
  1422                 TVIMPSTEnums::ESVCEUpdatingContacts == subService->SubServiceState() ) 
       
  1423             {
       
  1424             // Unsubscribe all lists here to get whole list contents when doing a new bind.
       
  1425            // Trap here to avoid unbind not being done if list operations should leave
       
  1426             TRAP_IGNORE( presenceSubService.UnsubscribeListsL() ); 
       
  1427             }           
       
  1428         }
       
  1429         
       
  1430     if( iSessionCntxtObserver )
       
  1431         {        
       
  1432         iSessionCntxtObserver->ServerUnBindL(ETrue); 
       
  1433         }
       
  1434     }
       
  1435 
       
  1436 // -------------------------------------------------------
       
  1437 // CVIMPSTEngine :: IsUnInstalled
       
  1438 // For Description see MVIMPSTEngine
       
  1439 // -------------------------------------------------------
       
  1440 //
       
  1441 TBool CVIMPSTEngine::IsUnInstalled( )
       
  1442     {
       
  1443     return iUnInstall;
       
  1444     }
       
  1445 //  End of File