libraries/iosrv/server/readwrite.h
changeset 0 7f656887cf89
child 83 706c7a69e448
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // readwrite.h
       
     2 // 
       
     3 // Copyright (c) 2006 - 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 #ifndef __READWRITE_H__
       
    14 #define __READWRITE_H__
       
    15 
       
    16 #include <e32base.h>
       
    17 #include "server.h"
       
    18 #include "iocli.h"
       
    19 #include "object.h"
       
    20 
       
    21 
       
    22 class CIoConsole;
       
    23 class CThreadOwner;
       
    24 
       
    25 class MIoReadWriter
       
    26 	{
       
    27 public:
       
    28 	virtual RIoReadWriteHandle::TMode IorwMode() const = 0;
       
    29 	};
       
    30 
       
    31 
       
    32 class MIoReader : public MIoReadWriter
       
    33 	{
       
    34 public:
       
    35 	virtual TBool IorReadPending() const = 0;
       
    36 	virtual TBool IorReadKeyPending() const = 0;
       
    37 	virtual TDes& IorReadBuf() = 0;
       
    38 	virtual void IorDataBuffered(TInt aLength) = 0;
       
    39 	virtual TBool IorDataIsBuffered() const = 0;
       
    40 	virtual TBool IorIsKeyCaptured(TUint aKeyCode, TUint aModifiers) = 0;
       
    41 	virtual void IorReadComplete(TInt aError) = 0;
       
    42 	virtual void IorReadKeyComplete(TInt aError, TUint aKeyCode, TUint aModifiers) = 0;
       
    43 	virtual TName IorName() = 0;
       
    44 	virtual void IorReaderChange(TUint aChange) = 0;
       
    45 	virtual void IorSetConsoleModeComplete(TInt aError) = 0;
       
    46 	};
       
    47 
       
    48 
       
    49 class MIoWriter : public MIoReadWriter
       
    50 	{
       
    51 public:
       
    52 	virtual TInt IowWriteLength() const = 0;
       
    53 	virtual TInt IowWrite(TDes& aBuf) = 0;
       
    54 	virtual void IowComplete(TInt aError) = 0;
       
    55 	virtual TName IowName() = 0;
       
    56 	virtual void IowCursorPos(TInt aError, TPoint aPos) = 0;
       
    57 	virtual void IowSetCursorPosAbsComplete(TInt aError) = 0;
       
    58 	virtual void IowSetCursorPosRelComplete(TInt aError) = 0;
       
    59 	virtual void IowSetCursorHeightComplete(TInt aError) = 0;
       
    60 	virtual void IowSetTitleComplete(TInt aError) = 0;
       
    61 	virtual void IowClearScreenComplete(TInt aError) = 0;
       
    62 	virtual void IowClearToEndOfLineComplete(TInt aError) = 0;
       
    63 	virtual void IowScreenSize(TInt aError, TSize aSize) = 0;
       
    64 	virtual void IowSetAttributesComplete(TInt aError) = 0;
       
    65 	virtual HBufC* IowTitleLC() = 0;
       
    66 	virtual TBool IowIsStdErr() const { return EFalse; }
       
    67 	};
       
    68 
       
    69 
       
    70 class MIoEndPoint
       
    71 	{
       
    72 public:
       
    73 	TBool IoepIsConsole() const;
       
    74 	virtual TName IoepName() const = 0;
       
    75 	virtual TBool IoepIsType(RIoHandle::TType aType) const = 0;
       
    76 	};
       
    77 
       
    78 class MIoReadEndPoint : public MIoEndPoint
       
    79 	{
       
    80 public:
       
    81 	virtual void IorepAttachL(MIoReader& aReader, RIoEndPoint::TReadMode aMode) = 0;
       
    82 	virtual void IorepDetach(MIoReader& aReader) = 0;
       
    83 	virtual void IorepReadL(MIoReader& aReader) = 0;
       
    84 	virtual void IorepSetForegroundReaderL(MIoReader& aReader) = 0;
       
    85 	virtual TBool IorepIsForegroundL(const MIoReader& aReader) const = 0;
       
    86 	virtual void IorepReadKeyL(MIoReader& aReader);
       
    87 	virtual void IorepSetConsoleModeL(RIoReadWriteHandle::TMode aMode, MIoReader& aReader);
       
    88 	static TBool AttachedToConsole(const MIoReadEndPoint* aEndPoint);
       
    89 	};
       
    90 
       
    91 
       
    92 class MIoWriteEndPoint : public MIoEndPoint
       
    93 	{
       
    94 public:
       
    95 	virtual void IowepAttachL(MIoWriter& aReader) = 0;
       
    96 	virtual void IowepDetach(MIoWriter& aReader) = 0;
       
    97 	virtual void IowepWriteL(MIoWriter& aWriter) = 0;
       
    98 	virtual void IowepWriteCancel(MIoWriter& aWriter) = 0;
       
    99 	virtual void IowepCursorPosL(MIoWriter& aWriter) const;
       
   100 	virtual void IowepSetCursorPosAbsL(const TPoint& aPoint, MIoWriter& aWriter);
       
   101 	virtual void IowepSetCursorPosRelL(const TPoint& aPoint, MIoWriter& aWriter);
       
   102 	virtual void IowepSetCursorHeightL(TInt aPercentage, MIoWriter& aWriter);
       
   103 	virtual void IowepSetTitleL(MIoWriter& aWriter);
       
   104 	virtual void IowepClearScreenL(MIoWriter& aWriter);
       
   105 	virtual void IowepClearToEndOfLineL(MIoWriter& aWriter);
       
   106 	virtual void IowepScreenSizeL(MIoWriter& aWriter) const;
       
   107 	virtual void IowepSetAttributesL(TUint aAttributes, ConsoleAttributes::TColor aForegroundColor, ConsoleAttributes::TColor aBackgroundColor, MIoWriter& aWriter);
       
   108 	static TBool AttachedToConsole(const MIoWriteEndPoint* aEndPoint);
       
   109 protected:
       
   110 	virtual TPoint IowepCursorPos() const;
       
   111 	virtual void IowepSetCursorPosAbs(const TPoint& aPoint);
       
   112 	virtual void IowepSetCursorPosRel(const TPoint& aPoint);
       
   113 	virtual void IowepSetCursorHeight(TInt aHeight);
       
   114 	virtual void IowepSetTitle(const TDesC& aTitle);
       
   115 	virtual void IowepClearScreen();
       
   116 	virtual void IowepClearToEndOfLine();
       
   117 	virtual TSize IowepScreenSize() const;
       
   118 	virtual void IowepSetAttributes(TUint aAttributes, ConsoleAttributes::TColor aForegroundColor, ConsoleAttributes::TColor aBackgroundColor);
       
   119 	};
       
   120 
       
   121 
       
   122 class CIoReadWriteObject : public CIoObject
       
   123 	{
       
   124 public:
       
   125 	TUint Id() const;
       
   126 	void SetOwnerL(TThreadId aOwningThread);
       
   127 	TInt Open(TThreadId aOwningThread);
       
   128 	void DoDuplicateL(const CIoReadWriteObject& aDuplicate);
       
   129 	TBool IsOwner(TThreadId aOwningThread) const;
       
   130 	TBool OpenedByOwner() const;
       
   131 	void SetConsole(CIoConsole& aConsole);
       
   132 	CIoConsole* Console();
       
   133 	const CIoConsole* Console() const;
       
   134 	MIoEndPoint* EndPoint();
       
   135 	virtual void SetModeL(const RMsg& aMessage);
       
   136 protected:
       
   137 	CIoReadWriteObject(TUint aId);
       
   138 	void Dump(const TDesC& aData) const;
       
   139 protected:
       
   140 	MIoEndPoint* iEndPoint;
       
   141 	RIoReadWriteHandle::TMode iMode;
       
   142 private:
       
   143 	const TUint iId;
       
   144 	TThreadId iOwningThreadId;
       
   145 	TBool iOpenedByOwner;
       
   146 	CIoConsole* iConsole;
       
   147 	};
       
   148 
       
   149 
       
   150 class CIoReadObject : public CIoReadWriteObject, public MIoReader
       
   151 	{
       
   152 public:
       
   153 	static CIoReadObject* NewLC(TInt aId);
       
   154 	virtual ~CIoReadObject();
       
   155 	void DuplicateL(const CIoReadObject& aDuplicate);
       
   156 	void AttachL(MIoReadEndPoint& aEndPoint, RIoEndPoint::TReadMode aMode);
       
   157 	void SetReadMode(RIoReadHandle::TReadMode aMode);
       
   158 	void SetToForegroundL();
       
   159 	TBool IsForegroundL() const;
       
   160 	void ReadL(const RMsg& aMessage);
       
   161 	void ReadCancel(const CIoSession& aSession);
       
   162 	void SetLineSeparatorL(const RMsg& aMessage);
       
   163 	void ReadKeyL(const RMsg& aMessage);
       
   164 	void ReadKeyCancel(const CIoSession& aSession);
       
   165 	void CaptureKeyL(const RMsg& aMessage);
       
   166 	void CancelCaptureKey(const RMsg& aMessage);
       
   167 	void CaptureAllKeys(const RMsg& aMessage);
       
   168 	void CancelCaptureAllKeys(const RMsg& aMessage);
       
   169 	void NotifyChange(const RMsg& aMessage);
       
   170 	void CancelNotifyChange(const CIoSession& aSession);
       
   171 public: // From CIoObject.
       
   172 	virtual TBool IsType(RIoHandle::TType aType) const;
       
   173 	virtual void SessionClosed(const CIoSession& aSession);
       
   174 public: // From CIoReadWriteObject.
       
   175 	virtual void SetModeL(const RMsg& aMessage);
       
   176 public: // From MIoReadWriter.
       
   177 	virtual RIoReadWriteHandle::TMode IorwMode() const;
       
   178 private: // From MIoReader.
       
   179 	virtual TBool IorReadPending() const;
       
   180 	virtual TBool IorReadKeyPending() const;
       
   181 	virtual TDes& IorReadBuf();
       
   182 	virtual void IorDataBuffered(TInt aLength);
       
   183 	virtual TBool IorDataIsBuffered() const;
       
   184 	virtual TBool IorIsKeyCaptured(TUint aKeyCode, TUint aModifier);
       
   185 	virtual void IorReadComplete(TInt aError);
       
   186 	virtual void IorReadKeyComplete(TInt aError, TUint aKeyCode, TUint aModifiers);
       
   187 	virtual TName IorName();
       
   188 	virtual void IorReaderChange(TUint aChange);
       
   189 	virtual void IorSetConsoleModeComplete(TInt aError);
       
   190 private:
       
   191 	CIoReadObject(TInt aId);
       
   192 	void ProcessRead();
       
   193 	void AllocateBufferL(TInt aLength);
       
   194 	void TryToCompleteRead();
       
   195 	void CompleteRead(TInt aError, TInt aLength);
       
   196 	void CompleteReadKey(TInt aError, RIoConsoleReadHandle::TConsoleKey& aConsoleKey);
       
   197 	MIoReadEndPoint* ReadEndPoint() const;
       
   198 	void CancelSetMode(const CIoSession& aSession);
       
   199 private:
       
   200 	class TCapturedKey
       
   201 		{
       
   202 	public:
       
   203 		TCapturedKey(TUint aKeyCode, TUint aModifierMask, TUint aModifiers);
       
   204 	public:
       
   205 		TUint iKeyCode;
       
   206 		TUint iModifierMask;
       
   207 		TUint iModifiers;
       
   208 		};
       
   209 private:
       
   210 	RIoReadHandle::TReadMode iReadMode;
       
   211 	TInt iMaxReadLength;
       
   212 	RMsg iReadMessage;
       
   213 	RMsg iReadKeyMessage;
       
   214 	HBufC* iBuf;
       
   215 	TPtr iPtr;
       
   216 	HBufC* iLineSeparator; // NULL means use default "\n"
       
   217 	RArray<TCapturedKey> iCapturedKeys;
       
   218 	RArray<RIoConsoleReadHandle::TConsoleKey> iKeyBuffer;
       
   219 	TBool iCaptureAllKeys;
       
   220 	TInt iCompleteErr; // non-zero if we have completed reading
       
   221 	RMsg iChangeNotifyMessage;
       
   222 	RMsg iSetModeMessage;
       
   223 	};
       
   224 
       
   225 
       
   226 class CIoWriteObject : public CIoReadWriteObject, public MIoWriter
       
   227 	{
       
   228 public:
       
   229 	static CIoWriteObject* NewLC(TInt aId);
       
   230 	~CIoWriteObject();
       
   231 	void DuplicateL(const CIoWriteObject& aDuplicate);
       
   232 	void AttachL(MIoWriteEndPoint& aEndPoint);
       
   233 	void WriteL(const RMsg& aMessage);
       
   234 	void WriteCancel(const CIoSession& aSession);
       
   235 	void CursorPosL(const RMsg& aMessage);
       
   236 	void SetCursorPosAbsL(const RMsg& aMessage);
       
   237 	void SetCursorPosRelL(const RMsg& aMessage);
       
   238 	void SetCursorHeightL(const RMsg& aMessage);
       
   239 	void SetTitleL(const RMsg& aMessage);
       
   240 	void ClearScreen(const RMsg& aMessage);
       
   241 	void ClearToEndOfLine(const RMsg& aMessage);
       
   242 	void ScreenSizeL(const RMsg& aMessage);
       
   243 	void SetAttributesL(const RMsg& aMessage);
       
   244 	void SetIsStdErr(TBool aFlag);
       
   245 public: // From CIoObject.
       
   246 	virtual TBool IsType(RIoHandle::TType aType) const;
       
   247 	virtual void SessionClosed(const CIoSession& aSession);
       
   248 public: // From MIoReadWriter.
       
   249 	virtual RIoReadWriteHandle::TMode IorwMode() const;
       
   250 private: // From MIoWriter.
       
   251 	virtual TInt IowWriteLength() const;
       
   252 	virtual TInt IowWrite(TDes& aBuf);
       
   253 	virtual void IowComplete(TInt aError);
       
   254 	virtual TName IowName();
       
   255 	virtual RIoWriteHandle::TMode IowWriteMode() const;
       
   256 	virtual void IowCursorPos(TInt aError, TPoint aPos);
       
   257 	virtual void IowSetCursorPosAbsComplete(TInt aError);
       
   258 	virtual void IowSetCursorPosRelComplete(TInt aError);
       
   259 	virtual void IowSetCursorHeightComplete(TInt aError);
       
   260 	virtual void IowSetTitleComplete(TInt aError);
       
   261 	virtual void IowClearScreenComplete(TInt aError);
       
   262 	virtual void IowClearToEndOfLineComplete(TInt aError);
       
   263 	virtual void IowScreenSize(TInt aError, TSize aSize);
       
   264 	virtual void IowSetAttributesComplete(TInt aError);
       
   265 	virtual HBufC* IowTitleLC();
       
   266 	virtual TBool IowIsStdErr() const;
       
   267 private:
       
   268 	CIoWriteObject(TInt aId);
       
   269 	MIoWriteEndPoint* WriteEndPoint() const;
       
   270 protected:
       
   271 	TInt iOffset;
       
   272 	TInt iWriteLength;
       
   273 	RMsg iWriteMessage;
       
   274 	RMsg iGetCursorPosMsg;
       
   275 	RMsg iSetCursorPosAbsMsg;
       
   276 	RMsg iSetCursorPosRelMsg;
       
   277 	RMsg iSetCursorHeightMsg;
       
   278 	RMsg iSetTitleMsg;
       
   279 	RMsg iClearScreenMsg;
       
   280 	RMsg iClearToEndOfLineMsg;
       
   281 	RMsg iGetScreenSizeMsg;
       
   282 	RMsg iSetAttributesMsg;
       
   283 	TBool iTriedConsoleScreenSize;
       
   284 	TBool iIsStdErr;
       
   285 	};
       
   286 
       
   287 #endif // __READWRITE_H__