obex/obexprotocol/obex/src/TObexServerStatePutOpReceiveObject.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     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 <obex/internal/obexinternalheader.h>
       
    18 #include "obexserverstatemachine.h"
       
    19 
       
    20 /**
       
    21 @file
       
    22 @internalComponent
       
    23 
       
    24 PUT Operation Receive State
       
    25 This state receive the object from the client and transfers to Ready once the exchange is finished
       
    26 A PUT, DISCONNECT or ABORT will be processed
       
    27 Any other OBEX operation will be answered with an OBEX error code
       
    28 */
       
    29 
       
    30 TObexServerStatePutOpReceiveObject::TObexServerStatePutOpReceiveObject()
       
    31 	{
       
    32 #ifdef __FLOG_ACTIVE
       
    33 	_LIT8(KName, "PutOpReceiveObject");
       
    34 	iName = KName;
       
    35 #endif
       
    36 	}
       
    37 
       
    38 void TObexServerStatePutOpReceiveObject::Entry(CObexServerStateMachine& aContext)
       
    39 	{
       
    40 	// Chain on to Put() to start receiving object
       
    41 	Put(aContext, aContext.LastReceivedPacket());
       
    42 	}
       
    43 
       
    44 void TObexServerStatePutOpReceiveObject::Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket)
       
    45 	{
       
    46 	// Process disconnect
       
    47 	PerformDisconnect(aContext, aPacket);
       
    48 	}
       
    49 
       
    50 void TObexServerStatePutOpReceiveObject::Put(CObexServerStateMachine& aContext, CObexPacket& aPacket)
       
    51 	{
       
    52 	//Initialise 'err' to KErrNone:
       
    53 	//if ParseNextReceivePacket returns an error, we want 
       
    54 	//IrOBEXUtil::ObexResponse to return that error unchanged
       
    55 	//See: IrOBEXUtil::ObexResponse
       
    56 	TInt err = KErrNone; 
       
    57 
       
    58 	// Process Put packet into receive object
       
    59 	if(aContext.TransObject()->ParseNextReceivePacket(aPacket) == CObexBaseObject::EError 
       
    60 		||(err = aContext.Notification().PutPacketIndication()) != KErrNone)
       
    61 		{// Error in receive
       
    62 		aContext.Transport().Send(IrOBEXUtil::ObexResponse(err, aContext.TransObject()->GetLastError()));
       
    63 		aContext.Notification().ErrorIndication(KErrGeneral);
       
    64 		aContext.ChangeState(CObexServerStateMachine::EReady);
       
    65 		}
       
    66 
       
    67 	//ConnectionID is compulsory if Target header was used at connection
       
    68 	else if ( aContext.Owner().CheckObjectForConnectionId(*(aContext.TransObject())))
       
    69 		{
       
    70 		if(aPacket.IsFinal())
       
    71 			{// Successfully received
       
    72 			aContext.ChangeState(CObexServerStateMachine::EPutOpFinal);
       
    73 			}
       
    74 		else // not final packet
       
    75 			{
       
    76 			aContext.Transport().Send(ERespContinue);
       
    77 			}
       
    78 		}
       
    79 	else
       
    80 		{
       
    81 		aContext.Transport().Send(ERespServiceUnavailable); //connectionID was incorrect or not received
       
    82 		}
       
    83 	}
       
    84 
       
    85 
       
    86 void TObexServerStatePutOpReceiveObject::Connect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    87 	{
       
    88 	// Send ERespConflict and return to Ready
       
    89 	RespondAndEndOperation(aContext, ERespConflict);
       
    90 	}
       
    91 
       
    92 void TObexServerStatePutOpReceiveObject::Get(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    93 	{
       
    94 	// Send ERespConflict and return to Ready
       
    95 	RespondAndEndOperation(aContext, ERespConflict);
       
    96 	}
       
    97 
       
    98 void TObexServerStatePutOpReceiveObject::SetPath(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    99 	{
       
   100 	// Send ERespConflict and return to Ready
       
   101 	RespondAndEndOperation(aContext, ERespConflict);
       
   102 	}
       
   103 
       
   104 void TObexServerStatePutOpReceiveObject::Abort(CObexServerStateMachine& aContext)
       
   105 	{
       
   106 	// Send ERespSuccess and return to Ready
       
   107 	aContext.Notification().AbortIndication();
       
   108 	RespondAndEndOperation(aContext, ERespSuccess);
       
   109 	}
       
   110 	
       
   111 void TObexServerStatePutOpReceiveObject::OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse)
       
   112 	{
       
   113 	// Send server app response and return to Ready
       
   114 	RespondAndEndOperation(aContext, aResponse);
       
   115 	}
       
   116 
       
   117