|
1 // consoleproxy.h |
|
2 // |
|
3 // Copyright (c) 2009 - 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 __CONSOLEPROXY_H__ |
|
14 #define __CONSOLEPROXY_H__ |
|
15 |
|
16 #include <e32base.h> |
|
17 #include <e32cons.h> |
|
18 #include <fshell/consoleextensions.h> |
|
19 |
|
20 class CConsoleProxyServer; |
|
21 class TServerParams; |
|
22 |
|
23 typedef CConsoleBase* (*TConsoleCreateFunction)(); |
|
24 typedef CConsoleProxyServer* (*TServerNewL)(TAny*); |
|
25 |
|
26 enum TConsoleProxyPanic |
|
27 { |
|
28 EConsoleAlreadyCreated = 0, |
|
29 ENoConsoleInstatiated = 1, |
|
30 }; |
|
31 |
|
32 void Panic(TConsoleProxyPanic aReason); |
|
33 |
|
34 class RConsoleProxy : public RSessionBase |
|
35 { |
|
36 public: |
|
37 enum TOpCode |
|
38 { |
|
39 EGetServer, |
|
40 ECreate, |
|
41 ERead, |
|
42 EReadKey, |
|
43 EReadCancel, |
|
44 EWrite, |
|
45 EGetCursorPos, |
|
46 ESetCursorPosAbs, |
|
47 ESetCursorPosRel, |
|
48 ESetCursorHeight, |
|
49 ESetTitle, |
|
50 EClearScreen, |
|
51 EClearToEndOfLine, |
|
52 EGetScreenSize, |
|
53 EGetKeyCode, |
|
54 EGetKeyModifiers, |
|
55 ESetAttributes, |
|
56 EIsConstructed, |
|
57 |
|
58 EOpCodeCustomBase = 1000, |
|
59 }; |
|
60 public: |
|
61 /** |
|
62 Create a new sub-thread to host a console and connect to it. |
|
63 |
|
64 @param aConsoleCreate Function pointer to create the console in the new thread |
|
65 @param aServer On return, the handle of the server running in the sub thread. Ownership is NOT returned |
|
66 to the caller. |
|
67 @param aServerThread On return, the handle to the thread that the server is running in. Ownership is |
|
68 returned to the caller. |
|
69 */ |
|
70 IMPORT_C TInt Connect(TConsoleCreateFunction aConsoleCreate, const TDesC& aThreadNameBase, |
|
71 TInt aStackSize, TInt aHeapMinSize, TInt aHeapMaxSize, |
|
72 RServer2& aServer, RThread& aServerThread); |
|
73 |
|
74 /** |
|
75 Create a new sub-thread to host a console and connect to it, using a custom CConsoleProxyServer derived |
|
76 server. |
|
77 |
|
78 @param aServerConstructor NewL of the server class |
|
79 @param aServerParams Parameters to pass into the server NewL. |
|
80 @param aServer On return, the handle of the server running in the sub thread. Ownership is NOT returned |
|
81 to the caller. |
|
82 @param aServerThread On return, the handle to the thread that the server is running in. Ownership is |
|
83 returned to the caller. |
|
84 */ |
|
85 IMPORT_C TInt Connect(TServerNewL aServerConstructor, TAny* aServerParams, const TDesC& aThreadNameBase, |
|
86 TInt aStackSize, TInt aHeapMinSize, TInt aHeapMaxSize, |
|
87 RServer2& aServer, RThread& aServerThread); |
|
88 |
|
89 /** |
|
90 Connects to a console hosted with the given server. |
|
91 */ |
|
92 IMPORT_C TInt Connect(RServer2 aServer); |
|
93 /** |
|
94 Connect to a console created within another process. |
|
95 */ |
|
96 IMPORT_C TInt Connect(const TDesC& aServerName, const TDesC& aServerArgs = KNullDesC); |
|
97 |
|
98 IMPORT_C TInt Server(RServer2& aServer); |
|
99 |
|
100 IMPORT_C TInt Create(const TDesC& aConsoleTitle, TSize aSize); |
|
101 IMPORT_C void Read(TRequestStatus& aStatus); |
|
102 IMPORT_C void Read(TPckg<TKeyCode>& aKeyCode, TPckg<TUint>& aKeyModifiers, TRequestStatus& aStatus); |
|
103 IMPORT_C void ReadCancel(); |
|
104 IMPORT_C TInt Write(const TDesC& aDescriptor); |
|
105 IMPORT_C TInt CursorPos(TPoint& aPos) const; |
|
106 IMPORT_C TInt SetCursorPosAbs(const TPoint& aPoint); |
|
107 IMPORT_C TInt SetCursorPosRel(const TPoint& aPoint); |
|
108 IMPORT_C TInt SetCursorHeight(TInt aPercentage); |
|
109 IMPORT_C TInt SetTitle(const TDesC& aTitle); |
|
110 IMPORT_C TInt ClearScreen(); |
|
111 IMPORT_C TInt ClearToEndOfLine(); |
|
112 IMPORT_C TInt GetScreenSize(TSize& aSize) const; |
|
113 IMPORT_C TInt GetKeyCode(TKeyCode& aCode) const; |
|
114 IMPORT_C TInt GetKeyModifiers(TUint& aModifiers) const; |
|
115 |
|
116 IMPORT_C void Create(const TDesC& aConsoleTitle, TSize aSize, TRequestStatus& aStatus); |
|
117 IMPORT_C void Write(const TDesC& aDescriptor, TRequestStatus& aStatus); |
|
118 IMPORT_C void CursorPos(TPckg<TPoint>& aPoint, TRequestStatus& aStatus) const; |
|
119 IMPORT_C void SetCursorPosAbs(const TPoint& aPoint, TRequestStatus& aStatus); |
|
120 IMPORT_C void SetCursorPosRel(const TPoint& aPoint, TRequestStatus& aStatus); |
|
121 IMPORT_C void SetCursorHeight(TInt aPercentage, TRequestStatus& aStatus); |
|
122 IMPORT_C void SetTitle(const TDesC& aTitle, TRequestStatus& aStatus); |
|
123 IMPORT_C void ClearScreen(TRequestStatus& aStatus); |
|
124 IMPORT_C void ClearToEndOfLine(TRequestStatus& aStatus); |
|
125 IMPORT_C void GetScreenSize(TPckg<TSize>& aSize, TRequestStatus& aStatus) const; |
|
126 IMPORT_C void SetAttributes(TUint aAttributes, ConsoleAttributes::TColor aForegroundColor, ConsoleAttributes::TColor aBackgroundColor, TRequestStatus& aStatus); |
|
127 IMPORT_C TInt IsConstructed(TBool& aLazy); |
|
128 private: |
|
129 TInt DoConnect(TServerParams* aParams, const TDesC& aThreadNameBase, |
|
130 TInt aStackSize, TInt aHeapMinSize, TInt aHeapMaxSize, |
|
131 RServer2& aServer, RThread& aServerThread); |
|
132 }; |
|
133 |
|
134 class CConsoleProxy : public CConsoleBase |
|
135 { |
|
136 public: |
|
137 /** |
|
138 Create a CConsoleBase wrapper around an RConsoleProxy. |
|
139 |
|
140 @param aProxySession A connected session. The handle will be duplicated by this class, |
|
141 so ownership is not transferred. |
|
142 */ |
|
143 IMPORT_C static CConsoleProxy* NewL(const RConsoleProxy& aProxySession); |
|
144 IMPORT_C ~CConsoleProxy(); |
|
145 public: // from CConsoleBase |
|
146 IMPORT_C virtual TInt Create(const TDesC &aTitle,TSize aSize); |
|
147 IMPORT_C virtual void Read(TRequestStatus &aStatus); |
|
148 IMPORT_C virtual void ReadCancel(); |
|
149 IMPORT_C virtual void Write(const TDesC &aDes); |
|
150 IMPORT_C virtual TPoint CursorPos() const; |
|
151 IMPORT_C virtual void SetCursorPosAbs(const TPoint &aPoint); |
|
152 IMPORT_C virtual void SetCursorPosRel(const TPoint &aPoint); |
|
153 IMPORT_C virtual void SetCursorHeight(TInt aPercentage); |
|
154 IMPORT_C virtual void SetTitle(const TDesC &aTitle); |
|
155 IMPORT_C virtual void ClearScreen(); |
|
156 IMPORT_C virtual void ClearToEndOfLine(); |
|
157 IMPORT_C virtual TSize ScreenSize() const; |
|
158 IMPORT_C virtual TKeyCode KeyCode() const; |
|
159 IMPORT_C virtual TUint KeyModifiers() const; |
|
160 protected: |
|
161 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); |
|
162 IMPORT_C CConsoleProxy(); |
|
163 IMPORT_C void ConstructL(const RConsoleProxy& aProxySession); |
|
164 protected: |
|
165 RConsoleProxy iConsole; |
|
166 TKeyCode iKeyCode; |
|
167 TUint iKeyModifiers; |
|
168 TPckg<TKeyCode> iKeyCodePckg; |
|
169 TPckg<TUint> iKeyModifiersPckg; |
|
170 }; |
|
171 |
|
172 class CConsoleProxySession; |
|
173 |
|
174 class MProxiedConsole |
|
175 { |
|
176 public: |
|
177 IMPORT_C static MProxiedConsole* DefaultL(CConsoleBase* aConsole); |
|
178 public: |
|
179 virtual void Open() = 0; |
|
180 virtual void Close() = 0; |
|
181 virtual CConsoleBase* Console() = 0; |
|
182 virtual void Read(CConsoleProxySession& aSession) = 0; |
|
183 virtual void ReadCancel() = 0; |
|
184 }; |
|
185 |
|
186 class TConsoleProxyServerNewLParams |
|
187 { |
|
188 public: |
|
189 TConsoleProxyServerNewLParams(const TDesC& aName, TInt aAoPriority, TConsoleCreateFunction aConsoleCreate = NULL) |
|
190 : iName(aName), iAoPriority(aAoPriority), iConsoleCreate(aConsoleCreate) {} |
|
191 public: |
|
192 const TDesC& iName; |
|
193 TInt iAoPriority; |
|
194 TConsoleCreateFunction iConsoleCreate; |
|
195 }; |
|
196 |
|
197 class CShutdownTimer; |
|
198 |
|
199 class CConsoleProxyServer : public CServer2 |
|
200 { |
|
201 public: |
|
202 static CConsoleProxyServer* NewL(TAny* aParams); // aParams is TConsoleProxyServerNewLParams* |
|
203 IMPORT_C static CConsoleProxyServer* NewL(const TDesC& aName, TInt aAoPriority, TConsoleCreateFunction aConsoleCreate = NULL); |
|
204 |
|
205 IMPORT_C virtual ~CConsoleProxyServer(); |
|
206 |
|
207 void AddSession(); |
|
208 void DropSession(); |
|
209 protected: |
|
210 IMPORT_C CConsoleProxyServer(TConsoleCreateFunction aConsoleCreate, TInt aAoPriority); |
|
211 IMPORT_C void ConstructL(const TDesC& aName); |
|
212 |
|
213 /** |
|
214 Called after a timeout when |
|
215 - no session connects to the server after startup |
|
216 - the last session disconnects |
|
217 and stops the active scheduler. Can be over-ridden to change the behaviour in these cases. |
|
218 */ |
|
219 IMPORT_C virtual void ShutdownTimerExpired(); |
|
220 |
|
221 // from CServer2: |
|
222 IMPORT_C virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const; |
|
223 protected: |
|
224 TConsoleCreateFunction iConsoleCreate; |
|
225 private: |
|
226 TInt iSessionCount; |
|
227 CShutdownTimer* iShutdownTimer; |
|
228 friend class CShutdownTimer; |
|
229 }; |
|
230 |
|
231 class CConsoleProxySession : public CSession2 |
|
232 { |
|
233 public: |
|
234 IMPORT_C CConsoleProxySession(TConsoleCreateFunction aConsoleCreate); |
|
235 IMPORT_C CConsoleProxySession(MProxiedConsole* aConsole); |
|
236 IMPORT_C virtual ~CConsoleProxySession(); |
|
237 |
|
238 CConsoleProxyServer* Server() { return (CConsoleProxyServer*)CSession2::Server();} |
|
239 |
|
240 |
|
241 // from CSession2: |
|
242 IMPORT_C virtual void ServiceL(const RMessage2& aMessage); |
|
243 IMPORT_C virtual void CreateL(); |
|
244 |
|
245 // callback from from MProxiedConsole: |
|
246 IMPORT_C void ReadComplete(TInt aStatus); |
|
247 protected: |
|
248 /** |
|
249 Creates the console using the given title and size. The console must not already have |
|
250 been created. |
|
251 */ |
|
252 IMPORT_C void DoCreateL(const TDesC& aTitle, const TSize& aSize); |
|
253 /** |
|
254 Instantiate the CConsoleBase class, but don't call Create() on it; return it wrapped up |
|
255 inside a MProxiedConsole derived class. |
|
256 */ |
|
257 IMPORT_C virtual MProxiedConsole* InstantiateConsoleL(); |
|
258 /** |
|
259 Called just after a console has been successfully Create()'d, to perform any extra |
|
260 configuration necessary. Default implementation does nothing. |
|
261 |
|
262 Note, iConsole will not have been set yet. If this leaves, it causes construction |
|
263 of the console to fail. |
|
264 */ |
|
265 IMPORT_C virtual void ConsoleCreatedL(MProxiedConsole* aConsole); |
|
266 private: |
|
267 void CreateL(const RMessage2& aMessage); |
|
268 protected: |
|
269 TConsoleCreateFunction iConsoleCreate; |
|
270 MProxiedConsole* iConsole; |
|
271 RMessagePtr2 iReadMessage; |
|
272 enum |
|
273 { |
|
274 EReadBasic, |
|
275 EReadKeys, |
|
276 } iReadType; |
|
277 TKeyCode iKeyCode; |
|
278 TUint iKeyModifiers; |
|
279 }; |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 #endif //__CONSOLEPROXY_H__ |