obex/obexprotocol/obex/src/TObexServerStateGetOpWaitForUser.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 Wait State
       
    24 This state issues the Get 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 GetOpSendObject
       
    30 */
       
    31 
       
    32 #ifdef __FLOG_ACTIVE
       
    33 _LIT8(KGetWaitCmpt, "getwait");
       
    34 
       
    35 #define GETWAIT_LOG(str) CObexLog::Write(KGetWaitCmpt, str)
       
    36 #else
       
    37 #define GETWAIT_LOG(str)
       
    38 #endif
       
    39 
       
    40 
       
    41 TObexServerStateGetOpWaitForUser::TObexServerStateGetOpWaitForUser()
       
    42 	{
       
    43 #ifdef __FLOG_ACTIVE
       
    44 	_LIT8(KName, "GetOpWaitForUser");
       
    45 	iName = KName;
       
    46 #endif
       
    47 	}
       
    48 
       
    49 void TObexServerStateGetOpWaitForUser::Entry(CObexServerStateMachine& aContext)
       
    50 	{
       
    51 	// Send notification to the Application
       
    52 	aContext.SetTransObject(NULL);
       
    53 	
       
    54 	GETWAIT_LOG(_L8("Upcalling..."));
       
    55 	aContext.Notification().GetRequestIndication(aContext.SpecObject());
       
    56 	}
       
    57 
       
    58 void TObexServerStateGetOpWaitForUser::Connect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    59 	{
       
    60 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    61 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    62 	}
       
    63 
       
    64 void TObexServerStateGetOpWaitForUser::Disconnect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    65 	{
       
    66 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    67 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    68 	}
       
    69 
       
    70 void TObexServerStateGetOpWaitForUser::Put(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    71 	{
       
    72 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    73 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    74 	}
       
    75 
       
    76 void TObexServerStateGetOpWaitForUser::Get(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    77 	{
       
    78 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    79 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    80 	}
       
    81 
       
    82 void TObexServerStateGetOpWaitForUser::SetPath(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    83 	{
       
    84 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    85 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    86 	}
       
    87 
       
    88 void TObexServerStateGetOpWaitForUser::Abort(CObexServerStateMachine& aContext)
       
    89 	{
       
    90 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    91 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    92 	}
       
    93 	
       
    94 void TObexServerStateGetOpWaitForUser::OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse /*aResponse*/)
       
    95 	{
       
    96 	// Raise Protocol Error (which will cause a Reset and cancel the notification)
       
    97 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    98 	}
       
    99 
       
   100 void TObexServerStateGetOpWaitForUser::Start(CObexServerStateMachine& /*aContext*/)
       
   101 	{
       
   102 	// Panic - trying to change interface during wait
       
   103 	IrOBEXUtil::Panic(EChangeInterfaceDuringWait);
       
   104 	}
       
   105 
       
   106 void TObexServerStateGetOpWaitForUser::Reset(CObexServerStateMachine& aContext)
       
   107 	{
       
   108 	// Cancel notification - if it has not already been activated
       
   109 	if (!aContext.IsCallBackActive())
       
   110 		{
       
   111 		aContext.Notification().CancelIndicationCallback();
       
   112 		}
       
   113 	aContext.CancelCallBack();
       
   114 	aContext.ChangeState(CObexServerStateMachine::EDisconnected);
       
   115 	}
       
   116 
       
   117 void TObexServerStateGetOpWaitForUser::RequestNotificationCompleted(CObexServerStateMachine& aContext, CObexBaseObject* aObject)
       
   118 	{
       
   119 	aContext.SetTransObject(aObject);
       
   120 	aContext.CallBack(TObexServerStateGetOpWaitForUser::ProcessNotification);
       
   121 	}
       
   122 
       
   123 void TObexServerStateGetOpWaitForUser::RequestNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse)
       
   124 	{
       
   125 	aContext.SetAppResponse(aAppResponse);
       
   126 	aContext.CallBack(TObexServerStateGetOpWaitForUser::ProcessErrorNotification);	
       
   127 	}
       
   128 
       
   129 /*static*/ TInt TObexServerStateGetOpWaitForUser::ProcessNotification(TAny* aPtr)
       
   130 	{
       
   131 	// Get hold of the Context and the returned object
       
   132 	CObexServerStateMachine& context = *static_cast<CObexServerStateMachine*>(aPtr);
       
   133 	
       
   134 	GETWAIT_LOG(_L8("Process notification"));
       
   135 	CObexBaseObject* object = context.TransObject();
       
   136 	
       
   137 	//Check and initialise object, move to GetOpSendObject
       
   138 	if (!object)
       
   139 		{
       
   140 		RespondAndEndOperation(context, ERespForbidden);
       
   141 		}
       
   142 	else if (object->InitSend(ERespContinue) != KErrNone)
       
   143 		{
       
   144 		RespondAndEndOperation(context, ERespInternalError);
       
   145 		}
       
   146 	else
       
   147 		{
       
   148 		//ConnectionID is compulsory if Target header was used at connection
       
   149 		if ( context.Owner().CheckObjectForConnectionId(*(context.SpecObject())))
       
   150 			{
       
   151 			context.ChangeState(CObexServerStateMachine::EGetOpSendObject);
       
   152 			}
       
   153 		else  //connectionID was incorrect or not received
       
   154 			{
       
   155 			context.Transport().Send(ERespServiceUnavailable); 
       
   156 			}
       
   157 		}
       
   158 	return KErrNone;
       
   159 	}
       
   160 
       
   161 /*static*/ TInt TObexServerStateGetOpWaitForUser::ProcessErrorNotification(TAny* aPtr)
       
   162 	{
       
   163 	// Get hold of the Context and the returned object
       
   164 	CObexServerStateMachine& context = *static_cast<CObexServerStateMachine*>(aPtr);
       
   165 	
       
   166 	RespondAndEndOperation(context, context.AppResponse());
       
   167 	
       
   168 	return KErrNone;
       
   169 	}
       
   170 
       
   171 TBool TObexServerStateGetOpWaitForUser::ValidResponse(TObexResponse aResponseCode)
       
   172 	{
       
   173 	return (aResponseCode>0 && aResponseCode<=255 &&  aResponseCode != ERespContinue && 
       
   174 	   aResponseCode != ERespSuccess  && aResponseCode != ERespCreated  && aResponseCode != ERespAccepted);  
       
   175 	}