|
1 /* |
|
2 * Copyright (c) 2005-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 |
|
21 #include "stdafx.h" |
|
22 #include "statexp.h" |
|
23 #include "statlist.h" |
|
24 |
|
25 ////////////////////////////////////////////////////////////////////////// |
|
26 // our thread-safe mechanism for list manipulation and back-end processing |
|
27 CRITICAL_SECTION CriticalSection; |
|
28 ////////////////////////////////////////////////////////////////////////// |
|
29 |
|
30 // get the version |
|
31 STAT_EXPORT const char * __cdecl Version() |
|
32 { |
|
33 return aList.Version(); |
|
34 } |
|
35 |
|
36 // set logging for main STAT connection interface |
|
37 STAT_EXPORT int __cdecl SetConnectionLogging(const char *pszLogPath) |
|
38 { |
|
39 EnterCriticalSection(&CriticalSection); |
|
40 |
|
41 int valid = aList.SetLogging(pszLogPath); |
|
42 |
|
43 LeaveCriticalSection(&CriticalSection); |
|
44 return valid; |
|
45 } |
|
46 |
|
47 // set logging for main STAT connection interface |
|
48 STAT_EXPORT void __cdecl CloseConnectionLogging() |
|
49 { |
|
50 EnterCriticalSection(&CriticalSection); |
|
51 |
|
52 aList.StopLogging(); |
|
53 |
|
54 LeaveCriticalSection(&CriticalSection); |
|
55 } |
|
56 |
|
57 // connect to the remote target |
|
58 STAT_EXPORT int __cdecl Connect(const STATCONNECTTYPE iConnectType, const char *pszPlatformType, void *Reserved1, void *Reserved2) |
|
59 { |
|
60 EnterCriticalSection(&CriticalSection); |
|
61 |
|
62 int valid = false; |
|
63 |
|
64 // unused parameters |
|
65 (void)Reserved1; |
|
66 (void)Reserved2; |
|
67 |
|
68 if (iConnectType && pszPlatformType && (*pszPlatformType)) |
|
69 valid = aList.CreateListMember(iConnectType, pszPlatformType); |
|
70 else |
|
71 strcpy(aList.szErrorText, "Invalid or missing parameter(s)"); |
|
72 |
|
73 LeaveCriticalSection(&CriticalSection); |
|
74 return valid; |
|
75 } |
|
76 |
|
77 STAT_EXPORT int __cdecl ConnectMT(const STATCONNECTTYPE iConnectType, const char *pszPlatformType) |
|
78 { |
|
79 EnterCriticalSection(&CriticalSection); |
|
80 |
|
81 int valid = Connect(iConnectType, pszPlatformType); |
|
82 if (valid) |
|
83 { |
|
84 aList.Member(valid)->SetMultithreaded(); |
|
85 } |
|
86 |
|
87 LeaveCriticalSection(&CriticalSection); |
|
88 return valid; |
|
89 } |
|
90 |
|
91 // set the delay between executed commands |
|
92 STAT_EXPORT int __cdecl SetCommandDelay(const int handle, const unsigned int iMillisecondDelay) |
|
93 { |
|
94 EnterCriticalSection(&CriticalSection); |
|
95 |
|
96 int valid = false; |
|
97 |
|
98 if (handle && aList.ListExists()) |
|
99 valid = aList.Member(handle)->SetCommandDelay(iMillisecondDelay); |
|
100 else |
|
101 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
102 |
|
103 LeaveCriticalSection(&CriticalSection); |
|
104 return valid; |
|
105 } |
|
106 |
|
107 // set logging for individual STAT connection command processing |
|
108 STAT_EXPORT int __cdecl SetCommandLogging(const int handle, |
|
109 const char *pszLogPath, |
|
110 MessageReporter *const aMessageReporter, |
|
111 const STATLOGLEVEL iLevel, |
|
112 const bool bAppend, |
|
113 void* Reserved1, |
|
114 void* Reserved2) |
|
115 { |
|
116 EnterCriticalSection(&CriticalSection); |
|
117 |
|
118 int valid = false; |
|
119 |
|
120 // unused parameters |
|
121 (void)iLevel; |
|
122 (void)Reserved1; |
|
123 (void)Reserved2; |
|
124 |
|
125 if (handle && aList.ListExists()) |
|
126 valid = aList.Member(handle)->SetLogging(STATDLLMember::ToUnicode(pszLogPath), bAppend, aMessageReporter); |
|
127 else |
|
128 strcpy(aList.szErrorText, "Invalid handle or connection does not exist"); |
|
129 |
|
130 LeaveCriticalSection(&CriticalSection); |
|
131 return valid; |
|
132 } |
|
133 |
|
134 // set image verification settings |
|
135 STAT_EXPORT int __cdecl SetImageVerification(const int handle, const char * pszRefDir, const bool bRemoveOldImages, const int iFactor) |
|
136 { |
|
137 EnterCriticalSection(&CriticalSection); |
|
138 |
|
139 int valid = false; |
|
140 |
|
141 if (handle && aList.ListExists()) |
|
142 valid = aList.Member(handle)->SetImageVerification(STATDLLMember::ToUnicode(pszRefDir), bRemoveOldImages, iFactor); |
|
143 else |
|
144 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
145 |
|
146 LeaveCriticalSection(&CriticalSection); |
|
147 return valid; |
|
148 } |
|
149 |
|
150 // open a script file within the member |
|
151 STAT_EXPORT int __cdecl OpenScriptFile(const int handle, const char *pszText, bool bIsFile) |
|
152 { |
|
153 if (handle && aList.ListExists()) |
|
154 return aList.Member(handle)->OpenScriptFile(STATDLLMember::ToUnicode(pszText), bIsFile); |
|
155 |
|
156 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
157 return false; |
|
158 } |
|
159 |
|
160 // run a command in the script engine |
|
161 STAT_EXPORT int __cdecl RunScript(const int handle, ScriptProgressMonitor *const monitor) |
|
162 { |
|
163 if (handle && aList.ListExists()) |
|
164 return aList.Member(handle)->RunScript(monitor); |
|
165 |
|
166 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
167 return false; |
|
168 } |
|
169 |
|
170 // send a command to the remote target |
|
171 STAT_EXPORT int __cdecl SendRawCommand(const int handle, const char *pszText, ScriptProgressMonitor *const monitor) |
|
172 { |
|
173 if (handle && aList.ListExists()) |
|
174 return aList.Member(handle)->SendRawCommand(STATDLLMember::ToUnicode(pszText), monitor); |
|
175 |
|
176 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
177 return false; |
|
178 } |
|
179 |
|
180 // send a command to the remote target |
|
181 STAT_EXPORT int __cdecl SendCommandFile(const int handle, const char *pszText, ScriptProgressMonitor *const monitor) |
|
182 { |
|
183 if (handle && aList.ListExists()) |
|
184 return aList.Member(handle)->SendCommandFile(STATDLLMember::ToUnicode(pszText), monitor); |
|
185 |
|
186 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
187 return false; |
|
188 } |
|
189 |
|
190 // get the number of commands in the current script |
|
191 STAT_EXPORT int __cdecl GetCommandCount(const int handle, const char *pszFile, int *commandCount) |
|
192 { |
|
193 if (handle && aList.ListExists()) |
|
194 return aList.Member(handle)->GetCommandCount(pszFile, commandCount); |
|
195 |
|
196 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
197 return false; |
|
198 } |
|
199 |
|
200 // get the number of current command |
|
201 STAT_EXPORT int __cdecl GetCurrentCommandNumber(const int handle, int *commandNumber) |
|
202 { |
|
203 if (handle && aList.ListExists()) |
|
204 return aList.Member(handle)->GetCurrentCommandNumber(commandNumber); |
|
205 |
|
206 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
207 return false; |
|
208 } |
|
209 |
|
210 // get the text received by the last command |
|
211 STAT_EXPORT const char* __cdecl GetReceivedData(const int handle) |
|
212 { |
|
213 if (handle && aList.ListExists()) |
|
214 return aList.Member(handle)->GetReceivedData(); |
|
215 |
|
216 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
217 return NULL; |
|
218 } |
|
219 |
|
220 // stop processing the current command on the remote target |
|
221 STAT_EXPORT int __cdecl StopProcessing(int handle) |
|
222 { |
|
223 if (handle && aList.ListExists()) |
|
224 return aList.Member(handle)->StopProcessing(); |
|
225 |
|
226 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
227 return false; |
|
228 } |
|
229 |
|
230 // get a bitmap snapshot of the remote target |
|
231 STAT_EXPORT int __cdecl GetSnapshot(const int handle, TBitmapFileHeader **ppFile, TBitmapInfoHeader **ppBitmap, char **ppData, unsigned long *pSize) |
|
232 { |
|
233 if (handle && aList.ListExists()) |
|
234 return aList.Member(handle)->GetSnapshot(ppFile, ppBitmap, ppData, pSize); |
|
235 |
|
236 strcpy(aList.szErrorText, "Invalid parameter(s) or connection does not exist"); |
|
237 return false; |
|
238 } |
|
239 |
|
240 // disconnect from the remote target |
|
241 STAT_EXPORT int __cdecl Disconnect(const int handle) |
|
242 { |
|
243 EnterCriticalSection(&CriticalSection); |
|
244 |
|
245 int valid = false; |
|
246 |
|
247 if (handle && aList.ListExists()) |
|
248 valid = aList.RemoveListMember(handle); |
|
249 else |
|
250 strcpy(aList.szErrorText, "Invalid handle or connection does not exist"); |
|
251 |
|
252 LeaveCriticalSection(&CriticalSection); |
|
253 return valid; |
|
254 } |
|
255 |
|
256 // get the last error thrown |
|
257 STAT_EXPORT const char * __cdecl GetError(const int handle) |
|
258 { |
|
259 if (handle && aList.ListExists()) |
|
260 return aList.Member(handle)->GetErrorText(); |
|
261 |
|
262 return aList.szErrorText; |
|
263 } |
|
264 |
|
265 // get the error text for a particular error code |
|
266 STAT_EXPORT const char * __cdecl GetErrorText(const int handle, int errorCode) |
|
267 { |
|
268 if (handle && aList.ListExists()) |
|
269 return aList.Member(handle)->GetErrorText(errorCode); |
|
270 |
|
271 return aList.szErrorText; |
|
272 } |
|
273 |
|
274 // get the TEF Shared Data |
|
275 STAT_EXPORT const char * __cdecl GetTEFSharedData(const int handle) |
|
276 { |
|
277 if (handle && aList.ListExists()) |
|
278 return aList.Member(handle)->GetTEFSharedData(); |
|
279 |
|
280 return NULL; |
|
281 } |
|
282 |
|
283 /////////////////////////////////////////////////////////////////////////////////////// |
|
284 // STD CALL ENTRYPOINTS |
|
285 /////////////////////////////////////////////////////////////////////////////////////// |
|
286 |
|
287 STAT_EXPORT const char * __stdcall StdVersion() |
|
288 { |
|
289 return Version(); |
|
290 } |
|
291 |
|
292 STAT_EXPORT const char * __stdcall StdGetError(const int handle) |
|
293 { |
|
294 return GetError(handle); |
|
295 } |
|
296 |
|
297 STAT_EXPORT const char * __stdcall StdGetErrorText(const int handle, int errorCode) |
|
298 { |
|
299 return GetErrorText(handle, errorCode); |
|
300 } |
|
301 |
|
302 STAT_EXPORT const char * __stdcall StdGetTEFSharedData(const int handle) |
|
303 { |
|
304 return GetTEFSharedData(handle); |
|
305 } |
|
306 |
|
307 STAT_EXPORT int __stdcall StdSetConnectionLogging(const char *filename) |
|
308 { |
|
309 return (SetConnectionLogging(filename)); |
|
310 } |
|
311 |
|
312 STAT_EXPORT void __stdcall StdCloseConnectionLogging() |
|
313 { |
|
314 CloseConnectionLogging(); |
|
315 } |
|
316 |
|
317 STAT_EXPORT int __stdcall StdConnect(const STATCONNECTTYPE iConnectType, const char *pszPlatformType, void *Reserved1, void *Reserved2) |
|
318 { |
|
319 return (Connect(iConnectType, pszPlatformType, Reserved1, Reserved2)); |
|
320 } |
|
321 |
|
322 STAT_EXPORT int __stdcall StdConnectMT(const STATCONNECTTYPE iConnectType, const char *pszPlatformType) |
|
323 { |
|
324 return (ConnectMT(iConnectType, pszPlatformType)); |
|
325 } |
|
326 |
|
327 STAT_EXPORT int __stdcall StdDisconnect(const int handle) |
|
328 { |
|
329 return Disconnect(handle); |
|
330 } |
|
331 |
|
332 STAT_EXPORT int __stdcall StdSetCommandDelay(const int handle, const unsigned int iMillisecondDelay) |
|
333 { |
|
334 return SetCommandDelay(handle, iMillisecondDelay); |
|
335 } |
|
336 |
|
337 STAT_EXPORT int __stdcall StdSetCommandLogging(const int handle, |
|
338 const char *pszLogPath, |
|
339 MessageReporter *const aMessageReporter, |
|
340 const STATLOGLEVEL iLevel, |
|
341 const bool bAppend, |
|
342 void* Reserved1, |
|
343 void* Reserved2) |
|
344 { |
|
345 return SetCommandLogging(handle, |
|
346 pszLogPath, |
|
347 aMessageReporter, |
|
348 iLevel, |
|
349 bAppend, |
|
350 Reserved1, |
|
351 Reserved2); |
|
352 } |
|
353 |
|
354 STAT_EXPORT int __stdcall StdSetImageVerification(const int handle, const char *pszRefDir, const bool bRemoveOldImages, const int iFactor) |
|
355 { |
|
356 return SetImageVerification(handle, pszRefDir, bRemoveOldImages, iFactor); |
|
357 } |
|
358 |
|
359 STAT_EXPORT int __stdcall StdOpenScriptFile(const int handle, LPCTSTR pszText, bool bIsFile) |
|
360 { |
|
361 return OpenScriptFile(handle, pszText, bIsFile); |
|
362 } |
|
363 |
|
364 STAT_EXPORT int __stdcall StdRunScript(const int handle, ScriptProgressMonitor *const monitor) |
|
365 { |
|
366 return RunScript(handle, monitor); |
|
367 } |
|
368 |
|
369 STAT_EXPORT int __stdcall StdSendRawCommand(const int handle, const char *pszText, ScriptProgressMonitor *const monitor) |
|
370 { |
|
371 return SendRawCommand(handle, pszText, monitor); |
|
372 } |
|
373 |
|
374 STAT_EXPORT int __stdcall StdSendCommandFile(const int handle, const char *pszFile, ScriptProgressMonitor *const monitor) |
|
375 { |
|
376 return SendCommandFile(handle, pszFile, monitor); |
|
377 } |
|
378 |
|
379 STAT_EXPORT int __stdcall StdGetCommandCount(const int handle, const char *pszFile, int *commandCount) |
|
380 { |
|
381 return GetCommandCount(handle, pszFile, commandCount); |
|
382 } |
|
383 |
|
384 STAT_EXPORT int __stdcall StdGetCurrentCommandNumber(const int handle, int *commandNumber) |
|
385 { |
|
386 return GetCurrentCommandNumber(handle, commandNumber); |
|
387 } |
|
388 |
|
389 STAT_EXPORT const char* __stdcall StdGetReceivedData(const int handle) |
|
390 { |
|
391 return GetReceivedData(handle); |
|
392 } |
|
393 |
|
394 STAT_EXPORT int __stdcall StdStopProcessing(int handle) |
|
395 { |
|
396 return StopProcessing(handle); |
|
397 } |
|
398 |
|
399 STAT_EXPORT int __stdcall StdGetSnapshot(int handle, TBitmapFileHeader **ppFile, TBitmapInfoHeader **ppBitmap, char **ppData, unsigned long *pSize) |
|
400 { |
|
401 return GetSnapshot(handle, ppFile, ppBitmap, ppData, pSize); |
|
402 } |