2
|
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 the License "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 |
package com.nokia.tcf.impl;
|
|
21 |
|
60
|
22 |
import com.nokia.tcf.Activator;
|
|
23 |
import com.nokia.tcf.api.*;
|
|
24 |
|
|
25 |
import org.eclipse.core.runtime.*;
|
|
26 |
|
2
|
27 |
import java.io.File;
|
|
28 |
import java.io.IOException;
|
|
29 |
import java.text.MessageFormat;
|
|
30 |
|
|
31 |
public class TCAPIConnection implements ITCAPIConnection {
|
|
32 |
|
|
33 |
static {
|
|
34 |
Activator plugin = Activator.getDefault();
|
|
35 |
IPath path = null;
|
|
36 |
String dePath = null;
|
|
37 |
if (plugin != null)
|
|
38 |
path = plugin.getDebuggerPath();
|
|
39 |
if (path != null)
|
|
40 |
dePath = path.toOSString();
|
|
41 |
if (dePath == null) {
|
|
42 |
System.loadLibrary("TCFClient");
|
|
43 |
} else {
|
|
44 |
try{
|
|
45 |
System.load(dePath + java.io.File.separator + "TCFClient.dll");
|
|
46 |
} catch (UnsatisfiedLinkError e) {
|
|
47 |
// if Carbide DLL is not found in DE,
|
|
48 |
// try to load one from the plugin itself
|
|
49 |
System.loadLibrary("TCFClient");
|
|
50 |
}
|
|
51 |
}
|
|
52 |
}
|
|
53 |
private TCErrorListenerList<ITCErrorListener> errorListenerList;
|
60
|
54 |
protected ITCCookie cookie; // this client's handle to native
|
|
55 |
protected ITCMessageIds messageIds; // this client's message ids
|
|
56 |
protected TCMessageInputStream inputStream; // this client's message input stream (not using message file)
|
2
|
57 |
protected ITCMessageOptions messageOptions; // this client's message options
|
60
|
58 |
protected TCFMonitorThread monitorThread; // the client's native monitor
|
2
|
59 |
public boolean stopTCFMonitorThread; // stream monitor start/stop flag
|
|
60 |
protected IStatus statusOK;
|
|
61 |
protected ITCConnection connection; // the client's connection
|
|
62 |
|
|
63 |
public ITCConnection getConnection() {
|
|
64 |
return this.connection;
|
|
65 |
}
|
|
66 |
public ITCMessageOptions getMessageOptions() {
|
|
67 |
return this.messageOptions;
|
|
68 |
}
|
|
69 |
/**
|
|
70 |
* Only constructor - fields are created using the public methods
|
|
71 |
*/
|
|
72 |
public TCAPIConnection() {
|
|
73 |
super();
|
|
74 |
this.errorListenerList = new TCErrorListenerList<ITCErrorListener>();
|
|
75 |
this.errorListenerList.clear();
|
|
76 |
this.connection = null;
|
|
77 |
IStatus status = new Status(Status.OK, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_NONE, "OK", null);
|
|
78 |
statusOK = status;
|
|
79 |
this.cookie = new TCCookie(-1, status, false, false);
|
|
80 |
this.inputStream = null;
|
|
81 |
this.messageIds = null;
|
|
82 |
this.messageOptions = null;
|
|
83 |
this.monitorThread = null;
|
|
84 |
this.stopTCFMonitorThread = false;
|
|
85 |
}
|
|
86 |
|
|
87 |
/* (non-Javadoc)
|
|
88 |
* @see com.nokia.tcf.api.ITCAPIConnection#addErrorListener(com.nokia.tcf.api.ITCErrorListener)
|
|
89 |
*/
|
|
90 |
public IStatus addErrorListener(ITCErrorListener inErrorListener) {
|
|
91 |
IStatus status = statusOK;
|
|
92 |
try {
|
|
93 |
errorListenerList.add(inErrorListener);
|
|
94 |
} catch (NullPointerException e) {
|
|
95 |
int err = (int)TCErrorConstants.TCAPI_ERR_ERRLISTENER_NULL;
|
|
96 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, err, TCErrorConstants.getErrorMessage(err), e);
|
|
97 |
}
|
|
98 |
// System.out.printf("addErrorListener status = %s\n", status.getMessage());
|
|
99 |
return status;
|
|
100 |
}
|
|
101 |
|
|
102 |
private IStatus checkConnected() {
|
|
103 |
IStatus status = statusOK;
|
|
104 |
if (this.connection == null || this.cookie.isConnected() == false) {
|
|
105 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MEDIA_NOT_OPEN,
|
|
106 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MEDIA_NOT_OPEN), null);
|
|
107 |
}
|
|
108 |
return status;
|
|
109 |
}
|
|
110 |
protected IStatus checkDecodeFormat(String decodeFormat) {
|
|
111 |
IStatus status = statusOK;
|
|
112 |
return status;
|
|
113 |
}
|
|
114 |
protected IStatus checkConnectionType(ITCConnection inConnection) {
|
|
115 |
IStatus status = statusOK;
|
60
|
116 |
String type = inConnection.getConnectionType();
|
|
117 |
if (type.compareToIgnoreCase("virtualserial") == 0) {
|
2
|
118 |
ITCVirtualSerialConnection c = (ITCVirtualSerialConnection)inConnection;
|
|
119 |
String p = c.getComPort();
|
|
120 |
if (p == null) {
|
|
121 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MISSING_MEDIA_DATA,
|
|
122 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MISSING_MEDIA_DATA), null);
|
|
123 |
}
|
60
|
124 |
} else if (type.compareToIgnoreCase("tcp") == 0) {
|
2
|
125 |
ITCRealTCPConnection c = (ITCRealTCPConnection)inConnection;
|
|
126 |
String ip = c.getIpAddress();
|
|
127 |
String p = c.getPort();
|
|
128 |
if (ip == null || p == null) {
|
|
129 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MISSING_MEDIA_DATA,
|
|
130 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MISSING_MEDIA_DATA), null);
|
|
131 |
}
|
60
|
132 |
} else if (type.compareToIgnoreCase("serial") == 0) {
|
2
|
133 |
ITCRealSerialConnection c = (ITCRealSerialConnection)inConnection;
|
|
134 |
long err = checkRealSerialSettings(c);
|
|
135 |
if (err != TCErrorConstants.TCAPI_ERR_NONE) {
|
|
136 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)err, TCErrorConstants.getErrorMessage(err), null);
|
|
137 |
}
|
|
138 |
} else {
|
|
139 |
// Add other connection types here
|
|
140 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_UNKNOWN_MEDIA_TYPE,
|
|
141 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_UNKNOWN_MEDIA_TYPE), null);
|
|
142 |
}
|
|
143 |
|
|
144 |
return status;
|
|
145 |
}
|
|
146 |
private IStatus checkConnection(ITCConnection inConnection) {
|
|
147 |
IStatus status = statusOK;
|
|
148 |
if (this.cookie.isConnected()) {
|
|
149 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_ALREADY_CONNECTED,
|
|
150 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_ALREADY_CONNECTED), null);
|
|
151 |
}
|
|
152 |
if (inConnection == null) {
|
|
153 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MISSING_CONNECTION_SPEC,
|
|
154 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MISSING_CONNECTION_SPEC), null);
|
|
155 |
}
|
|
156 |
if (status.isOK()) {
|
|
157 |
String decodeFormat = inConnection.getDecodeFormat();
|
|
158 |
status = checkDecodeFormat(decodeFormat);
|
|
159 |
}
|
|
160 |
if (status.isOK()) {
|
|
161 |
long retryI = inConnection.getRetryInterval();
|
|
162 |
long retryT = inConnection.getRetryTimeout();
|
|
163 |
if (retryI == 0 || retryT == 0 || retryI > retryT) {
|
|
164 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_INVALID_RETRY_PERIODS,
|
|
165 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_INVALID_RETRY_PERIODS), null);
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
if (status.isOK()) {
|
|
170 |
status = checkConnectionType(inConnection);
|
|
171 |
}
|
|
172 |
|
|
173 |
return status;
|
|
174 |
}
|
|
175 |
private long checkRealSerialSettings(ITCRealSerialConnection c) {
|
|
176 |
String[] setting = new String[6];
|
|
177 |
setting[0] = c.getBaudRate();
|
|
178 |
setting[1] = c.getComPort();
|
|
179 |
setting[2] = c.getDataBits();
|
|
180 |
setting[3] = c.getFlowControl();
|
|
181 |
setting[4] = c.getParity();
|
|
182 |
setting[5] = c.getStopBits();
|
|
183 |
for (int i = 0; i < 6; i++) {
|
|
184 |
if (setting[i] == null) {
|
|
185 |
return TCErrorConstants.TCAPI_ERR_MISSING_MEDIA_DATA;
|
|
186 |
}
|
|
187 |
}
|
|
188 |
if ((setting[2] != ITCRealSerialConnection.DATABITS_4) && (setting[2] != ITCRealSerialConnection.DATABITS_5) && (setting[2] != ITCRealSerialConnection.DATABITS_6) &&
|
|
189 |
(setting[2] != ITCRealSerialConnection.DATABITS_7) && (setting[2] != ITCRealSerialConnection.DATABITS_8)) {
|
|
190 |
return TCErrorConstants.TCAPI_ERR_COMM_INVALID_DATABITS;
|
|
191 |
}
|
|
192 |
if ((setting[3] != ITCRealSerialConnection.FLOWCONTROL_HW) && (setting[3] != ITCRealSerialConnection.FLOWCONTROL_NONE) && (setting[3] != ITCRealSerialConnection.FLOWCONTROL_SW)) {
|
|
193 |
return TCErrorConstants.TCAPI_ERR_COMM_INVALID_FLOWCONTROL;
|
|
194 |
}
|
|
195 |
if ((setting[4] != ITCRealSerialConnection.PARITY_EVEN) && (setting[4] != ITCRealSerialConnection.PARITY_NONE) && (setting[4] != ITCRealSerialConnection.PARITY_ODD)) {
|
|
196 |
return TCErrorConstants.TCAPI_ERR_COMM_INVALID_PARITY;
|
|
197 |
}
|
|
198 |
if ((setting[5] != ITCRealSerialConnection.STOPBITS_1) && (setting[5] != ITCRealSerialConnection.STOPBITS_1_5) && (setting[5] != ITCRealSerialConnection.STOPBITS_2)) {
|
|
199 |
return TCErrorConstants.TCAPI_ERR_COMM_INVALID_STOPBITS;
|
|
200 |
}
|
|
201 |
|
|
202 |
return TCErrorConstants.TCAPI_ERR_NONE;
|
|
203 |
}
|
|
204 |
private IStatus checkMessage(ITCMessage inMessage) {
|
|
205 |
IStatus status = statusOK;
|
|
206 |
|
|
207 |
if (inMessage == null) {
|
|
208 |
// inMessage cannot be null
|
|
209 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MISSING_MESSAGE,
|
|
210 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MISSING_MESSAGE), null);
|
|
211 |
} else if (inMessage.size() == 0) {
|
|
212 |
// bytes to send may be 0 if we're doing the header (header is the message)
|
|
213 |
if (this.messageOptions.getMessageEncodeFormat() == ITCMessageOptions.ENCODE_NO_FORMAT) {
|
|
214 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MISSING_MESSAGE,
|
|
215 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MISSING_MESSAGE), null);
|
|
216 |
}
|
|
217 |
}
|
|
218 |
if (status.isOK()) {
|
|
219 |
// check options
|
|
220 |
if (inMessage.isUseMyMessageId()) {
|
|
221 |
if (this.messageOptions.getMessageEncodeFormat() == ITCMessageOptions.ENCODE_NO_FORMAT) {
|
|
222 |
// use my id, but don't encode = error
|
|
223 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MESSAGE_OPTIONS_CONFLICT,
|
|
224 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MESSAGE_OPTIONS_CONFLICT), null);
|
|
225 |
} else {
|
|
226 |
// use my id, and encode = OK
|
|
227 |
}
|
|
228 |
} else {
|
|
229 |
if (this.messageOptions.getMessageEncodeFormat() == ITCMessageOptions.ENCODE_NO_FORMAT) {
|
|
230 |
// don't use my id, and don't encode = OK
|
|
231 |
} else {
|
|
232 |
// don't use my id, but encode = warning (we'll go ahead send this message raw)
|
|
233 |
status = new Status(Status.WARNING, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MESSAGE_OPTIONS_CONFLICT,
|
|
234 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MESSAGE_OPTIONS_CONFLICT), null);
|
|
235 |
}
|
|
236 |
}
|
|
237 |
}
|
|
238 |
return status;
|
|
239 |
}
|
|
240 |
private IStatus checkMessageIds(ITCMessageIds inMessageIds) {
|
|
241 |
IStatus status = statusOK;
|
|
242 |
|
|
243 |
if (inMessageIds == null || inMessageIds.size() == 0) {
|
|
244 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_NO_MESSAGESIDS_REGISTERED,
|
|
245 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_NO_MESSAGESIDS_REGISTERED), null);
|
|
246 |
}
|
|
247 |
if (status.isOK()) {
|
|
248 |
if (inMessageIds.size() > 256) {
|
|
249 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MESSAGEID_MAXIMUM,
|
|
250 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MESSAGEID_MAXIMUM), null);
|
|
251 |
}
|
|
252 |
}
|
|
253 |
return status;
|
|
254 |
}
|
|
255 |
|
|
256 |
|
|
257 |
private IStatus checkMessageOptions(ITCMessageOptions inMessageOptions) {
|
|
258 |
IStatus status = statusOK;
|
|
259 |
|
|
260 |
if (inMessageOptions == null) {
|
|
261 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_MISSING_MESSAGE_OPTIONS,
|
|
262 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_MISSING_MESSAGE_OPTIONS), null);
|
|
263 |
}
|
|
264 |
// if (status.isOK()) {
|
|
265 |
// long option = inMessageOptions.getMessageDestination();
|
|
266 |
// String file = inMessageOptions.getMessageFile().toOSString();
|
|
267 |
// if (option == ITCMessageOptions.DESTINATION_CLIENTFILE) {
|
|
268 |
// status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_FEATURE_NOT_IMPLEMENTED,
|
|
269 |
// TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_FEATURE_NOT_IMPLEMENTED), null);
|
|
270 |
// }
|
|
271 |
// }
|
|
272 |
|
|
273 |
if (status.isOK()) {
|
|
274 |
long option = inMessageOptions.getMessageEncodeFormat();
|
|
275 |
switch ((int)option) {
|
|
276 |
case (int)ITCMessageOptions.ENCODE_NO_FORMAT:
|
|
277 |
case (int)ITCMessageOptions.ENCODE_FORMAT:
|
|
278 |
case (int)ITCMessageOptions.ENCODE_TRK_FORMAT:
|
|
279 |
break;
|
|
280 |
default:
|
|
281 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_INVALID_ENCODE_FORMAT,
|
|
282 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_INVALID_ENCODE_FORMAT), null);
|
|
283 |
}
|
|
284 |
}
|
|
285 |
if (status.isOK()) {
|
|
286 |
long option = inMessageOptions.getUnWrapFormat();
|
|
287 |
switch ((int)option) {
|
|
288 |
case (int)ITCMessageOptions.UNWRAP_DELETE_HEADERS:
|
|
289 |
case (int)ITCMessageOptions.UNWRAP_LEAVE_HEADERS:
|
|
290 |
break;
|
|
291 |
default:
|
|
292 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_INVALID_MESSAGE_UNWRAP_OPTION,
|
|
293 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_INVALID_MESSAGE_UNWRAP_OPTION), null);
|
|
294 |
}
|
|
295 |
}
|
|
296 |
|
|
297 |
if (status.isOK()) {
|
|
298 |
long bufferSize = inMessageOptions.getInputStreamSize();
|
|
299 |
if (bufferSize <= 0) {
|
|
300 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_INVALID_STREAM_BUFFER_SIZE,
|
|
301 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_INVALID_STREAM_BUFFER_SIZE), null);
|
|
302 |
}
|
|
303 |
}
|
|
304 |
|
|
305 |
return status;
|
|
306 |
}
|
|
307 |
|
|
308 |
protected IStatus checkConnectOptions(ITCConnection inConnection,
|
|
309 |
ITCMessageOptions inMessageOptions, ITCMessageIds inMessageIds) {
|
|
310 |
|
|
311 |
IStatus status = statusOK;
|
|
312 |
|
|
313 |
status = checkConnection(inConnection);
|
|
314 |
|
|
315 |
if (status.isOK()) {
|
|
316 |
status = checkMessageOptions(inMessageOptions);
|
|
317 |
}
|
|
318 |
if (status.isOK()) {
|
|
319 |
status = checkMessageIds(inMessageIds);
|
|
320 |
}
|
|
321 |
return status;
|
|
322 |
}
|
60
|
323 |
protected IStatus finishConnect(String type, String[] settings,
|
2
|
324 |
ITCConnection inConnection, ITCMessageOptions inMessageOptions, ITCMessageIds inMessageIds) {
|
|
325 |
IStatus status = statusOK;
|
|
326 |
// connect
|
|
327 |
long[] clientId = new long[1];
|
|
328 |
clientId[0] = -1;
|
|
329 |
long[] options = new long[3];
|
|
330 |
options[0] = inConnection.getRetryInterval(); // connection options
|
|
331 |
options[1] = inConnection.getRetryTimeout();
|
|
332 |
options[2] = 0;
|
|
333 |
long[] moptions = new long[2];
|
|
334 |
moptions[0] = inMessageOptions.getUnWrapFormat();
|
|
335 |
moptions[1] = inMessageOptions.getOSTVersion();
|
|
336 |
String filePath = null;
|
|
337 |
if (inMessageOptions.getMessageDestination() == ITCMessageOptions.DESTINATION_CLIENTFILE) {
|
|
338 |
filePath = inMessageOptions.getMessageFile().toOSString();
|
|
339 |
try {
|
|
340 |
ensureWritableFile(filePath);
|
|
341 |
} catch (IOException e) {
|
|
342 |
String msg = e.getMessage();
|
|
343 |
long err = TCErrorConstants.TCAPI_ERR_CREATE_FILE;
|
|
344 |
String tcErr = String.format("%s OSError: %s", TCErrorConstants.getErrorMessage(err), msg);
|
|
345 |
status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
|
|
346 |
(int)TCErrorConstants.TCAPI_ERR_CREATE_FILE, tcErr, e);
|
|
347 |
}
|
|
348 |
}
|
|
349 |
|
|
350 |
try {
|
|
351 |
long ret = nativeConnect(type, options, settings, moptions, filePath, clientId);
|
|
352 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
353 |
this.cookie.setClientId(clientId[0]);
|
|
354 |
this.cookie.setConnected(true);
|
|
355 |
this.connection = inConnection;
|
|
356 |
this.messageOptions = inMessageOptions;
|
|
357 |
} else {
|
|
358 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
359 |
}
|
|
360 |
} catch (Exception e) {
|
|
361 |
// exception is thrown ONLY when err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA from native
|
|
362 |
// and the message is the OS error generated
|
|
363 |
String msg = e.getMessage();
|
|
364 |
long ret = TCErrorConstants.TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
|
|
365 |
String tcErr = String.format("%s OSError: %s", TCErrorConstants.getErrorMessage(ret), msg);
|
|
366 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, tcErr, null);
|
|
367 |
}
|
|
368 |
// send message ids to capture
|
|
369 |
if (status.isOK()) {
|
|
370 |
int number = (int)inMessageIds.size();
|
|
371 |
byte[] ids = new byte[number];
|
|
372 |
for (int i = 0; i < number; i++) {
|
|
373 |
ids[i] = inMessageIds.getMessageIds().get(i);
|
|
374 |
}
|
|
375 |
long ret = nativeSetMessageIds(this.cookie.getClientId(), ids);
|
|
376 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
377 |
this.messageIds = inMessageIds;
|
|
378 |
} else {
|
|
379 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
380 |
}
|
|
381 |
}
|
|
382 |
// setup input stream
|
|
383 |
if (status.isOK() && inMessageOptions.getMessageDestination() == ITCMessageOptions.DESTINATION_INPUTSTREAM) {
|
|
384 |
inputStream = new TCMessageInputStream(this,
|
|
385 |
inMessageOptions.getInputStreamSize(),
|
|
386 |
cookie.getClientId());
|
|
387 |
try {
|
|
388 |
inputStream.open();
|
|
389 |
} catch (IOException e) {
|
|
390 |
// stream didn't open
|
|
391 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
|
|
392 |
e.printStackTrace();
|
|
393 |
}
|
|
394 |
}
|
|
395 |
// create error monitor
|
|
396 |
if (status.isOK()) {
|
|
397 |
String monitorName = String.format("TCFMonitor%d", this.cookie.getClientId());
|
|
398 |
monitorThread = new TCFMonitorThread(this, monitorName);
|
|
399 |
stopTCFMonitorThread = false;
|
|
400 |
monitorThread.start();
|
|
401 |
}
|
|
402 |
|
|
403 |
// start capture
|
|
404 |
if (status.isOK()) {
|
|
405 |
long ret = nativeStart(this.cookie.getClientId());
|
|
406 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
407 |
this.cookie.setMessageProcessing(true);
|
|
408 |
} else {
|
|
409 |
// error in starting capture
|
|
410 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
411 |
}
|
|
412 |
}
|
|
413 |
if (!status.isOK()) {
|
|
414 |
// an error occurred along the way - unravel what we've done
|
|
415 |
if (this.cookie.isMessageProcessing()) {
|
|
416 |
long ret = nativeStop(this.cookie.getClientId());
|
|
417 |
// ignore error
|
|
418 |
this.cookie.setMessageProcessing(false);
|
|
419 |
}
|
|
420 |
if (this.monitorThread != null) {
|
|
421 |
this.stopTCFMonitorThread = true;
|
|
422 |
try {
|
|
423 |
this.monitorThread.join();
|
|
424 |
} catch (InterruptedException e) {
|
|
425 |
}
|
|
426 |
this.monitorThread = null;
|
|
427 |
}
|
|
428 |
if (this.inputStream != null && this.inputStream.isOpen()) {
|
|
429 |
try {
|
|
430 |
this.inputStream.close();
|
|
431 |
} catch (IOException e) {
|
|
432 |
}
|
|
433 |
this.inputStream = null;
|
|
434 |
}
|
|
435 |
if (this.cookie.isConnected()) {
|
|
436 |
long ret = nativeDisconnect(this.getClientId());
|
|
437 |
this.cookie.setConnected(false);
|
|
438 |
this.cookie.setClientId(-1);
|
|
439 |
}
|
|
440 |
}
|
|
441 |
return status;
|
|
442 |
}
|
|
443 |
/* (non-Javadoc)
|
|
444 |
* @see com.nokia.tcf.api.ITCAPIConnection#connect(com.nokia.tcf.api.ITCConnection, com.nokia.tcf.api.ITCMessageOptions, com.nokia.tcf.api.ITCMessageIds)
|
|
445 |
*/
|
|
446 |
public IStatus connect(ITCConnection inConnection,
|
|
447 |
ITCMessageOptions inMessageOptions, ITCMessageIds inMessageIds) {
|
|
448 |
|
|
449 |
IStatus status = checkConnectOptions(inConnection, inMessageOptions, inMessageIds);
|
|
450 |
String[] settings = null;
|
60
|
451 |
String type = null;
|
2
|
452 |
|
|
453 |
// do connect
|
|
454 |
if (status.isOK()) {
|
|
455 |
settings = null;
|
|
456 |
type = inConnection.getConnectionType();
|
60
|
457 |
if (type.compareToIgnoreCase("tcp") == 0) {
|
2
|
458 |
settings = new String[3];
|
|
459 |
ITCRealTCPConnection t = (ITCRealTCPConnection)inConnection;
|
|
460 |
settings[0] = t.getIpAddress();
|
|
461 |
settings[1] = t.getPort();
|
|
462 |
settings[2] = t.getDecodeFormat().toLowerCase();
|
60
|
463 |
} else if (type.compareToIgnoreCase("virtualserial") == 0) {
|
2
|
464 |
settings = new String[2];
|
|
465 |
ITCVirtualSerialConnection s = (ITCVirtualSerialConnection)inConnection;
|
|
466 |
settings[0] = s.getComPort();
|
|
467 |
settings[1] = s.getDecodeFormat().toLowerCase();
|
60
|
468 |
} else if (type.compareToIgnoreCase("serial") == 0) {
|
2
|
469 |
settings = new String[7];
|
|
470 |
ITCRealSerialConnection s = (ITCRealSerialConnection)inConnection;
|
|
471 |
settings[0] = s.getComPort();
|
|
472 |
settings[1] = s.getBaudRate();
|
|
473 |
settings[2] = s.getDataBits();
|
|
474 |
settings[3] = s.getParity();
|
|
475 |
settings[4] = s.getStopBits();
|
|
476 |
settings[5] = s.getFlowControl();
|
|
477 |
settings[6] = s.getDecodeFormat().toLowerCase();
|
60
|
478 |
} else if (type.compareToIgnoreCase("usb") == 0) {
|
2
|
479 |
settings = new String[1];
|
60
|
480 |
} else {
|
|
481 |
// Add other connections here
|
2
|
482 |
}
|
|
483 |
}
|
|
484 |
return finishConnect(type, settings, inConnection, inMessageOptions, inMessageIds);
|
|
485 |
}
|
60
|
486 |
protected void ensureWritableFile(String filePath) throws IOException {
|
2
|
487 |
// ensure file path points to a writable regular file
|
|
488 |
IPath path = new Path(filePath);
|
|
489 |
File file = path.toFile();
|
|
490 |
if (!file.exists()) {
|
|
491 |
file.createNewFile();
|
|
492 |
}
|
|
493 |
else { // file exists
|
|
494 |
if (file.isDirectory()) {
|
|
495 |
throw new IOException(MessageFormat.format("Path is a directory: {0}", filePath));
|
|
496 |
}
|
|
497 |
else if (!file.canWrite()) {
|
|
498 |
throw new IOException(MessageFormat.format("File exists and is not writable: {0}", filePath));
|
|
499 |
}
|
|
500 |
}
|
|
501 |
}
|
|
502 |
|
|
503 |
/* (non-Javadoc)
|
|
504 |
* @see com.nokia.tcf.api.ITCAPIConnection#connect(com.nokia.tcf.api.ITCMessageOptions, com.nokia.tcf.api.ITCMessageIds)
|
|
505 |
*/
|
|
506 |
public IStatus connect(ITCMessageOptions inMessageOptions, ITCMessageIds inMessageIds) {
|
|
507 |
// not currently implemented or tested
|
|
508 |
long ret = TCErrorConstants.TCAPI_ERR_FEATURE_NOT_IMPLEMENTED;
|
|
509 |
IStatus status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
510 |
return status;
|
|
511 |
}
|
|
512 |
|
|
513 |
/* (non-Javadoc)
|
|
514 |
* @see com.nokia.tcf.api.ITCAPIConnection#disconnect()
|
|
515 |
*/
|
|
516 |
public IStatus disconnect() {
|
|
517 |
IStatus status = statusOK;
|
|
518 |
|
|
519 |
IStatus connectStatus = checkConnected();
|
|
520 |
// ignore error
|
|
521 |
if (connectStatus.isOK()) {
|
|
522 |
if (this.cookie.isMessageProcessing()) {
|
|
523 |
long ret = nativeStop(this.cookie.getClientId());
|
|
524 |
this.cookie.setMessageProcessing(false);
|
|
525 |
if (ret != TCErrorConstants.TCAPI_ERR_NONE) {
|
|
526 |
status = new Status(IStatus.ERROR,Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
527 |
}
|
|
528 |
}
|
|
529 |
if (this.monitorThread != null) {
|
|
530 |
this.stopTCFMonitorThread = true;
|
|
531 |
this.monitorThread.stop = true;
|
|
532 |
try {
|
|
533 |
this.monitorThread.join();
|
|
534 |
} catch (InterruptedException e) {
|
|
535 |
}
|
|
536 |
this.monitorThread = null;
|
|
537 |
}
|
|
538 |
if (this.inputStream != null && this.inputStream.isOpen()) {
|
|
539 |
try {
|
|
540 |
this.inputStream.close();
|
|
541 |
} catch (IOException e) {
|
|
542 |
}
|
|
543 |
this.inputStream = null;
|
|
544 |
}
|
|
545 |
if (this.cookie.isConnected()) {
|
|
546 |
long ret = nativeDisconnect(this.cookie.getClientId());
|
|
547 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
548 |
this.cookie.setConnected(false);
|
|
549 |
this.cookie.setClientId(-1);
|
|
550 |
} else {
|
|
551 |
// error from nativeDisconnect
|
|
552 |
status = new Status(Status.ERROR,Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
553 |
}
|
|
554 |
}
|
|
555 |
}
|
|
556 |
return status;
|
|
557 |
}
|
|
558 |
|
|
559 |
// private methods
|
|
560 |
/**
|
|
561 |
* This is called from TCFMonitorThread to send errors to registered listeners
|
|
562 |
*/
|
|
563 |
public void fireErrorListeners(long errorCode, String errorString) {
|
|
564 |
int s = this.errorListenerList.size();
|
|
565 |
// System.out.printf("fireErrorListeners s = %d\n", s);
|
|
566 |
for (int i = 0; i < s; i++) {
|
|
567 |
ITCErrorListener e = (ITCErrorListener)this.errorListenerList.get(i);
|
|
568 |
if (e != null) {
|
|
569 |
int errorStatus = Status.ERROR;
|
|
570 |
if (errorCode == TCErrorConstants.TCAPI_INFO_COMM_RECONNECTED)
|
|
571 |
errorStatus = Status.INFO;
|
|
572 |
IStatus status = new Status(errorStatus, Activator.PLUGIN_ID, (int)errorCode, errorString, null);
|
|
573 |
e.errorOccurred(status);
|
|
574 |
}
|
|
575 |
}
|
|
576 |
}
|
|
577 |
|
|
578 |
public long getClientId() {
|
|
579 |
return this.cookie.getClientId();
|
|
580 |
}
|
|
581 |
|
|
582 |
/* (non-Javadoc)
|
|
583 |
* @see com.nokia.tcf.api.ITCAPIConnection#getConnections()
|
|
584 |
*/
|
|
585 |
public ITCConnection[] getConnections() {
|
|
586 |
IStatus status = statusOK;
|
|
587 |
ITCConnection[] connections = null;
|
|
588 |
long numberConnections = 0;
|
|
589 |
long[] number = new long[1];
|
|
590 |
long ret = nativeGetNumberConnections(number);
|
|
591 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
592 |
numberConnections = number[0];
|
|
593 |
} else {
|
|
594 |
// error processing from nativeGetNumberConnections
|
|
595 |
status = new Status(Status.ERROR,Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
596 |
}
|
|
597 |
if (numberConnections > 0)
|
|
598 |
{
|
|
599 |
connections = new ITCConnection[(int)numberConnections];
|
|
600 |
for (int inIndex = 0; inIndex < numberConnections; inIndex++)
|
|
601 |
{
|
60
|
602 |
String[] type = new String[1];
|
2
|
603 |
ret = nativeGetTypeOfConnection(inIndex, type);
|
60
|
604 |
if (type[0].compareToIgnoreCase("virtualserial") == 0) {
|
2
|
605 |
ITCVirtualSerialConnection outConnection = (ITCVirtualSerialConnection)TCFClassFactory.createITCVirtualSerialConnection(null);
|
60
|
606 |
String[] outType = new String[1];
|
2
|
607 |
long[] outOptions = new long[3];
|
|
608 |
String[] outSettings = new String[2];
|
|
609 |
ret = nativeGetConnectionSettings(inIndex, outType, outOptions, outSettings);
|
|
610 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
611 |
outConnection.setConnectionType(outType[0]);
|
|
612 |
outConnection.setRetryInterval(outOptions[0]);
|
|
613 |
outConnection.setRetryTimeout(outOptions[1]);
|
60
|
614 |
outConnection.setComPort(outSettings[0]);
|
|
615 |
outConnection.setDecodeFormat(outSettings[1]);
|
2
|
616 |
|
|
617 |
connections[inIndex] = outConnection;
|
|
618 |
} else {
|
|
619 |
// error processing from nativeGetConnectionSettings
|
|
620 |
status = new Status(Status.ERROR,Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
621 |
}
|
60
|
622 |
} else if (type[0].compareToIgnoreCase("serial") == 0) {
|
2
|
623 |
ITCRealSerialConnection outConnection = (ITCRealSerialConnection)TCFClassFactory.createITCRealSerialConnection(null);
|
60
|
624 |
String[] outType = new String[1];
|
2
|
625 |
long[] outOptions = new long[6];
|
60
|
626 |
String[] outSettings = new String[7];
|
2
|
627 |
ret = nativeGetConnectionSettings(inIndex, outType, outOptions, outSettings);
|
|
628 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
629 |
outConnection.setConnectionType(outType[0]);
|
|
630 |
outConnection.setRetryInterval(outOptions[0]);
|
|
631 |
outConnection.setRetryTimeout(outOptions[1]);
|
|
632 |
outConnection.setComPort(outSettings[0]);
|
|
633 |
outConnection.setBaudRate(outSettings[1]);
|
|
634 |
outConnection.setDataBits(outSettings[2]);
|
|
635 |
outConnection.setParity(outSettings[3]);
|
|
636 |
outConnection.setStopBits(outSettings[4]);
|
|
637 |
outConnection.setFlowControl(outSettings[5]);
|
60
|
638 |
outConnection.setDecodeFormat(outSettings[6]);
|
2
|
639 |
|
|
640 |
connections[inIndex] = outConnection;
|
|
641 |
} else {
|
|
642 |
// error processing from nativeGetConnectionSettings
|
|
643 |
status = new Status(Status.ERROR,Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
644 |
}
|
60
|
645 |
} else if (type[0].compareToIgnoreCase("tcp") == 0) {
|
|
646 |
ITCRealTCPConnection outConnection = (ITCRealTCPConnection)TCFClassFactory.createITCRealTCPConnection(null, null);
|
|
647 |
String[] outType = new String[1];
|
|
648 |
long[] outOptions = new long[3];
|
|
649 |
String[] outSettings = new String[3];
|
|
650 |
ret = nativeGetConnectionSettings(inIndex, outType, outOptions, outSettings);
|
|
651 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
652 |
outConnection.setConnectionType(outType[0]);
|
|
653 |
outConnection.setRetryInterval(outOptions[0]);
|
|
654 |
outConnection.setRetryTimeout(outOptions[1]);
|
|
655 |
outConnection.setIpAddress(outSettings[0]);
|
|
656 |
outConnection.setPort(outSettings[1]);
|
|
657 |
outConnection.setDecodeFormat(outSettings[2]);
|
|
658 |
|
|
659 |
connections[inIndex] = outConnection;
|
|
660 |
} else {
|
|
661 |
// error processing from nativeGetConnectionSettings
|
|
662 |
status = new Status(Status.ERROR,Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
663 |
}
|
|
664 |
} else if (type[0].compareToIgnoreCase("usb") == 0) {
|
|
665 |
// Finish this sometime when real USB is used on PC
|
|
666 |
} else {
|
2
|
667 |
// Add other connection types here
|
|
668 |
}
|
|
669 |
}
|
|
670 |
}
|
|
671 |
return connections;
|
|
672 |
}
|
|
673 |
|
|
674 |
/* (non-Javadoc)
|
|
675 |
* @see com.nokia.tcf.api.ITCAPIConnection#getInputStream()
|
|
676 |
*/
|
|
677 |
public ITCMessageInputStream getInputStream() {
|
|
678 |
return this.inputStream;
|
|
679 |
}
|
|
680 |
|
|
681 |
/* (non-Javadoc)
|
|
682 |
* @see com.nokia.tcf.api.ITCAPIConnection#getVersions()
|
|
683 |
*/
|
|
684 |
public ITCVersion[] getVersions() {
|
|
685 |
IStatus status = statusOK;
|
|
686 |
ITCVersion[] versions = null;
|
|
687 |
status = checkConnected();
|
|
688 |
if (status.isOK()) {
|
|
689 |
// we're connected call native
|
|
690 |
long numberVersions = nativeGetNumberVersionEntities(this.cookie.getClientId());
|
|
691 |
if (numberVersions > 0) {
|
|
692 |
versions = new TCVersion[(int)numberVersions];
|
|
693 |
String[] versStrings = new String[(int)numberVersions];
|
|
694 |
long numberGotten = nativeGetVersion(this.cookie.getClientId(), numberVersions, versStrings);
|
|
695 |
for (int i = 0; i < numberGotten; i++) {
|
|
696 |
versions[i] = new TCVersion(versStrings[i]);
|
|
697 |
}
|
|
698 |
}
|
|
699 |
}
|
|
700 |
return versions;
|
|
701 |
}
|
|
702 |
/* (non-Javadoc)
|
|
703 |
* @see com.nokia.tcf.api.ITCAPIConnection#removeErrorListener(com.nokia.tcf.api.ITCErrorListener)
|
|
704 |
*/
|
|
705 |
public IStatus removeErrorListener(ITCErrorListener inErrorListener) {
|
|
706 |
IStatus status = statusOK;
|
|
707 |
// System.out.printf("removeErrorListener\n");
|
|
708 |
this.errorListenerList.remove(inErrorListener);
|
|
709 |
return status;
|
|
710 |
}
|
|
711 |
/* (non-Javadoc)
|
|
712 |
* @see com.nokia.tcf.api.ITCAPIConnection#sendMessage(com.nokia.tcf.api.ITCMessage)
|
|
713 |
*/
|
|
714 |
public IStatus sendMessage(ITCMessage inMessage) {
|
|
715 |
IStatus status = statusOK;
|
|
716 |
status = checkConnected();
|
|
717 |
if (status.isOK()) {
|
|
718 |
// we are connected are we processing?
|
|
719 |
if (this.cookie.isMessageProcessing()) {
|
|
720 |
// we are running, check message
|
|
721 |
status = checkMessage(inMessage);
|
|
722 |
if (status.getSeverity() != Status.ERROR) {
|
|
723 |
// Status.OK or Status.WARNING (still attempt to send on warning)
|
|
724 |
// Encode if option is set
|
|
725 |
|
|
726 |
long[] formattingOptions = new long[5];
|
|
727 |
formattingOptions[0] = 0;
|
60
|
728 |
formattingOptions[1] = messageOptions.getMessageEncodeFormat(); // add protocol or not
|
|
729 |
formattingOptions[2] = messageOptions.getOSTVersion(); // OST version byte to use if OST
|
|
730 |
formattingOptions[3] = inMessage.getMyMessageId(); // message ID to use of adding protocol
|
|
731 |
formattingOptions[4] = (inMessage.isUseMyMessageId() == true) ? 1 : 0; // use my ID or not
|
2
|
732 |
String[] settings = new String[1];
|
|
733 |
settings[0] = connection.getDecodeFormat().toLowerCase();
|
|
734 |
try {
|
|
735 |
long ret = TCErrorConstants.TCAPI_ERR_NONE;
|
|
736 |
if (inMessage == null) { // OK if we're just sending a header
|
|
737 |
ret = nativeSendMessage(this.cookie.getClientId(), formattingOptions, settings, null);
|
|
738 |
} else {
|
|
739 |
ret = nativeSendMessage(this.cookie.getClientId(), formattingOptions, settings, inMessage.getMessage());
|
|
740 |
}
|
|
741 |
if (ret != TCErrorConstants.TCAPI_ERR_NONE) {
|
|
742 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
743 |
}
|
|
744 |
} catch (Exception e) {
|
|
745 |
// exception is thrown ONLY when err = TCAPI_ERR_COMM_ERROR from native
|
|
746 |
// message is OS Error
|
|
747 |
String msg = e.getMessage();
|
|
748 |
long ret = TCErrorConstants.TCAPI_ERR_COMM_ERROR;
|
|
749 |
String tcErr = String.format("%s OSError: %s", TCErrorConstants.getErrorMessage(ret), msg);
|
|
750 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, tcErr, null);
|
|
751 |
}
|
|
752 |
}
|
|
753 |
} else {
|
|
754 |
// we are stopped
|
|
755 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_ROUTING_STOPPED,
|
|
756 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_ROUTING_STOPPED), null);
|
|
757 |
}
|
|
758 |
}
|
|
759 |
return status;
|
|
760 |
}
|
|
761 |
/* (non-Javadoc)
|
|
762 |
* @see com.nokia.tcf.api.ITCAPIConnection#setTCMessageIds(com.nokia.tcf.api.ITCMessageIds)
|
|
763 |
*/
|
|
764 |
public IStatus setTCMessageIds(ITCMessageIds inMessageIds) {
|
|
765 |
IStatus status = statusOK;
|
|
766 |
status = checkMessageIds(inMessageIds);
|
|
767 |
if (status.isOK()) {
|
|
768 |
// input is OK
|
|
769 |
status = checkConnected();
|
|
770 |
if (status.isOK()) {
|
|
771 |
// connected
|
|
772 |
if (this.cookie.isMessageProcessing()) {
|
|
773 |
// must be stopped to set new IDs
|
|
774 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)TCErrorConstants.TCAPI_ERR_ROUTING_IN_PROGRESS,
|
|
775 |
TCErrorConstants.getErrorMessage(TCErrorConstants.TCAPI_ERR_ROUTING_IN_PROGRESS), null);
|
|
776 |
}
|
|
777 |
}
|
|
778 |
}
|
|
779 |
if (status.isOK()) {
|
|
780 |
// everything OK, so we can save our IDs and register them
|
|
781 |
this.messageIds = inMessageIds;
|
|
782 |
int size = (int)inMessageIds.size();
|
|
783 |
byte[] messageids = new byte[size];
|
|
784 |
for (int i = 0; i < size; i++) {
|
|
785 |
messageids[0] = inMessageIds.getMessageIds().get(i);
|
|
786 |
}
|
|
787 |
long ret = nativeSetMessageIds(this.cookie.getClientId(), messageids);
|
|
788 |
if (ret != TCErrorConstants.TCAPI_ERR_NONE) {
|
|
789 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret,
|
|
790 |
TCErrorConstants.getErrorMessage(ret), null);
|
|
791 |
}
|
|
792 |
}
|
|
793 |
return status;
|
|
794 |
}
|
|
795 |
/* (non-Javadoc)
|
|
796 |
* @see com.nokia.tcf.api.ITCAPIConnection#start()
|
|
797 |
*/
|
|
798 |
public IStatus start() {
|
|
799 |
IStatus status = statusOK;
|
|
800 |
// check connected
|
|
801 |
status = checkConnected();
|
|
802 |
if (status.isOK()) {
|
|
803 |
if (this.cookie.isMessageProcessing() == false) {
|
|
804 |
// call native
|
|
805 |
long ret = nativeStart(this.cookie.getClientId());
|
|
806 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
807 |
this.cookie.setMessageProcessing(true);
|
|
808 |
} else {
|
|
809 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
810 |
}
|
|
811 |
}
|
|
812 |
}
|
|
813 |
|
|
814 |
return status;
|
|
815 |
}
|
|
816 |
/* (non-Javadoc)
|
|
817 |
* @see com.nokia.tcf.api.ITCAPIConnection#stop()
|
|
818 |
*/
|
|
819 |
public IStatus stop() {
|
|
820 |
IStatus status = statusOK;
|
|
821 |
status = checkConnected();
|
|
822 |
if (status.isOK()) {
|
|
823 |
if (this.cookie.isMessageProcessing()) {
|
|
824 |
long ret = nativeStop(this.cookie.getClientId());
|
|
825 |
if (ret == TCErrorConstants.TCAPI_ERR_NONE) {
|
|
826 |
this.cookie.setMessageProcessing(false);
|
|
827 |
} else {
|
|
828 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
829 |
}
|
|
830 |
}
|
|
831 |
}
|
|
832 |
return status;
|
|
833 |
}
|
|
834 |
/* (non-Javadoc)
|
|
835 |
* @see com.nokia.tcf.api.ITCAPIConnection#testConnection()
|
|
836 |
*/
|
|
837 |
public IStatus testConnection() {
|
|
838 |
IStatus status = statusOK;
|
|
839 |
status = checkConnected();
|
|
840 |
if (status.isOK()) {
|
|
841 |
long ret = nativeTestConnection(this.cookie.getClientId());
|
|
842 |
if (ret != TCErrorConstants.TCAPI_ERR_NONE) {
|
|
843 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)(ret), TCErrorConstants.getErrorMessage((int)ret), null);
|
|
844 |
}
|
|
845 |
}
|
|
846 |
return status;
|
|
847 |
}
|
60
|
848 |
protected IStatus doTestConnection(String type, String[] settings, ITCConnection inConnection) {
|
2
|
849 |
IStatus status = statusOK;
|
|
850 |
// test connection
|
|
851 |
long[] options = new long[3];
|
|
852 |
options[0] = inConnection.getRetryInterval(); // connection options
|
|
853 |
options[1] = inConnection.getRetryTimeout();
|
|
854 |
options[2] = 0;
|
|
855 |
long ret = nativeTestConnection(type, options, settings);
|
|
856 |
if (ret != TCErrorConstants.TCAPI_ERR_NONE) {
|
|
857 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
858 |
}
|
|
859 |
return status;
|
|
860 |
}
|
|
861 |
/* (non-Javadoc)
|
|
862 |
* @see com.nokia.tcf.api.ITCAPIConnection#testConnection(com.nokia.tcf.api.ITCConnection)
|
|
863 |
*/
|
|
864 |
public IStatus testConnection(ITCConnection inConnection) {
|
|
865 |
IStatus status = statusOK;
|
|
866 |
String[] settings = null;
|
60
|
867 |
String type = inConnection.getConnectionType();
|
|
868 |
if (type.compareToIgnoreCase("serial") == 0) {
|
2
|
869 |
settings = new String[7];
|
|
870 |
ITCRealSerialConnection s = (ITCRealSerialConnection)inConnection;
|
|
871 |
settings[0] = s.getComPort();
|
|
872 |
settings[1] = s.getBaudRate();
|
|
873 |
settings[2] = s.getDataBits();
|
|
874 |
settings[3] = s.getParity();
|
|
875 |
settings[4] = s.getStopBits();
|
|
876 |
settings[5] = s.getFlowControl();
|
|
877 |
settings[6] = s.getDecodeFormat().toLowerCase();
|
60
|
878 |
} else if (type.compareToIgnoreCase("tcp") == 0) {
|
2
|
879 |
settings = new String[3];
|
|
880 |
ITCRealTCPConnection s = (ITCRealTCPConnection)inConnection;
|
|
881 |
settings[0] = s.getIpAddress();
|
|
882 |
settings[1] = s.getPort();
|
|
883 |
settings[2] = s.getDecodeFormat().toLowerCase();
|
60
|
884 |
} else if (type.compareToIgnoreCase("usb") == 0) {
|
2
|
885 |
settings = new String[1];
|
60
|
886 |
// finish this sometime when real USB is used on PC
|
|
887 |
} else if (type.compareToIgnoreCase("virtualserial") == 0) {
|
2
|
888 |
settings = new String[2];
|
|
889 |
ITCVirtualSerialConnection s = (ITCVirtualSerialConnection)inConnection;
|
|
890 |
settings[0] = s.getComPort();
|
|
891 |
settings[1] = s.getDecodeFormat().toLowerCase();
|
60
|
892 |
} else {
|
|
893 |
// add new connections here
|
2
|
894 |
long err = TCErrorConstants.TCAPI_ERR_MEDIA_NOT_SUPPORTED;
|
|
895 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)err, TCErrorConstants.getErrorMessage((int)err), null);
|
|
896 |
}
|
|
897 |
if (status.isOK()) {
|
|
898 |
status = doTestConnection(type, settings, inConnection);
|
|
899 |
/* // test connection
|
|
900 |
long[] options = new long[3];
|
|
901 |
options[0] = inConnection.getRetryInterval(); // connection options
|
|
902 |
options[1] = inConnection.getRetryTimeout();
|
|
903 |
options[2] = inConnection.getDecodeFormat();
|
|
904 |
long ret = nativeTestConnection(type, options, settings);
|
|
905 |
if (ret != TCErrorConstants.TCAPI_ERR_NONE) {
|
|
906 |
status = new Status(Status.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
907 |
} */
|
|
908 |
}
|
|
909 |
return status;
|
|
910 |
}
|
|
911 |
public IStatus clearMessageFile() {
|
|
912 |
IStatus status = statusOK;
|
|
913 |
IStatus connStatus = checkConnected();
|
|
914 |
if (connStatus.isOK()) {
|
|
915 |
if (messageOptions.getMessageDestination() == ITCMessageOptions.DESTINATION_CLIENTFILE) {
|
|
916 |
if (messageOptions.getMessageFile() != null) {
|
|
917 |
long ret = nativeClearFile(cookie.getClientId());
|
|
918 |
if (ret != TCErrorConstants.TCAPI_ERR_NONE) {
|
|
919 |
status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, (int)ret, TCErrorConstants.getErrorMessage(ret), null);
|
|
920 |
}
|
|
921 |
}
|
|
922 |
}
|
|
923 |
}
|
|
924 |
return status;
|
|
925 |
}
|
|
926 |
|
|
927 |
// natives
|
|
928 |
// connect/disconnect
|
60
|
929 |
protected native long nativeConnect(String inType, long[] inOptions, String[] inSettings, long[] inMessageOptions, String inFilePath, long[] outClientId);
|
|
930 |
protected native long nativeDisconnect(long inClientId);
|
2
|
931 |
// connections
|
|
932 |
protected native long nativeGetNumberConnections(long[] outNumber);
|
60
|
933 |
protected native long nativeGetTypeOfConnection(long inIndex, String[] outType);
|
|
934 |
protected native long nativeGetConnectionSettings(long inIndex, String[] outType, long[] outOptions, String[] outSettings);
|
2
|
935 |
// port handling errors
|
|
936 |
public native boolean nativePollError(long inClienId, int[] outErrorCode, boolean[] outHasOSErrorCode, long[] outOSErrorCode);
|
|
937 |
// versions
|
60
|
938 |
protected native long nativeGetNumberVersionEntities(long inClientId);
|
|
939 |
protected native long nativeGetVersion(long inClientId, long inNumToGet, String[] outVersion);
|
2
|
940 |
// input stream
|
|
941 |
public native long nativePollInputStream(long inClientId, long[] outNumberTotalMessages);
|
|
942 |
public native long nativePollInputStream2(long inClientId, long inNumberMessagesToPeek, long[] outNumberMessagesPeeked, long[] outNumberBytesPeeked);
|
|
943 |
public native long nativeGetInputStreamMessageBytes(long inClientId, long inNumberMessagesToPeek, long[] outNumberBytesPerMessage);
|
|
944 |
public native long nativeReadInputStream(long inClientId, long inNumberMessagesToRead, long[] outNumberMessagesRead, long[] outNumberBytesRead, long inNumberMaxBytes, byte[] outMessages);
|
|
945 |
public native long nativeOpenInputStream(long inClientId, String inBaseFilePath, long inInputStreamSize, boolean inOverFlowToFile);
|
|
946 |
public native long nativeCloseInputStream(long inClientId);
|
|
947 |
// message file
|
60
|
948 |
protected native long nativeClearFile(long inClientId);
|
2
|
949 |
// send message
|
60
|
950 |
protected native long nativeSendMessage(long inClientId, long[] inFormattingOptions, String[] inSettings, byte[] inMessage);
|
2
|
951 |
// register message IDs
|
60
|
952 |
protected native long nativeSetMessageIds(long inClientId, byte[] inMessageIds);
|
2
|
953 |
// start/stop processing
|
60
|
954 |
protected native long nativeStart(long inClientId);
|
|
955 |
protected native long nativeStop(long inClientId);
|
2
|
956 |
// test connections
|
60
|
957 |
protected native long nativeTestConnection(String inType, long[] inOptions, String[] inSettings);
|
|
958 |
protected native long nativeTestConnection(long inClientId);
|
2
|
959 |
// start/stop server - done from plugin activator start/stop methods
|
|
960 |
public native long nativeStartServer();
|
|
961 |
public native long nativeStopServer();
|
|
962 |
}
|