obex/obexprotocol/obex/src/TObexServerStatePutOpFinal.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 Final PUT Operation Receive State
       
    25 Waiting for reply from server app to an async notification PutCompleteIndication
       
    26 
       
    27 Any OBEX operation will cause a Protocol Error
       
    28 Chaging the MObexServerNotifyAsync via CObexServer::Start() will cause a Panic
       
    29 A Reset event (Protocol Error, Server Stop, Transport Down) will cancel the notification and move the machine to Disconnected
       
    30 The NotificationComplete event send the response back to the client and mvoe the state machine to Ready
       
    31 */
       
    32 
       
    33 TObexServerStatePutOpFinal::TObexServerStatePutOpFinal()
       
    34 	{
       
    35 #ifdef __FLOG_ACTIVE
       
    36 	_LIT8(KName, "PutOpFinalPut");
       
    37 	iName = KName;
       
    38 #endif
       
    39 	}
       
    40 
       
    41 void TObexServerStatePutOpFinal::Entry(CObexServerStateMachine& aContext)
       
    42 	{
       
    43 	// Chain on to Put() to start receiving object
       
    44 	//return Put(aContext, aContext.LastReceivedPacket());
       
    45 	aContext.Notification().PutCompleteIndication();
       
    46 	}
       
    47 
       
    48 void TObexServerStatePutOpFinal::Connect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    49 	{
       
    50 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    51 	}
       
    52 
       
    53 void TObexServerStatePutOpFinal::Disconnect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    54 	{
       
    55 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    56 	}
       
    57 
       
    58 void TObexServerStatePutOpFinal::Put(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    59 	{
       
    60 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    61 	}
       
    62 
       
    63 void TObexServerStatePutOpFinal::Get(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    64 	{
       
    65 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    66 	}
       
    67 
       
    68 void TObexServerStatePutOpFinal::SetPath(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    69 	{
       
    70 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    71 	}
       
    72 
       
    73 void TObexServerStatePutOpFinal::Abort(CObexServerStateMachine& aContext)
       
    74 	{
       
    75 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    76 	}
       
    77 	
       
    78 void TObexServerStatePutOpFinal::OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse /*aResponse*/)
       
    79 	{
       
    80 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    81 	}
       
    82 
       
    83 void TObexServerStatePutOpFinal::Start(CObexServerStateMachine& /*aContext*/)
       
    84 	{
       
    85 	// Panic - trying to change interface during wait
       
    86 	IrOBEXUtil::Panic(EChangeInterfaceDuringWait);
       
    87 	}
       
    88 
       
    89 // Utility function to handle the optional header set to send at the completion of the Put
       
    90 void TObexServerStatePutOpFinal::PrepareFinalResponseHeaderSet(CObexHeader* aHeader, CObexHeaderSet& aHeaderSet, CObexPacket& aPacket)
       
    91 	{
       
    92 	//	We have some additional headers to send, on a best effort
       
    93 	//	basis...
       
    94 	TObexInternalHeader intHeader;
       
    95 	aHeaderSet.First();
       
    96 	TBool insertedOK=ETrue;
       
    97 
       
    98 	while(insertedOK && (aHeaderSet.This(aHeader)==KErrNone))
       
    99 		{
       
   100 		switch(aHeader->Type())
       
   101 			{
       
   102 		case CObexHeader::EUnicode:
       
   103 			intHeader.Set(aHeader->HI(), aHeader->AsUnicode());
       
   104 			break;
       
   105 			
       
   106 		case CObexHeader::EByteSeq:
       
   107 			intHeader.Set(aHeader->HI(), (const_cast<TUint8*> ((aHeader->AsByteSeq()).Ptr())), (aHeader->AsByteSeq()).Size());
       
   108 			break;
       
   109 			
       
   110 		case CObexHeader::EByte:
       
   111 			intHeader.Set(aHeader->HI(), aHeader->AsByte());
       
   112 			break;
       
   113 			
       
   114 		case CObexHeader::EFourByte:
       
   115 			intHeader.Set(aHeader->HI(), aHeader->AsFourByte());
       
   116 			break;
       
   117 			}
       
   118 
       
   119 		insertedOK=aPacket.InsertData(intHeader); 
       
   120 							
       
   121 		(void)aHeaderSet.Next();
       
   122 		}
       
   123 	}
       
   124 	
       
   125 void TObexServerStatePutOpFinal::Reset(CObexServerStateMachine& aContext)
       
   126 	{
       
   127 	// Cancel notification - if it has not already been activated
       
   128 	if (!aContext.IsCallBackActive())
       
   129 		{
       
   130 		aContext.Notification().CancelIndicationCallback();
       
   131 		}
       
   132 	aContext.CancelCallBack();
       
   133 	aContext.ChangeState(CObexServerStateMachine::EDisconnected);
       
   134 	}
       
   135 	
       
   136 void TObexServerStatePutOpFinal::RequestCompleteNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse)
       
   137 	{
       
   138 	aContext.SetAppResponse(aAppResponse);
       
   139 	aContext.CallBack(TObexServerStatePutOpFinal::ProcessNotification);
       
   140 	}
       
   141 	
       
   142 TInt TObexServerStatePutOpFinal::ProcessNotification(TAny* aPtr)
       
   143 	{
       
   144 	CObexServerStateMachine& context = *static_cast<CObexServerStateMachine*>(aPtr);
       
   145 	
       
   146 	context.Transport().SendPacket().Init(context.AppResponse());
       
   147 	context.Transport().SendPacket().SetFinal();	//	Because it is
       
   148 	
       
   149 	// Check for additional headers to send
       
   150 	if(context.PutFinalResponseHeaderSet())
       
   151 		{
       
   152 		PrepareFinalResponseHeaderSet(	context.GetHeader(),
       
   153 						*(context.PutFinalResponseHeaderSet()),
       
   154 						context.Transport().SendPacket());
       
   155 		// delete the headers now they've been used
       
   156 		context.SetPutFinalResponseHeaderSet(NULL);
       
   157 		}
       
   158 	
       
   159 	context.Transport().Send();
       
   160 	context.ChangeState(CObexServerStateMachine::EReady);
       
   161 	
       
   162 	return KErrNone;
       
   163 	}
       
   164 
       
   165 TBool TObexServerStatePutOpFinal::ValidResponse(TObexResponse aResponseCode)
       
   166 	{
       
   167 	return (aResponseCode>0 && aResponseCode<=255 && aResponseCode != ERespContinue);
       
   168 	}
       
   169