|
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: Implementation of HtiAdmin main. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <coecntrl.h> |
|
19 #include <w32std.h> |
|
20 #include <commdb.h> |
|
21 |
|
22 #include <HtiCfg.h> |
|
23 #include <HtiCommPluginInterface.h> // for KHTICommInterfaceUid |
|
24 |
|
25 |
|
26 #include "htienginewrapper.h" |
|
27 #include "chtiadminengine.h" |
|
28 |
|
29 |
|
30 #ifdef __ENABLE_LOGGING__ |
|
31 |
|
32 #include <flogger.h> |
|
33 |
|
34 _LIT(KLogFolder, "hti"); |
|
35 _LIT(KLogFile, "htiadmin.txt"); |
|
36 #define HTI_LOG_TEXT(a1) {_LIT(temp, a1); RFileLogger::Write(KLogFolder, KLogFile, EFileLoggingModeAppend, temp);} |
|
37 #define HTI_LOG_FORMAT(a1,a2) {_LIT(temp, a1); RFileLogger::WriteFormat(KLogFolder, KLogFile, EFileLoggingModeAppend, temp, (a2));} |
|
38 #define HTI_LOG_DES(a1) {RFileLogger::Write(KLogFolder, KLogFile, EFileLoggingModeAppend, (a1));} |
|
39 |
|
40 #else // __ENABLE_LOGGING__ |
|
41 |
|
42 #define HTI_LOG_TEXT(a1) |
|
43 #define HTI_LOG_FORMAT(a1,a2) |
|
44 #define HTI_LOG_DES(a1) |
|
45 |
|
46 #endif // __ENABLE_LOGGING__ |
|
47 |
|
48 // CONSTANTS |
|
49 _LIT( KHtiWatchDogMatchPattern, "HtiWatchDog*" ); |
|
50 _LIT( KHtiFrameworkExe, "HtiFramework.exe" ); |
|
51 _LIT( KHtiMatchPattern, "HtiFramework*" ); |
|
52 _LIT( KHtiFrameworkCaption, "HTI status: " ); |
|
53 _LIT( KHtiAutoStartCaption, "AutoStart: " ); |
|
54 _LIT( KHtiVersionCaption, "Version: " ); |
|
55 _LIT( KHtiSelectedCommCaption, "Communication: " ); |
|
56 _LIT( KHtiAdminStartParameter, "admin" ); |
|
57 _LIT( KHtiAdminVersionFormat, "%u.%u.%u (%uwk%02u)" ); |
|
58 _LIT( KHtiAdminAboutVersionFormat, "Version %u.%u.%u - " ); |
|
59 const static TInt KTerminateReason = 1; |
|
60 |
|
61 const TInt32 KHTIImplUidIsaComm = {0x1020DEBD}; |
|
62 const TInt32 KHTIImplUidSerial = {0x10210CCA}; |
|
63 const TInt32 KHTIImplUidBluetooth = {0x200212CC}; |
|
64 const TInt32 KHTIImplUidIPComm = {0x200212CE}; |
|
65 const TInt32 KHTIImplUidUsbSerialComm = {0x200212D0}; |
|
66 const TInt32 KHTIImplUidTraceComm = {0x200212D8}; |
|
67 |
|
68 // configuration file constants |
|
69 _LIT( KCfgFilePath, "\\"); |
|
70 _LIT( KHtiCfg, "hti.cfg" ); |
|
71 _LIT( KHtiBtCommCfg, "HTIBtComm.cfg" ); |
|
72 _LIT( KHtiSerialCommCfg , "HTISerialComm.cfg" ); |
|
73 _LIT( KHtiIPCommCfg, "HTIIPComm.cfg" ); |
|
74 // hti.cfg |
|
75 _LIT8( KCommPlugin, "CommPlugin" ); |
|
76 _LIT8( KPriority, "Priority" ); |
|
77 _LIT8( KShowConsole, "ShowConsole" ); |
|
78 _LIT8( KEnableHtiWatchDog, "EnableHtiWatchDog" ); |
|
79 _LIT8( KEnableHtiAutoStart, "EnableHtiAutoStart" ); |
|
80 _LIT8( KShowErrorDialogs, "ShowErrorDialogs" ); |
|
81 // HtiBtComm.cfg |
|
82 _LIT8( KBtDeviceAddress, "BtDeviceAddress" ); |
|
83 _LIT8( KBtDeviceName, "BtDeviceName" ); |
|
84 // HtiSerialComm.cfg |
|
85 _LIT8( KCommPortNumber, "CommPort" ); |
|
86 // HTIIPComm.cfg |
|
87 _LIT8( KLocalPort, "LocalPort" ); |
|
88 _LIT8( KRemoteHost, "RemoteHost" ); |
|
89 _LIT8( KRemotePort, "RemotePort" ); |
|
90 _LIT8( KIAPName, "IAPName"); |
|
91 |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 |
|
95 CHtiAdminEngine::CHtiAdminEngine() |
|
96 { |
|
97 iIAPsArray = NULL; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 CHtiAdminEngine* CHtiAdminEngine::NewLC(HtiEngineWrapper *aEngineWrapper) |
|
102 { |
|
103 CHtiAdminEngine* self = new (ELeave) CHtiAdminEngine(); |
|
104 CleanupStack::PushL(self); |
|
105 self->ConstructL(aEngineWrapper); |
|
106 return self; |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 CHtiAdminEngine* CHtiAdminEngine::NewL(HtiEngineWrapper *aEngineWrapper) |
|
111 { |
|
112 CHtiAdminEngine* self = CHtiAdminEngine::NewLC(aEngineWrapper); |
|
113 CleanupStack::Pop(); // self; |
|
114 return self; |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 void CHtiAdminEngine::ConstructL(HtiEngineWrapper *aEngineWrapper) |
|
119 { |
|
120 iEngineWrapper = aEngineWrapper; |
|
121 iHtiCfg = CHtiCfg::NewL(); |
|
122 |
|
123 CheckStatusesL(); |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 void CHtiAdminEngine::CheckStatusesL() |
|
128 { |
|
129 UpdateConsoleStatus(); |
|
130 UpdateWatchDogStatus(); |
|
131 UpdateAutoStartStatus(); |
|
132 UpdateSelectedComm(); |
|
133 UpdateStatusL(); |
|
134 } |
|
135 |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 CHtiAdminEngine::~CHtiAdminEngine() |
|
139 { |
|
140 KillTimer(); |
|
141 delete iHtiCfg; |
|
142 delete iPluginNameArray; |
|
143 delete iPluginDataTypeArray; |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 void CHtiAdminEngine::StartHtiL() |
|
148 { |
|
149 |
|
150 RProcess prs; |
|
151 TInt err; |
|
152 TBool isRunning = EFalse; |
|
153 if ( OpenHtiProcess( prs ) ) |
|
154 { |
|
155 if ( prs.ExitType() == EExitPending ) |
|
156 { |
|
157 isRunning = ETrue; |
|
158 iEngineWrapper->updateStatus(HtiEngineWrapper::Running); |
|
159 } |
|
160 prs.Close(); |
|
161 } |
|
162 |
|
163 if ( !isRunning ) |
|
164 { |
|
165 HTI_LOG_TEXT( "create process" ); |
|
166 err = prs.Create( KHtiFrameworkExe, KHtiAdminStartParameter ); |
|
167 if ( err == KErrNone ) |
|
168 { |
|
169 prs.Resume(); |
|
170 prs.Close(); |
|
171 UpdateStatusL(); |
|
172 HTI_LOG_TEXT("create done"); |
|
173 } |
|
174 else |
|
175 { |
|
176 iEngineWrapper->updateStatus(HtiEngineWrapper::Error); |
|
177 HTI_LOG_TEXT("create error"); |
|
178 } |
|
179 } |
|
180 |
|
181 } |
|
182 |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 |
|
186 void CHtiAdminEngine::StopHtiL() |
|
187 { |
|
188 HTI_LOG_TEXT("Stop"); |
|
189 |
|
190 // kill the watchdog to prevent it from restarting HTI again |
|
191 KillHtiWatchDogL(); |
|
192 |
|
193 RProcess prs; |
|
194 if ( OpenHtiProcess( prs ) ) |
|
195 { |
|
196 if ( prs.ExitType() == EExitPending ) |
|
197 { |
|
198 HTI_LOG_TEXT("try to kill"); |
|
199 prs.Kill( KTerminateReason ); |
|
200 UpdateStatusL(); |
|
201 } |
|
202 else |
|
203 { |
|
204 iEngineWrapper->updateStatus(HtiEngineWrapper::Stopped); |
|
205 } |
|
206 prs.Close(); |
|
207 } |
|
208 |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 |
|
213 void CHtiAdminEngine::EnableBtByAddressL(const TDesC& aAddress) |
|
214 { |
|
215 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
216 iHtiCfg->SetParameterL( KCommPlugin, _L8( "BTSERIAL" ) ); |
|
217 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
218 |
|
219 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiBtCommCfg ) ); |
|
220 iHtiCfg->RemoveParameterL( KBtDeviceName ); |
|
221 iHtiCfg->RemoveParameterL( KBtDeviceAddress ); |
|
222 |
|
223 TBuf8<KMaxParameterValueLength> value; |
|
224 value.Copy(aAddress); |
|
225 iHtiCfg->SetParameterL( KBtDeviceAddress, value); |
|
226 |
|
227 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiBtCommCfg); |
|
228 UpdateSelectedComm(); |
|
229 |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 void CHtiAdminEngine::EnableBtByNameL(const TDesC& aAddress) |
|
234 { |
|
235 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
236 iHtiCfg->SetParameterL( KCommPlugin, _L8( "BTSERIAL" ) ); |
|
237 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
238 |
|
239 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiBtCommCfg ) ); |
|
240 iHtiCfg->RemoveParameterL( KBtDeviceName ); |
|
241 iHtiCfg->RemoveParameterL( KBtDeviceAddress ); |
|
242 |
|
243 TBuf8<KMaxParameterValueLength> value; |
|
244 value.Copy(aAddress); |
|
245 iHtiCfg->SetParameterL( KBtDeviceName, value); |
|
246 |
|
247 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiBtCommCfg ); |
|
248 UpdateSelectedComm(); |
|
249 } |
|
250 |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 void CHtiAdminEngine::BtSearchL() |
|
254 { |
|
255 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
256 iHtiCfg->SetParameterL( KCommPlugin, _L8( "BTSERIAL" ) ); |
|
257 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
258 |
|
259 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiBtCommCfg ) ); |
|
260 iHtiCfg->RemoveParameterL( KBtDeviceName ); |
|
261 iHtiCfg->RemoveParameterL( KBtDeviceAddress ); |
|
262 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiBtCommCfg ); |
|
263 UpdateSelectedComm(); |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 void CHtiAdminEngine::IPListenL(const TDesC& aPort, const TDesC& aIAP) |
|
268 { |
|
269 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
270 iHtiCfg->SetParameterL( KCommPlugin, _L8("IPCOMM")); |
|
271 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
272 |
|
273 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiIPCommCfg ) ); |
|
274 |
|
275 TBuf8<KMaxParameterValueLength> port; |
|
276 port.Copy(aPort); |
|
277 iHtiCfg->SetParameterL( KLocalPort, port); |
|
278 |
|
279 TBuf8<KMaxParameterValueLength> iap; |
|
280 iap.Copy(aIAP); |
|
281 iHtiCfg->SetParameterL(KIAPName, iap); |
|
282 |
|
283 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiIPCommCfg ); |
|
284 UpdateSelectedComm(); |
|
285 |
|
286 } |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 void CHtiAdminEngine::IPConnectL(const TDesC& aHost, const TDesC& aPort, const TDesC& aIAP) |
|
290 { |
|
291 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
292 iHtiCfg->SetParameterL( KCommPlugin, _L8( "IPCOMM" ) ); |
|
293 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
294 |
|
295 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiIPCommCfg ) ); |
|
296 iHtiCfg->RemoveParameterL( KLocalPort ); |
|
297 |
|
298 TBuf8<KMaxParameterValueLength> value; |
|
299 value.Copy(aHost); |
|
300 iHtiCfg->SetParameterL( KRemoteHost, value); |
|
301 |
|
302 TBuf8<KMaxParameterValueLength> port; |
|
303 port.Copy(aPort); |
|
304 iHtiCfg->SetParameterL(KRemotePort, port); |
|
305 |
|
306 TBuf8<KMaxParameterValueLength> iap; |
|
307 iap.Copy(aIAP); |
|
308 iHtiCfg->SetParameterL(KIAPName, iap); |
|
309 |
|
310 iHtiCfg->SaveCfgL(KCfgFilePath, KHtiIPCommCfg); |
|
311 UpdateSelectedComm(); |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 void CHtiAdminEngine::EnableSerialL(const TDesC& aComPortNumber) |
|
316 { |
|
317 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
318 iHtiCfg->SetParameterL( KCommPlugin, _L8( "SERIAL" ) ); |
|
319 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
320 |
|
321 TBuf8<KMaxParameterValueLength> value; |
|
322 value.Copy(aComPortNumber); |
|
323 iHtiCfg->SetParameterL( KCommPortNumber, value ); |
|
324 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiSerialCommCfg ); |
|
325 UpdateSelectedComm(); |
|
326 } |
|
327 |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 void CHtiAdminEngine::EnableOtherCommL(const TDesC& aSelectedPluginName) |
|
331 { |
|
332 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
333 |
|
334 TInt namePosition; |
|
335 iPluginNameArray->Find(aSelectedPluginName, namePosition); |
|
336 |
|
337 //Save correct data type for selected plugin |
|
338 iHtiCfg->SetParameterL( KCommPlugin, iPluginDataTypeArray->MdcaPoint(namePosition) ); |
|
339 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
340 UpdateSelectedComm(); |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------------------------- |
|
344 void CHtiAdminEngine::SetPriorityBackgroundL() |
|
345 { |
|
346 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
347 iHtiCfg->SetParameterL( KPriority, _L8("1")); |
|
348 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
349 |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 void CHtiAdminEngine::SetPriorityForegroundL() |
|
354 { |
|
355 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
356 iHtiCfg->SetParameterL( KPriority, _L8("2")); |
|
357 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
358 |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------------------------- |
|
362 void CHtiAdminEngine::SetPriorityHighL() |
|
363 { |
|
364 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
365 iHtiCfg->SetParameterL( KPriority, _L8("3")); |
|
366 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
367 |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 void CHtiAdminEngine::SetPriorityAbsoluteHighL() |
|
372 { |
|
373 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
374 iHtiCfg->SetParameterL( KPriority, _L8("4")); |
|
375 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------------------------- |
|
379 void CHtiAdminEngine::AutoStartEnableL(TBool aEnableAutoStart) |
|
380 { |
|
381 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
382 if(aEnableAutoStart) |
|
383 { |
|
384 iHtiCfg->SetParameterL( KEnableHtiAutoStart, _L8("1")); |
|
385 } |
|
386 else |
|
387 { |
|
388 iHtiCfg->SetParameterL( KEnableHtiAutoStart, _L8("0")); |
|
389 } |
|
390 |
|
391 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
392 UpdateAutoStartStatus(); |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------------------------- |
|
396 void CHtiAdminEngine::WatchDogEnableL(TBool aEnableWDog) |
|
397 { |
|
398 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
399 |
|
400 if(aEnableWDog) |
|
401 { |
|
402 iHtiCfg->SetParameterL( KEnableHtiWatchDog, _L8("1")); |
|
403 } |
|
404 else |
|
405 { |
|
406 iHtiCfg->SetParameterL( KEnableHtiWatchDog, _L8("0")); |
|
407 } |
|
408 |
|
409 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
410 UpdateWatchDogStatus(); |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 void CHtiAdminEngine::ConsoleEnableL(TBool aEnableConsole) |
|
415 { |
|
416 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
417 |
|
418 if(aEnableConsole) |
|
419 { |
|
420 iHtiCfg->SetParameterL( KShowConsole, _L8("1")); |
|
421 } |
|
422 else |
|
423 { |
|
424 iHtiCfg->SetParameterL( KShowConsole, _L8("0")); |
|
425 } |
|
426 |
|
427 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
428 UpdateConsoleStatus(); |
|
429 } |
|
430 |
|
431 // --------------------------------------------------------------------------- |
|
432 void CHtiAdminEngine::ErrorDialogsEnableL(TBool aEnableErrorDialogs) |
|
433 { |
|
434 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
435 |
|
436 if(aEnableErrorDialogs) |
|
437 { |
|
438 iHtiCfg->SetParameterL( KShowErrorDialogs, _L8("1")); |
|
439 } |
|
440 else |
|
441 { |
|
442 iHtiCfg->SetParameterL( KShowErrorDialogs, _L8("0")); |
|
443 } |
|
444 |
|
445 iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg ); |
|
446 } |
|
447 |
|
448 // --------------------------------------------------------------------------- |
|
449 void CHtiAdminEngine::SetHtiCfgParamL(const TDesC& aParamName, const TDesC& aParamValue) |
|
450 { |
|
451 SetCfgParamL(aParamName, aParamValue, KHtiCfg); |
|
452 } |
|
453 |
|
454 // --------------------------------------------------------------------------- |
|
455 void CHtiAdminEngine::SetBtCfgParamL(const TDesC& aParamName, const TDesC& aParamValue) |
|
456 { |
|
457 SetCfgParamL(aParamName, aParamValue, KHtiBtCommCfg); |
|
458 } |
|
459 |
|
460 // --------------------------------------------------------------------------- |
|
461 void CHtiAdminEngine::SetSerialCfgParamL(const TDesC& aParamName, const TDesC& aParamValue) |
|
462 { |
|
463 SetCfgParamL(aParamName, aParamValue, KHtiSerialCommCfg); |
|
464 } |
|
465 |
|
466 // --------------------------------------------------------------------------- |
|
467 void CHtiAdminEngine::SetIPCfgParamL(const TDesC& aParamName, const TDesC& aParamValue) |
|
468 { |
|
469 SetCfgParamL(aParamName, aParamValue, KHtiIPCommCfg); |
|
470 } |
|
471 |
|
472 // --------------------------------------------------------------------------- |
|
473 void CHtiAdminEngine::SetCfgParamL(const TDesC& aParamName, const TDesC& aParamValue, const TDesC& aFileName) |
|
474 { |
|
475 TBuf8<KMaxParameterNameLength> name; |
|
476 name.Copy(aParamName); |
|
477 |
|
478 TBuf8<KMaxParameterValueLength> value; |
|
479 value.Copy(aParamValue); |
|
480 |
|
481 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, aFileName ) ); |
|
482 |
|
483 iHtiCfg->SetParameterL( name, value ); |
|
484 iHtiCfg->SaveCfgL( KCfgFilePath, aFileName); |
|
485 } |
|
486 |
|
487 // --------------------------------------------------------------------------- |
|
488 void CHtiAdminEngine::GetHtiCfgParamL(const TDesC& aParamName, TDes& aParamValue) |
|
489 { |
|
490 GetCfgParamL(aParamName, aParamValue, KHtiCfg); |
|
491 } |
|
492 |
|
493 // --------------------------------------------------------------------------- |
|
494 void CHtiAdminEngine::GetBtCfgParamL(const TDesC& aParamName, TDes& aParamValue) |
|
495 { |
|
496 GetCfgParamL(aParamName, aParamValue, KHtiBtCommCfg); |
|
497 } |
|
498 |
|
499 // --------------------------------------------------------------------------- |
|
500 void CHtiAdminEngine::GetSerialCfgParamL(const TDesC& aParamName, TDes& aParamValue) |
|
501 { |
|
502 GetCfgParamL(aParamName, aParamValue, KHtiSerialCommCfg); |
|
503 } |
|
504 |
|
505 // --------------------------------------------------------------------------- |
|
506 void CHtiAdminEngine::GetIPCfgParamL(const TDesC& aParamName, TDes& aParamValue) |
|
507 { |
|
508 GetCfgParamL(aParamName, aParamValue, KHtiIPCommCfg); |
|
509 } |
|
510 |
|
511 // --------------------------------------------------------------------------- |
|
512 void CHtiAdminEngine::GetCfgParamL(const TDesC& aParamName, TDes& aParamValue, const TDesC& aFileName) |
|
513 { |
|
514 TBuf8<KMaxParameterNameLength> name; |
|
515 name.Copy(aParamName); |
|
516 |
|
517 TBuf<KMaxParameterValueLength> value; |
|
518 |
|
519 TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, aFileName ) ); |
|
520 aParamValue.Copy(iHtiCfg->GetParameterL(name)); |
|
521 } |
|
522 |
|
523 // --------------------------------------------------------------------------- |
|
524 void CHtiAdminEngine::GetSelectedComm(TDes& aPluginName) |
|
525 { |
|
526 TBuf8<KMaxParameterValueLength> commValue; |
|
527 TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
528 if ( !err ) |
|
529 { |
|
530 TRAP( err, commValue = iHtiCfg->GetParameterL( KCommPlugin ) ); |
|
531 } |
|
532 // Use default if not found from config |
|
533 if ( commValue.Length() == 0 ) |
|
534 { |
|
535 commValue.Copy(KCommDefaultImplementation ); |
|
536 } |
|
537 TInt typePosition; |
|
538 iPluginDataTypeArray->Find(commValue, typePosition); |
|
539 aPluginName.Copy(iPluginNameArray->MdcaPoint(typePosition)); |
|
540 } |
|
541 |
|
542 // --------------------------------------------------------------------------- |
|
543 TBool CHtiAdminEngine::OpenHtiProcess( RProcess& aPrs ) |
|
544 { |
|
545 HTI_LOG_TEXT( "OpenHtiProcess" ); |
|
546 |
|
547 TFullName processName; |
|
548 TInt err; |
|
549 |
|
550 TFindProcess finder( KHtiMatchPattern ); |
|
551 err = finder.Next( processName ); |
|
552 if ( err == KErrNone ) |
|
553 { |
|
554 HTI_LOG_TEXT( "try to open..." ); |
|
555 err = aPrs.Open( finder ); |
|
556 HTI_LOG_TEXT( "opened" ); |
|
557 |
|
558 if ( err == KErrNone ) |
|
559 { |
|
560 HTI_LOG_TEXT( "OpenHtiProcess OK" ); |
|
561 return ETrue; |
|
562 } |
|
563 else |
|
564 { |
|
565 iEngineWrapper->updateStatus(HtiEngineWrapper::Error); |
|
566 } |
|
567 } |
|
568 else if ( err == KErrNotFound ) |
|
569 { |
|
570 iEngineWrapper->updateStatus(HtiEngineWrapper::Stopped); |
|
571 } |
|
572 else |
|
573 { |
|
574 iEngineWrapper->updateStatus(HtiEngineWrapper::Error); |
|
575 } |
|
576 |
|
577 HTI_LOG_TEXT( "OpenHtiProcess NOK" ); |
|
578 |
|
579 return EFalse; |
|
580 } |
|
581 |
|
582 // --------------------------------------------------------------------------- |
|
583 void CHtiAdminEngine::UpdateStatusL() |
|
584 { |
|
585 HTI_LOG_TEXT( "UpdateStatusL" ); |
|
586 RProcess prs; |
|
587 if ( OpenHtiProcess( prs ) ) |
|
588 { |
|
589 HTI_LOG_TEXT( "Update display" ); |
|
590 TExitType exT = prs.ExitType(); |
|
591 |
|
592 switch ( exT ) |
|
593 { |
|
594 case EExitPending: |
|
595 { |
|
596 iEngineWrapper->updateStatus(HtiEngineWrapper::Running); |
|
597 |
|
598 // start timer to watch the status |
|
599 if ( !iPeriodic ) |
|
600 { |
|
601 iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
602 iPeriodic->Start( 5 * 1000 * 1000, |
|
603 5 * 1000 * 1000, |
|
604 TCallBack( TimerCallBackL, this ) ); |
|
605 } |
|
606 } |
|
607 break; |
|
608 |
|
609 case EExitKill: |
|
610 case EExitTerminate: |
|
611 { |
|
612 iEngineWrapper->updateStatus(HtiEngineWrapper::Stopped); |
|
613 KillTimer(); |
|
614 } |
|
615 break; |
|
616 |
|
617 case EExitPanic: |
|
618 { |
|
619 iEngineWrapper->updateStatus(HtiEngineWrapper::Panic); |
|
620 KillTimer(); |
|
621 } |
|
622 break; |
|
623 }; |
|
624 prs.Close(); |
|
625 } |
|
626 else |
|
627 { |
|
628 KillTimer(); |
|
629 } |
|
630 } |
|
631 |
|
632 // --------------------------------------------------------------------------- |
|
633 void CHtiAdminEngine::KillHtiWatchDogL() |
|
634 { |
|
635 TFullName processName; |
|
636 TFindProcess finder( KHtiWatchDogMatchPattern ); |
|
637 TInt err = finder.Next( processName ); |
|
638 if ( err == KErrNone ) |
|
639 { |
|
640 HTI_LOG_TEXT( "HTI watchdog process found. Trying to open and kill it..." ); |
|
641 RProcess prs; |
|
642 User::LeaveIfError( prs.Open( finder ) ); |
|
643 prs.Kill( KTerminateReason ); |
|
644 prs.Close(); |
|
645 HTI_LOG_TEXT( "HTI watchdog killed" ); |
|
646 } |
|
647 } |
|
648 |
|
649 // --------------------------------------------------------------------------- |
|
650 void CHtiAdminEngine::KillTimer() |
|
651 { |
|
652 if ( iPeriodic ) |
|
653 { |
|
654 iPeriodic->Cancel(); |
|
655 delete iPeriodic; |
|
656 iPeriodic = NULL; |
|
657 } |
|
658 } |
|
659 |
|
660 // --------------------------------------------------------------------------- |
|
661 TInt CHtiAdminEngine::TimerCallBackL( TAny* aPtr ) |
|
662 { |
|
663 ( (CHtiAdminEngine*)aPtr )->UpdateStatusL(); |
|
664 return ETrue; |
|
665 } |
|
666 |
|
667 |
|
668 // --------------------------------------------------------------------------- |
|
669 void CHtiAdminEngine::UpdateAutoStartStatus() |
|
670 { |
|
671 HTI_LOG_TEXT( "UpdateAutoStartStatus" ); |
|
672 TInt value = KErrNotFound; |
|
673 TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
674 if ( !err ) |
|
675 { |
|
676 TRAP( err, value = iHtiCfg->GetParameterIntL(KEnableHtiAutoStart) ); |
|
677 } |
|
678 |
|
679 if ( value == KErrNotFound ) |
|
680 { |
|
681 // Use default values if not found from config. |
|
682 #ifdef __WINS__ |
|
683 value = 0; |
|
684 #else |
|
685 value = 1; |
|
686 #endif |
|
687 } |
|
688 |
|
689 if ( value == 0 ) |
|
690 { |
|
691 iEngineWrapper->updateAutostartStatus( HtiEngineWrapper::AutoStartDisabled ); |
|
692 } |
|
693 else if ( value == 1 ) |
|
694 { |
|
695 iEngineWrapper->updateAutostartStatus( HtiEngineWrapper::AutoStartEnabled ); |
|
696 } |
|
697 else |
|
698 { |
|
699 iEngineWrapper->updateAutostartStatus( HtiEngineWrapper::AutoStartUnknown ); |
|
700 } |
|
701 } |
|
702 |
|
703 // --------------------------------------------------------------------------- |
|
704 void CHtiAdminEngine::UpdateConsoleStatus() |
|
705 { |
|
706 HTI_LOG_TEXT( "UpdateConsoleStatus" ); |
|
707 TInt value = KErrNotFound; |
|
708 TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
709 if(!err) |
|
710 { |
|
711 TRAP( err, value = iHtiCfg->GetParameterIntL(KShowConsole) ); |
|
712 } |
|
713 |
|
714 if ( value == KErrNotFound ) |
|
715 { |
|
716 value = 0; |
|
717 } |
|
718 |
|
719 iEngineWrapper->updateConsoleStatus(value); |
|
720 } |
|
721 |
|
722 // --------------------------------------------------------------------------- |
|
723 void CHtiAdminEngine::UpdateWatchDogStatus() |
|
724 { |
|
725 HTI_LOG_TEXT( "UpdateWatchDogStatus" ); |
|
726 TInt value = KErrNotFound; |
|
727 TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
728 if(!err) |
|
729 { |
|
730 TRAP( err, value = iHtiCfg->GetParameterIntL(KEnableHtiWatchDog) ); |
|
731 } |
|
732 |
|
733 if ( value == KErrNotFound ) |
|
734 { |
|
735 value = 0; |
|
736 } |
|
737 |
|
738 iEngineWrapper->updateWatchDogStatus(value); |
|
739 } |
|
740 |
|
741 // --------------------------------------------------------------------------- |
|
742 void CHtiAdminEngine::UpdateSelectedComm() |
|
743 { |
|
744 HTI_LOG_TEXT( "UpdateSelectedComm" ); |
|
745 TBuf<64> commPlugin; |
|
746 TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) ); |
|
747 if ( !err ) |
|
748 { |
|
749 TBuf8<KMaxParameterValueLength> commValue; |
|
750 TRAP( err, commValue = iHtiCfg->GetParameterL( KCommPlugin ) ); |
|
751 if ( err == KErrNone ) |
|
752 { |
|
753 commPlugin.Copy( commValue ); |
|
754 } |
|
755 } |
|
756 // Use default if not found from config |
|
757 if ( commPlugin.Length() == 0 ) |
|
758 { |
|
759 commPlugin.Copy(KCommDefaultImplementation ); |
|
760 } |
|
761 iEngineWrapper->updateSelectedComm( commPlugin ); |
|
762 |
|
763 if ( commPlugin.Compare( _L( "SERIAL" ) ) == 0 ) |
|
764 { |
|
765 TInt portNum = 0; |
|
766 TRAP( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiSerialCommCfg ) ); |
|
767 if ( err == KErrNone ) |
|
768 { |
|
769 TRAP( err, portNum = iHtiCfg->GetParameterIntL( KCommPortNumber ) ); |
|
770 } |
|
771 TBuf<16> portBuf; |
|
772 portBuf.Copy( _L( "Port: " ) ); |
|
773 portBuf.AppendNum( portNum ); |
|
774 iEngineWrapper->updateCommDetails( portBuf ); |
|
775 } |
|
776 |
|
777 else if ( commPlugin.Compare( _L( "BTSERIAL" ) ) == 0 ) |
|
778 { |
|
779 TBuf<64> hostBuf; |
|
780 TRAP( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiBtCommCfg ) ); |
|
781 if ( err == KErrNone ) |
|
782 { |
|
783 TBuf8<KMaxParameterValueLength> hostValue; |
|
784 TRAP( err, hostValue = iHtiCfg->GetParameterL( KBtDeviceAddress ) ); |
|
785 if ( err != KErrNone ) |
|
786 { |
|
787 TRAP( err, hostValue = iHtiCfg->GetParameterL( KBtDeviceName ) ); |
|
788 } |
|
789 if ( err == KErrNone ) |
|
790 { |
|
791 hostBuf.Copy( hostValue ); |
|
792 } |
|
793 } |
|
794 if ( hostBuf.Length() > 0 ) |
|
795 { |
|
796 hostBuf.Insert( 0, _L( "Host: " ) ); |
|
797 } |
|
798 iEngineWrapper->updateCommDetails(hostBuf); |
|
799 } |
|
800 |
|
801 else if ( commPlugin.Compare( _L( "IPCOMM" ) ) == 0 ) |
|
802 { |
|
803 TBuf<128> hostBuf; |
|
804 TRAP( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiIPCommCfg ) ); |
|
805 if ( err == KErrNone ) |
|
806 { |
|
807 TInt localPort = 0; |
|
808 TRAP( err, localPort = iHtiCfg->GetParameterIntL( KLocalPort ) ); |
|
809 if ( err == KErrNone && localPort > 0 ) |
|
810 { |
|
811 hostBuf.Copy( _L( "Listen: " ) ); |
|
812 hostBuf.AppendNum( localPort ); |
|
813 } |
|
814 else |
|
815 { |
|
816 TBuf8<KMaxParameterValueLength> remoteHost; |
|
817 TInt remotePort = 0; |
|
818 TRAP( err, remoteHost = iHtiCfg->GetParameterL( KRemoteHost ) ); |
|
819 if ( err == KErrNone ) |
|
820 { |
|
821 TRAP( err, remotePort = iHtiCfg->GetParameterIntL( |
|
822 KRemotePort ) ); |
|
823 } |
|
824 if ( err == KErrNone ) |
|
825 { |
|
826 hostBuf.Copy( remoteHost ); |
|
827 hostBuf.Insert( 0, _L("Connect: " ) ); |
|
828 hostBuf.Append( ':' ); |
|
829 hostBuf.AppendNum( remotePort ); |
|
830 } |
|
831 else |
|
832 { |
|
833 hostBuf.Copy( _L( "Invalid config!" ) ); |
|
834 } |
|
835 } |
|
836 } |
|
837 iEngineWrapper->updateCommDetails(hostBuf); |
|
838 } |
|
839 |
|
840 else |
|
841 { |
|
842 iEngineWrapper->updateCommDetails(KNullDesC); |
|
843 } |
|
844 } |
|
845 |
|
846 // --------------------------------------------------------------------------- |
|
847 void CleanupRArray( TAny* object ) |
|
848 { |
|
849 ( ( RImplInfoPtrArray* ) object )->ResetAndDestroy(); |
|
850 } |
|
851 |
|
852 // --------------------------------------------------------------------------- |
|
853 CDesCArray* CHtiAdminEngine::SearchCommPluginsL() |
|
854 { |
|
855 const TInt pluginNameArrayGranularity (15); |
|
856 iPluginNameArray = new (ELeave) CDesCArrayFlat(pluginNameArrayGranularity); |
|
857 iPluginDataTypeArray = new (ELeave) CDesC8ArrayFlat(pluginNameArrayGranularity); |
|
858 |
|
859 RImplInfoPtrArray implInfoArray; |
|
860 CleanupStack::PushL( TCleanupItem( CleanupRArray, &implInfoArray ) ); |
|
861 |
|
862 REComSession::ListImplementationsL( KHTICommInterfaceUid, implInfoArray ); |
|
863 |
|
864 for ( TInt i = 0; i < implInfoArray.Count(); ++i ) |
|
865 { |
|
866 iPluginNameArray->AppendL(implInfoArray[i]->DisplayName()); |
|
867 iPluginDataTypeArray->AppendL(implInfoArray[i]->DataType()); |
|
868 } |
|
869 |
|
870 CleanupStack::PopAndDestroy(); //implInfoArray |
|
871 |
|
872 return iPluginNameArray; |
|
873 } |
|
874 |
|
875 // --------------------------------------------------------------------------- |
|
876 CDesCArray* CHtiAdminEngine::SearchIAPsL() |
|
877 { |
|
878 if(iIAPsArray) |
|
879 { |
|
880 return iIAPsArray; |
|
881 } |
|
882 |
|
883 TBuf<KMaxParameterValueLength> name; |
|
884 const TInt arrayGranularity (10); |
|
885 iIAPsArray = new (ELeave) CDesCArrayFlat(arrayGranularity); |
|
886 |
|
887 // Get IAP names from the database |
|
888 CCommsDatabase* db = CCommsDatabase::NewL(EDatabaseTypeIAP);; |
|
889 CleanupStack::PushL(db); |
|
890 db->ShowHiddenRecords(); |
|
891 CCommsDbTableView* view = db->OpenTableLC(TPtrC(IAP)); |
|
892 TInt res = view->GotoFirstRecord(); |
|
893 |
|
894 while(res == KErrNone) |
|
895 { |
|
896 view->ReadTextL(TPtrC(COMMDB_NAME), name); |
|
897 iIAPsArray->InsertL(0, name); |
|
898 res = view->GotoNextRecord(); |
|
899 } |
|
900 |
|
901 CleanupStack::PopAndDestroy(view); //view |
|
902 CleanupStack::PopAndDestroy(db); //db |
|
903 |
|
904 return iIAPsArray; |
|
905 } |