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 |
// INCLUDE FILES
|
|
18 |
#include <e32std.h>
|
|
19 |
#include <e32base.h>
|
|
20 |
#include "logging.h"
|
|
21 |
#include "toolsusbportlistener.h"
|
|
22 |
#include "toolslaunchmgr.h"
|
|
23 |
|
|
24 |
#define SafeDelete(x) { if (x) delete x; x = NULL; }
|
|
25 |
|
|
26 |
_LIT(KTRKSERVER, "trkserver.exe");
|
|
27 |
//_LIT(KTRACESERVER, "traceserver.exe");
|
|
28 |
|
|
29 |
_LIT(KCMDLINECONNTYPEUSB, "-usb");
|
|
30 |
_LIT(KCMDLINECONNTYPEXTI, "-xti");
|
|
31 |
|
|
32 |
|
|
33 |
// LOCAL FUNCTION PROTOTYPES
|
|
34 |
|
|
35 |
// LOCAL CONSTANTS
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
//
|
|
40 |
// CToolsLaunchMgr::NewL
|
|
41 |
//
|
|
42 |
CToolsLaunchMgr* CToolsLaunchMgr::NewL()
|
|
43 |
{
|
|
44 |
CToolsLaunchMgr* self = new(ELeave) CToolsLaunchMgr;
|
|
45 |
self->ConstructL();
|
|
46 |
return self;
|
|
47 |
}
|
|
48 |
|
|
49 |
//
|
|
50 |
// CTrkEngine::NewLC
|
|
51 |
//
|
|
52 |
CToolsLaunchMgr* CToolsLaunchMgr::NewLC()
|
|
53 |
{
|
|
54 |
CToolsLaunchMgr* self = new(ELeave) CToolsLaunchMgr;
|
|
55 |
CleanupStack::PushL(self);
|
|
56 |
|
|
57 |
self->ConstructL();
|
|
58 |
|
|
59 |
return self;
|
|
60 |
}
|
|
61 |
|
|
62 |
|
|
63 |
//
|
|
64 |
// CToolsLaunchMgr::ConstructL
|
|
65 |
// Constructor
|
|
66 |
//
|
|
67 |
void CToolsLaunchMgr::ConstructL()
|
|
68 |
{
|
|
69 |
iUsbPortListener = new CToolsUsbPortListener(this);
|
|
70 |
TRAPD(err, iUsbPortListener->ListenL());
|
|
71 |
if (err != KErrNone)
|
|
72 |
LOG_MSG("Failed to start the USB port listener");
|
|
73 |
|
|
74 |
// Adding TRKAPP to the launch list
|
|
75 |
CToolsProcess* toolsProcess = CToolsProcess::NewL(KTRKSERVER, KCMDLINECONNTYPEUSB, KCMDLINECONNTYPEXTI);
|
|
76 |
iToolsProcessList.Append(toolsProcess);
|
|
77 |
|
|
78 |
// Adding TRACESWITCH app
|
|
79 |
// For now, we are disabling the autostart of traceserver from toolsstarter
|
|
80 |
// When traceserver connects to the tracecore ost ldd at bootup time,
|
|
81 |
// there is a problem for getting the data from the ldd.
|
|
82 |
// Until this problem is fixed, traceswitch needs to be started after the bootup
|
|
83 |
// for plug-n-play trace support.
|
|
84 |
//_LIT(KNOXTI, "");
|
|
85 |
|
|
86 |
//toolsProcess = CToolsProcess::NewL(KTRACESERVER, KCMDLINECONNTYPEUSB, KNOXTI);
|
|
87 |
//iToolsProcessList.Append(toolsProcess);
|
|
88 |
}
|
|
89 |
|
|
90 |
//
|
|
91 |
// CToolsLaunchMgr::CToolsLaunchMgr
|
|
92 |
// Constructor
|
|
93 |
//
|
|
94 |
CToolsLaunchMgr::CToolsLaunchMgr()
|
|
95 |
: iUsbPortListener(NULL),
|
|
96 |
iToolsProcessList(1),
|
|
97 |
iToolListenerList(1)
|
|
98 |
{
|
|
99 |
|
|
100 |
}
|
|
101 |
|
|
102 |
//
|
|
103 |
// CToolsLaunchMgr::~CToolsLaunchMgr
|
|
104 |
// Destructor
|
|
105 |
//
|
|
106 |
CToolsLaunchMgr::~CToolsLaunchMgr()
|
|
107 |
{
|
|
108 |
SafeDelete(iUsbPortListener);
|
|
109 |
iToolsProcessList.ResetAndDestroy();
|
|
110 |
iToolsProcessList.Close();
|
|
111 |
iToolListenerList.ResetAndDestroy();
|
|
112 |
iToolListenerList.Close();
|
|
113 |
}
|
|
114 |
|
|
115 |
//
|
|
116 |
// CToolsLaunchMgr::Launch
|
|
117 |
//
|
|
118 |
void CToolsLaunchMgr::Launch()
|
|
119 |
{
|
|
120 |
if (iUsbPortListener->IsConnectionAvailable())
|
|
121 |
{
|
|
122 |
LaunchTools(EUsb);
|
|
123 |
}
|
|
124 |
else
|
|
125 |
{
|
|
126 |
LaunchTools(EXti);
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
//
|
|
131 |
// CToolsLaunchMgr::ConnectionAvailable
|
|
132 |
//
|
|
133 |
void CToolsLaunchMgr::ConnectionAvailable()
|
|
134 |
{
|
|
135 |
|
|
136 |
for (TInt i=0; i<iToolListenerList.Count(); i++)
|
|
137 |
{
|
|
138 |
iToolListenerList[i]->ConnStatusChanged(EUsbConnected);
|
|
139 |
|
|
140 |
}
|
|
141 |
|
|
142 |
}
|
|
143 |
|
|
144 |
//
|
|
145 |
// CToolsLaunchMgr::LaunchTools
|
|
146 |
//
|
|
147 |
void CToolsLaunchMgr::LaunchTools(TCmdLineConnType aConnType)
|
|
148 |
{
|
|
149 |
// remove this process from our list
|
|
150 |
for (TInt i=0; i<iToolsProcessList.Count(); i++)
|
|
151 |
{
|
|
152 |
TInt err = iToolsProcessList[i]->Start(aConnType);
|
|
153 |
|
|
154 |
if (err != KErrNone)
|
|
155 |
{
|
|
156 |
LOG_MSG2("Failed to start the process: %d", err);
|
|
157 |
}
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
//
|
|
162 |
// CToolsLaunchMgr::ConnectionAvailable
|
|
163 |
//
|
|
164 |
void CToolsLaunchMgr::ConnectionUnAvailable()
|
|
165 |
{
|
|
166 |
for (TInt i=0; i<iToolListenerList.Count(); i++)
|
|
167 |
{
|
|
168 |
iToolListenerList[i]->ConnStatusChanged(EUsbNotConnected);
|
|
169 |
|
|
170 |
}
|
|
171 |
}
|
|
172 |
|
|
173 |
//
|
|
174 |
// CToolsLaunchMgr::StopTools
|
|
175 |
//
|
|
176 |
void CToolsLaunchMgr::StopTools()
|
|
177 |
{
|
|
178 |
// remove this process from our list
|
|
179 |
for (TInt i=0; i<iToolsProcessList.Count(); i++)
|
|
180 |
{
|
|
181 |
iToolsProcessList[i]->Stop();
|
|
182 |
}
|
|
183 |
}
|
|
184 |
//
|
|
185 |
// CToolsLaunchMgr::GetUsbConnStatus()
|
|
186 |
//
|
|
187 |
// To Find out the usb connection status
|
|
188 |
//
|
|
189 |
TConnectionStatus CToolsLaunchMgr::GetUsbConnStatus()
|
|
190 |
{
|
|
191 |
return (iUsbPortListener->GetUsbConnStatus());
|
|
192 |
|
|
193 |
}
|
|
194 |
//
|
|
195 |
// CToolsLaunchMgr::RegisterListener()
|
|
196 |
//
|
|
197 |
// To register the cable connection events
|
|
198 |
//
|
|
199 |
|
|
200 |
void CToolsLaunchMgr::RegisterListener(MConnStateListener* aListener)
|
|
201 |
{
|
|
202 |
iToolListenerList.Append(aListener);
|
|
203 |
}
|
|
204 |
|
|
205 |
//
|
|
206 |
// CToolsLaunchMgr::UnregisterListener()
|
|
207 |
//
|
|
208 |
// To unregister the cable connection events
|
|
209 |
//
|
|
210 |
void CToolsLaunchMgr::UnregisterListener(MConnStateListener* aListener)
|
|
211 |
{
|
|
212 |
for (TInt i=0; i<iToolListenerList.Count(); i++)
|
|
213 |
{
|
|
214 |
if(iToolListenerList[i] == aListener)
|
|
215 |
{
|
|
216 |
iToolListenerList.Remove(i);
|
|
217 |
}
|
|
218 |
|
|
219 |
}
|
|
220 |
|
|
221 |
}
|
|
222 |
//
|
|
223 |
// CToolsLaunchMgr::CloseCrashLogger()
|
|
224 |
//
|
|
225 |
// To close the mobile crash logger
|
|
226 |
//
|
|
227 |
|
|
228 |
TInt CToolsLaunchMgr::CloseCrashLogger()
|
|
229 |
{
|
|
230 |
TInt err = KErrNone;
|
|
231 |
|
|
232 |
//The old mobile crash file name is "d_exc_mc.exe" and the new one is "mc_useragent.exe"
|
|
233 |
//This is the string that needs to be passed to the RProcess::Open call to get a handle.
|
|
234 |
//The complete process name actually includes the UID info as well.
|
|
235 |
//Instead of hard coding the process name, its better to just
|
|
236 |
//search for the process and find it that way.
|
|
237 |
//_LIT16(KCrashLoggerName, "mc_useragent.exe[1020e519]0001");
|
|
238 |
_LIT16(KOldCrashLoggerName, "d_exc_mc*");
|
|
239 |
_LIT16(KCrashLoggerName, "mc_useragent*");
|
|
240 |
|
|
241 |
err = TerminateProcess(KOldCrashLoggerName);
|
|
242 |
err = TerminateProcess(KCrashLoggerName);
|
|
243 |
|
|
244 |
return err;
|
|
245 |
}
|
|
246 |
|
|
247 |
//
|
|
248 |
// CToolsLaunchMgr::TerminateProcess
|
|
249 |
//
|
|
250 |
// Terminates the given process
|
|
251 |
//
|
|
252 |
TInt CToolsLaunchMgr::TerminateProcess(const TDesC& aProcessName)
|
|
253 |
{
|
|
254 |
_LIT16(KCrashLoggerClMsg, "Closing crash logger");
|
|
255 |
|
|
256 |
TFindProcess find(aProcessName);
|
|
257 |
TFullName name;
|
|
258 |
|
|
259 |
TInt err = find.Next(name);
|
|
260 |
if (KErrNone == err)
|
|
261 |
{
|
|
262 |
RProcess process;
|
|
263 |
err = process.Open(find);
|
|
264 |
|
|
265 |
if (KErrNone == err)
|
|
266 |
{
|
|
267 |
User::InfoPrint(KCrashLoggerClMsg);
|
|
268 |
process.Kill(KErrNone);
|
|
269 |
}
|
|
270 |
}
|
|
271 |
return err;
|
|
272 |
}
|