|
1 // persistentconsole.h |
|
2 // |
|
3 // Copyright (c) 2008 - 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 __PERSISTENTCONSOLE_H__ |
|
14 #define __PERSISTENTCONSOLE_H__ |
|
15 |
|
16 #include <e32base.h> |
|
17 #include "console.h" |
|
18 |
|
19 class TConsoleTitleSetter : public MIoWriter |
|
20 { |
|
21 public: |
|
22 TConsoleTitleSetter(HBufC*& aTitle); |
|
23 private: //from MIoReadWriter: |
|
24 virtual RIoReadWriteHandle::TMode IorwMode() const; |
|
25 private: //from MIoWriter: |
|
26 virtual TInt IowWriteLength() const; |
|
27 virtual TInt IowWrite(TDes& aBuf); |
|
28 virtual void IowComplete(TInt aError); |
|
29 virtual TName IowName(); |
|
30 virtual void IowCursorPos(TInt aError, TPoint aPos); |
|
31 virtual void IowSetCursorPosAbsComplete(TInt aError); |
|
32 virtual void IowSetCursorPosRelComplete(TInt aError); |
|
33 virtual void IowSetCursorHeightComplete(TInt aError); |
|
34 virtual void IowSetTitleComplete(TInt aError); |
|
35 virtual void IowClearScreenComplete(TInt aError); |
|
36 virtual void IowClearToEndOfLineComplete(TInt aError); |
|
37 virtual void IowScreenSize(TInt aError, TSize aSize); |
|
38 virtual void IowSetAttributesComplete(TInt aError); |
|
39 virtual HBufC* IowTitleLC(); |
|
40 private: |
|
41 HBufC*& iTitle; |
|
42 }; |
|
43 |
|
44 |
|
45 class CIoPersistentConsole |
|
46 : public CIoConsole |
|
47 { |
|
48 class TIoWriterProxy; |
|
49 class TIoReaderProxy; |
|
50 public: |
|
51 static CIoPersistentConsole* NewLC(const TDesC& aName, const TDesC& aTitle, CIoServer& aServer, const RMsg& aMessage); |
|
52 virtual ~CIoPersistentConsole(); |
|
53 |
|
54 TBool CanConnectReaderL(const MIoReadEndPoint& aReader) const; |
|
55 void AttachTransientReaderL(MIoReadEndPoint& aReader, CIoSession* aDetachOnClose); |
|
56 void DetachTransientReader(); |
|
57 const MIoReadEndPoint* TransientReader() const; |
|
58 TBool CanConnectWriterL(const MIoWriteEndPoint& aWriter) const; |
|
59 void AttachTransientWriterL(MIoWriteEndPoint& aWriter, CIoSession* aDetachOnClose); |
|
60 void DetachTransientWriter(); |
|
61 const MIoWriteEndPoint* TransientWriter() const; |
|
62 MIoWriteEndPoint* TransientWriter(); |
|
63 |
|
64 void NotifyReadDetachL(const RMsg& aMessage); |
|
65 void CancelNotifyReadDetach(TRequestStatus* aClientStatus); |
|
66 void NotifyWriteDetachL(const RMsg& aMessage); |
|
67 void CancelNotifyWriteDetach(TRequestStatus* aClientStatus); |
|
68 |
|
69 TName TransientReaderName(); |
|
70 TName TransientWriterName(); |
|
71 |
|
72 TThreadId Creator(); |
|
73 |
|
74 // From CObject: |
|
75 virtual TName Name() const; |
|
76 // From CIoObject. |
|
77 virtual TBool IsType(RIoHandle::TType aType) const; |
|
78 virtual void SessionClosed(const CIoSession& aSession); |
|
79 virtual void ClosedBy(const CIoSession& aSession); |
|
80 // From MIoReadEndPoint. |
|
81 virtual void IorepReadL(MIoReader& aReader); |
|
82 virtual void IorepReadKeyL(MIoReader& aReader); |
|
83 virtual void IorepSetConsoleModeL(RIoReadWriteHandle::TMode aMode, MIoReader& aReader); |
|
84 // From MIoWriteEndPoint. |
|
85 virtual void IowepWriteL(MIoWriter& aWriter); |
|
86 virtual void IowepWriteCancel(MIoWriter& aWriter); |
|
87 virtual void IowepCursorPosL(MIoWriter& aWriter) const; |
|
88 virtual void IowepSetCursorPosAbsL(const TPoint& aPoint, MIoWriter& aWriter); |
|
89 virtual void IowepSetCursorPosRelL(const TPoint& aPoint, MIoWriter& aWriter); |
|
90 virtual void IowepSetCursorHeightL(TInt aPercentage, MIoWriter& aWriter); |
|
91 virtual void IowepSetTitleL(MIoWriter& aWriter); |
|
92 virtual void IowepClearScreenL(MIoWriter& aWriter); |
|
93 virtual void IowepClearToEndOfLineL(MIoWriter& aWriter); |
|
94 virtual void IowepScreenSizeL(MIoWriter& aWriter) const; |
|
95 virtual void IowepSetAttributesL(TUint aAttributes, ConsoleAttributes::TColor aForegroundColor, ConsoleAttributes::TColor aBackgroundColor, MIoWriter& aWriter); |
|
96 private: |
|
97 // from CIoEndPoint: |
|
98 virtual TInt HandleReaderAttached(MIoReader& aReader); |
|
99 virtual void HandleReaderDetached(MIoReader& aReader); |
|
100 virtual void ForegroundReaderChanged(); |
|
101 virtual TInt HandleWriterAttached(MIoWriter& aWriter); |
|
102 virtual void HandleWriterDetached(MIoWriter& aWriter); |
|
103 virtual void HandleForegroundReaderChanged(); |
|
104 |
|
105 void SendReadDetachNotifications(); |
|
106 void SendWriteDetachNotifications(); |
|
107 |
|
108 TInt ReaderProxyIndex(MIoReader* aReader) const; |
|
109 TInt WriterProxyIndex(MIoWriter* aWriter) const; |
|
110 TIoWriterProxy& GetWriterProxy(MIoWriter* aWriter) const; |
|
111 TIoReaderProxy& GetReaderProxy(MIoReader* aReader) const; |
|
112 private: |
|
113 CIoPersistentConsole(CIoServer& aServer); |
|
114 void ConstructL(const TDesC& aName, const TDesC& aTitle, const RMsg& aMessage); |
|
115 |
|
116 class TIoWriterProxy : public MIoWriter |
|
117 { |
|
118 public: |
|
119 TIoWriterProxy(MIoWriter& aWriter, CIoPersistentConsole& aOwner); |
|
120 void TransientWriterAttached(MIoWriteEndPoint& aWriteEndPoint); |
|
121 void TransientWriterDetach(MIoWriteEndPoint& aWriteEndPoint); |
|
122 |
|
123 void WriteL(MIoWriteEndPoint* aEndPoint); |
|
124 void WriteCancel(MIoWriteEndPoint* aEndPoint); |
|
125 MIoWriter& ClientWriter() const; |
|
126 void GetCursorPosL(MIoWriteEndPoint* aEndPoint); |
|
127 void SetCursorPosAbsL(const TPoint& aPos, MIoWriteEndPoint* aEndPoint); |
|
128 void SetCursorPosRelL(const TPoint& aPos, MIoWriteEndPoint* aEndPoint); |
|
129 void SetCursorHeightL(TInt aPercentage, MIoWriteEndPoint* aEndPoint); |
|
130 void SetTitleL(MIoWriteEndPoint* aEndPoint); |
|
131 void ClearScreenL(MIoWriteEndPoint* aEndPoint); |
|
132 void ClearToEndOfLineL(MIoWriteEndPoint* aEndPoint); |
|
133 void GetScreenSizeL(MIoWriteEndPoint* aEndPoint); |
|
134 void SetAttributesL(TUint aAttributes, ConsoleAttributes::TColor aForegroundColor, ConsoleAttributes::TColor aBackgroundColor, MIoWriteEndPoint* aEndPoint); |
|
135 |
|
136 // from MIoReadWriter |
|
137 virtual RIoReadWriteHandle::TMode IorwMode() const; |
|
138 |
|
139 // from MIoWriter |
|
140 virtual TInt IowWriteLength() const; |
|
141 virtual TInt IowWrite(TDes& aBuf); |
|
142 virtual void IowComplete(TInt aError); |
|
143 virtual TName IowName(); |
|
144 virtual void IowCursorPos(TInt aError, TPoint aPos); |
|
145 virtual void IowSetCursorPosAbsComplete(TInt aError); |
|
146 virtual void IowSetCursorPosRelComplete(TInt aError); |
|
147 virtual void IowSetCursorHeightComplete(TInt aError); |
|
148 virtual void IowSetTitleComplete(TInt aError); |
|
149 virtual void IowClearScreenComplete(TInt aError); |
|
150 virtual void IowClearToEndOfLineComplete(TInt aError); |
|
151 virtual void IowScreenSize(TInt aError, TSize aSize); |
|
152 virtual void IowSetAttributesComplete(TInt aError); |
|
153 virtual HBufC* IowTitleLC(); |
|
154 private: |
|
155 enum TFlags |
|
156 { |
|
157 EWritePending = 0x0001, |
|
158 EGetCursorPosPending = 0x0002, |
|
159 ESetCursorPosAbsPending = 0x0004, |
|
160 ESetCursorPosRelPending = 0x0008, |
|
161 EClearScreenPending = 0x0010, |
|
162 EClearToEndOfLinePending= 0x0020, |
|
163 EGetScreenSizePending = 0x0040, |
|
164 EDetaching = 0x0080, |
|
165 ESetCursorHeightPending = 0x0100, |
|
166 ESetTitlePending = 0x0200, |
|
167 ESetAttributesPending = 0x0400 |
|
168 }; |
|
169 private: |
|
170 TBool GetFlag(TFlags aFlag); |
|
171 void SetFlag(TFlags aFlag); |
|
172 void ClearFlag(TFlags aFlag); |
|
173 private: |
|
174 MIoWriter& iWriter; |
|
175 CIoPersistentConsole& iOwner; |
|
176 TUint iFlags; |
|
177 TPoint iSetCursPosAbsPoint; |
|
178 TPoint iSetCursPosRelPoint; |
|
179 TInt iSetCursorHeight; |
|
180 TUint iAttributes; |
|
181 ConsoleAttributes::TColor iForegroundColor; |
|
182 ConsoleAttributes::TColor iBackgroundColor; |
|
183 }; |
|
184 |
|
185 class TIoReaderProxy : public MIoReader |
|
186 { |
|
187 public: |
|
188 TIoReaderProxy(MIoReader& aReader, CIoPersistentConsole& aOwner); |
|
189 void TransientReaderAttached(MIoReadEndPoint& aReader); |
|
190 |
|
191 void ReadL(MIoReadEndPoint* aEndPoint); |
|
192 void ReadKeyL(MIoReadEndPoint* aEndPoint); |
|
193 void SetConsoleModeL(MIoReadEndPoint* aEndPoint, RIoReadWriteHandle::TMode aMode); |
|
194 MIoReader& ClientReader() const; |
|
195 |
|
196 // from MIoReadWriter |
|
197 virtual RIoReadWriteHandle::TMode IorwMode() const; |
|
198 |
|
199 // from MIoReader |
|
200 virtual TBool IorReadPending() const; |
|
201 virtual TBool IorReadKeyPending() const; |
|
202 virtual TDes& IorReadBuf(); |
|
203 virtual void IorDataBuffered(TInt aLength); |
|
204 virtual TBool IorDataIsBuffered() const; |
|
205 virtual TBool IorIsKeyCaptured(TUint aKeyCode, TUint aModifiers); |
|
206 virtual void IorReadComplete(TInt aError); |
|
207 virtual void IorReadKeyComplete(TInt aError, TUint aKeyCode, TUint aModifiers); |
|
208 virtual TName IorName(); |
|
209 virtual void IorReaderChange(TUint aChange); |
|
210 virtual void IorSetConsoleModeComplete(TInt aError); |
|
211 private: |
|
212 MIoReader& iReader; |
|
213 CIoPersistentConsole& iOwner; |
|
214 TBool iDetaching; |
|
215 TBool iSetConsoleModePending; |
|
216 RIoReadWriteHandle::TMode iSetConsoleMode; |
|
217 }; |
|
218 private: |
|
219 CIoServer& iServer; |
|
220 RThread iCreator; |
|
221 TName iName; // name for the persistent console, used to identify it |
|
222 HBufC* iTitle; // title for the console, passed to CConsoleBase::SetTitle |
|
223 MIoReadEndPoint* iTransientReadEndPoint; |
|
224 CIoSession* iReadEndPointDetachOnClose; |
|
225 MIoWriteEndPoint* iTransientWriteEndPoint; |
|
226 CIoSession* iWriteEndPointDetachOnClose; |
|
227 |
|
228 RPointerArray<TIoWriterProxy> iWriterProxies; |
|
229 RPointerArray<TIoReaderProxy> iReaderProxies; |
|
230 |
|
231 RIoReadWriteHandle::TMode iPersistentConsoleMode; |
|
232 |
|
233 RArray<RMsg> iReadDetachNotifications; |
|
234 RArray<RMsg> iWriteDetachNotifications; |
|
235 |
|
236 TConsoleTitleSetter iTitleSetter; |
|
237 }; |
|
238 |
|
239 #endif //__PERSISTENTCONSOLE_H__ |