60
|
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 |
#include "stdafx.h"
|
|
19 |
#include "TCAPIConnectionJni.h"
|
|
20 |
#include "TCConstants.h"
|
|
21 |
#include "TCErrorConstants.h"
|
|
22 |
#include "ClientManager.h"
|
|
23 |
#include "ServerClient.h"
|
|
24 |
#include "TCDebugLog.h"
|
|
25 |
#include "InputStream.h"
|
|
26 |
#include "ErrorMonitorData.h"
|
|
27 |
#include <list>
|
|
28 |
#include <vector>
|
|
29 |
|
|
30 |
extern CClientManager* gManager;
|
|
31 |
|
|
32 |
#ifdef _DEBUG
|
|
33 |
extern BOOL gDoLogging;
|
|
34 |
char TCDebugMsg[100];
|
|
35 |
#define TCDEBUGOPEN() if (gDoLogging) { gManager->m_DebugLog->WaitForAccess(); }
|
|
36 |
#define TCDEBUGLOGS(s) if (gDoLogging) { sprintf(TCDebugMsg,"%s", s); gManager->m_DebugLog->log(TCDebugMsg); }
|
|
37 |
#define TCDEBUGLOGA1(s, a1) if (gDoLogging) { sprintf(TCDebugMsg, s, a1); gManager->m_DebugLog->log(TCDebugMsg); }
|
|
38 |
#define TCDEBUGLOGA2(s, a1, a2) if (gDoLogging) { sprintf(TCDebugMsg, s, a1, a2); gManager->m_DebugLog->log(TCDebugMsg); }
|
|
39 |
#define TCDEBUGLOGA3(s, a1, a2, a3) if (gDoLogging) { sprintf(TCDebugMsg, s, a1, a2, a3); gManager->m_DebugLog->log(TCDebugMsg); }
|
|
40 |
#define TCDEBUGCLOSE() if (gDoLogging) { gManager->m_DebugLog->ReleaseAccess(); }
|
|
41 |
#else
|
|
42 |
#define TCDEBUGOPEN()
|
|
43 |
#define TCDEBUGLOGS(s)
|
|
44 |
#define TCDEBUGLOGA1(s, a1)
|
|
45 |
#define TCDEBUGLOGA2(s, a1, a2)
|
|
46 |
#define TCDEBUGLOGA3(s, a1, a2, a3)
|
|
47 |
#define TCDEBUGCLOSE()
|
|
48 |
#endif
|
|
49 |
|
|
50 |
#ifdef _DEBUG
|
|
51 |
FILE* fLog1 = NULL;
|
|
52 |
FILE* fLog2 = NULL;
|
|
53 |
static void OpenLogFile1(char* filename);
|
|
54 |
static void CloseLogFile1();
|
|
55 |
static void OpenLogFile2(char* filename);
|
|
56 |
static void CloseLogFile2();
|
|
57 |
#define OPENLOGf1(f) OpenLogFile1(f)
|
|
58 |
#define CLOSELOG1() CloseLogFile1()
|
|
59 |
#define OPENLOGf2(f) OpenLogFile2(f)
|
|
60 |
#define CLOSELOG2() CloseLogFile2()
|
|
61 |
#else
|
|
62 |
#define OPENLOGf1(f)
|
|
63 |
#define CLOSELOG1()
|
|
64 |
#endif
|
|
65 |
|
|
66 |
static void ConvertRealSerialSettingsToHost(char* pBaud, char* pDataBits, char* pParity, char* pStopBits, char* pFlowControl, pRealSerialConnectData pData);
|
|
67 |
static void ConvertRealSerialSettingsToServer(const char* pBaud, const char* pDataBits, const char* pParity, const char* pStopBits, const char* pFlowControl, pRealSerialConnectData pData);
|
|
68 |
static const char* GetErrorText(unsigned long error);
|
|
69 |
/*
|
|
70 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
71 |
* Method: nativeConnect
|
|
72 |
* Signature: (Ljava/lang/String;[J[Ljava/lang/String;[JLjava/lang/String;[J)J
|
|
73 |
*/
|
|
74 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeConnect
|
|
75 |
(JNIEnv *env, jobject pThis, jstring inType, jlongArray inOptions, jobjectArray inSettings, jlongArray inMessageOptions, jstring inFilePath, jlongArray outClientId)
|
|
76 |
{
|
|
77 |
// inOptions are connection options
|
|
78 |
// inMessageOptions are client's message options
|
|
79 |
// inFilePath will be null if message destination is not DESTINATION_CLIENTFILE
|
|
80 |
long ret = TCAPI_ERR_NONE;
|
|
81 |
unsigned long osError = 0;
|
|
82 |
long clientId;
|
|
83 |
|
|
84 |
TCDEBUGOPEN();
|
|
85 |
|
|
86 |
TCDEBUGLOGS("nativeConnect\n");
|
|
87 |
|
|
88 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
89 |
|
|
90 |
{
|
|
91 |
jboolean isCopy = false;
|
|
92 |
// options per connection
|
|
93 |
jlong* pOptions = env->GetLongArrayElements(inOptions, &isCopy);
|
|
94 |
DWORD retryInterval = (DWORD)pOptions[0];
|
|
95 |
DWORD retryTimeout = (DWORD)pOptions[1];
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
env->ReleaseLongArrayElements(inOptions, pOptions, 0);
|
|
100 |
|
|
101 |
pOptions = env->GetLongArrayElements(inMessageOptions, &isCopy);
|
|
102 |
|
|
103 |
// options per client
|
|
104 |
long unWrapFormat = pOptions[0];
|
|
105 |
long ostVersion = pOptions[1];
|
|
106 |
env->ReleaseLongArrayElements(inMessageOptions, pOptions, 0);
|
|
107 |
|
|
108 |
|
|
109 |
TCDEBUGLOGA2(" retryInterval=%d, retryTimeout=%d\n", retryInterval, retryTimeout);
|
|
110 |
|
|
111 |
TCDEBUGLOGA3(" unWrapFormat=%d, ostVersion=%d destination=%s\n", unWrapFormat, ostVersion, ((inFilePath == NULL) ? "stream" : "file"));
|
|
112 |
|
|
113 |
char* pType = (char*)env->GetStringUTFChars(inType, &isCopy);
|
|
114 |
TCDEBUGLOGA1(" pType = %s\n", pType);
|
|
115 |
|
|
116 |
if (strcmp(pType, "musti") == 0 || strcmp(pType, "platsim") == 0)
|
|
117 |
{
|
|
118 |
jstring addString = (jstring)env->GetObjectArrayElement(inSettings, 0);
|
|
119 |
jstring portString = (jstring)env->GetObjectArrayElement(inSettings, 1);
|
|
120 |
jstring chanString = (jstring)env->GetObjectArrayElement(inSettings, 2);
|
|
121 |
jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 3);
|
|
122 |
|
|
123 |
const char* pAddress = env->GetStringUTFChars(addString, NULL);
|
|
124 |
const char* pPort = env->GetStringUTFChars(portString, NULL);
|
|
125 |
const char* pChan = env->GetStringUTFChars(chanString, NULL);
|
|
126 |
const char* pDecode = env->GetStringUTFChars(decodeString, NULL);
|
|
127 |
|
|
128 |
TCDEBUGLOGA2(" TCP: ipAddress=%s, ipPort=%s\n", pAddress, pPort);
|
|
129 |
TCDEBUGLOGA2(" TCP: channel=%s, decode=%s\n", pChan, pDecode);
|
|
130 |
|
|
131 |
ServerCommandData cmd;
|
|
132 |
cmd.command = eCmdConnect;
|
|
133 |
strncpy(cmd.connectSettings.connectType, pType, MAX_CONNECTION_TYPE);
|
|
134 |
strncpy(cmd.connectSettings.tcpSettings.ipAddress, pAddress, MAX_IPADDRESS_SIZE);
|
|
135 |
strncpy(cmd.connectSettings.tcpSettings.ipPort, pPort, MAX_PORT_SIZE);
|
|
136 |
|
|
137 |
cmd.connectSettings.retryInterval = retryInterval;
|
|
138 |
cmd.connectSettings.retryTimeout = retryTimeout;
|
|
139 |
strncpy(cmd.connectSettings.decodeFormat, pDecode, MAX_DECODE_FORMAT);
|
|
140 |
|
|
141 |
if (pChan != NULL)
|
|
142 |
{
|
|
143 |
if (strcmp(pChan, "1") == 0)
|
|
144 |
{
|
|
145 |
cmd.connectSettings.traceBoxChannel = 1;
|
|
146 |
}
|
|
147 |
else
|
|
148 |
{
|
|
149 |
cmd.connectSettings.traceBoxChannel = 2;
|
|
150 |
}
|
|
151 |
}
|
|
152 |
else
|
|
153 |
{
|
|
154 |
cmd.connectSettings.traceBoxChannel = 2;
|
|
155 |
}
|
|
156 |
|
|
157 |
|
|
158 |
cmd.clientOptions.unWrapFormat = unWrapFormat;
|
|
159 |
cmd.clientOptions.ostVersion = ostVersion;
|
|
160 |
|
|
161 |
gManager->m_Server->SendCommand(&cmd);
|
|
162 |
gManager->m_Server->GetResponse(&cmd);
|
|
163 |
|
|
164 |
if (cmd.response == eRspError)
|
|
165 |
{
|
|
166 |
TCDEBUGLOGA1(" from server: ret = %d\n", cmd.error);
|
|
167 |
ret = cmd.error;
|
|
168 |
osError = cmd.osError;
|
|
169 |
}
|
|
170 |
else
|
|
171 |
{
|
|
172 |
TCDEBUGLOGA1(" from server: id = %d\n", cmd.clientId);
|
|
173 |
clientId = cmd.clientId;
|
|
174 |
|
|
175 |
gManager->WaitForErrorMonitorListAccess();
|
|
176 |
TCDEBUGLOGS(" TODO: create error monitor storage if server connected\n");
|
|
177 |
CErrorMonitor* monitor = new CErrorMonitor(clientId);
|
|
178 |
if (monitor != NULL)
|
|
179 |
{
|
|
180 |
monitor->CreateData();
|
|
181 |
gManager->AddErrorMonitor(monitor);
|
|
182 |
}
|
|
183 |
|
|
184 |
gManager->ReleaseErrorMonitorListAccess();
|
|
185 |
|
|
186 |
TCDEBUGLOGA1(" clientId=%d\n", clientId);
|
|
187 |
jlong jClientId = clientId;
|
|
188 |
env->SetLongArrayRegion(outClientId, 0, 1, &jClientId);
|
|
189 |
|
|
190 |
}
|
|
191 |
env->ReleaseStringUTFChars(addString, pAddress);
|
|
192 |
env->ReleaseStringUTFChars(portString, pPort);
|
|
193 |
env->ReleaseStringUTFChars(chanString, pChan);
|
|
194 |
env->ReleaseStringUTFChars(decodeString, pDecode);
|
|
195 |
}
|
|
196 |
else if (strcmp(pType, "tcp") == 0)
|
|
197 |
{
|
|
198 |
jstring addString = (jstring)env->GetObjectArrayElement(inSettings, 0);
|
|
199 |
jstring portString = (jstring)env->GetObjectArrayElement(inSettings, 1);
|
|
200 |
jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 2);
|
|
201 |
|
|
202 |
const char* pAddress = env->GetStringUTFChars(addString, NULL);
|
|
203 |
const char* pPort = env->GetStringUTFChars(portString, NULL);
|
|
204 |
const char* pDecode = env->GetStringUTFChars(decodeString, NULL);
|
|
205 |
|
|
206 |
TCDEBUGLOGA3(" TCP: ipAddress=%s, ipPort=%s decode=%s\n", pAddress, pPort, pDecode);
|
|
207 |
|
|
208 |
ServerCommandData cmd;
|
|
209 |
cmd.command = eCmdConnect;
|
|
210 |
strncpy(cmd.connectSettings.connectType, pType, MAX_CONNECTION_TYPE);
|
|
211 |
strncpy(cmd.connectSettings.tcpSettings.ipAddress, pAddress, MAX_IPADDRESS_SIZE);
|
|
212 |
strncpy(cmd.connectSettings.tcpSettings.ipPort, pPort, MAX_PORT_SIZE);
|
|
213 |
|
|
214 |
cmd.connectSettings.retryInterval = retryInterval;
|
|
215 |
cmd.connectSettings.retryTimeout = retryTimeout;
|
|
216 |
strncpy(cmd.connectSettings.decodeFormat, pDecode, MAX_DECODE_FORMAT);
|
|
217 |
cmd.clientOptions.unWrapFormat = unWrapFormat;
|
|
218 |
cmd.clientOptions.ostVersion = ostVersion;
|
|
219 |
|
|
220 |
gManager->m_Server->SendCommand(&cmd);
|
|
221 |
gManager->m_Server->GetResponse(&cmd);
|
|
222 |
|
|
223 |
if (cmd.response == eRspError)
|
|
224 |
{
|
|
225 |
TCDEBUGLOGA1(" from server: ret = %d\n", cmd.error);
|
|
226 |
ret = cmd.error;
|
|
227 |
osError = cmd.osError;
|
|
228 |
}
|
|
229 |
else
|
|
230 |
{
|
|
231 |
TCDEBUGLOGA1(" from server: id = %d\n", cmd.clientId);
|
|
232 |
clientId = cmd.clientId;
|
|
233 |
|
|
234 |
gManager->WaitForErrorMonitorListAccess();
|
|
235 |
TCDEBUGLOGS(" TODO: create error monitor storage if server connected\n");
|
|
236 |
CErrorMonitor* monitor = new CErrorMonitor(clientId);
|
|
237 |
if (monitor != NULL)
|
|
238 |
{
|
|
239 |
monitor->CreateData();
|
|
240 |
gManager->AddErrorMonitor(monitor);
|
|
241 |
}
|
|
242 |
|
|
243 |
gManager->ReleaseErrorMonitorListAccess();
|
|
244 |
|
|
245 |
TCDEBUGLOGA1(" clientId=%d\n", clientId);
|
|
246 |
jlong jClientId = clientId;
|
|
247 |
env->SetLongArrayRegion(outClientId, 0, 1, &jClientId);
|
|
248 |
|
|
249 |
}
|
|
250 |
env->ReleaseStringUTFChars(addString, pAddress);
|
|
251 |
env->ReleaseStringUTFChars(portString, pPort);
|
|
252 |
env->ReleaseStringUTFChars(decodeString, pDecode);
|
|
253 |
}
|
|
254 |
else if (strcmp(pType, "virtualserial") == 0)
|
|
255 |
{
|
|
256 |
jstring portString = (jstring)env->GetObjectArrayElement(inSettings, 0);
|
|
257 |
const char* pPort = env->GetStringUTFChars(portString, NULL);
|
|
258 |
jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 1);
|
|
259 |
const char* pDecode = env->GetStringUTFChars(decodeString, NULL);
|
|
260 |
|
|
261 |
TCDEBUGLOGA2(" vserial: pPort=%s decode=%s\n", pPort, pDecode);
|
|
262 |
|
|
263 |
ServerCommandData cmd;
|
|
264 |
cmd.command = eCmdConnect;
|
|
265 |
strncpy(cmd.connectSettings.connectType, pType, MAX_CONNECTION_TYPE);
|
|
266 |
strncpy(cmd.connectSettings.virtualSerialSettings.comPort, pPort, MAX_COMPORT_SIZE);
|
|
267 |
|
|
268 |
cmd.connectSettings.retryInterval = retryInterval;
|
|
269 |
cmd.connectSettings.retryTimeout = retryTimeout;
|
|
270 |
strncpy(cmd.connectSettings.decodeFormat, pDecode, MAX_DECODE_FORMAT);
|
|
271 |
cmd.clientOptions.unWrapFormat = unWrapFormat;
|
|
272 |
cmd.clientOptions.ostVersion = ostVersion;
|
|
273 |
|
|
274 |
gManager->m_Server->SendCommand(&cmd);
|
|
275 |
gManager->m_Server->GetResponse(&cmd);
|
|
276 |
|
|
277 |
if (cmd.response == eRspError)
|
|
278 |
{
|
|
279 |
TCDEBUGLOGA1(" from server: ret = %d\n", cmd.error);
|
|
280 |
ret = cmd.error;
|
|
281 |
osError = cmd.osError;
|
|
282 |
}
|
|
283 |
else
|
|
284 |
{
|
|
285 |
TCDEBUGLOGA1(" from server: id = %d\n", cmd.clientId);
|
|
286 |
clientId = cmd.clientId;
|
|
287 |
|
|
288 |
gManager->WaitForErrorMonitorListAccess();
|
|
289 |
CErrorMonitor* monitor = new CErrorMonitor(clientId);
|
|
290 |
if (monitor != NULL)
|
|
291 |
{
|
|
292 |
monitor->CreateData();
|
|
293 |
gManager->AddErrorMonitor(monitor);
|
|
294 |
}
|
|
295 |
|
|
296 |
gManager->ReleaseErrorMonitorListAccess();
|
|
297 |
|
|
298 |
TCDEBUGLOGA1(" clientId=%d\n", clientId);
|
|
299 |
jlong jClientId = clientId;
|
|
300 |
env->SetLongArrayRegion(outClientId, 0, 1, &jClientId);
|
|
301 |
}
|
|
302 |
env->ReleaseStringUTFChars(portString, pPort);
|
|
303 |
env->ReleaseStringUTFChars(decodeString, pDecode);
|
|
304 |
}
|
|
305 |
else if (strcmp(pType, "serial") == 0)
|
|
306 |
{
|
|
307 |
jstring portString = (jstring)env->GetObjectArrayElement(inSettings, 0);
|
|
308 |
const char* pPort = env->GetStringUTFChars(portString, NULL);
|
|
309 |
|
|
310 |
jstring baudString = (jstring)env->GetObjectArrayElement(inSettings, 1);
|
|
311 |
const char* pBaud = env->GetStringUTFChars(baudString, NULL);
|
|
312 |
|
|
313 |
jstring dataBitsString = (jstring)env->GetObjectArrayElement(inSettings, 2);
|
|
314 |
const char* pDataBits = env->GetStringUTFChars(dataBitsString, NULL);
|
|
315 |
|
|
316 |
jstring parityString = (jstring)env->GetObjectArrayElement(inSettings, 3);
|
|
317 |
const char* pParity = env->GetStringUTFChars(parityString, NULL);
|
|
318 |
|
|
319 |
jstring stopBitsString = (jstring)env->GetObjectArrayElement(inSettings, 4);
|
|
320 |
const char* pStopBits = env->GetStringUTFChars(stopBitsString, NULL);
|
|
321 |
|
|
322 |
jstring flowControlString = (jstring)env->GetObjectArrayElement(inSettings, 5);
|
|
323 |
const char* pFlowControl = env->GetStringUTFChars(flowControlString, NULL);
|
|
324 |
|
|
325 |
jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 6);
|
|
326 |
const char* pDecode = env->GetStringUTFChars(decodeString, NULL);
|
|
327 |
|
|
328 |
TCDEBUGLOGA3(" real serial: pPort=%s pBaud=%s pDataBits=%s\n", pPort, pBaud, pDataBits);
|
|
329 |
|
|
330 |
ServerCommandData cmd;
|
|
331 |
cmd.command = eCmdConnect;
|
|
332 |
strncpy(cmd.connectSettings.connectType, pType, MAX_CONNECTION_TYPE);
|
|
333 |
strncpy(cmd.connectSettings.realSerialSettings.comPort, pPort, MAX_COMPORT_SIZE);
|
|
334 |
ConvertRealSerialSettingsToServer(pBaud, pDataBits, pParity, pStopBits, pFlowControl, &cmd.connectSettings.realSerialSettings);
|
|
335 |
|
|
336 |
cmd.connectSettings.retryInterval = retryInterval;
|
|
337 |
cmd.connectSettings.retryTimeout = retryTimeout;
|
|
338 |
strncpy(cmd.connectSettings.decodeFormat, pDecode, MAX_DECODE_FORMAT);
|
|
339 |
cmd.clientOptions.unWrapFormat = unWrapFormat;
|
|
340 |
cmd.clientOptions.ostVersion = ostVersion;
|
|
341 |
|
|
342 |
gManager->m_Server->SendCommand(&cmd);
|
|
343 |
gManager->m_Server->GetResponse(&cmd);
|
|
344 |
|
|
345 |
if (cmd.response == eRspError)
|
|
346 |
{
|
|
347 |
TCDEBUGLOGA1(" from server: ret = %d\n", cmd.error);
|
|
348 |
ret = cmd.error;
|
|
349 |
osError = cmd.osError;
|
|
350 |
}
|
|
351 |
else
|
|
352 |
{
|
|
353 |
TCDEBUGLOGA1(" from server: id = %d\n", cmd.clientId);
|
|
354 |
clientId = cmd.clientId;
|
|
355 |
|
|
356 |
gManager->WaitForErrorMonitorListAccess();
|
|
357 |
CErrorMonitor* monitor = new CErrorMonitor(clientId);
|
|
358 |
if (monitor != NULL)
|
|
359 |
{
|
|
360 |
monitor->CreateData();
|
|
361 |
gManager->AddErrorMonitor(monitor);
|
|
362 |
}
|
|
363 |
|
|
364 |
gManager->ReleaseErrorMonitorListAccess();
|
|
365 |
|
|
366 |
TCDEBUGLOGA1(" clientId=%d\n", clientId);
|
|
367 |
jlong jClientId = clientId;
|
|
368 |
env->SetLongArrayRegion(outClientId, 0, 1, &jClientId);
|
|
369 |
}
|
|
370 |
env->ReleaseStringUTFChars(portString, pPort);
|
|
371 |
env->ReleaseStringUTFChars(baudString, pBaud);
|
|
372 |
env->ReleaseStringUTFChars(dataBitsString, pDataBits);
|
|
373 |
env->ReleaseStringUTFChars(parityString, pParity);
|
|
374 |
env->ReleaseStringUTFChars(stopBitsString, pStopBits);
|
|
375 |
env->ReleaseStringUTFChars(flowControlString, pFlowControl);
|
|
376 |
env->ReleaseStringUTFChars(decodeString, pDecode);
|
|
377 |
}
|
|
378 |
else
|
|
379 |
{
|
|
380 |
TCDEBUGLOGS(" TCAPI_ERR_MEDIA_NOT_SUPPORTED\n");
|
|
381 |
ret = TCAPI_ERR_MEDIA_NOT_SUPPORTED;
|
|
382 |
}
|
|
383 |
|
|
384 |
env->ReleaseStringUTFChars(inType, pType);
|
|
385 |
|
|
386 |
|
|
387 |
// handle message destinations
|
|
388 |
// input stream is done by java on open input stream not here
|
|
389 |
// message file is done here
|
|
390 |
if (ret == TCAPI_ERR_NONE)
|
|
391 |
{
|
|
392 |
long destination = DESTINATION_INPUTSTREAM;
|
|
393 |
char* pMessageFile = NULL;
|
|
394 |
if (inFilePath != NULL)
|
|
395 |
{
|
|
396 |
destination = DESTINATION_CLIENTFILE;
|
|
397 |
jboolean isCopy=FALSE;
|
|
398 |
pMessageFile = (char*)env->GetStringUTFChars(inFilePath, &isCopy);
|
|
399 |
|
|
400 |
// send to TCFServer
|
|
401 |
ServerCommandData cmd;
|
|
402 |
cmd.command = eCmdOpenMessageFile;
|
|
403 |
cmd.clientId = clientId;
|
|
404 |
cmd.destinationOptions.destination = eDestinationFile;
|
|
405 |
strncpy(cmd.destinationOptions.destinationFile, pMessageFile, MAX_FILEPATH);
|
|
406 |
gManager->m_Server->SendCommand(&cmd);
|
|
407 |
gManager->m_Server->GetResponse(&cmd);
|
|
408 |
|
|
409 |
env->ReleaseStringUTFChars(inFilePath, pMessageFile);
|
|
410 |
}
|
|
411 |
}
|
|
412 |
}
|
|
413 |
|
|
414 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
415 |
|
|
416 |
TCDEBUGLOGA3("nativeConnect return ret=%d, osError=%d : %s\n", ret, osError, GetErrorText(osError));
|
|
417 |
|
|
418 |
TCDEBUGCLOSE();
|
|
419 |
|
|
420 |
if (ret != TCAPI_ERR_NONE && osError > 0)
|
|
421 |
{
|
|
422 |
jclass clazz = env->FindClass("Ljava/lang/Exception;");
|
|
423 |
env->ThrowNew(clazz, GetErrorText(osError));
|
|
424 |
}
|
|
425 |
|
|
426 |
return ret;
|
|
427 |
}
|
|
428 |
|
|
429 |
/*
|
|
430 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
431 |
* Method: nativeDisconnect
|
|
432 |
* Signature: (J)J
|
|
433 |
*/
|
|
434 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeDisconnect
|
|
435 |
(JNIEnv *env, jobject pThis, jlong inClientId)
|
|
436 |
{
|
|
437 |
long ret = TCAPI_ERR_NONE;
|
|
438 |
|
|
439 |
TCDEBUGOPEN();
|
|
440 |
TCDEBUGLOGS("nativeDisconnect\n");
|
|
441 |
|
|
442 |
if (gManager->m_Server == NULL)
|
|
443 |
{
|
|
444 |
TCDEBUGLOGS(" TCAPI_ERR_INVALID_HANDLE - gServer NULL\n");
|
|
445 |
ret = TCAPI_ERR_INVALID_HANDLE;
|
|
446 |
}
|
|
447 |
else if (inClientId <= 0)
|
|
448 |
{
|
|
449 |
TCDEBUGLOGS(" TCAPI_ERR_INVALID_HANDLE - inClientId <= 0\n");
|
|
450 |
ret = TCAPI_ERR_INVALID_HANDLE;
|
|
451 |
}
|
|
452 |
else
|
|
453 |
{
|
|
454 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
455 |
|
|
456 |
BOOL found = FALSE;
|
|
457 |
long id = inClientId;
|
|
458 |
|
|
459 |
TCDEBUGLOGA1(" look for clientId=%d\n", id);
|
|
460 |
|
|
461 |
TCDEBUGLOGS(" TODO: tell server to disconnect this client\n");
|
|
462 |
ServerCommandData cmdrsp;
|
|
463 |
pServerCommandData pCmdrsp = &cmdrsp;
|
|
464 |
pCmdrsp->command = eCmdDisconnect;
|
|
465 |
pCmdrsp->clientId = id;
|
|
466 |
|
|
467 |
gManager->m_Server->SendCommand(pCmdrsp);
|
|
468 |
gManager->m_Server->GetResponse(pCmdrsp);
|
|
469 |
if (pCmdrsp->response == eRspError)
|
|
470 |
{
|
|
471 |
ret = pCmdrsp->error;
|
|
472 |
}
|
|
473 |
|
|
474 |
{
|
|
475 |
gManager->WaitForErrorMonitorListAccess();
|
|
476 |
TCDEBUGLOGS(" TODO: destroy error monitor for this client\n");
|
|
477 |
CErrorMonitor *monitor = gManager->FindErrorMonitor(id);
|
|
478 |
if (monitor != NULL)
|
|
479 |
{
|
|
480 |
gManager->RemoveErrorMonitor(monitor);
|
|
481 |
delete monitor;
|
|
482 |
}
|
|
483 |
gManager->ReleaseErrorMonitorListAccess();
|
|
484 |
}
|
|
485 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
486 |
}
|
|
487 |
|
|
488 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
489 |
TCDEBUGCLOSE();
|
|
490 |
return ret;
|
|
491 |
}
|
|
492 |
/*
|
|
493 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
494 |
* Method: nativeGetNumberConnections
|
|
495 |
* Signature: ([J)J
|
|
496 |
*/
|
|
497 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetNumberConnections
|
|
498 |
(JNIEnv *env, jobject pThis, jlongArray outNumber)
|
|
499 |
{
|
|
500 |
long ret = TCAPI_ERR_NONE;
|
|
501 |
long number = 0;
|
|
502 |
|
|
503 |
TCDEBUGOPEN();
|
|
504 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
505 |
|
|
506 |
TCDEBUGLOGS("nativeGetNumberConnections\n");
|
|
507 |
ServerCommandData cmdrsp;
|
|
508 |
pServerCommandData pCmdrsp = &cmdrsp;
|
|
509 |
pCmdrsp->command = eCmdGetNumberConnections;
|
|
510 |
|
|
511 |
BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
|
|
512 |
|
|
513 |
BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
|
|
514 |
if (pCmdrsp->response == eRspError)
|
|
515 |
{
|
|
516 |
ret = pCmdrsp->error;
|
|
517 |
}
|
|
518 |
else
|
|
519 |
{
|
|
520 |
number = pCmdrsp->numConnections;
|
|
521 |
|
|
522 |
jlong jNumber = number;
|
|
523 |
env->SetLongArrayRegion(outNumber, 0, 1, &jNumber);
|
|
524 |
|
|
525 |
TCDEBUGLOGA1(" number=%d\n", number);
|
|
526 |
}
|
|
527 |
|
|
528 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
529 |
|
|
530 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
531 |
TCDEBUGCLOSE();
|
|
532 |
return ret;
|
|
533 |
}
|
|
534 |
|
|
535 |
/*
|
|
536 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
537 |
* Method: nativeGetTypeOfConnection
|
|
538 |
* Signature: (J[Ljava/lang/String;)J
|
|
539 |
*/
|
|
540 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetTypeOfConnection
|
|
541 |
(JNIEnv *env, jobject pThis, jlong inIndex, jobjectArray outType)
|
|
542 |
{
|
|
543 |
long ret = TCAPI_ERR_NONE;
|
|
544 |
|
|
545 |
TCDEBUGOPEN();
|
|
546 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
547 |
|
|
548 |
TCDEBUGLOGS("nativeGetTypeOfConnection\n");
|
|
549 |
ServerCommandData cmdrsp;
|
|
550 |
pServerCommandData pCmdrsp = &cmdrsp;
|
|
551 |
pCmdrsp->command = eCmdGetConnectionType;
|
|
552 |
pCmdrsp->index = inIndex;
|
|
553 |
|
|
554 |
BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
|
|
555 |
|
|
556 |
BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
|
|
557 |
if (pCmdrsp->response == eRspError)
|
|
558 |
{
|
|
559 |
ret = pCmdrsp->error;
|
|
560 |
}
|
|
561 |
else
|
|
562 |
{
|
|
563 |
env->SetObjectArrayElement(outType, 0, env->NewStringUTF(pCmdrsp->connectSettings.connectType));
|
|
564 |
}
|
|
565 |
|
|
566 |
|
|
567 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
568 |
|
|
569 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
570 |
TCDEBUGCLOSE();
|
|
571 |
|
|
572 |
return ret;
|
|
573 |
}
|
|
574 |
|
|
575 |
|
|
576 |
/*
|
|
577 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
578 |
* Method: nativeGetConnectionSettings
|
|
579 |
* Signature: (J[Ljava/lang/String;[J[Ljava/lang/String;)J
|
|
580 |
*/
|
|
581 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetConnectionSettings
|
|
582 |
(JNIEnv *env, jobject pThis, jlong inIndex, jobjectArray outType, jlongArray outOptions, jobjectArray outSettings)
|
|
583 |
{
|
|
584 |
long ret = TCAPI_ERR_FEATURE_NOT_IMPLEMENTED;
|
|
585 |
|
|
586 |
TCDEBUGOPEN();
|
|
587 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
588 |
|
|
589 |
TCDEBUGLOGS("nativeGetConnectionSettings\n");
|
|
590 |
ServerCommandData cmdrsp;
|
|
591 |
pServerCommandData pCmdrsp = &cmdrsp;
|
|
592 |
pCmdrsp->command = eCmdGetConnection;
|
|
593 |
pCmdrsp->index = inIndex;
|
|
594 |
|
|
595 |
BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
|
|
596 |
|
|
597 |
BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
|
|
598 |
if (pCmdrsp->response == eRspError)
|
|
599 |
{
|
|
600 |
ret = pCmdrsp->error;
|
|
601 |
}
|
|
602 |
else
|
|
603 |
{
|
|
604 |
env->SetObjectArrayElement(outType, 0, env->NewStringUTF(pCmdrsp->connectSettings.connectType));
|
|
605 |
if (strcmp(pCmdrsp->connectSettings.connectType, "musti") == 0 || strcmp(pCmdrsp->connectSettings.connectType, "platsim") == 0)
|
|
606 |
{
|
|
607 |
env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.tcpSettings.ipAddress));
|
|
608 |
env->SetObjectArrayElement(outSettings, 1, env->NewStringUTF(pCmdrsp->connectSettings.tcpSettings.ipPort));
|
|
609 |
char *pChan = NULL;
|
|
610 |
if (pCmdrsp->connectSettings.traceBoxChannel == 1)
|
|
611 |
pChan = "1";
|
|
612 |
else
|
|
613 |
pChan = "2";
|
|
614 |
env->SetObjectArrayElement(outSettings, 2, env->NewStringUTF(pChan));
|
|
615 |
env->SetObjectArrayElement(outSettings, 3, env->NewStringUTF(pCmdrsp->connectSettings.decodeFormat));
|
|
616 |
}
|
|
617 |
else if (strcmp(pCmdrsp->connectSettings.connectType, "tcp") == 0)
|
|
618 |
{
|
|
619 |
env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.tcpSettings.ipAddress));
|
|
620 |
env->SetObjectArrayElement(outSettings, 1, env->NewStringUTF(pCmdrsp->connectSettings.tcpSettings.ipPort));
|
|
621 |
env->SetObjectArrayElement(outSettings, 2, env->NewStringUTF(pCmdrsp->connectSettings.decodeFormat));
|
|
622 |
}
|
|
623 |
else if (strcmp(pCmdrsp->connectSettings.connectType, "virtualserial") == 0)
|
|
624 |
{
|
|
625 |
env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.virtualSerialSettings.comPort));
|
|
626 |
env->SetObjectArrayElement(outSettings, 1, env->NewStringUTF(pCmdrsp->connectSettings.decodeFormat));
|
|
627 |
}
|
|
628 |
else if (strcmp(pCmdrsp->connectSettings.connectType, "serial") == 0)
|
|
629 |
{
|
|
630 |
env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.realSerialSettings.comPort));
|
|
631 |
|
|
632 |
char baud[10], databits[10], parity[10], stopbits[10], flowcontrol[15];
|
|
633 |
ConvertRealSerialSettingsToHost(baud, databits, parity, stopbits, flowcontrol, &pCmdrsp->connectSettings.realSerialSettings);
|
|
634 |
env->SetObjectArrayElement(outSettings, 1, env->NewStringUTF(baud));
|
|
635 |
env->SetObjectArrayElement(outSettings, 2, env->NewStringUTF(databits));
|
|
636 |
env->SetObjectArrayElement(outSettings, 3, env->NewStringUTF(parity));
|
|
637 |
env->SetObjectArrayElement(outSettings, 4, env->NewStringUTF(stopbits));
|
|
638 |
env->SetObjectArrayElement(outSettings, 5, env->NewStringUTF(flowcontrol));
|
|
639 |
env->SetObjectArrayElement(outSettings, 6, env->NewStringUTF(pCmdrsp->connectSettings.decodeFormat));
|
|
640 |
}
|
|
641 |
else if (strcmp(pCmdrsp->connectSettings.connectType, "usb") == 0)
|
|
642 |
{
|
|
643 |
env->SetObjectArrayElement(outSettings, 0, env->NewStringUTF(pCmdrsp->connectSettings.usbSettings.device));
|
|
644 |
}
|
|
645 |
jlong jRetryInterval = pCmdrsp->connectSettings.retryInterval;
|
|
646 |
env->SetLongArrayRegion(outOptions, 0, 1, &jRetryInterval);
|
|
647 |
jlong jRetryTimeout = pCmdrsp->connectSettings.retryTimeout;
|
|
648 |
env->SetLongArrayRegion(outOptions, 1, 1, &jRetryTimeout);
|
|
649 |
}
|
|
650 |
|
|
651 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
652 |
|
|
653 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
654 |
TCDEBUGCLOSE();
|
|
655 |
return ret;
|
|
656 |
}
|
|
657 |
|
|
658 |
/*
|
|
659 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
660 |
* Method: nativePollError
|
|
661 |
* Signature: (J[I[Z[J)Z
|
|
662 |
*/
|
|
663 |
JNIEXPORT jboolean JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativePollError
|
|
664 |
(JNIEnv *env, jobject pThis, jlong inClientId, jintArray outErrorCode,
|
|
665 |
jbooleanArray outHasOSErrorCode, jlongArray outOSErrorCode)
|
|
666 |
{
|
|
667 |
jboolean foundError = false;
|
|
668 |
long id = inClientId;
|
|
669 |
LONG tcfError = TCAPI_ERR_NONE;
|
|
670 |
|
|
671 |
TCDEBUGOPEN();
|
|
672 |
TCDEBUGLOGS("nativePollError\n");
|
|
673 |
// TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
674 |
|
|
675 |
gManager->WaitForErrorMonitorListAccess();
|
|
676 |
|
|
677 |
if (gManager->ErrorMonitorListSize() > 0)
|
|
678 |
{
|
|
679 |
// TCDEBUGLOGA1(" size of gManager->ErrorMonitorListSize=%d\n", gManager->ErrorMonitorListSize());
|
|
680 |
|
|
681 |
CErrorMonitor* errorMonitor = gManager->FindErrorMonitor(id);
|
|
682 |
// TCDEBUGLOGA1(" errorMonitor = %x\n", errorMonitor);
|
|
683 |
|
|
684 |
if (errorMonitor != NULL)
|
|
685 |
{
|
|
686 |
// TCDEBUGLOGS(" found client\n");
|
|
687 |
|
|
688 |
BOOL osErrorUsed = FALSE;
|
|
689 |
DWORD osError = 0;
|
|
690 |
BOOL found = errorMonitor->GetError(&tcfError, &osErrorUsed, &osError);
|
|
691 |
if (found)
|
|
692 |
{
|
|
693 |
// TCDEBUGLOGA1("nativePollError error for client=%d\n", inClientId);
|
|
694 |
// TCDEBUGLOGA3(" found tcfError=%d, osErrorUsed=%d, osError=%d\n",
|
|
695 |
// tcfError, osErrorUsed, osError);
|
|
696 |
|
|
697 |
foundError = true;
|
|
698 |
jint jval = tcfError;
|
|
699 |
env->SetIntArrayRegion(outErrorCode, 0, 1, &jval);
|
|
700 |
jboolean jos = osErrorUsed;
|
|
701 |
env->SetBooleanArrayRegion(outHasOSErrorCode, 0, 1, &jos);
|
|
702 |
jlong jlval = osError;
|
|
703 |
env->SetLongArrayRegion(outOSErrorCode, 0, 1, &jlval);
|
|
704 |
|
|
705 |
// TCDEBUGOPEN();
|
|
706 |
// TCDEBUGLOGS("nativePollError found error\n");
|
|
707 |
// TCDEBUGCLOSE();
|
|
708 |
}
|
|
709 |
}
|
|
710 |
}
|
|
711 |
gManager->ReleaseErrorMonitorListAccess();
|
|
712 |
|
|
713 |
TCDEBUGLOGA2(" return foundError=%d tcfError=%d\n", foundError, tcfError);
|
|
714 |
|
|
715 |
TCDEBUGCLOSE();
|
|
716 |
return foundError;
|
|
717 |
}
|
|
718 |
|
|
719 |
/*
|
|
720 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
721 |
* Method: nativeGetNumberVersionEntities
|
|
722 |
* Signature: (J)J
|
|
723 |
*/
|
|
724 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetNumberVersionEntities
|
|
725 |
(JNIEnv *env, jobject pThis, jlong inClientId)
|
|
726 |
{
|
|
727 |
long number = 0;
|
|
728 |
long id = inClientId;
|
|
729 |
|
|
730 |
TCDEBUGOPEN();
|
|
731 |
TCDEBUGLOGS("nativeGetNumberVersionEntities\n");
|
|
732 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
733 |
|
|
734 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
735 |
|
|
736 |
// eCmdGetNumberVersions
|
|
737 |
ServerCommandData cmdrsp;
|
|
738 |
pServerCommandData pCmdrsp = &cmdrsp;
|
|
739 |
pCmdrsp->command = eCmdGetNumberVersions;
|
|
740 |
pCmdrsp->clientId = id;
|
|
741 |
|
|
742 |
BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
|
|
743 |
|
|
744 |
BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
|
|
745 |
if (pCmdrsp->response == eRspError)
|
|
746 |
{
|
|
747 |
}
|
|
748 |
else
|
|
749 |
{
|
|
750 |
number = pCmdrsp->number + 1; // + 1 for DLL version
|
|
751 |
}
|
|
752 |
|
|
753 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
754 |
|
|
755 |
TCDEBUGLOGA1(" numberVersions = %d\n", number);
|
|
756 |
TCDEBUGCLOSE();
|
|
757 |
return number;
|
|
758 |
}
|
|
759 |
|
|
760 |
/*
|
|
761 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
762 |
* Method: nativeGetVersion
|
|
763 |
* Signature: (JJ[Ljava/lang/String;)J
|
|
764 |
*/
|
|
765 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetVersion
|
|
766 |
(JNIEnv *env, jobject pThis, jlong inClientId, jlong inNumToGet, jobjectArray outVersion)
|
|
767 |
{
|
|
768 |
long ret = TCAPI_ERR_NONE;
|
|
769 |
long id = inClientId;
|
|
770 |
|
|
771 |
TCDEBUGOPEN();
|
|
772 |
TCDEBUGLOGS("nativeGetVersion\n");
|
|
773 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
774 |
|
|
775 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
776 |
|
|
777 |
// eCmdGetVersion
|
|
778 |
ServerCommandData cmdrsp;
|
|
779 |
pServerCommandData pCmdrsp = &cmdrsp;
|
|
780 |
pCmdrsp->command = eCmdGetVersion;
|
|
781 |
pCmdrsp->clientId = id;
|
|
782 |
|
|
783 |
|
|
784 |
// index = 0 ==> TCFClient.dll version
|
|
785 |
env->SetObjectArrayElement(outVersion, 0, env->NewStringUTF(gManager->m_Version));
|
|
786 |
long numberGot = 1;
|
|
787 |
|
|
788 |
if (inNumToGet > 0)
|
|
789 |
{
|
|
790 |
// index = 1 ==> TCFServer.exe version
|
|
791 |
pCmdrsp->command = eCmdGetVersion;
|
|
792 |
pCmdrsp->clientId = id;
|
|
793 |
pCmdrsp->index = 1;
|
|
794 |
BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
|
|
795 |
BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
|
|
796 |
if (pCmdrsp->response == eRspOK)
|
|
797 |
{
|
|
798 |
env->SetObjectArrayElement(outVersion, 1, env->NewStringUTF(pCmdrsp->version));
|
|
799 |
numberGot++;
|
|
800 |
|
|
801 |
if (inNumToGet > 1)
|
|
802 |
{
|
|
803 |
// index = 2 ==> connection version
|
|
804 |
pCmdrsp->command = eCmdGetVersion;
|
|
805 |
pCmdrsp->clientId = id;
|
|
806 |
pCmdrsp->index = 2;
|
|
807 |
BOOL sent = gManager->m_Server->SendCommand(pCmdrsp);
|
|
808 |
BOOL recd = gManager->m_Server->GetResponse(pCmdrsp);
|
|
809 |
if (pCmdrsp->response == eRspOK)
|
|
810 |
{
|
|
811 |
env->SetObjectArrayElement(outVersion, 2, env->NewStringUTF(pCmdrsp->version));
|
|
812 |
numberGot++;
|
|
813 |
}
|
|
814 |
}
|
|
815 |
}
|
|
816 |
}
|
|
817 |
|
|
818 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
819 |
|
|
820 |
TCDEBUGLOGA1(" return numberGot=%d\n", numberGot);
|
|
821 |
TCDEBUGCLOSE();
|
|
822 |
return numberGot;
|
|
823 |
}
|
|
824 |
|
|
825 |
/*
|
|
826 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
827 |
* Method: nativePollInputStream
|
|
828 |
* Signature: (J[J)J
|
|
829 |
*/
|
|
830 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativePollInputStream
|
|
831 |
(JNIEnv *env, jobject pThis, jlong inClientId, jlongArray outNumberMessages)
|
|
832 |
{
|
|
833 |
long ret = TCAPI_ERR_NONE;
|
|
834 |
long number = 0;
|
|
835 |
long id = inClientId;
|
|
836 |
|
|
837 |
TCDEBUGOPEN();
|
|
838 |
TCDEBUGLOGS("nativePollInputStream\n");
|
|
839 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
840 |
|
|
841 |
TCDEBUGLOGS(" TODO: get number from client's input stream\n");
|
|
842 |
|
|
843 |
gManager->WaitForStreamListAccess();
|
|
844 |
|
|
845 |
CInputStream* inputStream = gManager->FindInputStream(id);
|
|
846 |
|
|
847 |
if (inputStream != NULL)
|
|
848 |
{
|
|
849 |
TCDEBUGLOGA1(" -- found id inputStream=%x\n", inputStream);
|
|
850 |
number = inputStream->GetNumberMessages();
|
|
851 |
}
|
|
852 |
|
|
853 |
gManager->ReleaseStreamListAccess();
|
|
854 |
jlong jNumber = number;
|
|
855 |
env->SetLongArrayRegion(outNumberMessages, 0, 1, &jNumber);
|
|
856 |
|
|
857 |
TCDEBUGLOGA2(" numberMessages=%d ret=%d\n", number, ret);
|
|
858 |
|
|
859 |
TCDEBUGCLOSE();
|
|
860 |
return ret;
|
|
861 |
}
|
|
862 |
/*
|
|
863 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
864 |
* Method: nativePollInputStream2
|
|
865 |
* Signature: (JJ[J[J)J
|
|
866 |
*/
|
|
867 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativePollInputStream2
|
|
868 |
(JNIEnv *env, jobject pThis, jlong inClientId, jlong inNumberMessagesToPeek, jlongArray outNumberMessagesPeeked, jlongArray outNumberBytesPeeked)
|
|
869 |
{
|
|
870 |
long ret = TCAPI_ERR_NONE;
|
|
871 |
long id = inClientId;
|
|
872 |
long numberToGet = inNumberMessagesToPeek;
|
|
873 |
long numberStored = 0;
|
|
874 |
DWORD numberBytes = 0;
|
|
875 |
|
|
876 |
TCDEBUGOPEN();
|
|
877 |
TCDEBUGLOGS("nativePollInputStream2\n");
|
|
878 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
879 |
|
|
880 |
gManager->WaitForStreamListAccess();
|
|
881 |
|
|
882 |
CInputStream* inputStream = gManager->FindInputStream(id);
|
|
883 |
|
|
884 |
if (inputStream != NULL)
|
|
885 |
{
|
|
886 |
TCDEBUGLOGA1(" -- found id inputStream=%x\n", inputStream);
|
|
887 |
numberStored = inputStream->GetNumberMessages();
|
|
888 |
|
|
889 |
if ((numberToGet == 0) || (numberToGet > numberStored))
|
|
890 |
{
|
|
891 |
numberToGet = numberStored;
|
|
892 |
}
|
|
893 |
if (numberToGet > 0)
|
|
894 |
{
|
|
895 |
inputStream->GetTotalMessageSize(numberToGet, numberBytes);
|
|
896 |
}
|
|
897 |
}
|
|
898 |
|
|
899 |
gManager->ReleaseStreamListAccess();
|
|
900 |
|
|
901 |
jlong jNumber = numberToGet;
|
|
902 |
env->SetLongArrayRegion(outNumberMessagesPeeked, 0, 1, &jNumber);
|
|
903 |
jNumber = numberBytes;
|
|
904 |
env->SetLongArrayRegion(outNumberBytesPeeked, 0, 1, &jNumber);
|
|
905 |
|
|
906 |
TCDEBUGLOGA3(" numberMessages=%d numberBytes=%d ret=%d\n", numberToGet, numberBytes, ret);
|
|
907 |
|
|
908 |
TCDEBUGCLOSE();
|
|
909 |
return ret;
|
|
910 |
}
|
|
911 |
|
|
912 |
|
|
913 |
/*
|
|
914 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
915 |
* Method: nativeGetInputStreamMessageBytes
|
|
916 |
* Signature: (JJ[J)J
|
|
917 |
*/
|
|
918 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeGetInputStreamMessageBytes
|
|
919 |
(JNIEnv *env, jobject pThis, jlong inClientId, jlong inNumberMessages, jlongArray outMessageSizes)
|
|
920 |
{
|
|
921 |
long ret = TCAPI_ERR_NONE;
|
|
922 |
long id = inClientId;
|
|
923 |
long numberToGet = inNumberMessages;
|
|
924 |
|
|
925 |
TCDEBUGOPEN();
|
|
926 |
TCDEBUGLOGS("nativeGetInputStreamMessageBytes\n");
|
|
927 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
928 |
|
|
929 |
gManager->WaitForStreamListAccess();
|
|
930 |
|
|
931 |
CInputStream* inputStream = gManager->FindInputStream(id);
|
|
932 |
|
|
933 |
if (inputStream != NULL)
|
|
934 |
{
|
|
935 |
TCDEBUGLOGA1(" -- found id inputStream=%x\n", inputStream);
|
|
936 |
DWORD* pSizes = new DWORD[numberToGet];
|
|
937 |
inputStream->GetMessageSizes(numberToGet, pSizes);
|
|
938 |
for (int i = 0; i < numberToGet; i++)
|
|
939 |
{
|
|
940 |
TCDEBUGLOGA2(" -- message size[%d] = %d\n", i, pSizes[i]);
|
|
941 |
jlong jsize = pSizes[i];
|
|
942 |
env->SetLongArrayRegion(outMessageSizes, i, 1, &jsize);
|
|
943 |
}
|
|
944 |
delete[] pSizes;
|
|
945 |
}
|
|
946 |
|
|
947 |
gManager->ReleaseStreamListAccess();
|
|
948 |
|
|
949 |
TCDEBUGLOGA1("nativeGetInputStreamMessageBytes ret=%d\n", ret);
|
|
950 |
|
|
951 |
TCDEBUGCLOSE();
|
|
952 |
|
|
953 |
return ret;
|
|
954 |
}
|
|
955 |
/*
|
|
956 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
957 |
* Method: nativeReadInputStream
|
|
958 |
* Signature: (JJ[J[JJ[B)J
|
|
959 |
*/
|
|
960 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeReadInputStream
|
|
961 |
(JNIEnv *env, jobject pThis, jlong inClientId, jlong inNumberMessages, jlongArray outNumberMessages, jlongArray outNumberBytesRead, jlong inNumberMaxBytes, jbyteArray outMessageData)
|
|
962 |
{
|
|
963 |
long ret = TCAPI_ERR_NONE;
|
|
964 |
long id = inClientId;
|
|
965 |
long numberToGet = inNumberMessages;
|
|
966 |
long numberMaxBytes = inNumberMaxBytes;
|
|
967 |
|
|
968 |
TCDEBUGOPEN();
|
|
969 |
TCDEBUGLOGS("nativeReadInputStream start\n");
|
|
970 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
971 |
|
|
972 |
gManager->WaitForStreamListAccess();
|
|
973 |
|
|
974 |
CInputStream* inputStream = gManager->FindInputStream(id);
|
|
975 |
if (inputStream != NULL)
|
|
976 |
{
|
|
977 |
long numberBytesRead = 0;
|
|
978 |
long numberMessagesRead = 0;
|
|
979 |
#if (0)
|
|
980 |
DWORD mSize = 0;
|
|
981 |
DWORD outOffset = 0;
|
|
982 |
BYTE* pData = new BYTE[64*1024];
|
|
983 |
for (int i = 0; i < numberToGet; i++)
|
|
984 |
{
|
|
985 |
TCDEBUGLOGS("nativeReadInputStream 1\n");
|
|
986 |
mSize = inputStream->GetNextMessageSize();
|
|
987 |
if ((numberBytesRead + mSize) > numberMaxBytes)
|
|
988 |
break;
|
|
989 |
if (mSize != 0)
|
|
990 |
{
|
|
991 |
mSize = inputStream->GetNextMessage(mSize, pData);
|
|
992 |
TCDEBUGLOGA3("outOffset = %d mSize = %d pData[0] = %02.2x\n", outOffset, mSize, pData[0]);
|
|
993 |
jbyte* pByte = (jbyte*)pData;
|
|
994 |
env->SetByteArrayRegion(outMessageData, outOffset, mSize, pByte);
|
|
995 |
outOffset += mSize;
|
|
996 |
numberBytesRead += mSize;
|
|
997 |
numberMessagesRead++;
|
|
998 |
|
|
999 |
if ((i % 500) == 0)
|
|
1000 |
Sleep(1);
|
|
1001 |
}
|
|
1002 |
}
|
|
1003 |
delete [] pData;
|
|
1004 |
#endif
|
|
1005 |
numberMessagesRead = inputStream->GetMessages(env, numberToGet, numberMaxBytes, numberBytesRead, numberMessagesRead, outMessageData);
|
|
1006 |
jlong jMsgs = numberMessagesRead;
|
|
1007 |
env->SetLongArrayRegion(outNumberMessages, 0, 1, &jMsgs);
|
|
1008 |
jlong jNum = numberBytesRead;
|
|
1009 |
env->SetLongArrayRegion(outNumberBytesRead, 0, 1, &jNum);
|
|
1010 |
|
|
1011 |
TCDEBUGLOGS("nativeReadInputStream 2\n");
|
|
1012 |
}
|
|
1013 |
|
|
1014 |
gManager->ReleaseStreamListAccess();
|
|
1015 |
|
|
1016 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1017 |
TCDEBUGCLOSE();
|
|
1018 |
return ret;
|
|
1019 |
}
|
|
1020 |
|
|
1021 |
/*
|
|
1022 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1023 |
* Method: nativeOpenInputStream
|
|
1024 |
* Signature: (JLjava/lang/String;JZ)J
|
|
1025 |
*/
|
|
1026 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeOpenInputStream
|
|
1027 |
(JNIEnv *env, jobject pThis, jlong inClientId, jstring inFileBaseName, jlong inStreamSize, jboolean inOverflowToFile)
|
|
1028 |
{
|
|
1029 |
long ret = TCAPI_ERR_NONE;
|
|
1030 |
|
|
1031 |
TCDEBUGOPEN();
|
|
1032 |
TCDEBUGLOGS("nativeOpenInputStream\n");
|
|
1033 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
1034 |
TCDEBUGLOGA1(" inFileBaseName=%x\n", inFileBaseName);
|
|
1035 |
TCDEBUGLOGA1(" inStreamSize=%d\n", inStreamSize);
|
|
1036 |
TCDEBUGLOGA1(" inOverflowToFile=%d\n", inOverflowToFile);
|
|
1037 |
|
|
1038 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1039 |
gManager->WaitForStreamListAccess();
|
|
1040 |
|
|
1041 |
char* pFileName = NULL;
|
|
1042 |
|
|
1043 |
if (inFileBaseName != NULL)
|
|
1044 |
{
|
|
1045 |
TCDEBUGLOGS("nativeOpenInputStream GetStringUTFChars on inFileBaseName\n");
|
|
1046 |
jboolean isCopy=FALSE;
|
|
1047 |
pFileName = (char*)env->GetStringUTFChars(inFileBaseName, &isCopy);
|
|
1048 |
TCDEBUGLOGS("nativeOpenInputStream return GetStringUTFChars\n");
|
|
1049 |
TCDEBUGLOGA1(" pFileName=%x\n", pFileName);
|
|
1050 |
// if (pFileName != NULL)
|
|
1051 |
// {
|
|
1052 |
// TCDEBUGLOGA1(" pFileName=%s\n", pFileName);
|
|
1053 |
// }
|
|
1054 |
}
|
|
1055 |
else
|
|
1056 |
{
|
|
1057 |
TCDEBUGLOGS("nativeOpenInputStream inFileBaseName == NULL\n");
|
|
1058 |
}
|
|
1059 |
|
|
1060 |
|
|
1061 |
TCDEBUGLOGS("nativeOpenInputStream continue after GetStringUTFChars\n");
|
|
1062 |
DWORD streamSize = inStreamSize;
|
|
1063 |
TCDEBUGLOGA1(" streamSize=%d\n", streamSize);
|
|
1064 |
|
|
1065 |
BOOL overflowOption = FALSE;
|
|
1066 |
TCDEBUGLOGA1(" overflowOption=%d\n", overflowOption);
|
|
1067 |
|
|
1068 |
long id = inClientId;
|
|
1069 |
|
|
1070 |
TCDEBUGLOGA1(" gManager->InputStreamListSize=%d\n", gManager->InputStreamListSize());
|
|
1071 |
|
|
1072 |
// create stream
|
|
1073 |
CInputStream* stream = new CInputStream(pFileName, streamSize, overflowOption, id);
|
|
1074 |
stream->CreateStream();
|
|
1075 |
gManager->AddInputStream(stream);
|
|
1076 |
|
|
1077 |
ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
|
|
1078 |
pCmdrsp->command = eCmdOpenStream;
|
|
1079 |
pCmdrsp->clientId = id;
|
|
1080 |
pCmdrsp->destinationOptions.destination = eDestinationInputStream;
|
|
1081 |
pCmdrsp->destinationOptions.streamSize = streamSize;
|
|
1082 |
pCmdrsp->destinationOptions.overFlowToFile = FALSE;
|
|
1083 |
if (pFileName != NULL)
|
|
1084 |
{
|
|
1085 |
strncpy(pCmdrsp->destinationOptions.destinationFile, pFileName, MAX_FILEPATH);
|
|
1086 |
}
|
|
1087 |
else
|
|
1088 |
{
|
|
1089 |
pCmdrsp->destinationOptions.destinationFile[0] = NULL;
|
|
1090 |
}
|
|
1091 |
if (inFileBaseName != NULL)
|
|
1092 |
{
|
|
1093 |
TCDEBUGLOGS("nativeOpenInputStream ReleaseStringUTFChars on inFileBaseName\n");
|
|
1094 |
env->ReleaseStringUTFChars(inFileBaseName, pFileName);
|
|
1095 |
}
|
|
1096 |
|
|
1097 |
gManager->m_Server->SendCommand(pCmdrsp);
|
|
1098 |
gManager->m_Server->GetResponse(pCmdrsp);
|
|
1099 |
|
|
1100 |
if (pCmdrsp->response == eRspError)
|
|
1101 |
{
|
|
1102 |
ret = pCmdrsp->error;
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
TCDEBUGLOGA1(" gManager->InputStreamListSize=%d\n", gManager->InputStreamListSize());
|
|
1106 |
|
|
1107 |
gManager->ReleaseStreamListAccess();
|
|
1108 |
|
|
1109 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1110 |
|
|
1111 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1112 |
TCDEBUGCLOSE();
|
|
1113 |
|
|
1114 |
return ret;
|
|
1115 |
}
|
|
1116 |
|
|
1117 |
/*
|
|
1118 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1119 |
* Method: nativeCloseInputStream
|
|
1120 |
* Signature: (J)J
|
|
1121 |
*/
|
|
1122 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeCloseInputStream
|
|
1123 |
(JNIEnv *env, jobject pThis, jlong inClientId)
|
|
1124 |
{
|
|
1125 |
long ret = TCAPI_ERR_NONE;
|
|
1126 |
|
|
1127 |
TCDEBUGOPEN();
|
|
1128 |
TCDEBUGLOGS("nativeCloseInputStream\n");
|
|
1129 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
1130 |
|
|
1131 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1132 |
gManager->WaitForStreamListAccess();
|
|
1133 |
|
|
1134 |
long id = inClientId;
|
|
1135 |
|
|
1136 |
TCDEBUGLOGA1(" gManager->InputStreamListSize=%d\n", gManager->InputStreamListSize());
|
|
1137 |
|
|
1138 |
TCDEBUGLOGS(" TODO: tell server to close this stream\n");
|
|
1139 |
|
|
1140 |
ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
|
|
1141 |
pCmdrsp->command = eCmdCloseStream;
|
|
1142 |
pCmdrsp->clientId = id;
|
|
1143 |
|
|
1144 |
gManager->m_Server->SendCommand(pCmdrsp);
|
|
1145 |
gManager->m_Server->GetResponse(pCmdrsp);
|
|
1146 |
|
|
1147 |
if (pCmdrsp->response == eRspError)
|
|
1148 |
{
|
|
1149 |
ret = pCmdrsp->error;
|
|
1150 |
}
|
|
1151 |
|
|
1152 |
CInputStream* inputStream = gManager->FindInputStream(id);
|
|
1153 |
if (inputStream != NULL)
|
|
1154 |
{
|
|
1155 |
TCDEBUGLOGA1(" -- found id inputStream=%x\n", inputStream);
|
|
1156 |
gManager->RemoveInputStream(inputStream);
|
|
1157 |
delete inputStream;
|
|
1158 |
}
|
|
1159 |
|
|
1160 |
TCDEBUGLOGA1(" gManager->InputStreamListSize=%d\n", gManager->InputStreamListSize());
|
|
1161 |
gManager->ReleaseStreamListAccess();
|
|
1162 |
|
|
1163 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1164 |
|
|
1165 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1166 |
TCDEBUGCLOSE();
|
|
1167 |
return ret;
|
|
1168 |
}
|
|
1169 |
|
|
1170 |
/*
|
|
1171 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1172 |
* Method: nativeSetMessageIds
|
|
1173 |
* Signature: (J[B)J
|
|
1174 |
*/
|
|
1175 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeSetMessageIds
|
|
1176 |
(JNIEnv *env, jobject pThis, jlong inClientId, jbyteArray inIds)
|
|
1177 |
{
|
|
1178 |
long ret = TCAPI_ERR_NONE;
|
|
1179 |
|
|
1180 |
TCDEBUGOPEN();
|
|
1181 |
TCDEBUGLOGS("nativeSetMessageIds\n");
|
|
1182 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
1183 |
|
|
1184 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1185 |
|
|
1186 |
ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
|
|
1187 |
|
|
1188 |
pCmdrsp->command = eCmdSetMessageIds;
|
|
1189 |
pCmdrsp->clientId = inClientId;
|
|
1190 |
jsize numberIds = env->GetArrayLength(inIds);
|
|
1191 |
pCmdrsp->number = numberIds;
|
|
1192 |
jboolean isCopy = FALSE;
|
|
1193 |
jbyte* bytes = env->GetByteArrayElements(inIds, &isCopy);
|
|
1194 |
for (int i = 0; i < numberIds; i++)
|
|
1195 |
{
|
|
1196 |
pCmdrsp->messageIds[i] = bytes[i];
|
|
1197 |
TCDEBUGLOGA1(" -- msgId = 0x%02.2X\n", pCmdrsp->messageIds[i]);
|
|
1198 |
}
|
|
1199 |
env->ReleaseByteArrayElements(inIds, bytes, 0);
|
|
1200 |
gManager->m_Server->SendCommand(pCmdrsp);
|
|
1201 |
gManager->m_Server->GetResponse(pCmdrsp);
|
|
1202 |
|
|
1203 |
if (pCmdrsp->response == eRspError)
|
|
1204 |
{
|
|
1205 |
ret = pCmdrsp->error;
|
|
1206 |
}
|
|
1207 |
|
|
1208 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1209 |
|
|
1210 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1211 |
TCDEBUGCLOSE();
|
|
1212 |
return ret;
|
|
1213 |
}
|
|
1214 |
|
|
1215 |
/*
|
|
1216 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1217 |
* Method: nativeClearFile
|
|
1218 |
* Signature: (J)J
|
|
1219 |
*/
|
|
1220 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeClearFile
|
|
1221 |
(JNIEnv *env, jobject pThis, jlong inClientId)
|
|
1222 |
{
|
|
1223 |
long ret = TCAPI_ERR_NONE;
|
|
1224 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1225 |
|
|
1226 |
long id = inClientId;
|
|
1227 |
|
|
1228 |
ServerCommandData cmdrsp;
|
|
1229 |
pServerCommandData pCmdrsp = &cmdrsp;
|
|
1230 |
pCmdrsp->command = eCmdClearMessageFile;
|
|
1231 |
pCmdrsp->clientId = id;
|
|
1232 |
|
|
1233 |
gManager->m_Server->SendCommand(pCmdrsp);
|
|
1234 |
gManager->m_Server->GetResponse(pCmdrsp);
|
|
1235 |
if (pCmdrsp->response == eRspError)
|
|
1236 |
{
|
|
1237 |
ret = pCmdrsp->error;
|
|
1238 |
}
|
|
1239 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1240 |
|
|
1241 |
return ret;
|
|
1242 |
}
|
|
1243 |
|
|
1244 |
/*
|
|
1245 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1246 |
* Method: nativeSendMessage
|
|
1247 |
* Signature: (J[J[Ljava/lang/String;[B)J
|
|
1248 |
*/
|
|
1249 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeSendMessage
|
|
1250 |
(JNIEnv *env, jobject pThis, jlong inClientId, jlongArray inFormattingOptions, jobjectArray inSettings, jbyteArray inMessage)
|
|
1251 |
{
|
|
1252 |
long ret = TCAPI_ERR_NONE;
|
|
1253 |
unsigned long osError = 0;
|
|
1254 |
|
|
1255 |
TCDEBUGOPEN();
|
|
1256 |
TCDEBUGLOGS("nativeSendMessage\n");
|
|
1257 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
1258 |
|
|
1259 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1260 |
|
|
1261 |
jboolean isCopy = false;
|
|
1262 |
// formatting options
|
|
1263 |
jlong* pOptions = env->GetLongArrayElements(inFormattingOptions, &isCopy);
|
|
1264 |
// long encodeFormat = (long)pOptions[0]; // not used
|
|
1265 |
long encodeOption = (long)pOptions[1]; // formatting option for protocol
|
|
1266 |
long protocolVersion = (long)pOptions[2]; // OST version byte to use if protocol is OST
|
|
1267 |
BYTE myId = (BYTE)(pOptions[3] & 0xff); // my message ID to use of adding protocol
|
|
1268 |
BOOL useMyId = (pOptions[4] == 1) ? TRUE : FALSE; // use my ID or not
|
|
1269 |
env->ReleaseLongArrayElements(inFormattingOptions, pOptions, 0);
|
|
1270 |
|
|
1271 |
jstring decodeString = (jstring)env->GetObjectArrayElement(inSettings, 0);
|
|
1272 |
const char* pDecode = env->GetStringUTFChars(decodeString, NULL); // not used
|
|
1273 |
env->ReleaseStringUTFChars(decodeString, pDecode);
|
|
1274 |
|
|
1275 |
jsize numberBytes = 0;
|
|
1276 |
if (inMessage != NULL)
|
|
1277 |
numberBytes = env->GetArrayLength(inMessage);
|
|
1278 |
long inLength = numberBytes; // this can be null
|
|
1279 |
|
|
1280 |
jbyte* inData = NULL;
|
|
1281 |
if (inLength > 0)
|
|
1282 |
inData = env->GetByteArrayElements(inMessage, &isCopy);
|
|
1283 |
|
|
1284 |
ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
|
|
1285 |
|
|
1286 |
pCmdrsp->command = eCmdSendMessage;
|
|
1287 |
pCmdrsp->clientId = inClientId;
|
|
1288 |
pCmdrsp->encodeOption = encodeOption;
|
|
1289 |
pCmdrsp->useMyId = useMyId;
|
|
1290 |
pCmdrsp->myId = myId;
|
|
1291 |
pCmdrsp->protocolVersion = protocolVersion & 0xff;
|
|
1292 |
|
|
1293 |
// send message to server
|
|
1294 |
pCmdrsp->osError = 0;
|
|
1295 |
gManager->m_Server->SendCommand(pCmdrsp, inLength, (BYTE*)inData);
|
|
1296 |
|
|
1297 |
TCDEBUGLOGS(" nativeSendMessage GetResponse\n");
|
|
1298 |
|
|
1299 |
// get response from server
|
|
1300 |
gManager->m_Server->GetResponse(pCmdrsp);
|
|
1301 |
|
|
1302 |
if (pCmdrsp->response == eRspError)
|
|
1303 |
{
|
|
1304 |
ret = pCmdrsp->error;
|
|
1305 |
osError = pCmdrsp->osError;
|
|
1306 |
}
|
|
1307 |
if (inData != NULL)
|
|
1308 |
env->ReleaseByteArrayElements(inMessage, inData, 0);
|
|
1309 |
|
|
1310 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1311 |
|
|
1312 |
TCDEBUGLOGA3("nativeSendMessage return ret=%d, osError=%d : %s\n", ret, osError, GetErrorText(osError));
|
|
1313 |
TCDEBUGCLOSE();
|
|
1314 |
|
|
1315 |
if (ret == TCAPI_ERR_COMM_ERROR && osError > 0)
|
|
1316 |
{
|
|
1317 |
jclass clazz = env->FindClass("Ljava/lang/Exception;");
|
|
1318 |
env->ThrowNew(clazz, GetErrorText(osError));
|
|
1319 |
}
|
|
1320 |
return ret;
|
|
1321 |
}
|
|
1322 |
|
|
1323 |
/*
|
|
1324 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1325 |
* Method: nativeStart
|
|
1326 |
* Signature: (J)J
|
|
1327 |
*/
|
|
1328 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeStart
|
|
1329 |
(JNIEnv *env, jobject pThis, jlong inClientId)
|
|
1330 |
{
|
|
1331 |
long ret = TCAPI_ERR_NONE;
|
|
1332 |
|
|
1333 |
TCDEBUGOPEN();
|
|
1334 |
TCDEBUGLOGS("nativeStart\n");
|
|
1335 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
1336 |
|
|
1337 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1338 |
|
|
1339 |
TCDEBUGLOGS(" TODO: tell server to start this client\n");
|
|
1340 |
ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
|
|
1341 |
|
|
1342 |
pCmdrsp->command = eCmdStart;
|
|
1343 |
pCmdrsp->clientId = inClientId;
|
|
1344 |
|
|
1345 |
gManager->m_Server->SendCommand(pCmdrsp);
|
|
1346 |
|
|
1347 |
gManager->m_Server->GetResponse(pCmdrsp);
|
|
1348 |
|
|
1349 |
if (pCmdrsp->response == eRspError)
|
|
1350 |
{
|
|
1351 |
ret = pCmdrsp->error;
|
|
1352 |
}
|
|
1353 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1354 |
|
|
1355 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1356 |
TCDEBUGCLOSE();
|
|
1357 |
return ret;
|
|
1358 |
}
|
|
1359 |
|
|
1360 |
/*
|
|
1361 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1362 |
* Method: nativeStop
|
|
1363 |
* Signature: (J)J
|
|
1364 |
*/
|
|
1365 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeStop
|
|
1366 |
(JNIEnv *env, jobject pThis, jlong inClientId)
|
|
1367 |
{
|
|
1368 |
long ret = TCAPI_ERR_NONE;
|
|
1369 |
|
|
1370 |
TCDEBUGOPEN();
|
|
1371 |
TCDEBUGLOGS("nativeStop\n");
|
|
1372 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
1373 |
|
|
1374 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1375 |
|
|
1376 |
TCDEBUGLOGS(" TODO: tell server to stop this client\n");
|
|
1377 |
ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
|
|
1378 |
|
|
1379 |
pCmdrsp->command = eCmdStop;
|
|
1380 |
pCmdrsp->clientId = inClientId;
|
|
1381 |
|
|
1382 |
gManager->m_Server->SendCommand(pCmdrsp);
|
|
1383 |
|
|
1384 |
gManager->m_Server->GetResponse(pCmdrsp);
|
|
1385 |
|
|
1386 |
if (pCmdrsp->response == eRspError)
|
|
1387 |
{
|
|
1388 |
ret = pCmdrsp->error;
|
|
1389 |
}
|
|
1390 |
|
|
1391 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1392 |
|
|
1393 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1394 |
TCDEBUGCLOSE();
|
|
1395 |
return ret;
|
|
1396 |
}
|
|
1397 |
|
|
1398 |
/*
|
|
1399 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1400 |
* Method: nativeTestConnection
|
|
1401 |
* Signature: (I[J[Ljava/lang/String;)J
|
|
1402 |
*/
|
|
1403 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeTestConnection__I_3J_3Ljava_lang_String_2
|
|
1404 |
(JNIEnv *env, jobject pThis, jint inType, jlongArray inOptions, jobjectArray inSettings)
|
|
1405 |
{
|
|
1406 |
long ret = TCAPI_ERR_FEATURE_NOT_IMPLEMENTED;
|
|
1407 |
|
|
1408 |
TCDEBUGOPEN();
|
|
1409 |
TCDEBUGLOGS("nativeTestConnection\n");
|
|
1410 |
|
|
1411 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1412 |
|
|
1413 |
TCDEBUGLOGS(" TODO: ask server to test this connection\n");
|
|
1414 |
|
|
1415 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1416 |
|
|
1417 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1418 |
TCDEBUGCLOSE();
|
|
1419 |
|
|
1420 |
return ret;
|
|
1421 |
}
|
|
1422 |
|
|
1423 |
/*
|
|
1424 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1425 |
* Method: nativeTestConnection
|
|
1426 |
* Signature: (J)J
|
|
1427 |
*/
|
|
1428 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeTestConnection__J
|
|
1429 |
(JNIEnv *env, jobject pThis, jlong inClientId)
|
|
1430 |
{
|
|
1431 |
long ret = TCAPI_ERR_FEATURE_NOT_IMPLEMENTED;
|
|
1432 |
|
|
1433 |
TCDEBUGOPEN();
|
|
1434 |
TCDEBUGLOGS("nativeTestConnection\n");
|
|
1435 |
TCDEBUGLOGA1(" inClientId=%d\n", inClientId);
|
|
1436 |
|
|
1437 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1438 |
|
|
1439 |
TCDEBUGLOGS(" TODO: ask server to test this client's connection\n");
|
|
1440 |
|
|
1441 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1442 |
|
|
1443 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1444 |
TCDEBUGCLOSE();
|
|
1445 |
|
|
1446 |
return ret;
|
|
1447 |
}
|
|
1448 |
/*
|
|
1449 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1450 |
* Method: nativeStartServer
|
|
1451 |
* Signature: ()J
|
|
1452 |
*/
|
|
1453 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeStartServer
|
|
1454 |
(JNIEnv *env, jobject pThis)
|
|
1455 |
{
|
|
1456 |
long ret = TCAPI_ERR_NONE;
|
|
1457 |
|
|
1458 |
TCDEBUGOPEN();
|
|
1459 |
TCDEBUGLOGS("nativeStartServer\n");
|
|
1460 |
|
|
1461 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1462 |
|
|
1463 |
ret = gManager->StartServer();
|
|
1464 |
|
|
1465 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1466 |
|
|
1467 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1468 |
TCDEBUGCLOSE();
|
|
1469 |
|
|
1470 |
return ret;
|
|
1471 |
}
|
|
1472 |
|
|
1473 |
/*
|
|
1474 |
* Class: com_nokia_tcf_impl_TCAPIConnection
|
|
1475 |
* Method: nativeStopServer
|
|
1476 |
* Signature: ()J
|
|
1477 |
*/
|
|
1478 |
JNIEXPORT jlong JNICALL Java_com_nokia_tcf_impl_TCAPIConnection_nativeStopServer
|
|
1479 |
(JNIEnv *env, jobject pThis)
|
|
1480 |
{
|
|
1481 |
long ret = TCAPI_ERR_NONE;
|
|
1482 |
|
|
1483 |
TCDEBUGOPEN();
|
|
1484 |
TCDEBUGLOGS("nativeStopServer\n");
|
|
1485 |
|
|
1486 |
gManager->m_Server->WaitforServerPipeAccess();
|
|
1487 |
|
|
1488 |
ret = gManager->StopServer();
|
|
1489 |
|
|
1490 |
gManager->m_Server->ReleaseServerPipeAccess();
|
|
1491 |
|
|
1492 |
TCDEBUGLOGA1(" return ret=%d\n", ret);
|
|
1493 |
TCDEBUGCLOSE();
|
|
1494 |
|
|
1495 |
return ret;
|
|
1496 |
}
|
|
1497 |
|
|
1498 |
void ConvertRealSerialSettingsToServer(const char* pBaud, const char* pDataBits, const char* pParity, const char* pStopBits, const char* pFlowControl, pRealSerialConnectData pData)
|
|
1499 |
{
|
|
1500 |
// no error checking - all error checking is done at the Java level
|
|
1501 |
pData->baudRate = atol(pBaud);
|
|
1502 |
pData->dataBits = atol(pDataBits);
|
|
1503 |
|
|
1504 |
pData->parity = eParityNone;
|
|
1505 |
if (strcmp(pParity, "odd") == 0)
|
|
1506 |
{
|
|
1507 |
pData->parity = eParityOdd;
|
|
1508 |
}
|
|
1509 |
else if (strcmp(pParity, "even") == 0)
|
|
1510 |
{
|
|
1511 |
pData->parity = eParityEven;
|
|
1512 |
}
|
|
1513 |
|
|
1514 |
pData->stopBits = eStopBits1;
|
|
1515 |
if (strcmp(pStopBits, "1.5") == 0)
|
|
1516 |
{
|
|
1517 |
pData->stopBits = eStopBits15;
|
|
1518 |
}
|
|
1519 |
else if (strcmp(pStopBits, "2") == 0)
|
|
1520 |
{
|
|
1521 |
pData->stopBits = eStopBits2;
|
|
1522 |
}
|
|
1523 |
|
|
1524 |
pData->flowControl = eFlowControlNone;
|
|
1525 |
if (strcmp(pFlowControl, "software") == 0)
|
|
1526 |
{
|
|
1527 |
pData->flowControl = eFlowControlSW;
|
|
1528 |
}
|
|
1529 |
else if (strcmp(pFlowControl, "hardware") == 0)
|
|
1530 |
{
|
|
1531 |
pData->flowControl = eFlowControlHW;
|
|
1532 |
}
|
|
1533 |
}
|
|
1534 |
void ConvertRealSerialSettingsToHost(char* pBaud, char* pDataBits, char* pParity, char* pStopBits, char* pFlowControl, pRealSerialConnectData pData)
|
|
1535 |
{
|
|
1536 |
sprintf(pBaud, "%ld", pData->baudRate);
|
|
1537 |
sprintf(pDataBits, "%ld", pData->dataBits);
|
|
1538 |
|
|
1539 |
switch (pData->parity)
|
|
1540 |
{
|
|
1541 |
default:
|
|
1542 |
case eParityNone:
|
|
1543 |
strcpy(pParity, "none");
|
|
1544 |
break;
|
|
1545 |
case eParityEven:
|
|
1546 |
strcpy(pParity, "even");
|
|
1547 |
break;
|
|
1548 |
case eParityOdd:
|
|
1549 |
strcpy(pParity, "odd");
|
|
1550 |
break;
|
|
1551 |
}
|
|
1552 |
|
|
1553 |
switch (pData->stopBits)
|
|
1554 |
{
|
|
1555 |
default:
|
|
1556 |
case eStopBits1:
|
|
1557 |
strcpy(pStopBits, "1");
|
|
1558 |
break;
|
|
1559 |
case eStopBits15:
|
|
1560 |
strcpy(pStopBits, "1.5");
|
|
1561 |
break;
|
|
1562 |
case eStopBits2:
|
|
1563 |
strcpy(pStopBits, "2");
|
|
1564 |
break;
|
|
1565 |
}
|
|
1566 |
|
|
1567 |
switch (pData->flowControl)
|
|
1568 |
{
|
|
1569 |
default:
|
|
1570 |
case eFlowControlNone:
|
|
1571 |
strcpy(pFlowControl, "none");
|
|
1572 |
break;
|
|
1573 |
case eFlowControlHW:
|
|
1574 |
strcpy(pFlowControl, "hardware");
|
|
1575 |
break;
|
|
1576 |
case eFlowControlSW:
|
|
1577 |
strcpy(pFlowControl, "software");
|
|
1578 |
break;
|
|
1579 |
}
|
|
1580 |
}
|
|
1581 |
|
|
1582 |
#ifdef _DEBUG
|
|
1583 |
void OpenLogFile1(char* filename)
|
|
1584 |
{
|
|
1585 |
if (fLog1 == NULL)
|
|
1586 |
fLog1 = _fsopen(filename, "at", _SH_DENYNO);
|
|
1587 |
}
|
|
1588 |
|
|
1589 |
void CloseLogFile1()
|
|
1590 |
{
|
|
1591 |
if (fLog1 != NULL)
|
|
1592 |
{
|
|
1593 |
fclose(fLog1);
|
|
1594 |
fLog1 = NULL;
|
|
1595 |
}
|
|
1596 |
}
|
|
1597 |
void OpenLogFile2(char* filename)
|
|
1598 |
{
|
|
1599 |
if (fLog2 == NULL)
|
|
1600 |
fLog2 = _fsopen(filename, "at", _SH_DENYNO);
|
|
1601 |
}
|
|
1602 |
|
|
1603 |
void CloseLogFile2()
|
|
1604 |
{
|
|
1605 |
if (fLog2 != NULL)
|
|
1606 |
{
|
|
1607 |
fclose(fLog2);
|
|
1608 |
fLog2 = NULL;
|
|
1609 |
}
|
|
1610 |
}
|
|
1611 |
void LogTime(FILE* f)
|
|
1612 |
{
|
|
1613 |
SYSTEMTIME sTime;
|
|
1614 |
GetLocalTime(&sTime);
|
|
1615 |
if (f)
|
|
1616 |
fprintf(f, "%02.2d%02.2d-%02.2d:%02.2d:%02.2d.%03.3d: ", sTime.wDay, sTime.wMonth, sTime.wHour, sTime.wMinute, sTime.wSecond, sTime.wMilliseconds);
|
|
1617 |
}
|
|
1618 |
#endif
|
|
1619 |
|
|
1620 |
static const char* GetErrorText(unsigned long error)
|
|
1621 |
{
|
|
1622 |
if (error == ERROR_FILE_NOT_FOUND)
|
|
1623 |
return "Could not open the device\n";
|
|
1624 |
|
|
1625 |
else if (error == ERROR_ACCESS_DENIED)
|
|
1626 |
return "The device is currently in use\n";
|
|
1627 |
|
|
1628 |
static char msg[256];
|
|
1629 |
FormatMessage(
|
|
1630 |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
1631 |
NULL,
|
|
1632 |
error,
|
|
1633 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
|
1634 |
(LPTSTR) &msg,
|
|
1635 |
sizeof(msg) - 1,
|
|
1636 |
NULL);
|
|
1637 |
|
|
1638 |
return msg;
|
|
1639 |
}
|