obex/obexprotocol/obex/src/TObexServerStatePutOpWaitForUser.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 PUT Operation Wait State
       
    24 This state issues the Put indication to the Application on entry and then waits for the response.
       
    25 
       
    26 Any OBEX operation will be cause a Protocol Error
       
    27 Chaging the MObexServerNotifyAsync via CObexServer::Start() will cause a Panic
       
    28 A Reset event (Protocol Error, Server Stop, Transport Down) will cancel the notification and move the machine to Disconnected
       
    29 The NotificationComplete event will queue a async one-shot to process the returned object, moving the machine to PutOpReceiveObject
       
    30 */
       
    31 
       
    32 TObexServerStatePutOpWaitForUser::TObexServerStatePutOpWaitForUser()
       
    33 	{
       
    34 #ifdef __FLOG_ACTIVE
       
    35 	_LIT8(KName, "PutOpWaitForUser");
       
    36 	iName = KName;
       
    37 #endif
       
    38 	}
       
    39 
       
    40 void TObexServerStatePutOpWaitForUser::Entry(CObexServerStateMachine& aContext)
       
    41 	{
       
    42 	// Send notification to the Application
       
    43 	aContext.SetTransObject(NULL);
       
    44 	
       
    45 	aContext.Notification().PutRequestIndication();
       
    46 	}
       
    47 
       
    48 void TObexServerStatePutOpWaitForUser::Connect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    49 	{
       
    50 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    51 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    52 	}
       
    53 
       
    54 void TObexServerStatePutOpWaitForUser::Disconnect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    55 	{
       
    56 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    57 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    58 	}
       
    59 
       
    60 void TObexServerStatePutOpWaitForUser::Put(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    61 	{
       
    62 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    63 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    64 	}
       
    65 
       
    66 void TObexServerStatePutOpWaitForUser::Get(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    67 	{
       
    68 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    69 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    70 	}
       
    71 
       
    72 void TObexServerStatePutOpWaitForUser::SetPath(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    73 	{
       
    74 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    75 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    76 	}
       
    77 
       
    78 void TObexServerStatePutOpWaitForUser::Abort(CObexServerStateMachine& aContext)
       
    79 	{
       
    80 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    81 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    82 	}
       
    83 	
       
    84 void TObexServerStatePutOpWaitForUser::OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse /*aResponse*/)
       
    85 	{
       
    86 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    87 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    88 	}
       
    89 
       
    90 void TObexServerStatePutOpWaitForUser::Start(CObexServerStateMachine& /*aContext*/)
       
    91 	{
       
    92 	// Panic - trying to change interface during wait
       
    93 	IrOBEXUtil::Panic(EChangeInterfaceDuringWait);
       
    94 	}
       
    95 
       
    96 void TObexServerStatePutOpWaitForUser::Reset(CObexServerStateMachine& aContext)
       
    97 	{
       
    98 	// Cancel notification - if it has not already been activated
       
    99 	if (!aContext.IsCallBackActive())
       
   100 		{
       
   101 		aContext.Notification().CancelIndicationCallback();
       
   102 		}
       
   103 	aContext.CancelCallBack();
       
   104 	aContext.ChangeState(CObexServerStateMachine::EDisconnected);
       
   105 	}
       
   106 
       
   107 void TObexServerStatePutOpWaitForUser::RequestNotificationCompleted(CObexServerStateMachine& aContext, CObexBaseObject* aObject)
       
   108 	{
       
   109 	aContext.SetTransObject(aObject);
       
   110 	aContext.CallBack(TObexServerStatePutOpWaitForUser::ProcessNotification);
       
   111 	}
       
   112 
       
   113 void TObexServerStatePutOpWaitForUser::RequestNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse)
       
   114 	{
       
   115 	aContext.SetAppResponse(aAppResponse);
       
   116 	aContext.CallBack(TObexServerStatePutOpWaitForUser::ProcessErrorNotification);
       
   117 	}
       
   118 
       
   119 /*static*/ TInt TObexServerStatePutOpWaitForUser::ProcessNotification(TAny* aPtr)
       
   120 	{
       
   121 	// Get hold of the Context and the returned object
       
   122 	CObexServerStateMachine& context = *static_cast<CObexServerStateMachine*>(aPtr);
       
   123 	
       
   124 	CObexBaseObject* object = context.TransObject();
       
   125 	
       
   126 	//Check and initialise object, move to PutOpReceiveObject
       
   127 	if(!object)
       
   128 		{
       
   129 		RespondAndEndOperation(context, ERespForbidden);
       
   130 		}
       
   131 	else if (object->InitReceive() != KErrNone)
       
   132 		{
       
   133 		RespondAndEndOperation(context, ERespInternalError);
       
   134 		}
       
   135 	else
       
   136 		{
       
   137 		context.Owner().SetCurrentOperation(CObex::EOpPut);
       
   138 		context.ChangeState(CObexServerStateMachine::EPutOpReceiveObject);
       
   139 		}
       
   140 	
       
   141 	return KErrNone;
       
   142 	}
       
   143 
       
   144 /*static*/ TInt TObexServerStatePutOpWaitForUser::ProcessErrorNotification(TAny* aPtr)
       
   145 	{
       
   146 	// Get hold of the Context and the returned object
       
   147 	CObexServerStateMachine& context = *static_cast<CObexServerStateMachine*>(aPtr);
       
   148 	
       
   149 	RespondAndEndOperation(context, context.AppResponse());
       
   150 	
       
   151 	return KErrNone;
       
   152 	}
       
   153 
       
   154 TBool TObexServerStatePutOpWaitForUser::ValidResponse(TObexResponse aResponseCode)
       
   155 	{
       
   156 	return (aResponseCode>0 && aResponseCode<=255 &&  aResponseCode != ERespContinue && 
       
   157 	   aResponseCode != ERespSuccess  && aResponseCode != ERespCreated  && aResponseCode != ERespAccepted);  
       
   158 	}
       
   159