plugins/consoles/rcons/server/win32/SocketCommandHandler.h
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // SocketCommandHandler.h
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #if !defined(AFX_SOCKETCOMMANDHANDLER_H__C4FCCE6D_0FA7_4D9F_AA7D_449E22C3ED74__INCLUDED_)
       
    14 #define AFX_SOCKETCOMMANDHANDLER_H__C4FCCE6D_0FA7_4D9F_AA7D_449E22C3ED74__INCLUDED_
       
    15 
       
    16 #if _MSC_VER > 1000
       
    17 #pragma once
       
    18 #endif // _MSC_VER > 1000
       
    19 
       
    20 
       
    21 #include "Base.h"
       
    22 #include "ClientSocket.h"
       
    23 
       
    24 
       
    25 class CDynamicReadBuffer;
       
    26 class CSocketCommandReader;
       
    27 
       
    28 
       
    29 class TPacketHeader
       
    30 	{
       
    31 public:
       
    32 	enum TPacketType
       
    33 		{
       
    34 		ECommandCreateConsoleWindow,
       
    35 		ECommandAttachKeyEventSocket,
       
    36 		ECommandWrite,
       
    37 		ECommandGetCursorPos,
       
    38 		ECommandSetAbsCursorPos,
       
    39 		ECommandSetRelCursorPos,
       
    40 		ECommandSetCursorHeight,
       
    41 		ECommandGetScreenSize,
       
    42 		ECommandSetTitle,
       
    43 		ECommandClearScreen,
       
    44 		ECommandClearToEndOfLine
       
    45 		};
       
    46 public:
       
    47 	TPacketType iType;
       
    48 	int iSize;
       
    49 	};
       
    50 
       
    51 
       
    52 class MSocketCommandHandler
       
    53 	{
       
    54 public:
       
    55 	virtual void HandleSocketCommand(TPacketHeader::TPacketType aCommand, const char* aPacket, int aPacketLength, CSocketCommandReader& aReader) = 0;
       
    56 	virtual void HandleSocketClosure(CSocketCommandReader& aReader) = 0;
       
    57 	};
       
    58 
       
    59 
       
    60 class CSocketCommandReader : public CBase, public MSocketReadHandler, public MSocketClosureObserver
       
    61 	{
       
    62 public:
       
    63 	static CSocketCommandReader* New(CClientSocket& aSocket, MSocketCommandHandler& aHandler);
       
    64 	virtual ~CSocketCommandReader();
       
    65 	void ChangeHandler(MSocketCommandHandler& aHandler);
       
    66 	void ReadCommand();
       
    67 	void SendResponse(char* aMessage, int aLength);
       
    68 	CClientSocket& ReleaseSocket();
       
    69 	CClientSocket& Socket() const;
       
    70 private:
       
    71 	CSocketCommandReader(CClientSocket& aSocket, MSocketCommandHandler& aHandler);
       
    72 	void Construct();
       
    73 	void QueueRead();
       
    74 private: // From MSocketReadHandler.
       
    75 	virtual void SocketReadComplete();
       
    76 private: // From MSocketClosureObserver.
       
    77 	virtual void HandleSocketClosure(CSocket& aSocket);
       
    78 private:
       
    79 	enum TState
       
    80 		{
       
    81 		EIdle,
       
    82 		EReadingHeader,
       
    83 		EReadingBody
       
    84 		};
       
    85 private:
       
    86 	CClientSocket* iSocket;
       
    87 	MSocketCommandHandler* iHandler;
       
    88 	TState iState;
       
    89 	TPacketHeader iPacketHeader;
       
    90 	CDynamicReadBuffer* iReadBuf;
       
    91 	};
       
    92 
       
    93 
       
    94 #endif // !defined(AFX_SOCKETCOMMANDHANDLER_H__C4FCCE6D_0FA7_4D9F_AA7D_449E22C3ED74__INCLUDED_)