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 |
#include "trkdebugmgrcallbacks.h"
|
|
19 |
#include "trkdebugmanager.h"
|
|
20 |
#ifndef __TEXT_SHELL__
|
|
21 |
#include "DebugNotifier.h"
|
|
22 |
#endif
|
|
23 |
// System includes
|
|
24 |
#include <e32debug.h>
|
|
25 |
|
|
26 |
//Constants
|
|
27 |
#ifndef __TEXT_SHELL__
|
|
28 |
_LIT(KLibraryName, "DebugNotifier.dll");
|
|
29 |
#endif
|
|
30 |
|
|
31 |
#define SafeDelete(x) { if (x) delete x; x = NULL; }
|
|
32 |
|
|
33 |
//
|
|
34 |
// CTrkDebugManager (source)
|
|
35 |
//
|
|
36 |
|
|
37 |
//
|
|
38 |
// CTrkDebugManager::CTrkDebugManager()
|
|
39 |
//
|
|
40 |
// Constructor
|
|
41 |
//
|
|
42 |
CTrkDebugManager::CTrkDebugManager() : iTrkEngine(NULL), iConnStatus(ETrkNotConnected), iDebugging(EFalse), iPlugAndPlay(ETrue),
|
|
43 |
iDebugMgrCallback(NULL)
|
|
44 |
#ifndef __TEXT_SHELL__
|
|
45 |
, iToolsConnectionListener(NULL)
|
|
46 |
#endif
|
|
47 |
{
|
|
48 |
|
|
49 |
}
|
|
50 |
|
|
51 |
//
|
|
52 |
// CTrkDebugManager::~CTrkDebugManager()
|
|
53 |
//
|
|
54 |
// Destructor
|
|
55 |
//
|
|
56 |
CTrkDebugManager::~CTrkDebugManager()
|
|
57 |
{
|
|
58 |
StopListening();
|
|
59 |
#ifndef __TEXT_SHELL__
|
|
60 |
SafeDelete(iToolsConnectionListener);
|
|
61 |
#endif
|
|
62 |
SafeDelete(iTrkEngine);
|
|
63 |
}
|
|
64 |
|
|
65 |
//
|
|
66 |
// CTrkDebugManager::ConstructL()
|
|
67 |
//
|
|
68 |
// Second level constructor
|
|
69 |
//
|
|
70 |
void CTrkDebugManager::ConstructL()
|
|
71 |
{
|
|
72 |
iTrkEngine = CTrkEngine::NewL(this);
|
|
73 |
#ifndef __TEXT_SHELL__
|
|
74 |
TRAPD(err,iToolsConnectionListener = CToolsConnectionListener::NewL(this));
|
|
75 |
if(!err)
|
|
76 |
iToolsConnectionListener->StartListening();
|
|
77 |
#endif
|
|
78 |
}
|
|
79 |
|
|
80 |
//
|
|
81 |
// CTrkDebugManager::NewL()
|
|
82 |
//
|
|
83 |
// Creates an instance of CTrkDebugManager
|
|
84 |
//
|
|
85 |
CTrkDebugManager* CTrkDebugManager::NewL()
|
|
86 |
{
|
|
87 |
CTrkDebugManager* self = new(ELeave) CTrkDebugManager();
|
|
88 |
CleanupStack::PushL(self);
|
|
89 |
self->ConstructL();
|
|
90 |
CleanupStack::Pop(self);
|
|
91 |
return self;
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
//
|
|
96 |
// CTrkDebugManager::NewLC()
|
|
97 |
//
|
|
98 |
// Creates an instance of CTrkDebugManager
|
|
99 |
//
|
|
100 |
CTrkDebugManager* CTrkDebugManager::NewLC()
|
|
101 |
{
|
|
102 |
CTrkDebugManager* self = new(ELeave) CTrkDebugManager();
|
|
103 |
CleanupStack::PushL(self);
|
|
104 |
self->ConstructL();
|
|
105 |
|
|
106 |
return self;
|
|
107 |
}
|
|
108 |
//
|
|
109 |
// CTrkDebugManager::StartDebugging()
|
|
110 |
//
|
|
111 |
// This method is to start debugging when the connection changes and also to handle command line arguments
|
|
112 |
//
|
|
113 |
void CTrkDebugManager::StartDebuggingL(TTrkConnType aConnType)
|
|
114 |
{
|
|
115 |
TRAPD(error, iTrkEngine->StartL(aConnType));
|
|
116 |
|
|
117 |
if (error != KErrNone)
|
|
118 |
{
|
|
119 |
iTrkEngine->GetErrorInfo(iConnMsg);
|
|
120 |
iConnStatus = ETrkNotConnected;
|
|
121 |
iTrkEngine->Stop();
|
|
122 |
}
|
|
123 |
else
|
|
124 |
{
|
|
125 |
iTrkEngine->GetConnectionInfo(iConnMsg);
|
|
126 |
iConnStatus = ETrkConnected;
|
|
127 |
}
|
|
128 |
User::Leave(error);
|
|
129 |
}
|
|
130 |
//
|
|
131 |
// CTrkSrvScheduler::StartDebuggingL()
|
|
132 |
//
|
|
133 |
// This method is to start debugging with the bluetooth connection
|
|
134 |
//
|
|
135 |
void CTrkDebugManager::StartDebuggingL()
|
|
136 |
{
|
|
137 |
TRAPD(error, iTrkEngine->StartL());
|
|
138 |
|
|
139 |
if (error != KErrNone)
|
|
140 |
{
|
|
141 |
iTrkEngine->GetErrorInfo(iConnMsg);
|
|
142 |
iConnStatus = ETrkNotConnected;
|
|
143 |
iTrkEngine->Stop();
|
|
144 |
}
|
|
145 |
else
|
|
146 |
{
|
|
147 |
iTrkEngine->GetConnectionInfo(iConnMsg);
|
|
148 |
iConnStatus = iTrkEngine->GetConnectionStatus();
|
|
149 |
}
|
|
150 |
}
|
|
151 |
//
|
|
152 |
// CTrkSrvScheduler::StopDebugging()
|
|
153 |
//
|
|
154 |
// This method is to stop the debugging
|
|
155 |
//
|
|
156 |
void CTrkDebugManager::StopDebugging()
|
|
157 |
{
|
|
158 |
iTrkEngine->Stop();
|
|
159 |
iConnStatus = ETrkNotConnected;
|
|
160 |
iConnMsg = KNullDesC;
|
|
161 |
}
|
|
162 |
//
|
|
163 |
// CTrkSrvScheduler::StopDebugging()
|
|
164 |
//
|
|
165 |
// To get the version info of TRK
|
|
166 |
//
|
|
167 |
void CTrkDebugManager::GetVersion(TTRKVersion& aVersion)
|
|
168 |
{
|
|
169 |
iTrkEngine->GetVersionInfo(aVersion.iMajor, aVersion.iMinor, aVersion.iMajorAPI, aVersion.iMinorAPI, aVersion.iBuild);
|
|
170 |
}
|
|
171 |
//
|
|
172 |
// CTrkSrvScheduler::GetConnectionMsg()
|
|
173 |
//
|
|
174 |
// To find out the connection msg
|
|
175 |
//
|
|
176 |
void CTrkDebugManager::GetConnectionMsg(TDes& aConnStatusMsg)
|
|
177 |
{
|
|
178 |
aConnStatusMsg = iConnMsg;
|
|
179 |
}
|
|
180 |
|
|
181 |
//
|
|
182 |
// CTrkDebugManager::ConnectToDebuggerL()
|
|
183 |
//
|
|
184 |
void CTrkDebugManager::ConnectToDebuggerL()
|
|
185 |
{
|
|
186 |
StartDebuggingL();
|
|
187 |
}
|
|
188 |
|
|
189 |
//
|
|
190 |
// CTrkSrvScheduler::DisConnect()
|
|
191 |
//
|
|
192 |
void CTrkDebugManager::DisConnect()
|
|
193 |
{
|
|
194 |
StopDebugging();
|
|
195 |
}
|
|
196 |
|
|
197 |
//
|
|
198 |
// CTrkDebugManager::GetCurrentConnData()
|
|
199 |
//
|
|
200 |
void CTrkDebugManager::GetCurrentConnData(TTrkConnData& aConnData)
|
|
201 |
{
|
|
202 |
iTrkEngine->GetConnectionData(aConnData);
|
|
203 |
}
|
|
204 |
|
|
205 |
//
|
|
206 |
//CTrkDebugManager::SetCurrentConnData()
|
|
207 |
//
|
|
208 |
void CTrkDebugManager::SetCurrentConnData(TTrkConnData& aConnData)
|
|
209 |
{
|
|
210 |
iTrkEngine->SetConnectionData(aConnData);
|
|
211 |
}
|
|
212 |
//
|
|
213 |
// CTrkDebugManager::IsDebugging()
|
|
214 |
// returns whether debugging started or not
|
|
215 |
//
|
|
216 |
TBool CTrkDebugManager::IsDebugging()
|
|
217 |
{
|
|
218 |
iDebugging = iTrkEngine->IsDebugging();
|
|
219 |
return iDebugging;
|
|
220 |
}
|
|
221 |
//
|
|
222 |
// CTrkDebugManager::GetPlugAndPlayOption()
|
|
223 |
// returns whether the plug and play is set or not
|
|
224 |
//
|
|
225 |
TBool CTrkDebugManager::GetPlugAndPlayOption()
|
|
226 |
{
|
|
227 |
return iPlugAndPlay;
|
|
228 |
|
|
229 |
}
|
|
230 |
//
|
|
231 |
// CTrkDebugManager::SetPlugAndPlayOption()
|
|
232 |
// To set the plug and play option
|
|
233 |
//
|
|
234 |
void CTrkDebugManager::SetPlugAndPlayOption(TBool aPlugAndPlay)
|
|
235 |
{
|
|
236 |
iPlugAndPlay = aPlugAndPlay;
|
|
237 |
|
|
238 |
}
|
|
239 |
// ----------------------------------------------------
|
|
240 |
// CTrkDebugManager::OnConnection
|
|
241 |
// Called when a connection is opened, right now nothing is done
|
|
242 |
// as connection is always established from the user side.
|
|
243 |
// This call would be useful when we add for connecting automatically
|
|
244 |
// when a USB cable is plugged in while TRK is running.
|
|
245 |
// ----------------------------------------------------
|
|
246 |
//
|
|
247 |
void CTrkDebugManager::OnConnection()
|
|
248 |
{
|
|
249 |
iConnStatus = ETrkConnected;
|
|
250 |
iTrkEngine->GetConnectionInfo(iConnMsg);
|
|
251 |
if (iDebugMgrCallback)
|
|
252 |
iDebugMgrCallback->DebugConnStatusChanged(iConnStatus);
|
|
253 |
}
|
|
254 |
|
|
255 |
// ----------------------------------------------------
|
|
256 |
// CTrkDebugManager::OnCloseConnection
|
|
257 |
// Called when a connection is closed, update any of the UI clients.
|
|
258 |
// ----------------------------------------------------
|
|
259 |
//
|
|
260 |
void CTrkDebugManager::OnCloseConnection()
|
|
261 |
{
|
|
262 |
iConnStatus = ETrkNotConnected;
|
|
263 |
if (iDebugMgrCallback)
|
|
264 |
iDebugMgrCallback->DebugConnStatusChanged(iConnStatus);
|
|
265 |
}
|
|
266 |
|
|
267 |
//
|
|
268 |
// ----------------------------------------------------
|
|
269 |
// CTrkDebugManager::DebuggingStarted
|
|
270 |
// Called when a debug session is started.
|
|
271 |
// ----------------------------------------------------
|
|
272 |
//
|
|
273 |
void CTrkDebugManager::DebuggingStarted()
|
|
274 |
{
|
|
275 |
iDebugging = ETrue;
|
|
276 |
if (iDebugMgrCallback)
|
|
277 |
iDebugMgrCallback->DebuggingStatusChanged(iDebugging);
|
|
278 |
}
|
|
279 |
|
|
280 |
//
|
|
281 |
// ----------------------------------------------------
|
|
282 |
// CTrkDebugManager::DebuggingEnded
|
|
283 |
// Called when a debug session is ended.
|
|
284 |
// ----------------------------------------------------
|
|
285 |
//
|
|
286 |
void CTrkDebugManager::DebuggingEnded()
|
|
287 |
{
|
|
288 |
iDebugging = EFalse;
|
|
289 |
if (iDebugMgrCallback)
|
|
290 |
iDebugMgrCallback->DebuggingStatusChanged(iDebugging);
|
|
291 |
}
|
|
292 |
|
|
293 |
//
|
|
294 |
//----------------------------------------------------
|
|
295 |
//CTrkDebugManager::OnAsyncConnectionFailed()
|
|
296 |
//Called when bluetooth connection falied
|
|
297 |
//----------------------------------------------------
|
|
298 |
//
|
|
299 |
void CTrkDebugManager::OnAsyncConnectionFailed()
|
|
300 |
{
|
|
301 |
|
|
302 |
iConnStatus = ETrkConnectionError;
|
|
303 |
iTrkEngine->GetErrorInfo(iConnMsg);
|
|
304 |
if (iDebugMgrCallback)
|
|
305 |
iDebugMgrCallback->DebugConnStatusChanged(iConnStatus);
|
|
306 |
|
|
307 |
}
|
|
308 |
|
|
309 |
//
|
|
310 |
//----------------------------------------------------
|
|
311 |
// CTrkDebugManager::ConnectionAvailable()
|
|
312 |
// Called when the usb connection available
|
|
313 |
//----------------------------------------------------
|
|
314 |
//
|
|
315 |
void CTrkDebugManager::ConnectionAvailable()
|
|
316 |
{
|
|
317 |
iPlugAndPlay = iTrkEngine->GetPlugPlaySetting();
|
|
318 |
|
|
319 |
if(!iDebugging && iPlugAndPlay)
|
|
320 |
{
|
|
321 |
StopDebugging();
|
|
322 |
TRAPD(error, StartDebuggingL(ETrkUsbDbgTrc));
|
|
323 |
if (!error)
|
|
324 |
{
|
|
325 |
TRAP(error, NotifyTheUserL());
|
|
326 |
}
|
|
327 |
if (iDebugMgrCallback)
|
|
328 |
iDebugMgrCallback->DebugConnStatusChanged(iConnStatus);
|
|
329 |
}
|
|
330 |
}
|
|
331 |
|
|
332 |
//
|
|
333 |
//----------------------------------------------------
|
|
334 |
// CTrkDebugManager::ConnectionUnAvailable()
|
|
335 |
// Called when the usb cable is disconnected
|
|
336 |
//----------------------------------------------------
|
|
337 |
//
|
|
338 |
void CTrkDebugManager::ConnectionUnAvailable()
|
|
339 |
{
|
|
340 |
TTrkConnType connType = iTrkEngine->GetConnectionType();
|
|
341 |
if(connType == ETrkUsbDbgTrc)
|
|
342 |
{
|
|
343 |
StopDebugging();
|
|
344 |
TRAPD(error, StartDebuggingL(ETrkXti));
|
|
345 |
if (!error)
|
|
346 |
{
|
|
347 |
// Nothing to do for now
|
|
348 |
}
|
|
349 |
if (iDebugMgrCallback)
|
|
350 |
iDebugMgrCallback->DebugConnStatusChanged(iConnStatus);
|
|
351 |
}
|
|
352 |
}
|
|
353 |
|
|
354 |
//
|
|
355 |
//----------------------------------------------------
|
|
356 |
// CTrkDebugManager::NotifyTheUser()
|
|
357 |
// To notify the user that debug services have started
|
|
358 |
//----------------------------------------------------
|
|
359 |
//
|
|
360 |
void CTrkDebugManager::NotifyTheUserL()
|
|
361 |
{
|
|
362 |
#ifndef __TEXT_SHELL__
|
|
363 |
RLibrary library;
|
|
364 |
// Dynamically load DLL
|
|
365 |
TInt err = library.Load(KLibraryName);
|
|
366 |
if(!err)
|
|
367 |
{
|
|
368 |
TLibraryFunction entry=library.Lookup(1);
|
|
369 |
IDebugNotifier* notify =(IDebugNotifier*)entry();
|
|
370 |
CleanupStack::PushL(notify);
|
|
371 |
notify->NotifyTheUserL();
|
|
372 |
CleanupStack::PopAndDestroy();
|
|
373 |
// Finished with the DLL
|
|
374 |
library.Close();
|
|
375 |
}
|
|
376 |
#endif
|
|
377 |
}
|
|
378 |
//
|
|
379 |
//----------------------------------------------------
|
|
380 |
// CTrkDebugManager::StopListening()
|
|
381 |
// To stop listening to cable connections
|
|
382 |
//----------------------------------------------------
|
|
383 |
//
|
|
384 |
void CTrkDebugManager::StopListening()
|
|
385 |
{
|
|
386 |
#ifndef __TEXT_SHELL__
|
|
387 |
if(iToolsConnectionListener)
|
|
388 |
iToolsConnectionListener->StopListening();
|
|
389 |
#endif
|
|
390 |
}
|