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