0
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 |
|
|
20 |
#include <e32base.h>
|
|
21 |
#include <e32cons.h>
|
|
22 |
|
|
23 |
#include "dbgtrccomm.h"
|
|
24 |
#include "dummytraceserver.h"
|
|
25 |
#include "dbgtrctest.h"
|
|
26 |
|
|
27 |
LOCAL_C CConsoleIO* consoleIO = NULL;
|
|
28 |
#define SafeDelete(x) { if (x) delete x; x = NULL; }
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
CKeyboardInput::CKeyboardInput(CConsoleBase* aConsole)
|
|
33 |
: CActive(EPriorityUserInput),
|
|
34 |
iConsole(aConsole)
|
|
35 |
{
|
|
36 |
CActiveScheduler::Add(this);
|
|
37 |
}
|
|
38 |
|
|
39 |
CKeyboardInput::~CKeyboardInput()
|
|
40 |
{
|
|
41 |
Cancel();
|
|
42 |
Deque();
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
void CKeyboardInput::ListenToKeyboard()
|
|
47 |
{
|
|
48 |
iConsole->Read(iStatus);
|
|
49 |
SetActive();
|
|
50 |
}
|
|
51 |
|
|
52 |
void CKeyboardInput::RunL()
|
|
53 |
{
|
|
54 |
TKeyCode key = iConsole->KeyCode();
|
|
55 |
if (key == 'q' || key == 'Q')
|
|
56 |
CActiveScheduler::Stop();
|
|
57 |
else
|
|
58 |
ListenToKeyboard();
|
|
59 |
}
|
|
60 |
|
|
61 |
void CKeyboardInput::DoCancel()
|
|
62 |
{
|
|
63 |
iConsole->ReadCancel();
|
|
64 |
}
|
|
65 |
|
|
66 |
CConsoleIO::CConsoleIO()
|
|
67 |
: iConsole(0),
|
|
68 |
iKeyboardInput(0)
|
|
69 |
{
|
|
70 |
TRAPD(error, iConsole = Console::NewL(_L("DBGTRCTEST"), TSize(KConsFullScreen, KConsFullScreen)));
|
|
71 |
if (error != KErrNone)
|
|
72 |
User::Panic(_L("DBGTRCTEST failed to allocate CConsoleBase"), __LINE__);
|
|
73 |
|
|
74 |
iKeyboardInput = new CKeyboardInput(iConsole);
|
|
75 |
if (iKeyboardInput == 0)
|
|
76 |
User::Panic(_L("DBGTRCTEST failed to allocate CKeyboardInput"), __LINE__);
|
|
77 |
|
|
78 |
iKeyboardInput->ListenToKeyboard();
|
|
79 |
}
|
|
80 |
|
|
81 |
CConsoleIO::~CConsoleIO()
|
|
82 |
{
|
|
83 |
SafeDelete(iKeyboardInput);
|
|
84 |
SafeDelete(iConsole);
|
|
85 |
}
|
|
86 |
|
|
87 |
//
|
|
88 |
// CConsoleIO::PrintToScreen
|
|
89 |
//
|
|
90 |
// Print a message to the screen
|
|
91 |
//
|
|
92 |
void CConsoleIO::PrintToScreen(TRefByValue<const TDesC> aFmt, ...)
|
|
93 |
{
|
|
94 |
VA_LIST(l);
|
|
95 |
VA_START(l, aFmt);
|
|
96 |
iBuffer.FormatList(aFmt, l);
|
|
97 |
|
|
98 |
iConsole->Printf(iBuffer);
|
|
99 |
}
|
|
100 |
|
|
101 |
//
|
|
102 |
// CConsoleIO::Terminating
|
|
103 |
//
|
|
104 |
// Notify user of termination
|
|
105 |
//
|
|
106 |
void CConsoleIO::Terminating()
|
|
107 |
{
|
|
108 |
iConsole->Printf(_L("\r\nPress any key to exit."));
|
|
109 |
iKeyboardInput->Cancel();
|
|
110 |
iConsole->Getch();
|
|
111 |
}
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
LOCAL_C void runBasicTests()
|
|
116 |
{
|
|
117 |
RDbgTrcComm acmPort;
|
|
118 |
|
|
119 |
TInt err = acmPort.Connect();
|
|
120 |
if (err != KErrNone)
|
|
121 |
{
|
|
122 |
consoleIO->PrintToScreen(_L("Connect failed: %d"), err);
|
|
123 |
return;
|
|
124 |
}
|
|
125 |
consoleIO->PrintToScreen(_L("Successfully the DbgTrc Comms server\n"));
|
|
126 |
|
|
127 |
|
|
128 |
err = acmPort.Open();
|
|
129 |
if (err != KErrNone)
|
|
130 |
{
|
|
131 |
consoleIO->PrintToScreen(_L("Opening port failed: %d\n"), err);
|
|
132 |
return;
|
|
133 |
}
|
|
134 |
consoleIO->PrintToScreen(_L("Successfully opened the DbgTrc Comm Port\n"));
|
|
135 |
|
|
136 |
|
|
137 |
TAcmConfig config;
|
|
138 |
err = acmPort.GetAcmConfig(config);
|
|
139 |
if (err != KErrNone)
|
|
140 |
{
|
|
141 |
consoleIO->PrintToScreen(_L("Unable to get port configuration: %d\n"), err);
|
|
142 |
return;
|
|
143 |
}
|
|
144 |
consoleIO->PrintToScreen(_L("Current ACM port number: %d\n"), config().iPortNumber);
|
|
145 |
|
|
146 |
err = acmPort.RegisterProtocolID(EOstProtTrk, EFalse);
|
|
147 |
if (err != KErrNone)
|
|
148 |
{
|
|
149 |
consoleIO->PrintToScreen(_L("Unable to register protocol: %d\n"), err);
|
|
150 |
return;
|
|
151 |
}
|
|
152 |
consoleIO->PrintToScreen(_L("Registered the protocol id: %d\n"), EOstProtTraceCore);
|
|
153 |
|
|
154 |
TAcmConfigV01 config1(*(TAcmConfigV01*)config.Ptr());
|
|
155 |
|
|
156 |
TBuf8<100> msg;
|
|
157 |
_LIT8(KTRACEMSG, "Test trace server message: %d\n");
|
|
158 |
|
|
159 |
TRequestStatus status;
|
|
160 |
|
|
161 |
for (TInt i=0; i<1000; i++)
|
|
162 |
{
|
|
163 |
msg.Format(KTRACEMSG, i);
|
|
164 |
acmPort.WriteMessage(status, msg, ETrue);
|
|
165 |
User::WaitForRequest(status);
|
|
166 |
|
|
167 |
User::After(100);
|
|
168 |
}
|
|
169 |
|
|
170 |
if (status.Int() != KErrNone)
|
|
171 |
{
|
|
172 |
consoleIO->PrintToScreen(_L("Unable to write the message: %d\n"), status.Int());
|
|
173 |
return;
|
|
174 |
}
|
|
175 |
consoleIO->PrintToScreen(_L("Successfuly sent the message\n"));
|
|
176 |
|
|
177 |
err = acmPort.UnRegisterProtocolID(EOstProtTraceCore);
|
|
178 |
if (err != KErrNone)
|
|
179 |
{
|
|
180 |
consoleIO->PrintToScreen(_L("Unable to unregister protocol: %d\n"), err);
|
|
181 |
return;
|
|
182 |
}
|
|
183 |
consoleIO->PrintToScreen(_L("Successfuly unregistered the protocol id: %d\n"), EOstProtTraceCore);
|
|
184 |
|
|
185 |
|
|
186 |
err = acmPort.Close();
|
|
187 |
if (err != KErrNone)
|
|
188 |
{
|
|
189 |
consoleIO->PrintToScreen(_L("Unable to close the port: %d\n"), err);
|
|
190 |
return;
|
|
191 |
}
|
|
192 |
consoleIO->PrintToScreen(_L("Successfuly closed the port\n"));
|
|
193 |
}
|
|
194 |
|
|
195 |
|
|
196 |
void MainL()
|
|
197 |
{
|
|
198 |
//RProcess().SetPriority(EPriorityHigh);
|
|
199 |
//RThread().SetPriority(EPriorityAbsoluteHigh);
|
|
200 |
|
|
201 |
consoleIO->PrintToScreen(_L("DBGTRCTEST App\r\n"));
|
|
202 |
|
|
203 |
//runBasicTests();
|
|
204 |
|
|
205 |
CDummyTraceServer* traceServer = CDummyTraceServer::NewLC(consoleIO);
|
|
206 |
traceServer->Start();
|
|
207 |
consoleIO->PrintToScreen(_L("Press q or Q to quit\n"));
|
|
208 |
|
|
209 |
CActiveScheduler::Start();
|
|
210 |
|
|
211 |
CleanupStack::PopAndDestroy(traceServer);
|
|
212 |
}
|
|
213 |
|
|
214 |
//
|
|
215 |
// EXE entrypoint
|
|
216 |
//
|
|
217 |
TInt E32Main()
|
|
218 |
{
|
|
219 |
__UHEAP_MARK;
|
|
220 |
|
|
221 |
CTrapCleanup* cleanupStack = CTrapCleanup::New();
|
|
222 |
if (cleanupStack == 0)
|
|
223 |
User::Panic(_L("DBGTRCTEST failed to allocate CTrapCleanup"), __LINE__);
|
|
224 |
|
|
225 |
CActiveScheduler* scheduler = new CActiveScheduler;
|
|
226 |
if (scheduler == 0)
|
|
227 |
User::Panic(_L("DBGTRCTEST failed to allocate CActiveScheduler"), __LINE__);
|
|
228 |
|
|
229 |
CActiveScheduler::Install(scheduler);
|
|
230 |
|
|
231 |
consoleIO = new CConsoleIO;
|
|
232 |
|
|
233 |
if (!consoleIO)
|
|
234 |
User::Panic(_L("DBGTRCTEST failed to allocate CTrkConsoleIO"), __LINE__);
|
|
235 |
|
|
236 |
TRAPD(error, MainL());
|
|
237 |
|
|
238 |
if (error != KErrNone)
|
|
239 |
{
|
|
240 |
consoleIO->PrintToScreen(_L("\r\nUnexpected error %d"), error);
|
|
241 |
consoleIO->Terminating();
|
|
242 |
}
|
|
243 |
|
|
244 |
SafeDelete(consoleIO);
|
|
245 |
SafeDelete(scheduler);
|
|
246 |
SafeDelete(cleanupStack);
|
|
247 |
|
|
248 |
__UHEAP_MARKEND;
|
|
249 |
|
|
250 |
User::Exit(0);
|
|
251 |
return 0;
|
|
252 |
}
|