|
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 "TrkEngineModel.h" |
|
20 #include "TrkEngine.h" |
|
21 #ifdef __USE_NEW_DEBUG_API__ |
|
22 #include "trkdispatchlayer2.h" |
|
23 #else |
|
24 #include "TrkDispatchLayer.h" |
|
25 #endif |
|
26 |
|
27 #ifndef __NOKIA_TEXT_SHELL__ |
|
28 #include "TrkSerialCommPort.h" |
|
29 #endif |
|
30 |
|
31 #ifndef __TEXT_SHELL__ |
|
32 #include "TrkBtSocketCommPort.h" |
|
33 #include "TrkUsbPortListener.h" |
|
34 #include "TrkDbgTrcCommPort.h" |
|
35 #endif //__TEXT_SHELL__ |
|
36 |
|
37 #ifdef __OEM_TRK__ |
|
38 #include "TrkDccCommPort.h" |
|
39 |
|
40 #ifdef __ENABLE_XTI__ |
|
41 #include "TrkXtiCommPort.h" |
|
42 #endif |
|
43 #endif //__OEM_TRK__ |
|
44 |
|
45 |
|
46 // |
|
47 // |
|
48 // CTrkEngine implementation |
|
49 // |
|
50 // |
|
51 |
|
52 // |
|
53 // CTrkEngine::NewL |
|
54 // |
|
55 EXPORT_C CTrkEngine* CTrkEngine::NewL() |
|
56 { |
|
57 CTrkEngine* self = new(ELeave) CTrkEngine; |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // |
|
63 // CTrkEngine::NewLC |
|
64 // |
|
65 EXPORT_C CTrkEngine* CTrkEngine::NewLC() |
|
66 { |
|
67 CTrkEngine* self = new(ELeave) CTrkEngine; |
|
68 CleanupStack::PushL(self); |
|
69 |
|
70 self->ConstructL(); |
|
71 |
|
72 return self; |
|
73 } |
|
74 |
|
75 |
|
76 EXPORT_C CTrkEngine* CTrkEngine::NewL(MTrkEngineCallback* aCallback) |
|
77 { |
|
78 CTrkEngine* self = new(ELeave) CTrkEngine; |
|
79 self->ConstructL(aCallback); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // |
|
84 // CTrkEngine::NewLC |
|
85 // |
|
86 EXPORT_C CTrkEngine* CTrkEngine::NewLC(MTrkEngineCallback* aCallback) |
|
87 { |
|
88 CTrkEngine* self = new(ELeave) CTrkEngine; |
|
89 CleanupStack::PushL(self); |
|
90 |
|
91 self->ConstructL(aCallback); |
|
92 |
|
93 return self; |
|
94 } |
|
95 |
|
96 // |
|
97 // CTrkEngine destructor |
|
98 // |
|
99 CTrkEngine::CTrkEngine() |
|
100 :iCommPort(NULL), |
|
101 iDispatchLayer(NULL), |
|
102 iModel(NULL), |
|
103 iCommPortListener(NULL), |
|
104 iInactivityTimerDisabler(NULL), |
|
105 iCallback(NULL), |
|
106 iCurrentConnType(ETrkBt) |
|
107 { |
|
108 } |
|
109 |
|
110 // |
|
111 // CTrkEngine::ConstructL |
|
112 // |
|
113 |
|
114 void CTrkEngine::ConstructL(MTrkEngineCallback* aCallback) |
|
115 { |
|
116 // make sure the kernel side device driver is not already loaded |
|
117 User::FreeLogicalDevice(KMetroTrkDriverName); |
|
118 // load the kernel side device driver |
|
119 #ifndef __WINS__ |
|
120 TInt err = User::LoadLogicalDevice(_L("TrkDriver.ldd")); |
|
121 if ((KErrAlreadyExists != err) && (KErrNone != err)) |
|
122 User::Leave(err); |
|
123 #endif |
|
124 |
|
125 iModel = CTrkEngineModel::NewL(); |
|
126 iCallback = aCallback; |
|
127 } |
|
128 |
|
129 // |
|
130 // CTrkEngine destructor |
|
131 // |
|
132 EXPORT_C CTrkEngine::~CTrkEngine() |
|
133 { |
|
134 #ifndef __TEXT_SHELL__ |
|
135 // if USB connection, then stop the cable listener as well. |
|
136 if (iCurrentConnType == ETrkUsbDbgTrc) |
|
137 { |
|
138 iCommPortListener->StopListening(); |
|
139 } |
|
140 #endif |
|
141 |
|
142 //Unload the driver stuff |
|
143 #ifndef __WINS__ |
|
144 TInt err = User::FreeLogicalDevice(KMetroTrkDriverName); |
|
145 if (KErrNone != err) |
|
146 User::Panic(_L("FreeLogicalDevice failed"), err); |
|
147 #endif |
|
148 |
|
149 SafeDelete(iDispatchLayer); |
|
150 SafeDelete(iModel); |
|
151 SafeDelete(iCommPortListener); |
|
152 SafeDelete(iInactivityTimerDisabler); |
|
153 } |
|
154 |
|
155 // |
|
156 // CTrkEngine::Start |
|
157 // |
|
158 EXPORT_C void CTrkEngine::StartL() |
|
159 { |
|
160 iModel->GetConnData(iCurrentConnData); |
|
161 iCurrentConnType = iCurrentConnData.iConnType; |
|
162 |
|
163 DoStartL(); |
|
164 } |
|
165 |
|
166 // |
|
167 // CTrkEngine::Start |
|
168 // |
|
169 EXPORT_C void CTrkEngine::StartL(TTrkConnType aConnType) |
|
170 { |
|
171 iModel->GetDefaultConnData(aConnType, iCurrentConnData); |
|
172 iCurrentConnType = iCurrentConnData.iConnType; |
|
173 |
|
174 DoStartL(); |
|
175 } |
|
176 |
|
177 // |
|
178 // CTrkEngine::Stop |
|
179 // |
|
180 EXPORT_C void CTrkEngine::Stop() |
|
181 { |
|
182 if (iDispatchLayer) |
|
183 { |
|
184 iDispatchLayer->StopListening(); |
|
185 SafeDelete(iDispatchLayer); |
|
186 iCommPort = NULL; //port is deleted by the framing layer |
|
187 } |
|
188 } |
|
189 |
|
190 // |
|
191 // CTrkEngine::GetVersionInfo |
|
192 // |
|
193 EXPORT_C void CTrkEngine::GetVersionInfo(TInt &aMajorVersion, TInt &aMinorVersion, TInt &aMajorAPIVersion, TInt &aMinorAPIVersion, TInt &aBuildNumber) |
|
194 { |
|
195 CTrkDispatchLayer::GetVersionInfo(aMajorVersion, aMinorVersion, aMajorAPIVersion, aMinorAPIVersion, aBuildNumber); |
|
196 } |
|
197 |
|
198 // |
|
199 // CTrkEngine::GetConnectionInfo |
|
200 // |
|
201 EXPORT_C void CTrkEngine::GetConnectionInfo(TDes& aMessage) |
|
202 { |
|
203 aMessage = KNullDesC; |
|
204 if (iCommPort) |
|
205 { |
|
206 iCommPort->GetConnectionInfo(aMessage); |
|
207 } |
|
208 } |
|
209 // |
|
210 // CTrkEngine::GetConnectionInfo |
|
211 // |
|
212 EXPORT_C TTrkConnStatus CTrkEngine::GetConnectionStatus() |
|
213 { |
|
214 if (iCommPort) |
|
215 { |
|
216 |
|
217 return(iCommPort->GetConnectionStatus()); |
|
218 } |
|
219 else |
|
220 return ETrkConnectionError; |
|
221 |
|
222 } |
|
223 // |
|
224 // CTrkEngine::GetErrorInfo |
|
225 // |
|
226 EXPORT_C void CTrkEngine::GetErrorInfo(TDes& aMessage) |
|
227 { |
|
228 if (iCommPort) |
|
229 { |
|
230 iCommPort->GetErrorInfo(aMessage); |
|
231 } |
|
232 else |
|
233 { |
|
234 aMessage = iErrorMessage; |
|
235 } |
|
236 } |
|
237 |
|
238 // |
|
239 // CTrkEngine::GetConnectionData |
|
240 // |
|
241 EXPORT_C void CTrkEngine::GetConnectionData(TTrkConnData& aConnData) |
|
242 { |
|
243 iModel->GetConnData(aConnData); |
|
244 } |
|
245 |
|
246 // |
|
247 // CTrkEngine::SetConnectionData |
|
248 // |
|
249 EXPORT_C TInt CTrkEngine::SetConnectionData(TTrkConnData& aConnData) |
|
250 { |
|
251 return iModel->SetConnData(aConnData); |
|
252 } |
|
253 |
|
254 // |
|
255 // CTrkEngine::IsDebugging |
|
256 // |
|
257 EXPORT_C TInt CTrkEngine::IsDebugging() |
|
258 { |
|
259 if (iDispatchLayer) |
|
260 { |
|
261 return iDispatchLayer->IsDebugging(); |
|
262 } |
|
263 return EFalse; |
|
264 } |
|
265 |
|
266 // |
|
267 // CTrkEngine::GetConnectionType |
|
268 // |
|
269 EXPORT_C TTrkConnType CTrkEngine::GetConnectionType() |
|
270 { |
|
271 return iCurrentConnType; |
|
272 } |
|
273 // |
|
274 // CTrkEngine::GetPlugPlaySetting() |
|
275 // |
|
276 EXPORT_C TBool CTrkEngine::GetPlugPlaySetting() |
|
277 { |
|
278 TBool PlugPLaySetting; |
|
279 PlugPLaySetting = iModel->GetPlugPlaySettingValue(); |
|
280 return PlugPLaySetting; |
|
281 |
|
282 } |
|
283 // |
|
284 // CTrkEngine::DoStartL |
|
285 // |
|
286 void CTrkEngine::DoStartL() |
|
287 { |
|
288 CreateCommInterfaceL(); |
|
289 |
|
290 // ownership of the comm port is passed down to CTrkFramingLayer |
|
291 iDispatchLayer = CTrkDispatchLayer::NewL(iCommPort, this); |
|
292 |
|
293 #ifndef __TEXT_SHELL__ |
|
294 // start listening for the cable connection. |
|
295 /* not required here as server starts listening |
|
296 |
|
297 if (iCurrentConnType == ETrkUsbDbgTrc) |
|
298 { |
|
299 if (!iCommPortListener) // create the listener only once |
|
300 iCommPortListener = new CTrkUsbPortListener(this); |
|
301 |
|
302 iCommPortListener->ListenL(); |
|
303 } |
|
304 */ |
|
305 #endif //__TEXT_SHELL__ |
|
306 |
|
307 iCommPort->OpenPortL(); |
|
308 if (iCommPort->IsConnectionEstablished()) |
|
309 { |
|
310 iDispatchLayer->Listen(); |
|
311 |
|
312 if (iCurrentConnData.iConnType == ETrkBt || iCurrentConnData.iConnType == ETrkSerial) |
|
313 iCommPort->SendDataL(_L8("Trk for Symbian OS started")); |
|
314 } |
|
315 |
|
316 } |
|
317 |
|
318 // |
|
319 // CTrkEngine::CreateCommInterfaceL |
|
320 // |
|
321 void CTrkEngine::CreateCommInterfaceL() |
|
322 { |
|
323 iCommPort = NULL; |
|
324 |
|
325 switch (iCurrentConnData.iCommType) |
|
326 { |
|
327 |
|
328 #ifndef __NOKIA_TEXT_SHELL__ |
|
329 case ESerialComm: |
|
330 { |
|
331 iCommPort = CTrkSerialCommPort::NewL(iCurrentConnData, iErrorMessage); |
|
332 break; |
|
333 } |
|
334 #endif |
|
335 |
|
336 #ifndef __TEXT_SHELL__ |
|
337 case EBtSocket: |
|
338 { |
|
339 iCommPort = CTrkBtSocketCommPort::NewL(iCurrentConnData, iErrorMessage, this); |
|
340 break; |
|
341 } |
|
342 case EDbgTrcComm: |
|
343 { |
|
344 iCommPort = CTrkDbgTrcCommPort::NewL(iCurrentConnData, iErrorMessage); |
|
345 break; |
|
346 } |
|
347 #endif //__TEXT_SHELL__ |
|
348 |
|
349 #ifdef __OEM_TRK__ |
|
350 case EDcc: |
|
351 { |
|
352 iCommPort = CTrkDccCommPort::NewL(iCurrentConnData, iErrorMessage); |
|
353 break; |
|
354 } |
|
355 |
|
356 #ifdef __ENABLE_XTI__ |
|
357 case EXti: |
|
358 { |
|
359 iCommPort = CTrkXtiCommPort::NewL(iCurrentConnData, iErrorMessage); |
|
360 break; |
|
361 } |
|
362 #endif |
|
363 #endif //__OEM_TRK__ |
|
364 |
|
365 default: |
|
366 { |
|
367 User::Leave(KErrNotFound); |
|
368 } |
|
369 } |
|
370 } |
|
371 |
|
372 /* |
|
373 * This is called by when BT socket finds the port and started to listen |
|
374 * |
|
375 */ |
|
376 void CTrkEngine::AsyncConnectionSuccessfulL() |
|
377 { |
|
378 iDispatchLayer->Listen(); |
|
379 |
|
380 if (iCurrentConnData.iConnType == ETrkBt || iCurrentConnData.iConnType == ETrkSerial) |
|
381 iCommPort->SendDataL(_L8("Trk for Symbian OS started")); |
|
382 |
|
383 if (iCallback) |
|
384 iCallback->OnConnection(); |
|
385 } |
|
386 |
|
387 /* |
|
388 * This is called when PC rejects the connection |
|
389 * |
|
390 */ |
|
391 void CTrkEngine::AsyncConnectionFailed() |
|
392 { |
|
393 iCallback->OnAsyncConnectionFailed(); |
|
394 } |
|
395 |
|
396 // |
|
397 // CTrkEngine::DebuggingStarted |
|
398 // Called from the dispatch layer to indicate the start of a debug session |
|
399 // |
|
400 void CTrkEngine::DebuggingStarted() |
|
401 { |
|
402 //start the inactivity timer |
|
403 StartInactivityTimerDisabler(); |
|
404 |
|
405 if (iCallback) |
|
406 iCallback->DebuggingStarted(); |
|
407 } |
|
408 |
|
409 // |
|
410 // CTrkEngine::DebuggingEnded |
|
411 // Called from the dispatch layer when a debug session ends. |
|
412 // |
|
413 void CTrkEngine::DebuggingEnded() |
|
414 { |
|
415 if (iCallback) |
|
416 iCallback->DebuggingEnded(); |
|
417 //deactivate inactivity timer |
|
418 SafeDelete(iInactivityTimerDisabler); |
|
419 } |
|
420 |
|
421 // CTrkEngine::StartInactivityTimerDisabler |
|
422 // |
|
423 void CTrkEngine::StartInactivityTimerDisabler() |
|
424 { |
|
425 iInactivityTimerDisabler = new(ELeave) CInactivityTimerDisabler; |
|
426 iInactivityTimerDisabler->ConstructL(); |
|
427 iInactivityTimerDisabler->Activate(); |
|
428 } |
|
429 |
|
430 // |
|
431 // DLL Entry point |
|
432 // |
|
433 #ifndef EKA2 |
|
434 TInt E32Dll(TDllReason) |
|
435 { |
|
436 return KErrNone; |
|
437 } |
|
438 #endif |
|
439 |