34 const TInt KNumConsoleImplementations = sizeof(KConsoleImplementations) / sizeof(LtkUtils::SLitC); |
35 const TInt KNumConsoleImplementations = sizeof(KConsoleImplementations) / sizeof(LtkUtils::SLitC); |
35 |
36 |
36 |
37 |
37 /** |
38 /** |
38 |
39 |
39 The default console implementation, used by iosrv. This console implentation has |
40 The default console implementation, used by iosrv. This console implementation has |
40 two reasons to exist: |
41 one reason to exist (there used to be more): |
41 |
42 |
42 1) To hunt for a suitable real console implementation to be used by default. On |
43 1) To hunt for a suitable real console implementation to be used by default. On |
43 GUI configurations this will either be guicons.dll or econseik.dll. On text |
44 GUI configurations this will either be guicons.dll or econseik.dll. On text |
44 configurations this will be econs.dll. |
45 configurations this will be econs.dll. |
45 |
46 |
46 2) To delay the creation of the real console implementation until it is known |
|
47 to be needed. This is useful because CCommandBase creates a default console |
|
48 even if --console has been specified on the command line. The default console |
|
49 may be used by the specified console during its construction to interact with |
|
50 the user (e.g. vt100tcpcons uses it to tell the user which TCP port and IP |
|
51 address it is listening on). However, if it weren't to be used, the user |
|
52 would see the default console briefly appear and then disappear when the |
|
53 actual console is created. Delaying the creation of the console underlying |
|
54 the default console avoids this. |
|
55 |
|
56 */ |
47 */ |
57 NONSHARABLE_CLASS(CDefaultConsole) : public CConsoleBase |
48 NONSHARABLE_CLASS(CDefaultConsole) : public CConsoleBase |
58 { |
49 { |
59 public: |
|
60 enum TPanicReason |
|
61 { |
|
62 EDoubleRead = 0, |
|
63 EUnableToCreateConsole = 1 |
|
64 }; |
|
65 public: |
50 public: |
66 CDefaultConsole(); |
51 CDefaultConsole(); |
67 virtual ~CDefaultConsole(); |
52 virtual ~CDefaultConsole(); |
68 virtual TInt Create(const TDesC &aTitle, TSize aSize); |
53 virtual TInt Create(const TDesC &aTitle, TSize aSize); |
69 virtual void Read(TRequestStatus& aStatus); |
54 virtual void Read(TRequestStatus& aStatus); |
79 virtual TSize ScreenSize() const; |
64 virtual TSize ScreenSize() const; |
80 virtual TKeyCode KeyCode() const; |
65 virtual TKeyCode KeyCode() const; |
81 virtual TUint KeyModifiers() const; |
66 virtual TUint KeyModifiers() const; |
82 virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); |
67 virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); |
83 private: |
68 private: |
84 void CreateIfRequired(); |
69 TInt DoCreate(); |
85 void CreateIfRequired() const; |
|
86 TInt TryCreateConsole(const TDesC& aImplementation); |
70 TInt TryCreateConsole(const TDesC& aImplementation); |
87 void Panic(TPanicReason aReason); |
|
88 private: |
71 private: |
89 HBufC* iTitle; |
72 HBufC* iTitle; |
90 TSize iSize; |
73 TSize iSize; |
91 RLibrary iConsoleLibrary; |
74 RLibrary iConsoleLibrary; |
92 CConsoleBase* iUnderlyingConsole; |
75 CConsoleBase* iUnderlyingConsole; |
107 { |
90 { |
108 iTitle = aTitle.Alloc(); |
91 iTitle = aTitle.Alloc(); |
109 if (iTitle) |
92 if (iTitle) |
110 { |
93 { |
111 iSize = aSize; |
94 iSize = aSize; |
112 return KErrNone; |
95 return DoCreate(); |
113 } |
96 } |
114 return KErrNoMemory; |
97 return KErrNoMemory; |
115 } |
98 } |
116 |
99 |
117 void CDefaultConsole::Read(TRequestStatus& aStatus) |
100 void CDefaultConsole::Read(TRequestStatus& aStatus) |
118 { |
101 { |
119 CreateIfRequired(); |
|
120 iUnderlyingConsole->Read(aStatus); |
102 iUnderlyingConsole->Read(aStatus); |
121 } |
103 } |
122 |
104 |
123 void CDefaultConsole::ReadCancel() |
105 void CDefaultConsole::ReadCancel() |
124 { |
106 { |
125 if (iUnderlyingConsole) |
107 iUnderlyingConsole->ReadCancel(); |
126 { |
|
127 iUnderlyingConsole->ReadCancel(); |
|
128 } |
|
129 } |
108 } |
130 |
109 |
131 void CDefaultConsole::Write(const TDesC& aDes) |
110 void CDefaultConsole::Write(const TDesC& aDes) |
132 { |
111 { |
133 CreateIfRequired(); |
|
134 iUnderlyingConsole->Write(aDes); |
112 iUnderlyingConsole->Write(aDes); |
135 } |
113 } |
136 |
114 |
137 TPoint CDefaultConsole::CursorPos() const |
115 TPoint CDefaultConsole::CursorPos() const |
138 { |
116 { |
139 CreateIfRequired(); |
|
140 return iUnderlyingConsole->CursorPos(); |
117 return iUnderlyingConsole->CursorPos(); |
141 } |
118 } |
142 |
119 |
143 void CDefaultConsole::SetCursorPosAbs(const TPoint& aPoint) |
120 void CDefaultConsole::SetCursorPosAbs(const TPoint& aPoint) |
144 { |
121 { |
145 CreateIfRequired(); |
|
146 iUnderlyingConsole->SetCursorPosAbs(aPoint); |
122 iUnderlyingConsole->SetCursorPosAbs(aPoint); |
147 } |
123 } |
148 |
124 |
149 void CDefaultConsole::SetCursorPosRel(const TPoint& aPoint) |
125 void CDefaultConsole::SetCursorPosRel(const TPoint& aPoint) |
150 { |
126 { |
151 CreateIfRequired(); |
|
152 iUnderlyingConsole->SetCursorPosRel(aPoint); |
127 iUnderlyingConsole->SetCursorPosRel(aPoint); |
153 } |
128 } |
154 |
129 |
155 void CDefaultConsole::SetCursorHeight(TInt aPercentage) |
130 void CDefaultConsole::SetCursorHeight(TInt aPercentage) |
156 { |
131 { |
157 CreateIfRequired(); |
|
158 iUnderlyingConsole->SetCursorHeight(aPercentage); |
132 iUnderlyingConsole->SetCursorHeight(aPercentage); |
159 } |
133 } |
160 |
134 |
161 void CDefaultConsole::SetTitle(const TDesC& aTitle) |
135 void CDefaultConsole::SetTitle(const TDesC& aTitle) |
162 { |
136 { |
163 CreateIfRequired(); |
|
164 iUnderlyingConsole->SetTitle(aTitle); |
137 iUnderlyingConsole->SetTitle(aTitle); |
165 } |
138 } |
166 |
139 |
167 void CDefaultConsole::ClearScreen() |
140 void CDefaultConsole::ClearScreen() |
168 { |
141 { |
169 CreateIfRequired(); |
|
170 iUnderlyingConsole->ClearScreen(); |
142 iUnderlyingConsole->ClearScreen(); |
171 } |
143 } |
172 |
144 |
173 void CDefaultConsole::ClearToEndOfLine() |
145 void CDefaultConsole::ClearToEndOfLine() |
174 { |
146 { |
175 CreateIfRequired(); |
|
176 iUnderlyingConsole->ClearToEndOfLine(); |
147 iUnderlyingConsole->ClearToEndOfLine(); |
177 } |
148 } |
178 |
149 |
179 TSize CDefaultConsole::ScreenSize() const |
150 TSize CDefaultConsole::ScreenSize() const |
180 { |
151 { |
181 CreateIfRequired(); |
|
182 return iUnderlyingConsole->ScreenSize(); |
152 return iUnderlyingConsole->ScreenSize(); |
183 } |
153 } |
184 |
154 |
185 TKeyCode CDefaultConsole::KeyCode() const |
155 TKeyCode CDefaultConsole::KeyCode() const |
186 { |
156 { |
187 CreateIfRequired(); |
|
188 return iUnderlyingConsole->KeyCode(); |
157 return iUnderlyingConsole->KeyCode(); |
189 } |
158 } |
190 |
159 |
191 TUint CDefaultConsole::KeyModifiers() const |
160 TUint CDefaultConsole::KeyModifiers() const |
192 { |
161 { |
193 CreateIfRequired(); |
|
194 return iUnderlyingConsole->KeyModifiers(); |
162 return iUnderlyingConsole->KeyModifiers(); |
195 } |
163 } |
196 |
164 |
197 TInt CDefaultConsole::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1) |
165 TInt CDefaultConsole::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1) |
198 { |
166 { |
199 CreateIfRequired(); |
|
200 return ((CDefaultConsole*)iUnderlyingConsole)->Extension_(aExtensionId, a0, a1); // Evil cast to work around the fact that Extension_ is protected in CConsoleBase. |
167 return ((CDefaultConsole*)iUnderlyingConsole)->Extension_(aExtensionId, a0, a1); // Evil cast to work around the fact that Extension_ is protected in CConsoleBase. |
201 } |
168 } |
202 |
169 |
203 void CDefaultConsole::CreateIfRequired() |
170 TInt CDefaultConsole::DoCreate() |
204 { |
171 { |
205 if (iUnderlyingConsole == NULL) |
172 TInt err = KErrGeneral; |
206 { |
|
207 TInt err = KErrGeneral; |
|
208 #ifdef __WINS__ |
173 #ifdef __WINS__ |
209 if (EmulatorNoGui()) |
174 if (EmulatorNoGui()) |
210 { |
175 { |
211 err = TryCreateConsole(_L("nullcons")); |
176 err = TryCreateConsole(_L("nullcons")); |
212 } |
177 } |
213 else if (EmulatorTextShell()) |
178 else if (EmulatorTextShell()) |
214 { |
179 { |
215 err = TryCreateConsole(_L("econs")); |
180 err = TryCreateConsole(_L("econs")); |
216 } |
181 } |
217 else |
182 else |
218 { |
|
219 #endif |
183 #endif |
|
184 { |
220 for (TInt i = 0; i < KNumConsoleImplementations; ++i) |
185 for (TInt i = 0; i < KNumConsoleImplementations; ++i) |
221 { |
186 { |
222 err = TryCreateConsole(KConsoleImplementations[i]); |
187 err = TryCreateConsole(KConsoleImplementations[i]); |
223 if (err == KErrNone) |
188 if (err == KErrNone) |
224 { |
189 { |
225 break; |
190 break; |
226 } |
191 } |
227 } |
192 } |
228 |
193 |
229 #ifdef __WINS__ |
194 } |
230 } |
195 return err; |
231 #endif |
|
232 |
|
233 __ASSERT_ALWAYS(err == KErrNone, Panic(EUnableToCreateConsole)); |
|
234 } |
|
235 } |
|
236 |
|
237 void CDefaultConsole::CreateIfRequired() const |
|
238 { |
|
239 const_cast<CDefaultConsole*>(this)->CreateIfRequired(); |
|
240 } |
196 } |
241 |
197 |
242 TInt CDefaultConsole::TryCreateConsole(const TDesC& aImplementation) |
198 TInt CDefaultConsole::TryCreateConsole(const TDesC& aImplementation) |
243 { |
199 { |
244 TInt err = iConsoleLibrary.Load(aImplementation); |
200 TInt err = iConsoleLibrary.Load(aImplementation); |