obex/obexprotocol/obex/src/TObexServerStateGetOpSendObject.cpp
changeset 57 f6055a57ae18
parent 0 d0791faffa3f
equal deleted inserted replaced
54:4dc88a4ac6f4 57:f6055a57ae18
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <obex.h>
       
    17 #include "obexserverstatemachine.h"
       
    18 
       
    19 /**
       
    20 @file
       
    21 @internalComponent
       
    22 
       
    23 GET Operation Send State
       
    24 This state sends the object to the client and transfers to Ready once the exchange is finished
       
    25 A GET, DISCONNECT or ABORT will be processed
       
    26 Any other OBEX operation will be answered with an OBEX error code
       
    27 */
       
    28 
       
    29 TObexServerStateGetOpSendObject::TObexServerStateGetOpSendObject()
       
    30 	{
       
    31 #ifdef __FLOG_ACTIVE
       
    32 	_LIT8(KName, "GetOpSendObject");
       
    33 	iName = KName;
       
    34 #endif
       
    35 	}
       
    36 
       
    37 void TObexServerStateGetOpSendObject::Entry(CObexServerStateMachine& aContext)
       
    38 	{
       
    39 	// Chain on to Get() to start sending object
       
    40 	Get(aContext, aContext.LastReceivedPacket());
       
    41 	}
       
    42 
       
    43 void TObexServerStateGetOpSendObject::Connect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    44 	{
       
    45 	// Send ERespConflict and return to Ready
       
    46 	RespondAndEndOperation(aContext, ERespConflict);
       
    47 	}
       
    48 
       
    49 void TObexServerStateGetOpSendObject::Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket)
       
    50 	{
       
    51 	// Process disconnect
       
    52 	PerformDisconnect(aContext, aPacket);
       
    53 	}
       
    54 
       
    55 void TObexServerStateGetOpSendObject::Put(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    56 	{
       
    57 	// Send ERespBadRequest and return to Ready
       
    58 	RespondAndEndOperation(aContext, ERespBadRequest);
       
    59 	}
       
    60 
       
    61 void TObexServerStateGetOpSendObject::Get(CObexServerStateMachine& aContext, CObexPacket& aPacket)
       
    62 	{
       
    63 	if(!aPacket.IsFinal())
       
    64 		{
       
    65 		// Raising a Protocol Error will cause a Reset event resulting in a move to Disconnected.
       
    66 		// So any code after this call will potentially be executed in a different state
       
    67 		aContext.Owner().Error(KErrCommsOverrun);
       
    68 		return;
       
    69 		}
       
    70 
       
    71 	// This section prepares the next packet to send, if an error is detected or it is the final packet
       
    72 	// the machine is moved to EReady.
       
    73 	TInt err = KErrGeneral;
       
    74 	if(aContext.TransObject()->PrepareNextSendPacket(aContext.Transport().SendPacket()) == CObexBaseObject::EError ||
       
    75 		(err = aContext.Notification().GetPacketIndication()) != KErrNone)
       
    76 		{
       
    77 		aContext.Transport().SendPacket().Init(IrOBEXUtil::ObexResponse(err, ERespInternalError));
       
    78 		aContext.ChangeState(CObexServerStateMachine::EReady);
       
    79 		}
       
    80 	else if(aContext.Transport().SendPacket().IsFinal())
       
    81 		{// This is the last packet of the object being returned to client
       
    82 		aContext.ChangeState(CObexServerStateMachine::EGetOpFinal);
       
    83 		return;	
       
    84 		}
       
    85 	// Send the resultant packet
       
    86 	aContext.Transport().SendPacket().SetFinal();
       
    87 	aContext.Transport().Send();
       
    88 	}
       
    89 
       
    90 void TObexServerStateGetOpSendObject::SetPath(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    91 	{
       
    92 	// Send ERespConflict and return to Ready
       
    93 	RespondAndEndOperation(aContext, ERespConflict);
       
    94 	}
       
    95 
       
    96 void TObexServerStateGetOpSendObject::Abort(CObexServerStateMachine& aContext)
       
    97 	{
       
    98 	// Send ERespSuccess and return to Ready
       
    99 	aContext.Notification().AbortIndication();
       
   100 	RespondAndEndOperation(aContext, ERespSuccess);
       
   101 	}
       
   102 	
       
   103 void TObexServerStateGetOpSendObject::OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse)
       
   104 	{
       
   105 	// Send server app response and return to Ready
       
   106 	RespondAndEndOperation(aContext, aResponse);
       
   107 	}
       
   108