imstutils/imconversationview/imcvuiengine/src/cimcvenginecchhandler.cpp
changeset 0 5e5d6b214f4f
child 3 3aab497fdbb7
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     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
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32def.h>
       
    21 #include <cchserver.h>
       
    22 #include <cchclient.h>
       
    23 #include <spsettings.h>
       
    24 #include <spproperty.h>
       
    25 #include "cimcvenginefactory.h"
       
    26 
       
    27 #include "cimcvenginecchhandler.h"
       
    28 #include "imcvuiliterals.h"
       
    29 
       
    30 #include "imcvlogger.h"
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CIMCVEngineCchHandler::CIMCVEngineCchHandler
       
    38 // ---------------------------------------------------------------------------
       
    39 // 
       
    40 CIMCVEngineCchHandler::CIMCVEngineCchHandler(TUint aServiceId, 
       
    41 											 CIMCVEngine& aEngine)
       
    42 : iServiceId(aServiceId),
       
    43 iEngine(aEngine)
       
    44     {        
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CIMCVEngineCchHandler::ConstructL
       
    49 // ---------------------------------------------------------------------------
       
    50 // 
       
    51 void CIMCVEngineCchHandler::ConstructL(  )
       
    52     {
       
    53     // Create service selection here
       
    54 	iCchClient = CCch::NewL();
       
    55 	
       
    56 	if (iCchClient)
       
    57 		{		
       
    58 		CCchService* service = iCchClient->GetService( iServiceId );	
       
    59 		
       
    60 		if( service )
       
    61 			{
       
    62 			service->SetObserver( *this );		
       
    63 			}
       
    64 		}		
       
    65 		
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CIMCVEngineCchHandler::NewL
       
    70 // ---------------------------------------------------------------------------
       
    71 // 
       
    72 CIMCVEngineCchHandler* 
       
    73     CIMCVEngineCchHandler::NewL( TUint aServiceId, CIMCVEngine& aEngine )
       
    74     {
       
    75     CIMCVEngineCchHandler* self = NewLC(aServiceId, aEngine);
       
    76     CleanupStack::Pop(self);
       
    77     return self;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CIMCVEngineCchHandler::NewLC
       
    82 // ---------------------------------------------------------------------------
       
    83 // 
       
    84 CIMCVEngineCchHandler* 
       
    85     CIMCVEngineCchHandler::NewLC(TUint aServiceId, CIMCVEngine& aEngine )
       
    86     {
       
    87     CIMCVEngineCchHandler* self =
       
    88         new (ELeave) CIMCVEngineCchHandler(aServiceId, aEngine);
       
    89     CleanupStack::PushL(self);
       
    90     self->ConstructL( );
       
    91     return self;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CIMCVEngineCchHandler::~CIMCVEngineCchHandler
       
    96 // ---------------------------------------------------------------------------
       
    97 // 
       
    98 CIMCVEngineCchHandler::~CIMCVEngineCchHandler()
       
    99     {
       
   100 	
       
   101 	if(iCchClient)
       
   102     	{
       
   103     	CCchService* service = iCchClient->GetService( iServiceId );
       
   104     	if( service )
       
   105 			{
       
   106 			service->RemoveObserver();
       
   107 			}    	
       
   108     	delete iCchClient; 	
       
   109     	}
       
   110    
       
   111     }
       
   112 
       
   113 
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CIMCVEngineCchHandler::GetServiceState
       
   117 // ---------------------------------------------------------------------------
       
   118 // 
       
   119 TInt CIMCVEngineCchHandler::GetServiceState(
       
   120 									TCCHSubserviceState& aCCHState
       
   121 									)
       
   122     {
       
   123    	TInt err = KErrNone;
       
   124    	CCchService* service = iCchClient->GetService( iServiceId );
       
   125    	TCchServiceStatus status;
       
   126 	status.SetState(ECCHUninitialized);
       
   127 
       
   128 	if( service )
       
   129 		{
       
   130 		// Get status from the client
       
   131 		err = service->GetStatus( ECCHIMSub, status );
       
   132 		}		
       
   133     
       
   134     aCCHState = status.State();
       
   135     
       
   136 	return err;   	
       
   137     }
       
   138 
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // CIMCVEngineCchHandler::EnableService
       
   142 // ---------------------------------------------------------------------------
       
   143 // 
       
   144 TInt CIMCVEngineCchHandler::EnableService()
       
   145     {
       
   146        
       
   147     // Retrieve service interface from the CCH client to be used to
       
   148 	// enable aServiceType
       
   149 	CCchService* service = iCchClient->GetService( iServiceId );
       
   150 	//Allowing Connectivity Dialogs for cch
       
   151     iCchClient->SetConnectivityDialogsAllowed( ETrue );
       
   152 
       
   153 	// By default set to fault value; if service pointer is valid then we
       
   154 	// return the disable value, otherwise we return KErrNotFound
       
   155 	TInt error = KErrNotFound;
       
   156 	if( service )
       
   157 		{		
       
   158 	
       
   159 		error = service->Enable( ECCHUnknown );
       
   160 		
       
   161 		}
       
   162     
       
   163 
       
   164 	return error;    
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CIMCVEngineCchHandler::GetAdapterUidL()
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 TInt CIMCVEngineCchHandler::GetAdapterUidL()
       
   172     {
       
   173     TInt ret = KErrNotFound;
       
   174     CSPProperty* property = CSPProperty::NewLC();
       
   175     CSPSettings* settings = CSPSettings::NewLC();
       
   176     TInt err = settings->FindPropertyL( iServiceId,
       
   177             EPropertyPCSPluginId,*property );   
       
   178     if (KErrNone == err)
       
   179         {
       
   180         property->GetValue( ret );
       
   181         }
       
   182     CleanupStack::PopAndDestroy( settings );
       
   183     CleanupStack::PopAndDestroy( property );
       
   184     return ret;
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CIMCVEngineCchHandler::GetUserIdL
       
   189 // ---------------------------------------------------------------------------
       
   190 // 
       
   191 HBufC* CIMCVEngineCchHandler::GetUserIdL()
       
   192     {
       
   193     HBufC* temp = NULL;
       
   194     CCchService* service = iCchClient->GetService( iServiceId );
       
   195     // By default set to fault value; if service pointer is valid then we
       
   196     // return the disable value, otherwise we return KErrNotFound
       
   197     TInt error = KErrNotFound;
       
   198     if( service )
       
   199        {                  
       
   200        RBuf username;
       
   201        username.Create(KMAXUSERIDLENGTH);
       
   202        CleanupClosePushL( username ); 
       
   203        error = service->GetConnectionParameter(ECCHIMSub,ECchUsername,username);
       
   204        User::LeaveIfError( error);
       
   205        if( username.Length() > 0)
       
   206           {
       
   207           temp = username.AllocL(); // ownership transferred 
       
   208           }       
       
   209        CleanupStack::PopAndDestroy( &username );
       
   210       }
       
   211     return temp;        
       
   212     }
       
   213     
       
   214 
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CIMCVEngineCchHandler::DisableService
       
   218 // ---------------------------------------------------------------------------
       
   219 // 
       
   220 TInt CIMCVEngineCchHandler::DisableService()
       
   221     {
       
   222        
       
   223     // Retrieve service interface from the CCH client to be used to
       
   224 	// enable aServiceType
       
   225 	CCchService* service = iCchClient->GetService( iServiceId );
       
   226 	// By default set to fault value; if service pointer is valid then we
       
   227 	// return the disable value, otherwise we return KErrNotFound
       
   228 	TInt error = KErrNotFound;
       
   229 	if( service )
       
   230 		{
       
   231 		error = service->Disable( ECCHUnknown );
       
   232 		}
       
   233     
       
   234 
       
   235 	return error;    
       
   236     }
       
   237 
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CIMCVEngineCchHandler::IsServiceLoggedIn
       
   241 // ---------------------------------------------------------------------------
       
   242 //        
       
   243 TBool CIMCVEngineCchHandler::IsServiceLoggedIn()
       
   244 	{	
       
   245 	TCCHSubserviceState serviceState = ECCHUninitialized;
       
   246 
       
   247 	TInt error = GetServiceState( serviceState ); 
       
   248 	    			
       
   249 	if ( !error && ECCHEnabled == serviceState )
       
   250 	    {
       
   251 	    return ETrue;	
       
   252 	    }
       
   253 	
       
   254 	return EFalse;	    
       
   255 	    
       
   256 	}
       
   257          	  
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CIMCVEngineCchHandler::ServiceStatusChanged
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CIMCVEngineCchHandler::ServiceStatusChanged(
       
   264 				TInt aServiceId,
       
   265 				const TCCHSubserviceType aType,
       
   266 				const TCchServiceStatus& aServiceStatus )
       
   267 	{	
       
   268 	TRAP_IGNORE(DoHandleServiceStatusChangedL(aServiceId, aType, aServiceStatus));
       
   269 	} 
       
   270 
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // CIMCVEngineCchHandler::DoHandleServiceStatusChanged
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 void CIMCVEngineCchHandler::DoHandleServiceStatusChangedL(
       
   277 				TInt aServiceId,
       
   278 				const TCCHSubserviceType aType,
       
   279 				const TCchServiceStatus& aServiceStatus )
       
   280 	{
       
   281 	
       
   282     IM_CV_LOGS(TXT("CVEngineCCHHnadler::DoHandleServiceStatusChangedL ") );   
       
   283 	
       
   284 	if (aType == ECCHIMSub)
       
   285 		{
       
   286 		MIMCVEngineCCHObserver::TServiceState notifyEvent = 
       
   287 									MIMCVEngineCCHObserver::ENotLoggedIn;
       
   288 		switch (aServiceStatus.State())
       
   289 			{
       
   290 			case ECCHUninitialized:
       
   291 				{
       
   292 				//Nothing to be done			
       
   293 				break;	
       
   294 				}
       
   295 			case ECCHDisabled:
       
   296 				{
       
   297 				IM_CV_LOGS(TXT("CVEngineCCHHnadler::DoHandleServiceStatusChangedL DISABLED"));   
       
   298 				iEngine.CloseAllOpenChatsL ();
       
   299 				iEngine.ReleaseConnectionL();
       
   300 				iEngine.DeleteContextL ();
       
   301 
       
   302 				break;	
       
   303 				}
       
   304 			case ECCHConnecting:
       
   305 				{
       
   306 				notifyEvent = MIMCVEngineCCHObserver::EConnecting;
       
   307 				break;	
       
   308 				}
       
   309 			case ECCHEnabled:
       
   310 				{
       
   311 				notifyEvent = MIMCVEngineCCHObserver::ELogin;
       
   312 				iEngine.CreateContextL();
       
   313 				break;	
       
   314 				}
       
   315 			case ECCHDisconnecting:
       
   316 				{
       
   317 				// If NetworkErrorLost error is received by CCH on this state, then do not close all chats
       
   318 				// as user would loose all the on-going conversation when the network connection is
       
   319 				// restored.				
       
   320 				if (aServiceStatus.Error () != KCCHErrorNetworkLost )
       
   321 				iEngine.CloseAllOpenChatsL();
       
   322 				notifyEvent = MIMCVEngineCCHObserver::EDisconnecting;
       
   323 				break;	
       
   324 				}
       
   325 			default:
       
   326 				{
       
   327 				break;	
       
   328 				}
       
   329 			}
       
   330 			
       
   331 		if (iObserver)
       
   332 			{
       
   333 			iObserver->ServiceStatusChanged( aServiceId,     								   
       
   334                                  notifyEvent );
       
   335 					
       
   336 			}
       
   337 										
       
   338 		}	        
       
   339 	} 
       
   340 
       
   341 // ---------------------------------------------------------------------------
       
   342 // CIMCVEngineCchHandler::RegisterObserver
       
   343 // ---------------------------------------------------------------------------
       
   344 //	
       
   345 void CIMCVEngineCchHandler::RegisterObserver(MIMCVEngineCCHObserver* aObserver)
       
   346 	{
       
   347 	if (aObserver)
       
   348 		{
       
   349 		iObserver = aObserver;
       
   350 		}
       
   351 	}
       
   352 
       
   353 
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // CIMCVEngineCchHandler::UnRegisterObserver
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 void CIMCVEngineCchHandler::UnRegisterObserver()
       
   360 	{
       
   361 	iObserver = NULL;	
       
   362 	}
       
   363 	        	  
       
   364 
       
   365 // End of file
       
   366