multimediacommsengine/tsrc/testdriver/siptester/src/TCmdSetUNSAFTimers.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <centralrepository.h>
       
    20 #include <unsafprotocolscrkeys.h>
       
    21 #include "CTcSIPContext.h"
       
    22 #include "TCmdSetUNSAFTimers.h"
       
    23 #include "SIPConstants.h"
       
    24 
       
    25 //This value must be same as declared in CUNSAFCRSettings.h
       
    26 const TInt KMaxServerNameLen = 256;
       
    27 
       
    28 /**
       
    29  * INPUT:
       
    30  *   Headers:		-
       
    31  *   Parameters:	KParamIAPName,
       
    32  *	 				KParamDomainName,
       
    33  *					KParamUNSAFBindingRequestInterval,
       
    34  *					KParamUNSAFUDPKeepaliveInterval
       
    35  *					KParamUNSAFTCPKeepaliveInterval
       
    36  *   IDs:			-
       
    37  *
       
    38  * OUTPUT:
       
    39  *   Parameters:	-
       
    40  *   IDs:			-
       
    41  */
       
    42 void TCmdSetUNSAFTimers::ExecuteL()
       
    43 	{
       
    44 	TInt requestInterval( 0 );
       
    45 	TInt udpKeepAlive( 0 );
       
    46 	TInt tcpKeepAlive( 0 );
       
    47 	TBool writeToRepository = ReadInputParametersL( requestInterval,
       
    48 													udpKeepAlive,
       
    49 													tcpKeepAlive );	
       
    50 
       
    51 	CRepository* repository = CRepository::NewLC( KCRUidUNSAFProtocols );
       
    52 	TUint32 key( 0 );
       
    53 	// Existing values in repository are not needed
       
    54 	TInt dummyRequestInterval( 0 );
       
    55 	TInt dummyUdpKeepAlive( 0 );
       
    56 	TInt dummyTcpKeepAlive( 0 );
       
    57 	TInt status = ReadTimerValuesL( *repository,
       
    58 								    key,
       
    59 								    dummyRequestInterval,
       
    60 								    dummyUdpKeepAlive,
       
    61 								    dummyTcpKeepAlive );
       
    62 	__ASSERT_ALWAYS( status == KErrNone || status == KErrNotFound,
       
    63 					 User::Leave( status ) );
       
    64 
       
    65 
       
    66 	if ( writeToRepository )
       
    67 		{		
       
    68 		SetValuesToRepositoryL( *repository,
       
    69 								status,
       
    70 								key,
       
    71 								requestInterval,
       
    72 								udpKeepAlive,
       
    73 								tcpKeepAlive );
       
    74 		}
       
    75 	else
       
    76 		{
       
    77 		if ( status == KErrNone )
       
    78 			{
       
    79 			RemoveParameterL( *repository,
       
    80 							  KUNSAFProtocolsIntervalUDPMask | key );
       
    81 			RemoveParameterL( *repository,
       
    82 							  KUNSAFProtocolsIntervalTCPMask | key );
       
    83 			RemoveParameterL( *repository,
       
    84 							  KUNSAFProtocolsSTUNRetransmitTimerMask | key );
       
    85 			RemoveParameterL( *repository,
       
    86 							  KUNSAFProtocolsDomainIntervalUDPMask | key );
       
    87 			RemoveParameterL( *repository,
       
    88 							  KUNSAFProtocolsDomainIntervalTCPMask | key );
       
    89 			}
       
    90 		}
       
    91 
       
    92 	CleanupStack::PopAndDestroy( repository );
       
    93 	}
       
    94 
       
    95 TBool TCmdSetUNSAFTimers::Match( const TTcIdentifier& aId )
       
    96 	{
       
    97 	return TTcSIPCommandBase::Match( aId, _L8("SetUNSAFTimers") );
       
    98 	}
       
    99 
       
   100 TTcCommandBase* TCmdSetUNSAFTimers::CreateL( MTcTestContext& aContext )
       
   101 	{
       
   102 	return new( ELeave ) TCmdSetUNSAFTimers( aContext );
       
   103 	}
       
   104 
       
   105 TBool
       
   106 TCmdSetUNSAFTimers::ReadInputParametersL( TInt& aBindingRequestInterval,
       
   107 									  	  TInt& aUdpKeepAliveInterval,
       
   108 									  	  TInt& aTcpKeepAliveInterval ) const
       
   109 	{
       
   110 	aBindingRequestInterval =
       
   111 		ExtractIntegerL( KParamUNSAFBindingRequestInterval,
       
   112 						 KErrNotFound,
       
   113 						 EFalse );
       
   114 	aUdpKeepAliveInterval =
       
   115 		ExtractIntegerL( KParamUNSAFUDPKeepaliveInterval,
       
   116 						 KErrNotFound,
       
   117 						 EFalse );
       
   118 	aTcpKeepAliveInterval =
       
   119 		ExtractIntegerL( KParamUNSAFTCPKeepaliveInterval,
       
   120 						 KErrNotFound,
       
   121 						 EFalse );
       
   122 	return ( aBindingRequestInterval >= 0 ||
       
   123 			 aUdpKeepAliveInterval >= 0 ||
       
   124 			 aTcpKeepAliveInterval >= 0 );
       
   125 	}
       
   126 
       
   127 void TCmdSetUNSAFTimers::SetValuesToRepositoryL(
       
   128 	CRepository& aRepository,
       
   129 	TInt aStatus,
       
   130 	TUint32 aKey,
       
   131 	TInt aBindingRequestInterval,
       
   132 	TInt aUdpKeepAliveInterval,
       
   133 	TInt aTcpKeepAliveInterval )
       
   134 	{
       
   135 	User::LeaveIfError(
       
   136 		aRepository.StartTransaction(
       
   137 			CRepository::EConcurrentReadWriteTransaction ) );
       
   138     aRepository.CleanupCancelTransactionPushL();
       
   139 
       
   140 	TPtrC8 iapName = ExtractTextL( KParamIAPName, EFalse );
       
   141 	if( iapName != KNullDesC8 )
       
   142 		{
       
   143 		TInt iapId = iContext.IAPIdL( iapName );
       
   144 		if ( aStatus == KErrNotFound )
       
   145 			{
       
   146 			aKey = CreateNewKeyL( aRepository,
       
   147                                   KUNSAFProtocolsIAPIdMask,
       
   148                                   KUNSAFProtocolsIAPTableMask );
       
   149 			WriteL( aRepository, KUNSAFProtocolsIAPIdMask | aKey, iapId );
       
   150 			}
       
   151 		WriteIapParamsL( aRepository,
       
   152 					 	 aKey,
       
   153 					 	 aBindingRequestInterval,
       
   154 					 	 aUdpKeepAliveInterval,
       
   155 					 	 aTcpKeepAliveInterval );
       
   156 		}
       
   157 	else
       
   158 		{
       
   159 		// Since IAP was not given, domain is now mandatory
       
   160 		TPtrC8 domainName = ExtractTextL( KParamDomainName, ETrue );
       
   161 		if ( aStatus == KErrNotFound )
       
   162 			{
       
   163 		    aKey = CreateNewKeyL( aRepository,
       
   164                                   KUNSAFProtocolsDomainMask,
       
   165                                   KUNSAFProtocolsDomainTableMask );
       
   166 		    WriteL( aRepository, KUNSAFProtocolsDomainMask | aKey, domainName );
       
   167 			}
       
   168 	    WriteDomainParamsL( aRepository, 
       
   169 							aKey,
       
   170 							aUdpKeepAliveInterval,
       
   171 							aTcpKeepAliveInterval );
       
   172 		}
       
   173 
       
   174 	TUint32 dummy( 0 );
       
   175     User::LeaveIfError( aRepository.CommitTransaction( dummy ) );
       
   176     CleanupStack::Pop( 1 ); // transaction
       
   177 	}
       
   178 
       
   179 void TCmdSetUNSAFTimers::WriteIapParamsL( CRepository& aRepository,
       
   180 										  TUint32 aKey,
       
   181 										  TInt aBindingRequestInterval,
       
   182 										  TInt aUdpKeepAliveInterval,
       
   183 										  TInt aTcpKeepAliveInterval )
       
   184     {    
       
   185     WriteL( aRepository, 
       
   186             KUNSAFProtocolsIntervalUDPMask | aKey,
       
   187             aUdpKeepAliveInterval );
       
   188 	WriteL( aRepository,
       
   189             KUNSAFProtocolsIntervalTCPMask | aKey,
       
   190             aTcpKeepAliveInterval );
       
   191     WriteL( aRepository,
       
   192             KUNSAFProtocolsSTUNRetransmitTimerMask | aKey,
       
   193             aBindingRequestInterval );
       
   194     }
       
   195 
       
   196 void TCmdSetUNSAFTimers::WriteDomainParamsL( CRepository& aRepository, 
       
   197 										     TUint32 aKey,
       
   198 										     TInt aUdpKeepAliveInterval,
       
   199 										     TInt aTcpKeepAliveInterval )
       
   200     {
       
   201     WriteL( aRepository,
       
   202             KUNSAFProtocolsDomainIntervalUDPMask | aKey,
       
   203             aUdpKeepAliveInterval );
       
   204 	WriteL( aRepository,
       
   205             KUNSAFProtocolsDomainIntervalTCPMask | aKey,
       
   206             aTcpKeepAliveInterval );
       
   207     }