multimediacommsengine/tsrc/MMCTestDriver/MCETester/src/TCmdGetState.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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 
       
    20 #include "MCEConstants.h"
       
    21 #include "TCmdGetState.h"
       
    22 #include "CTcMCEContext.h"
       
    23 #include <MCESession.h>
       
    24 #include "CTcMCEReceived.h"
       
    25 
       
    26 
       
    27 void TCmdGetState::ExecuteL()
       
    28 	{
       
    29 
       
    30 	// -- Execution ------
       
    31 	
       
    32 	// Get an item off the receive queue (waits until timeout if none is present)
       
    33 
       
    34 	TInt timeout = ExtractIntegerL( KParamTimeout, KDefaultReceiveTimeout, 
       
    35 									EFalse );
       
    36 	CTcMCEReceived& item = iContext.ReceivedSessionItemL( timeout );	
       
    37 	
       
    38 	const CMceSession* session = NULL;
       
    39 	
       
    40 	if ( item.Session() )
       
    41 		{
       
    42 		session = item.Session();
       
    43 		}
       
    44 	
       
    45 	if ( !session ) 
       
    46 		{	
       
    47 		// If first item doesn't contain a session
       
    48 		User::Leave(KErrNotFound); 	
       
    49 		}	
       
    50 
       
    51  	CMceSession* expectedSession = reinterpret_cast<CMceSession*>
       
    52  		(GetObjectForIdL(KSessionId, ETrue));
       
    53 	
       
    54 	/*if ( session != expectedSession && session != expectedSession )
       
    55 		{
       
    56 		// If the first item's containing session is not the expected
       
    57 		User::Leave(KErrNotFound); 
       
    58 		}
       
    59 	*/		
       
    60 	CMceSession::TState state = item.Session()->State();
       
    61 	//SessionState();
       
    62 	
       
    63 	TBool connectionActive = session->ConnectionActive();
       
    64 	
       
    65 	// -- Response creation ----------------------------------------------------	
       
    66 
       
    67 	// Add Session
       
    68 	AddIdResponseL( KSessionId, *session );
       
    69 	
       
    70 	// Add state
       
    71 	AddIntegerResponseL(KResponseState, state);
       
    72 	AddTextualSessionStateL(state);
       
    73 	
       
    74 	// Add connection state
       
    75 	AddBooleanResponseL(KResponseConnectionActive, connectionActive);	
       
    76 	
       
    77 	// Add Headers
       
    78 	AddHeadersL( item.Headers() ); 
       
    79 	
       
    80 	// Add Body
       
    81 	if (item.Body())
       
    82 		{
       
    83 		if (item.Body()->Length() > 0)
       
    84 			{	
       
    85 			AddTextResponseL(KResponseBody, *(item.Body()));	
       
    86 			}
       
    87 		}
       
    88 	
       
    89 	// Add StatusCode
       
    90 	AddIntegerResponseL(KResponseStatusCode, item.StatusCode());
       
    91 
       
    92 	// Add ReasonPhrase
       
    93 	if (item.ReasonPhrase())
       
    94 		{
       
    95 		if (item.ReasonPhrase()->Length() > 0)
       
    96 			{	
       
    97 			AddTextResponseL(KResponseReasonPhrase, 
       
    98 				 			 *(item.ReasonPhrase()));	
       
    99 			}
       
   100 		}
       
   101 	
       
   102 	// Add Error
       
   103 	if ( item.Error() != KErrNone )
       
   104 		{
       
   105 		AddIntegerResponseL( KResponseError, item.Error() );
       
   106 		}	
       
   107 	}
       
   108 
       
   109 TBool TCmdGetState::Match( const TTcIdentifier& aId )
       
   110 	{
       
   111 	return TTcMceCommandBase::Match( aId, _L8("GetState") );
       
   112 	}
       
   113 
       
   114 TTcCommandBase* TCmdGetState::CreateL( MTcTestContext& aContext )
       
   115 	{
       
   116 	return new( ELeave ) TCmdGetState( aContext );
       
   117 	}