obex/obexprotocol/obex/inc/obexserverstatemachine.h
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 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 
       
    22 #ifndef OBEX_SERVER_STATE_MACHINE_H
       
    23 #define OBEX_SERVER_STATE_MACHINE_H
       
    24 
       
    25 #include <obextypes.h>
       
    26 #include <obex/internal/obexpacket.h>
       
    27 #include <obex/transport/obextransportcontrollerbase.h>
       
    28 #include "obexserveroperationstates.h"
       
    29 #include "OBEXUTIL.H"
       
    30 #include "logger.h"
       
    31 
       
    32 #ifdef __FLOG_ACTIVE
       
    33 _LIT8(KStateMachineCmpt, "statemachine");
       
    34 
       
    35 #define STATE_LOG(str) CObexLog::Write(KStateMachineCmpt, str)
       
    36 #define STATE_LOG_2(str, a, b) CObexLog::WriteFormat(KStateMachineCmpt, str, a, b)
       
    37 #else
       
    38 #define STATE_LOG(str)
       
    39 #define STATE_LOG_2(str, a, b)
       
    40 #endif
       
    41 
       
    42 /**
       
    43 The OBEX Server state machine's context.
       
    44 This class holds all the state context information and acts
       
    45 as the interface between CObexServer and the current state
       
    46 @see TObexServerOperationState
       
    47 */
       
    48 NONSHARABLE_CLASS(CObexServerStateMachine) : public CBase
       
    49 	{
       
    50 public:
       
    51 	enum TObexServerOperationStateEnum
       
    52 		{
       
    53 		EDisconnected,
       
    54 		ETransportConnected,
       
    55 		EObexConnecting,
       
    56 		EWaitForUserPassword,
       
    57 		EReady,
       
    58 		EPutOpWaitForUser,
       
    59 		EPutOpReceiveObject,
       
    60 		EGetOpReceiveSpecification,
       
    61 		EGetOpWaitForUser,
       
    62 		EGetOpSendObject,
       
    63 		ESetPathOp,
       
    64 		EPutOpFinal,
       
    65 		EGetOpFinal,
       
    66 		EDisconnecting,
       
    67 		EEndOfStates
       
    68 		};
       
    69 	
       
    70 	static CObexServerStateMachine* NewL(CObexServer& aOwner, CObexTransportControllerBase& aTransport);
       
    71 	~CObexServerStateMachine();
       
    72 	
       
    73 	
       
    74 	// Events
       
    75 	void ChangeState(TObexServerOperationStateEnum aState);
       
    76 	void OnPacketReceive(CObexPacket& aPacket);
       
    77 	void TransportUp();
       
    78 	void TransportDown();
       
    79 	void Error();
       
    80 	TInt RequestNotificationCompleted(CObexBaseObject* aObject);
       
    81 	TInt RequestNotificationCompleted(TObexResponse aAppResponse);
       
    82 	TInt RequestCompleteNotificationCompleted(TObexResponse aAppResponse);
       
    83 	void ConnectionComplete();
       
    84 	void Start(MObexServerNotifyAsync& aNotify);
       
    85 	void Stop();
       
    86 	void OverrideRequestHandling(TObexResponse aResponse);
       
    87 	void WriteComplete();	
       
    88 	void ReadActivityDetected();
       
    89 	
       
    90 	// Getter/setter functions
       
    91 	CObexPacket& LastReceivedPacket() const; // no setter needed as is only ever set in OnPacketReceive()
       
    92 	
       
    93 	// Object specifiying object to GET
       
    94 	CObexBaseObject* SpecObject() const; 	// Don't need a setter as we own
       
    95 	
       
    96 	// Object returned from Application for GET/PUT
       
    97 	CObexBaseObject* TransObject() const;
       
    98 	void SetTransObject(CObexBaseObject* aTransObject);
       
    99 	
       
   100 	// Access to CObexServer members
       
   101 	CObexTransportControllerBase& Transport() const;
       
   102 	CObexServer& Owner() const;
       
   103 	MObexServerNotifyAsync& Notification() const;
       
   104 	
       
   105 	// Header set for final Put response
       
   106 	CObexHeaderSet* PutFinalResponseHeaderSet();
       
   107 	void SetPutFinalResponseHeaderSet(CObexHeaderSet* aHeaderSet);
       
   108 	CObexHeader* GetHeader(); // don't need setter as we own
       
   109 
       
   110 	// Call-back used to wrap NotificationComplete event
       
   111 	void CallBack(TInt (*aFunction)(TAny* aPtr));
       
   112 	void CancelCallBack();
       
   113 	TBool IsCallBackActive() const;
       
   114 	TObexResponse AppResponse() const;
       
   115 	void SetAppResponse(TObexResponse aAppResponse);
       
   116 
       
   117 	void ControlledTransportDown();
       
   118 
       
   119 private:
       
   120 	CObexServerStateMachine(CObexServer& aOwner, CObexTransportControllerBase& aTransport);
       
   121 	void ConstructL();
       
   122 	
       
   123 private:
       
   124 	TFixedArray<TObexServerOperationState, EEndOfStates> iStates;	
       
   125 	TObexServerOperationState* iCurrentState;
       
   126 	
       
   127 	CObexPacket* iLastReceivedPacket;
       
   128 	CObexBaseObject* iSpecObject;
       
   129 	CObexBaseObject* iTransObject;
       
   130 	CObexTransportControllerBase& iTransport;
       
   131 	
       
   132 	CObexServer& iOwner;
       
   133 	MObexServerNotifyAsync* iNotification;
       
   134 
       
   135 	CObexHeaderSet* iPutFinalResponseHeaderSet;
       
   136 	CObexHeader* iHeader;
       
   137 
       
   138 	TBool iServerStarted;
       
   139 	
       
   140 	CAsyncCallBack* iCallBack;
       
   141 	TObexResponse iAppResponse;
       
   142 	TObexServerOperationStateEnum iCurrentStateEnum;
       
   143 	};
       
   144 
       
   145 #endif	// OBEX_SERVER_STATE_MACHINE_H
       
   146