0
|
1 |
/*
|
|
2 |
* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "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 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "TrkConsole.h"
|
|
20 |
#include "trksrvclisession.h"
|
|
21 |
|
|
22 |
|
|
23 |
#define SHOW_CONSOLE
|
|
24 |
|
|
25 |
#ifdef SHOW_CONSOLE
|
|
26 |
static CTrkConsoleIO* TrkIO = NULL;
|
|
27 |
#endif
|
|
28 |
|
|
29 |
#define SafeDelete(x) { if (x) delete x; x = NULL; }
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
//
|
|
35 |
//
|
|
36 |
// CKeyboardInput implementation
|
|
37 |
//
|
|
38 |
//
|
|
39 |
|
|
40 |
//
|
|
41 |
// CKeyboardInput constructor
|
|
42 |
//
|
|
43 |
CKeyboardInput::CKeyboardInput(CConsoleBase* aConsole)
|
|
44 |
: CActive(EPriorityUserInput),
|
|
45 |
iConsole(aConsole)
|
|
46 |
{
|
|
47 |
CActiveScheduler::Add(this);
|
|
48 |
}
|
|
49 |
|
|
50 |
//
|
|
51 |
// CKeyboardInput destructor
|
|
52 |
//
|
|
53 |
CKeyboardInput::~CKeyboardInput()
|
|
54 |
{
|
|
55 |
Cancel();
|
|
56 |
Deque();
|
|
57 |
}
|
|
58 |
|
|
59 |
//
|
|
60 |
// CKeyboardInput::ListenToKeyboard
|
|
61 |
//
|
|
62 |
// Wait for a key to be pressed
|
|
63 |
//
|
|
64 |
void CKeyboardInput::ListenToKeyboard()
|
|
65 |
{
|
|
66 |
iConsole->Read(iStatus);
|
|
67 |
SetActive();
|
|
68 |
}
|
|
69 |
|
|
70 |
//
|
|
71 |
// CKeyboardInput::RunL
|
|
72 |
//
|
|
73 |
// Called when a key is pressed
|
|
74 |
//
|
|
75 |
void CKeyboardInput::RunL()
|
|
76 |
{
|
|
77 |
TKeyCode key = iConsole->KeyCode();
|
|
78 |
if (key == 'q' || key == 'Q')
|
|
79 |
CActiveScheduler::Stop();
|
|
80 |
else
|
|
81 |
ListenToKeyboard();
|
|
82 |
}
|
|
83 |
|
|
84 |
//
|
|
85 |
// CKeyboardInput::DoCancel
|
|
86 |
//
|
|
87 |
// Stop waiting for keyboard input
|
|
88 |
//
|
|
89 |
void CKeyboardInput::DoCancel()
|
|
90 |
{
|
|
91 |
iConsole->ReadCancel();
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
//
|
|
96 |
//
|
|
97 |
// CTrkConsoleIO implementation
|
|
98 |
//
|
|
99 |
//
|
|
100 |
|
|
101 |
//
|
|
102 |
// CTrkConsoleIO constructor
|
|
103 |
//
|
|
104 |
CTrkConsoleIO::CTrkConsoleIO()
|
|
105 |
: iConsole(0),
|
|
106 |
iKeyboardInput(0)
|
|
107 |
{
|
|
108 |
TRAPD(error, iConsole = Console::NewL(_L("TRK"), TSize(KConsFullScreen, KConsFullScreen)));
|
|
109 |
if (error != KErrNone)
|
|
110 |
User::Panic(_L("TRK failed to allocate CConsoleBase"), __LINE__);
|
|
111 |
|
|
112 |
iKeyboardInput = new CKeyboardInput(iConsole);
|
|
113 |
if (iKeyboardInput == 0)
|
|
114 |
User::Panic(_L("TRK failed to allocate CKeyboardInput"), __LINE__);
|
|
115 |
|
|
116 |
iKeyboardInput->ListenToKeyboard();
|
|
117 |
}
|
|
118 |
|
|
119 |
//
|
|
120 |
// CTrkConsoleIO destructor
|
|
121 |
//
|
|
122 |
CTrkConsoleIO::~CTrkConsoleIO()
|
|
123 |
{
|
|
124 |
SafeDelete(iKeyboardInput);
|
|
125 |
SafeDelete(iConsole);
|
|
126 |
}
|
|
127 |
|
|
128 |
//
|
|
129 |
// CTrkConsoleIO::PrintToScreen
|
|
130 |
//
|
|
131 |
// Print a message to the screen
|
|
132 |
//
|
|
133 |
void CTrkConsoleIO::PrintToScreen(TRefByValue<const TDesC> aFmt, ...)
|
|
134 |
{
|
|
135 |
VA_LIST(l);
|
|
136 |
VA_START(l, aFmt);
|
|
137 |
iBuffer.FormatList(aFmt, l);
|
|
138 |
|
|
139 |
iConsole->Printf(iBuffer);
|
|
140 |
}
|
|
141 |
|
|
142 |
//
|
|
143 |
// CTrkConsoleIO::Terminating
|
|
144 |
//
|
|
145 |
// Notify user of termination
|
|
146 |
//
|
|
147 |
void CTrkConsoleIO::Terminating()
|
|
148 |
{
|
|
149 |
iConsole->Printf(_L("\r\nPress any key to exit."));
|
|
150 |
iKeyboardInput->Cancel();
|
|
151 |
iConsole->Getch();
|
|
152 |
}
|
|
153 |
//
|
|
154 |
// MainL
|
|
155 |
//
|
|
156 |
// Create the engine and the communications interface and start the active scheduler
|
|
157 |
//
|
|
158 |
void MainL()
|
|
159 |
{
|
|
160 |
RProcess().SetPriority(EPriorityHigh);
|
|
161 |
RThread().SetPriority(EPriorityAbsoluteHigh);
|
|
162 |
|
|
163 |
RTrkSrvCliSession trkSession;
|
|
164 |
TTrkConnStatus iConnStatus;
|
|
165 |
TBuf<KMaxPath> buf;
|
|
166 |
TInt majorVersion, minorVersion, majorAPIVersion, minorAPIVersion, buildNumber;
|
|
167 |
|
|
168 |
TInt err = trkSession.ConnectToServer();
|
|
169 |
if (!err)
|
|
170 |
{
|
|
171 |
// Ideally we need to connect here, but when the TRK server is started, connect automatically happens.
|
|
172 |
// So we don't need to explicitly connect here. If the server is changed not to connect automatically at startup
|
|
173 |
// then we need to connect here.
|
|
174 |
//err = trkSession.Connect();
|
|
175 |
if(!err)
|
|
176 |
{
|
|
177 |
trkSession.GetDebugConnStatus(iConnStatus, buf);
|
|
178 |
trkSession.GetTrkVersion(majorVersion, minorVersion, majorAPIVersion, minorAPIVersion, buildNumber);
|
|
179 |
}
|
|
180 |
}
|
|
181 |
|
|
182 |
#ifdef SHOW_CONSOLE
|
|
183 |
TrkIO->PrintToScreen(_L("Welcome to TRK for Symbian OS\r\n"));
|
|
184 |
TrkIO->PrintToScreen(_L("Version %d.%d.%d\r\n"), majorVersion, minorVersion, buildNumber);
|
|
185 |
TrkIO->PrintToScreen(_L("Implementing TRK API version %d.%d\r\n"), majorAPIVersion, minorAPIVersion);
|
|
186 |
TrkIO->PrintToScreen(_L("Press 'Q' to quit.\r\n\r\n"));
|
|
187 |
#endif
|
|
188 |
|
|
189 |
#ifdef SHOW_CONSOLE
|
|
190 |
_LIT(KLfCr, "\r\n");
|
|
191 |
|
|
192 |
TPtrC ptr(buf);
|
|
193 |
TInt pos = 0;
|
|
194 |
TInt lineStart = 0;
|
|
195 |
TInt length = 0;
|
|
196 |
|
|
197 |
while (KErrNotFound != (pos = ptr.Find(KLfCr)))
|
|
198 |
{
|
|
199 |
ptr.Set(&buf[lineStart], pos);
|
|
200 |
lineStart = lineStart + pos + 2;
|
|
201 |
TrkIO->PrintToScreen(ptr);
|
|
202 |
TrkIO->PrintToScreen(KLfCr);
|
|
203 |
length = buf.Length() - lineStart;
|
|
204 |
if (length > 0)
|
|
205 |
{
|
|
206 |
ptr.Set(&buf[lineStart], length);
|
|
207 |
}
|
|
208 |
}
|
|
209 |
#endif
|
|
210 |
|
|
211 |
CActiveScheduler::Start();
|
|
212 |
|
|
213 |
trkSession.DisConnect();
|
|
214 |
trkSession.ShutDownServer();
|
|
215 |
trkSession.Close();
|
|
216 |
}
|
|
217 |
|
|
218 |
//
|
|
219 |
// EXE entrypoint
|
|
220 |
//
|
|
221 |
TInt E32Main()
|
|
222 |
{
|
|
223 |
__UHEAP_MARK;
|
|
224 |
|
|
225 |
CTrapCleanup* cleanupStack = CTrapCleanup::New();
|
|
226 |
if (cleanupStack == 0)
|
|
227 |
User::Panic(_L("TRK failed to allocate CTrapCleanup"), __LINE__);
|
|
228 |
|
|
229 |
CActiveScheduler* scheduler = new CActiveScheduler;
|
|
230 |
if (scheduler == 0)
|
|
231 |
User::Panic(_L("TRK failed to allocate CActiveScheduler"), __LINE__);
|
|
232 |
|
|
233 |
CActiveScheduler::Install(scheduler);
|
|
234 |
|
|
235 |
#ifdef SHOW_CONSOLE
|
|
236 |
TrkIO = new CTrkConsoleIO;
|
|
237 |
|
|
238 |
if (!TrkIO)
|
|
239 |
User::Panic(_L("TRK failed to allocate CTrkConsoleIO"), __LINE__);
|
|
240 |
#endif
|
|
241 |
|
|
242 |
TRAPD(error, MainL());
|
|
243 |
|
|
244 |
#ifdef SHOW_CONSOLE
|
|
245 |
if (error != KErrNone)
|
|
246 |
{
|
|
247 |
TrkIO->PrintToScreen(_L("\r\nUnexpected error %d"), error);
|
|
248 |
TrkIO->Terminating();
|
|
249 |
}
|
|
250 |
SafeDelete(TrkIO);
|
|
251 |
#endif
|
|
252 |
|
|
253 |
SafeDelete(scheduler);
|
|
254 |
SafeDelete(cleanupStack);
|
|
255 |
|
|
256 |
__UHEAP_MARKEND;
|
|
257 |
|
|
258 |
User::Exit(0);
|
|
259 |
return 0;
|
|
260 |
}
|