uiservicetab/vimpstengine/src/cvimpstenginecchhandler.cpp
branchRCL_3
changeset 28 3104fc151679
parent 27 2b7283837edb
child 29 9a48e301e94b
equal deleted inserted replaced
27:2b7283837edb 28:3104fc151679
     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 handling the use of Cch - All CCH Events go thro this class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32def.h>
       
    22 #include <cchserver.h>
       
    23 #include <cchclient.h>
       
    24 
       
    25 #include "cvimpstenginecchhandler.h"
       
    26 #include "tvimpstconsts.h"
       
    27 
       
    28 #include "f32file.h"
       
    29 #include "uiservicetabtracer.h"
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CVIMPSTEngineCchHandler::CVIMPSTEngineCchHandler
       
    37 // ---------------------------------------------------------------------------
       
    38 // 
       
    39 CVIMPSTEngineCchHandler::CVIMPSTEngineCchHandler(TUint aServiceId, MVIMPSTEngineCchUiEventObserver& aCchUiEventObserver)
       
    40 : iServiceId(aServiceId),iCchUiEventObserver(aCchUiEventObserver)
       
    41     {        
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CVIMPSTEngineCchHandler::ConstructL
       
    46 // ---------------------------------------------------------------------------
       
    47 // 
       
    48 void CVIMPSTEngineCchHandler::ConstructL(  )
       
    49     {
       
    50 	TRACER_AUTO;
       
    51     
       
    52      // Create service selection here
       
    53 	 iCchClient = CCch::NewL();
       
    54 	 TRACE("CCch::NewL");
       
    55 	 iSettingsStore = CVIMPSTSettingsStore::NewL();
       
    56 	 TRACE("CVIMPSTSettingsStore::NewL");
       
    57 	
       
    58 	if (iCchClient)
       
    59 		{		
       
    60 		CCchService* service = iCchClient->GetService( iServiceId );
       
    61 		TRACE("CCch::GetService");
       
    62 		
       
    63 		if( service )
       
    64 			{
       
    65 			service->SetObserver( *this );
       
    66 			TRACE("CCchService::SetObserver");
       
    67 			}
       
    68 		}
       
    69 		
       
    70 	//Configure CCHUI notes
       
    71 	MCchUi& cchUiApi = iCchClient->CchUiApi();
       
    72 	TRACE("CCch::CchUiApi");
       
    73 	
       
    74 	// Set observer to listen cchui events for change connection.
       
    75     cchUiApi.AddObserverL( *this );  // parameter is MCchUiObserver
       
    76     TRACE("MCchUi::CchUiApi");
       
    77 
       
    78 	// Configure CCHUI API to show all notes/dialogs except connecting note.
       
    79 	// Also configure that only VoIP and IM subservices are allowed (notes are
       
    80 	// shown only for those).
       
    81 	RArray<MCchUiObserver::TCchUiDialogType> allowedNotes;
       
    82 	TRACE("MCchUiObserver::TCchUiDialogType");
       
    83 	RArray<TCCHSubserviceType> allowedSubServices;
       
    84 	TRACE("TCCHSubserviceType");
       
    85 	CleanupClosePushL( allowedNotes );
       
    86 	TRACE("allowedNotes");
       
    87 	CleanupClosePushL( allowedSubServices );
       
    88 	TRACE("allowedSubServices");
       
    89 
       
    90 	allowedNotes.AppendL( MCchUiObserver::ECchUiDialogTypeUsernamePasswordFailed );
       
    91 	TRACE("ECchUiDialogTypeUsernamePasswordFailed");
       
    92 	allowedNotes.AppendL( MCchUiObserver::ECchUiDialogTypeAuthenticationFailed );
       
    93 	TRACE("ECchUiDialogTypeAuthenticationFailed");
       
    94 	allowedNotes.AppendL( MCchUiObserver::ECchUiDialogTypeNoConnectionDefined );
       
    95 	TRACE("ECchUiDialogTypeNoConnectionDefined");
       
    96 	allowedNotes.AppendL( MCchUiObserver::ECchUiDialogTypeNoConnectionAvailable );
       
    97 	TRACE("ECchUiDialogTypeNoConnectionAvailable");
       
    98 	allowedNotes.AppendL( MCchUiObserver::ECchUiDialogTypeConfirmChangeConnection );
       
    99 	TRACE("ECchUiDialogTypeConfirmChangeConnection");
       
   100 	allowedNotes.AppendL( MCchUiObserver::ECchUiDialogTypeChangeConnection );
       
   101 	TRACE("ECchUiDialogTypeChangeConnection");
       
   102 	allowedNotes.AppendL( MCchUiObserver::ECchUiDialogTypeDefectiveSettings );
       
   103 	TRACE("ECchUiDialogTypeDefectiveSettings");
       
   104 	allowedNotes.AppendL( MCchUiObserver::ECchUiDialogTypeErrorInConnection );
       
   105 	TRACE("ECchUiDialogTypeErrorInConnection");
       
   106 
       
   107 	allowedSubServices.AppendL( ECCHUnknown );
       
   108 	TRACE("ECCHUnknown");
       
   109 	allowedSubServices.AppendL( ECCHVoIPSub );
       
   110 	TRACE("ECCHVoIPSub");
       
   111 	allowedSubServices.AppendL( ECCHIMSub );
       
   112 	TRACE("ECCHIMSub");
       
   113 	allowedSubServices.AppendL( ECCHPresenceSub );
       
   114 	TRACE("ECCHPresenceSub");
       
   115 
       
   116 	cchUiApi.ConfigureVisualizationL( 
       
   117 				allowedNotes, allowedSubServices );
       
   118 	TRACE("ConfigureVisualizationL");
       
   119 
       
   120 	CleanupStack::PopAndDestroy( &allowedSubServices );
       
   121 	TRACE("allowedSubServices::pop");
       
   122 	CleanupStack::PopAndDestroy( &allowedNotes );
       
   123 	TRACE("allowedNotes::pop");
       
   124 	
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CVIMPSTEngineCchHandler::NewL
       
   129 // ---------------------------------------------------------------------------
       
   130 // 
       
   131 CVIMPSTEngineCchHandler* CVIMPSTEngineCchHandler::NewL(TUint aServiceId,
       
   132         MVIMPSTEngineCchUiEventObserver& aCchUiEventObserver )
       
   133         {
       
   134 	TRACER_AUTO;
       
   135 	TRACE("ServiceId: %d", aServiceId );
       
   136     								 
       
   137     CVIMPSTEngineCchHandler* self = NewLC(aServiceId, aCchUiEventObserver );
       
   138     CleanupStack::Pop(self);
       
   139     return self;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CVIMPSTEngineCchHandler::NewLC
       
   144 // ---------------------------------------------------------------------------
       
   145 // 
       
   146 CVIMPSTEngineCchHandler* CVIMPSTEngineCchHandler::NewLC(TUint aServiceId ,MVIMPSTEngineCchUiEventObserver& aCchUiEventObserver)
       
   147     {
       
   148 	TRACER_AUTO;
       
   149     CVIMPSTEngineCchHandler* self =
       
   150         new (ELeave) CVIMPSTEngineCchHandler(aServiceId, aCchUiEventObserver);
       
   151     
       
   152     TRACE("ServiceId: %d", aServiceId );
       
   153     CleanupStack::PushL(self);
       
   154     self->ConstructL( );
       
   155     return self;
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CVIMPSTEngineCchHandler::~CVIMPSTEngineCchHandler
       
   160 // ---------------------------------------------------------------------------
       
   161 // 
       
   162 CVIMPSTEngineCchHandler::~CVIMPSTEngineCchHandler()
       
   163     {
       
   164 	TRACER_AUTO;
       
   165 	TRACE( "ServiceId: %d", iServiceId );
       
   166     if(iCchClient)
       
   167     	{
       
   168     	CCchService* service = iCchClient->GetService( iServiceId );
       
   169     	if( service )
       
   170 			{
       
   171 			service->RemoveObserver();
       
   172 			}
       
   173     	}
       
   174     delete iCchClient; 
       
   175     delete iSettingsStore;
       
   176     iObserverStructure.Reset();
       
   177     iObserverStructure.Close();
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CVIMPSTEngineCchHandler::ShutdownCch
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 //TODO: not used any where.. need to be removed.
       
   185 void CVIMPSTEngineCchHandler::ShutdownCch()
       
   186     {
       
   187 	TRACER_AUTO;
       
   188 	TRACE("ServiceId: %d", iServiceId );
       
   189     if ( iCchClient )
       
   190         {        
       
   191         delete iCchClient;
       
   192         iCchClient = NULL;
       
   193         }
       
   194     
       
   195     }    
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // CVIMPSTEngineCchHandler::GetServiceState
       
   200 // ---------------------------------------------------------------------------
       
   201 // 
       
   202 TInt CVIMPSTEngineCchHandler::GetServiceState(TUint aServiceId,
       
   203 									TInt aSubServiceType, 
       
   204 									TCCHSubserviceState& aCCHState
       
   205 									)
       
   206     {
       
   207 	TRACER_AUTO;
       
   208     
       
   209 	TRACE( "ServiceId: %d, SubServiceType:%d", aServiceId, aSubServiceType );    
       
   210    	TInt err = KErrNotFound;
       
   211    	if ( iCchClient )
       
   212 	   	{
       
   213 	   	CCchService* service = iCchClient->GetService( aServiceId );
       
   214 	   	TCchServiceStatus status;
       
   215 		status.SetState(ECCHUninitialized);
       
   216 
       
   217 		if( service )
       
   218 			{
       
   219 			// Get status from the client
       
   220 			err = service->GetStatus( TCCHSubserviceType(aSubServiceType), status );
       
   221 			if (KErrNone == err)
       
   222 				{
       
   223 				aCCHState = status.State();	
       
   224 				}
       
   225 			}		
       
   226 	   	}
       
   227    	TRACE( "aCCHState: (%d)", aCCHState );
       
   228 
       
   229     return err;   	
       
   230     }
       
   231 
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CVIMPSTEngineCchHandler::EnableService
       
   235 // ---------------------------------------------------------------------------
       
   236 // 
       
   237 TInt CVIMPSTEngineCchHandler::EnableService()
       
   238     {
       
   239 	TRACER_AUTO;
       
   240 	TRACE( "ServiceId: %d", iServiceId );
       
   241     TInt error = KErrNotFound;
       
   242     if ( iCchClient )
       
   243 	    {
       
   244 	    iCchClient->SetConnectivityDialogsAllowed( ETrue );
       
   245 
       
   246 		CCchService* service = iCchClient->GetService( iServiceId );
       
   247 		if( service )
       
   248 			{
       
   249 		TRACE( "CCHClient->Enable" );
       
   250 			error = service->Enable( ECCHUnknown );		
       
   251 			}
       
   252 	    }
       
   253 	
       
   254     TRACE( " stat: (%d)", error );
       
   255     
       
   256 
       
   257 	return error;
       
   258     
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CVIMPSTEngineCchHandler::DisableService
       
   263 // ---------------------------------------------------------------------------
       
   264 // 
       
   265 TInt CVIMPSTEngineCchHandler::DisableService()
       
   266     {
       
   267 	TRACER_AUTO;
       
   268 	TRACE( "ServiceId: %d", iServiceId );
       
   269 	TInt error = KErrNotFound;
       
   270 	
       
   271 	if(iCchClient)
       
   272 		{
       
   273 		CCchService* service = iCchClient->GetService( iServiceId );
       
   274 	    if( service )
       
   275 			{
       
   276 	    TRACE( "CCHClient->Disable" );	
       
   277 			error = service->Disable( ECCHUnknown );
       
   278 			}		
       
   279 		}
       
   280 	
       
   281 	TRACE( "stat: (%d)", error );
       
   282 			
       
   283     
       
   284     return error;
       
   285     
       
   286     }
       
   287  
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CVIMPSTEngineCchHandler::ServiceStatusChanged
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CVIMPSTEngineCchHandler::ServiceStatusChanged(
       
   294 				TInt aServiceId,
       
   295 				const TCCHSubserviceType aType,
       
   296 				const TCchServiceStatus& aServiceStatus )
       
   297     {
       
   298 	TRACER_AUTO;
       
   299 
       
   300     // Disable the service only if the login to one of the subservices fails
       
   301     // 1.ECCHVoIPSub
       
   302     // 2.ECCHPresenceSub
       
   303     // 3.ECCHIMSub
       
   304     if( aServiceStatus.Error() == KCCHErrorLoginFailed &&
       
   305             (ECCHVoIPSub == aType ||
       
   306              ECCHPresenceSub == aType ||
       
   307              ECCHIMSub == aType))
       
   308         {
       
   309         DisableService();
       
   310         }
       
   311 
       
   312     if((aServiceStatus.Error() == KCCHErrorAuthenticationFailed )||(aServiceStatus.Error() == KCCHErrorLoginFailed))
       
   313         {
       
   314         TInt loginfailed = 0;
       
   315         TRAP_IGNORE( iSettingsStore->SetL(iServiceId ,EServiceSuccessfullLogin ,loginfailed) );  
       
   316         }
       
   317     TInt count  = iObserverStructure.Count();
       
   318     for(TInt i = 0; i< count; i++)
       
   319         {
       
   320         if(aType == iObserverStructure[i].iSubserviceType )
       
   321             {
       
   322             TRAP_IGNORE(iObserverStructure[i].iObserver->CchEventOccuredL( 
       
   323                     aServiceId, 
       
   324                     aServiceStatus.State(),
       
   325                     aServiceStatus.Error() ));
       
   326             }
       
   327         }
       
   328 
       
   329     }
       
   330 	    
       
   331 // ---------------------------------------------------------------------------
       
   332 // CVIMPSTEngineCchHandler::RegisterCchObserverL
       
   333 // ---------------------------------------------------------------------------
       
   334 // 
       
   335 void CVIMPSTEngineCchHandler::RegisterCchObserverL(MVIMPSTEngineCchHandlerObserver* aObserver,
       
   336                                                    TCCHSubserviceType aSubServiceType )
       
   337     {
       
   338 	TRACER_AUTO;
       
   339     if(aObserver)
       
   340     	{
       
   341     	 TObserverStructure obsstruct;
       
   342 	     obsstruct.iObserver = aObserver;
       
   343 	     obsstruct.iSubserviceType = aSubServiceType;
       
   344 	     iObserverStructure.Append(obsstruct);
       
   345     	}
       
   346    
       
   347     }    
       
   348 // ---------------------------------------------------------------------------
       
   349 // CVIMPSTEngineCchHandler::UnRegisterCchObserver
       
   350 // ---------------------------------------------------------------------------
       
   351 // 
       
   352 void CVIMPSTEngineCchHandler::UnRegisterCchObserver(TCCHSubserviceType aSubServiceType )
       
   353     {
       
   354 	TRACER_AUTO;
       
   355     TInt count  = iObserverStructure.Count();
       
   356     for(TInt i = 0; i < count; i++)
       
   357     	{
       
   358     	if(aSubServiceType == iObserverStructure[i].iSubserviceType)
       
   359     		{
       
   360     		iObserverStructure[i].iObserver = NULL;
       
   361     		iObserverStructure.Remove(i);
       
   362     		iObserverStructure.Compress();
       
   363     		break;
       
   364     		}
       
   365     	}
       
   366     }    
       
   367 
       
   368 // ---------------------------------------------------------------------------
       
   369 // CVIMPSTEngineCchHandler::GetConParametersL
       
   370 // ---------------------------------------------------------------------------
       
   371 // 
       
   372 HBufC* CVIMPSTEngineCchHandler::GetConParametersL(			
       
   373 		    TCchConnectionParameter aConnParam )
       
   374     {
       
   375 	TRACER_AUTO;
       
   376 	TRACE( "ServiceId: %d", iServiceId );
       
   377 	TRACE( "TCchConnectionParameter aConnParam: (%d)", aConnParam );
       
   378     HBufC* temp = NULL;
       
   379     TInt error = KErrNotFound;
       
   380     if(iCchClient)  
       
   381 	    {
       
   382 		CCchService* service = iCchClient->GetService( iServiceId );    
       
   383 		if( service )
       
   384 		   {              
       
   385 		   RBuf buffer;
       
   386 	       CleanupClosePushL( buffer );
       
   387 		   buffer.CreateL(KVIMPSTUISPSMaxPropertyLength);
       
   388 		   
       
   389 		   TRACE( "CCHClient->GetConnectionParameter" );
       
   390 		   error = service->GetConnectionParameter(ECCHUnknown,aConnParam,buffer);
       
   391 		   User::LeaveIfError( error);
       
   392 
       
   393 		   //extract only the user id in case
       
   394 		   // Check for prefix and remove if found
       
   395 		   TInt prefixLocation = buffer.Locate( ':' );
       
   396 		   if ( KErrNotFound != prefixLocation  && ECchUsername == aConnParam )
       
   397 		       {
       
   398 		   TRACE( "Prefix found -> remove");
       
   399 		       temp = buffer.Mid(prefixLocation+1 ).AllocL(); // ownership transferred  
       
   400 		       }
       
   401 		   else
       
   402 		       {
       
   403 		   TRACE("No Prefix found");
       
   404 		       temp = buffer.AllocL(); // ownership transferred  
       
   405 		       }
       
   406 		   TRACE( "Return Value: Error: %d ", error );
       
   407 		   CleanupStack::PopAndDestroy( &buffer );
       
   408 		   }
       
   409 	    }
       
   410     return temp;
       
   411     }
       
   412 
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // Set cch connection parameter.
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 TInt CVIMPSTEngineCchHandler::SetConnectionParameter(     
       
   419     TCchConnectionParameter aConnParam,
       
   420     const TDesC& aConnParamValue )
       
   421     {
       
   422 	TRACER_AUTO;
       
   423     TRACE( "ServiceId: %d", iServiceId );
       
   424     TRACE( "TCchConnectionParameter aConnParam: (%d)", aConnParam );
       
   425     TInt error = KErrNotFound;
       
   426     if(iCchClient)
       
   427         {
       
   428         CCchService* service = iCchClient->GetService( iServiceId );
       
   429         TRACE( "CCHClient->SetConnectionParameter");
       
   430         if (service)
       
   431 	        {
       
   432 	        error =  service->SetConnectionParameter( 
       
   433 	                  ECCHUnknown, aConnParam, aConnParamValue );
       
   434 	        }
       
   435         }    
       
   436     TRACE( "error: %d", error );
       
   437     return error;
       
   438     }
       
   439     
       
   440 
       
   441 
       
   442         
       
   443 // ---------------------------------------------------------------------------
       
   444 // CVIMPSTEngineCchHandler::ChangeConnectionL
       
   445 // ---------------------------------------------------------------------------
       
   446 //
       
   447 TInt CVIMPSTEngineCchHandler::ChangeConnectionL()
       
   448     {
       
   449 	TRACER_AUTO;
       
   450 	TRACE( "ServiceId: %d", iServiceId );
       
   451    
       
   452     TInt err = KErrNone;
       
   453     if (iCchClient)
       
   454 	    {
       
   455 	    MCchUi& cchUiApi = iCchClient->CchUiApi();
       
   456 		TRAP(err, cchUiApi.ShowDialogL(iServiceId, 
       
   457 						MCchUiObserver::ECchUiDialogTypeChangeConnection););
       
   458 	    }
       
   459     
       
   460     return err;    
       
   461     } 
       
   462     
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 // CchUiApi
       
   466 // ---------------------------------------------------------------------------
       
   467 //
       
   468 MCchUi& CVIMPSTEngineCchHandler::CchUiApi() const
       
   469 	{
       
   470 	return iCchClient->CchUiApi();	
       
   471 	}
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 // CVIMPSTEngineCchHandler::IsPasswordAvailableL
       
   475 //  To check whether password available in settings or not
       
   476 //  Returns true if password is present in the settings else returns false    
       
   477 // ---------------------------------------------------------------------------
       
   478 //
       
   479 TBool CVIMPSTEngineCchHandler::IsPasswordAvailable(TCchConnectionParameter aConnParam )
       
   480     {
       
   481 	TRACER_AUTO;
       
   482 	TRACE( "TCchConnectionParameter aConnParam: (%d)", aConnParam );
       
   483     TInt passwordSet = EFalse;
       
   484     if(iCchClient)  
       
   485         {
       
   486         CCchService* service = iCchClient->GetService( iServiceId );    
       
   487         if( service )
       
   488             {              
       
   489         TRACE( "CCHClient->GetConnectionParameter");
       
   490             service->GetConnectionParameter( ECCHUnknown,aConnParam,passwordSet );
       
   491             }
       
   492         }
       
   493     return passwordSet;
       
   494     }
       
   495 
       
   496 // ---------------------------------------------------------------------------
       
   497 // CVIMPSTEngineCchHandler::ConnectivityDialogsCompletedL
       
   498 // ---------------------------------------------------------------------------
       
   499 //
       
   500 
       
   501 void CVIMPSTEngineCchHandler::ConnectivityDialogsCompletedL(
       
   502         TInt aServiceId, MCchUiObserver::TCchUiOperationResult aOperationResult )
       
   503     { 
       
   504 	TRACER_AUTO;
       
   505     if((iServiceId == aServiceId)&&(aOperationResult == ECchUiClientOperationResultConnectionChanged))
       
   506         {
       
   507         iCchUiEventObserver.HandleChangeConnectionEventL();
       
   508         }
       
   509     }
       
   510 
       
   511 // End of file
       
   512