Line 0
Link Here
|
|
|
1 |
--- src/SerialImp.c.orig 2009-02-04 22:06:16.000000000 +0000 |
2 |
+++ src/SerialImp.c 2015-05-11 16:52:36.000000000 +0100 |
3 |
@@ -1,60 +1,79 @@ |
4 |
/*------------------------------------------------------------------------- |
5 |
-| RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. |
6 |
-| RXTX is a native interface to serial ports in java. |
7 |
-| Copyright 1997-2009 by Trent Jarvi tjarvi@qbang.org and others who |
8 |
-| actually wrote it. See individual source files for more information. |
9 |
+| RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. |
10 |
+| RXTX is a native interface to serial ports in java. |
11 |
+| Copyright 1997-2009 by Trent Jarvi tjarvi@qbang.org and others who |
12 |
+| actually wrote it. See individual source files for more information. |
13 |
| |
14 |
-| A copy of the LGPL v 2.1 may be found at |
15 |
-| http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is |
16 |
-| here for your convenience. |
17 |
+| A copy of the LGPL v 2.1 may be found at |
18 |
+| http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is |
19 |
+| here for your convenience. |
20 |
| |
21 |
-| This library is free software; you can redistribute it and/or |
22 |
-| modify it under the terms of the GNU Lesser General Public |
23 |
-| License as published by the Free Software Foundation; either |
24 |
-| version 2.1 of the License, or (at your option) any later version. |
25 |
+| This library is free software; you can redistribute it and/or |
26 |
+| modify it under the terms of the GNU Lesser General Public |
27 |
+| License as published by the Free Software Foundation; either |
28 |
+| version 2.1 of the License, or (at your option) any later version. |
29 |
| |
30 |
-| This library is distributed in the hope that it will be useful, |
31 |
-| but WITHOUT ANY WARRANTY; without even the implied warranty of |
32 |
-| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
33 |
-| Lesser General Public License for more details. |
34 |
+| This library is distributed in the hope that it will be useful, |
35 |
+| but WITHOUT ANY WARRANTY; without even the implied warranty of |
36 |
+| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
37 |
+| Lesser General Public License for more details. |
38 |
| |
39 |
-| An executable that contains no derivative of any portion of RXTX, but |
40 |
-| is designed to work with RXTX by being dynamically linked with it, |
41 |
-| is considered a "work that uses the Library" subject to the terms and |
42 |
-| conditions of the GNU Lesser General Public License. |
43 |
+| An executable that contains no derivative of any portion of RXTX, but |
44 |
+| is designed to work with RXTX by being dynamically linked with it, |
45 |
+| is considered a "work that uses the Library" subject to the terms and |
46 |
+| conditions of the GNU Lesser General Public License. |
47 |
| |
48 |
-| The following has been added to the RXTX License to remove |
49 |
-| any confusion about linking to RXTX. We want to allow in part what |
50 |
-| section 5, paragraph 2 of the LGPL does not permit in the special |
51 |
-| case of linking over a controlled interface. The intent is to add a |
52 |
-| Java Specification Request or standards body defined interface in the |
53 |
-| future as another exception but one is not currently available. |
54 |
+| The following has been added to the RXTX License to remove |
55 |
+| any confusion about linking to RXTX. We want to allow in part what |
56 |
+| section 5, paragraph 2 of the LGPL does not permit in the special |
57 |
+| case of linking over a controlled interface. The intent is to add a |
58 |
+| Java Specification Request or standards body defined interface in the |
59 |
+| future as another exception but one is not currently available. |
60 |
| |
61 |
-| http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface |
62 |
+| http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface |
63 |
| |
64 |
-| As a special exception, the copyright holders of RXTX give you |
65 |
-| permission to link RXTX with independent modules that communicate with |
66 |
-| RXTX solely through the Sun Microsytems CommAPI interface version 2, |
67 |
-| regardless of the license terms of these independent modules, and to copy |
68 |
-| and distribute the resulting combined work under terms of your choice, |
69 |
-| provided that every copy of the combined work is accompanied by a complete |
70 |
-| copy of the source code of RXTX (the version of RXTX used to produce the |
71 |
-| combined work), being distributed under the terms of the GNU Lesser General |
72 |
-| Public License plus this exception. An independent module is a |
73 |
-| module which is not derived from or based on RXTX. |
74 |
+| As a special exception, the copyright holders of RXTX give you |
75 |
+| permission to link RXTX with independent modules that communicate with |
76 |
+| RXTX solely through the Sun Microsytems CommAPI interface version 2, |
77 |
+| regardless of the license terms of these independent modules, and to copy |
78 |
+| and distribute the resulting combined work under terms of your choice, |
79 |
+| provided that every copy of the combined work is accompanied by a complete |
80 |
+| copy of the source code of RXTX (the version of RXTX used to produce the |
81 |
+| combined work), being distributed under the terms of the GNU Lesser General |
82 |
+| Public License plus this exception. An independent module is a |
83 |
+| module which is not derived from or based on RXTX. |
84 |
| |
85 |
-| Note that people who make modified versions of RXTX are not obligated |
86 |
-| to grant this special exception for their modified versions; it is |
87 |
-| their choice whether to do so. The GNU Lesser General Public License |
88 |
-| gives permission to release a modified version without this exception; this |
89 |
-| exception also makes it possible to release a modified version which |
90 |
-| carries forward this exception. |
91 |
+| Note that people who make modified versions of RXTX are not obligated |
92 |
+| to grant this special exception for their modified versions; it is |
93 |
+| their choice whether to do so. The GNU Lesser General Public License |
94 |
+| gives permission to release a modified version without this exception; this |
95 |
+| exception also makes it possible to release a modified version which |
96 |
+| carries forward this exception. |
97 |
| |
98 |
-| You should have received a copy of the GNU Lesser General Public |
99 |
-| License along with this library; if not, write to the Free |
100 |
-| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
101 |
-| All trademarks belong to their respective owners. |
102 |
+| You should have received a copy of the GNU Lesser General Public |
103 |
+| License along with this library; if not, write to the Free |
104 |
+| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
105 |
+| All trademarks belong to their respective owners. |
106 |
--------------------------------------------------------------------------*/ |
107 |
+/** |
108 |
+ * 9th May 2015 - james.c.elstone (at) ntlworld.com: |
109 |
+ * |
110 |
+ * Added STDOUT debug stream, so can see when used with OpenJDK in |
111 |
+ * console terminal. Useful for seeing events interleaved, with OS |
112 |
+ * activity. Just put '#define DEBUG_STDOUT' just below... |
113 |
+ * |
114 |
+ * Altered behaviour of SIGABRT in RXTXPort(interruptEventLoop) |
115 |
+ * to prevent Core Dump from being performed on POSIX compliant OS. |
116 |
+ * |
117 |
+ * Sorted out null termination on all debug strings! |
118 |
+ * |
119 |
+ * Clearing of char array for sprintfs, driver enumerated multilpe |
120 |
+ * times, leaving the content behind in places. |
121 |
+ * |
122 |
+ **/ |
123 |
+ |
124 |
+//#define DEBUG_STDOUT |
125 |
+ |
126 |
#if defined(__MWERKS__) /* dima */ |
127 |
#include "RXTXPort.h" /* dima */ |
128 |
#else /* dima */ |
129 |
@@ -64,7 +83,7 @@ |
130 |
#include "gnu_io_RXTXPort.h" |
131 |
#endif /* dima */ |
132 |
#ifdef __LCC__ /* windows lcc compiler for fd_set. probably wrong */ |
133 |
-# include<winsock.h> |
134 |
+# include<winsock.h> |
135 |
#endif /* __LCC__ */ |
136 |
#include <time.h> |
137 |
#include <stdio.h> |
138 |
@@ -91,23 +110,23 @@ |
139 |
#ifdef HAVE_TERMIOS_H |
140 |
# include <termios.h> |
141 |
#endif /* HAVE_TERMIOS_H */ |
142 |
-# include <signal.h> |
143 |
+# include <signal.h> |
144 |
#ifdef HAVE_SIGNAL_H |
145 |
-# include <signal.h> |
146 |
+# include <signal.h> |
147 |
#endif /* HAVE_SIGNAL_H */ |
148 |
#ifdef HAVE_SYS_SIGNAL_H |
149 |
-# include <sys/signal.h> |
150 |
+# include <sys/signal.h> |
151 |
#endif /* HAVE_SYS_SIGNAL_H */ |
152 |
#include <sys/types.h> |
153 |
#ifdef HAVE_SYS_TIME_H |
154 |
-# include <sys/time.h> |
155 |
+# include <sys/time.h> |
156 |
#endif /* HAVE_SYS_TIME_H */ |
157 |
-# include <fcntl.h> |
158 |
+# include <fcntl.h> |
159 |
#ifdef HAVE_SYS_FCNTL_H |
160 |
-# include <sys/fcntl.h> |
161 |
+# include <sys/fcntl.h> |
162 |
#endif /* HAVE_SYS_FCNTL_H */ |
163 |
#ifdef HAVE_SYS_FILE_H |
164 |
-# include <sys/file.h> |
165 |
+# include <sys/file.h> |
166 |
#endif /* HAVE_SYS_FILE_H */ |
167 |
#ifdef LFS /* File Lock Server */ |
168 |
# include <sys/socket.h> |
169 |
@@ -167,59 +186,59 @@ |
170 |
/*---------------------------------------------------------- |
171 |
cfmakeraw |
172 |
|
173 |
- accept: termios to be set to raw |
174 |
- perform: initializes the termios structure. |
175 |
- return: int 0 on success |
176 |
- exceptions: none |
177 |
- comments: this is how linux cfmakeraw works. |
178 |
- termios(3) manpage |
179 |
+ accept: termios to be set to raw |
180 |
+ perform: initializes the termios structure. |
181 |
+ return: int 0 on success |
182 |
+ exceptions: none |
183 |
+ comments: this is how linux cfmakeraw works. |
184 |
+ termios(3) manpage |
185 |
----------------------------------------------------------*/ |
186 |
|
187 |
int cfmakeraw ( struct termios *term ) |
188 |
{ |
189 |
- ENTER( "cfmakeraw" ); |
190 |
+ report( "Entering - cfmakeraw\n" ); |
191 |
term->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); |
192 |
term->c_oflag &= ~OPOST; |
193 |
term->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); |
194 |
term->c_cflag &= ~(CSIZE|PARENB); |
195 |
term->c_cflag |= CS8; |
196 |
- LEAVE( "cfmakeraw" ); |
197 |
+ report( "Leaving - cfmakeraw\n" ); |
198 |
return( 0 ); |
199 |
} |
200 |
#endif /* __sun__ || __hpux__ */ |
201 |
|
202 |
#ifdef DEBUG_TIMING |
203 |
-struct timeval snow, enow, seloop, eeloop; |
204 |
-#define report_time_eventLoop( ) { \ |
205 |
- if ( seloop.tv_sec == eeloop.tv_sec && seloop.tv_usec == eeloop.tv_usec ) \ |
206 |
+ struct timeval snow, enow, seloop, eeloop; |
207 |
+ #define report_time_eventLoop( ) { \ |
208 |
+ if ( seloop.tv_sec == eeloop.tv_sec && seloop.tv_usec == eeloop.tv_usec ) \ |
209 |
+ { \ |
210 |
+ gettimeofday(&eeloop, NULL); \ |
211 |
+ seloop.tv_sec = eeloop.tv_sec; \ |
212 |
+ seloop.tv_usec = eeloop.tv_usec; \ |
213 |
+ printf("%8i sec : %8i usec\n", eeloop.tv_sec - seloop.tv_sec, eeloop.tv_usec - seloop.tv_usec); \ |
214 |
+ } \ |
215 |
+ } |
216 |
+ #define report_time( ) \ |
217 |
{ \ |
218 |
- gettimeofday(&eeloop, NULL); \ |
219 |
- seloop.tv_sec = eeloop.tv_sec; \ |
220 |
- seloop.tv_usec = eeloop.tv_usec; \ |
221 |
- printf("%8i sec : %8i usec\n", eeloop.tv_sec - seloop.tv_sec, eeloop.tv_usec - seloop.tv_usec); \ |
222 |
- } \ |
223 |
-} |
224 |
-#define report_time( ) \ |
225 |
-{ \ |
226 |
- struct timeval now; \ |
227 |
- gettimeofday(&now, NULL); \ |
228 |
- mexPrintf("%8s : %5i : %8i sec : %8i usec\n", __TIME__, __LINE__, now.tv_sec, now.tv_usec); \ |
229 |
-} |
230 |
-#define report_time_start( ) \ |
231 |
-{ \ |
232 |
- gettimeofday(&snow, NULL); \ |
233 |
- mexPrintf("%8s : %5i : %8i sec : %8i usec", __TIME__, __LINE__, snow.tv_sec, snow.tv_usec); \ |
234 |
-} |
235 |
-#define report_time_end( ) \ |
236 |
-{ \ |
237 |
- gettimeofday(&enow, NULL); \ |
238 |
- mexPrintf("%8i sec : %8i usec\n", enow.tv_sec - snow.tv_sec, enow.tv_sec - snow.tv_sec?snow.tv_usec-enow.tv_usec:enow.tv_usec - snow.tv_usec); \ |
239 |
-} |
240 |
+ struct timeval now; \ |
241 |
+ gettimeofday(&now, NULL); \ |
242 |
+ mexPrintf("%8s : %5i : %8i sec : %8i usec\n", __TIME__, __LINE__, now.tv_sec, now.tv_usec); \ |
243 |
+ } |
244 |
+ #define report_time_start( ) \ |
245 |
+ { \ |
246 |
+ gettimeofday(&snow, NULL); \ |
247 |
+ mexPrintf("%8s : %5i : %8i sec : %8i usec", __TIME__, __LINE__, snow.tv_sec, snow.tv_usec); \ |
248 |
+ } |
249 |
+ #define report_time_end( ) \ |
250 |
+ { \ |
251 |
+ gettimeofday(&enow, NULL); \ |
252 |
+ mexPrintf("%8i sec : %8i usec\n", enow.tv_sec - snow.tv_sec, enow.tv_sec - snow.tv_sec?snow.tv_usec-enow.tv_usec:enow.tv_usec - snow.tv_usec); \ |
253 |
+ } |
254 |
#else |
255 |
-#define report_time_eventLoop( ){}; |
256 |
-#define report_time( ) {} |
257 |
-#define report_time_start( ) {} |
258 |
-#define report_time_end( ) {} |
259 |
+ #define report_time_eventLoop( ){}; |
260 |
+ #define report_time( ) {} |
261 |
+ #define report_time_start( ) {} |
262 |
+ #define report_time_end( ) {} |
263 |
#endif /* DEBUG_TIMING */ |
264 |
|
265 |
|
266 |
@@ -229,16 +248,16 @@ |
267 |
/*---------------------------------------------------------- |
268 |
RXTXPort.Initialize |
269 |
|
270 |
- accept: The JNIEnv and jobj of the thread, the original eis. |
271 |
- perform: fill in the needed variables with this threads values |
272 |
- return: none |
273 |
- exceptions: none |
274 |
- comments: java variables (especially JNIEnv) should not be shared |
275 |
- between threads. Right now we build a local struct with |
276 |
- the thread's info before using the variabls. This is |
277 |
- especially true for send_event. |
278 |
- |
279 |
- See also JNI_OnLoad() if the thread does not have the values |
280 |
+ accept: The JNIEnv and jobj of the thread, the original eis. |
281 |
+ perform: fill in the needed variables with this threads values |
282 |
+ return: none |
283 |
+ exceptions: none |
284 |
+ comments: java variables (especially JNIEnv) should not be shared |
285 |
+ between threads. Right now we build a local struct with |
286 |
+ the thread's info before using the variabls. This is |
287 |
+ especially true for send_event. |
288 |
+ |
289 |
+ See also JNI_OnLoad() if the thread does not have the values |
290 |
----------------------------------------------------------*/ |
291 |
struct event_info_struct build_threadsafe_eis( |
292 |
JNIEnv *env, |
293 |
@@ -264,13 +283,13 @@ |
294 |
/*---------------------------------------------------------- |
295 |
RXTXPort.Initialize |
296 |
|
297 |
- accept: none |
298 |
- perform: Initialize the native library |
299 |
- return: none |
300 |
- exceptions: none |
301 |
- comments: Basically this just causes rxtx to ignore signals. signal |
302 |
- handlers where tried but the VM (circa 1.1) did not like it. |
303 |
- |
304 |
+ accept: none |
305 |
+ perform: Initialize the native library |
306 |
+ return: none |
307 |
+ exceptions: none |
308 |
+ comments: Basically this just causes rxtx to ignore signals. signal |
309 |
+ handlers where tried but the VM (circa 1.1) did not like it. |
310 |
+ |
311 |
It also allows for some sanity checks on linux boxes if DEBUG |
312 |
is enabled. |
313 |
----------------------------------------------------------*/ |
314 |
@@ -284,9 +303,9 @@ |
315 |
char message[80]; |
316 |
#endif /* DEBUG && __linux__ */ |
317 |
/* This bit of code checks to see if there is a signal handler installed |
318 |
- for SIGIO, and installs SIG_IGN if there is not. This is necessary |
319 |
- for the native threads jdk, but we don't want to do it with green |
320 |
- threads, because it slows things down. Go figure. */ |
321 |
+ for SIGIO, and installs SIG_IGN if there is not. This is necessary |
322 |
+ for the native threads jdk, but we don't want to do it with green |
323 |
+ threads, because it slows things down. Go figure. */ |
324 |
|
325 |
/* POSIX signal handling functions */ |
326 |
#if !defined(WIN32) |
327 |
@@ -306,7 +325,7 @@ |
328 |
sigaction(SIGIO, &new_action, NULL); |
329 |
} |
330 |
#endif /* !WIN32 */ |
331 |
- ENTER( "RXTXPort:Initialize" ); |
332 |
+ report( "Entering - RXTXPort:Initialize\n" ); |
333 |
#ifdef PRERELEASE |
334 |
/* this is just for avoiding confusion while testing new libraries */ |
335 |
#ifdef DEBUG_MW |
336 |
@@ -322,32 +341,33 @@ |
337 |
/* Lets let people who upgraded kernels know they may have problems */ |
338 |
if (uname (&name) == -1) |
339 |
{ |
340 |
- report( "RXTX WARNING: cannot get system name\n" ); |
341 |
- LEAVE( "RXTXPort:Initialize" ); |
342 |
+ report( "RXTX WARNING: cannot get system name\n" ); |
343 |
+ report( "Leaving - RXTXPort:Initialize\n" ); |
344 |
return; |
345 |
} |
346 |
if(strcmp(name.release,UTS_RELEASE)!=0) |
347 |
{ |
348 |
- sprintf( message, LINUX_KERNEL_VERSION_ERROR, UTS_RELEASE, |
349 |
+ memset(&message[0], 0, sizeof(message)); |
350 |
+ sprintf( message, "%s%s%s\n", LINUX_KERNEL_VERSION_ERROR, UTS_RELEASE, |
351 |
name.release ); |
352 |
report( message ); |
353 |
getchar(); |
354 |
} |
355 |
- LEAVE( "RXTXPort:Initialize" ); |
356 |
+ report( "Leaving - RXTXPort:Initialize\n" ); |
357 |
#endif /* DEBUG && __linux__ */ |
358 |
} |
359 |
|
360 |
/*---------------------------------------------------------- |
361 |
RXTXPort.find_preopened_ports |
362 |
- accept: The device to find if preopened. ie "/dev/ttyS0" |
363 |
- perform: find the filedescriptor if preopened |
364 |
- return: fd |
365 |
- exceptions: none |
366 |
- comments: see |
367 |
- RXTXPort.nativeStaticSetDSR |
368 |
- RXTXPort.nativeStaticSetDTR |
369 |
- RXTXPort.nativeStaticSetRTS |
370 |
- RXTXPort.nativeStaticSetSerialPortParams |
371 |
+ accept: The device to find if preopened. ie "/dev/ttyS0" |
372 |
+ perform: find the filedescriptor if preopened |
373 |
+ return: fd |
374 |
+ exceptions: none |
375 |
+ comments: see |
376 |
+ RXTXPort.nativeStaticSetDSR |
377 |
+ RXTXPort.nativeStaticSetDTR |
378 |
+ RXTXPort.nativeStaticSetRTS |
379 |
+ RXTXPort.nativeStaticSetSerialPortParams |
380 |
This is used so people can setDTR low before calling the |
381 |
Java open(). |
382 |
----------------------------------------------------------*/ |
383 |
@@ -401,13 +421,13 @@ |
384 |
/*---------------------------------------------------------- |
385 |
configure_port |
386 |
|
387 |
- accept: env, file descriptor |
388 |
- perform: set the termios struct to sane settings and |
389 |
- return: 0 on success |
390 |
- exceptions: IOExcepiton |
391 |
- comments: Very often people complain about not being able to get past |
392 |
- this function and it turns out to be permissions on the |
393 |
- device file or bios has the device disabled. |
394 |
+ accept: Env, file descriptor |
395 |
+ perform: set the termios struct to sane settings and |
396 |
+ return: 0 on success |
397 |
+ exceptions: IOExcepiton |
398 |
+ comments: Very often people complain about not being able to get past |
399 |
+ this function and it turns out to be permissions on the |
400 |
+ device file or bios has the device disabled. |
401 |
----------------------------------------------------------*/ |
402 |
int configure_port( int fd ) |
403 |
{ |
404 |
@@ -446,31 +466,31 @@ |
405 |
/*---------------------------------------------------------- |
406 |
get_java_baudrate |
407 |
|
408 |
- accept: the native speed setting |
409 |
- perform: translate the native speed to a Java speed |
410 |
- return: the Java speed |
411 |
- exceptions: none |
412 |
- comments: This is used by open() (indirectly) and |
413 |
- nativeStaticGetBaudRate() |
414 |
+ accept: the native speed setting |
415 |
+ perform: translate the native speed to a Java speed |
416 |
+ return: the Java speed |
417 |
+ exceptions: none |
418 |
+ comments: This is used by open() (indirectly) and |
419 |
+ nativeStaticGetBaudRate() |
420 |
----------------------------------------------------------*/ |
421 |
int get_java_baudrate( int native_speed ) |
422 |
{ |
423 |
switch( native_speed ) |
424 |
{ |
425 |
- case B0: return 0; |
426 |
- case B50: return 50; |
427 |
- case B75: return 75; |
428 |
- case B110: return 110; |
429 |
- case B134: return 134; |
430 |
- case B150: return 150; |
431 |
- case B200: return 200; |
432 |
- case B300: return 300; |
433 |
- case B600: return 600; |
434 |
- case B1200: return 1200; |
435 |
- case B1800: return 1800; |
436 |
- case B2400: return 2400; |
437 |
- case B4800: return 4800; |
438 |
- case B9600: return 9600; |
439 |
+ case B0: return 0; |
440 |
+ case B50: return 50; |
441 |
+ case B75: return 75; |
442 |
+ case B110: return 110; |
443 |
+ case B134: return 134; |
444 |
+ case B150: return 150; |
445 |
+ case B200: return 200; |
446 |
+ case B300: return 300; |
447 |
+ case B600: return 600; |
448 |
+ case B1200: return 1200; |
449 |
+ case B1800: return 1800; |
450 |
+ case B2400: return 2400; |
451 |
+ case B4800: return 4800; |
452 |
+ case B9600: return 9600; |
453 |
#ifdef B14400 |
454 |
case B14400: return 14400; |
455 |
#endif /* B14400 */ |
456 |
@@ -536,13 +556,13 @@ |
457 |
/*---------------------------------------------------------- |
458 |
set_java_vars |
459 |
|
460 |
- accept: fd of the preopened device |
461 |
- perform: Now that the object is instatiated, set the Java variables |
462 |
- to the preopened states. |
463 |
- return: none |
464 |
- exceptions: none |
465 |
- comments: preopened refers to the fact that the serial port has |
466 |
- been configured before the Java open() has been called. |
467 |
+ accept: fd of the preopened device |
468 |
+ perform: Now that the object is instatiated, set the Java variables |
469 |
+ to the preopened states. |
470 |
+ return: none |
471 |
+ exceptions: none |
472 |
+ comments: preopened refers to the fact that the serial port has |
473 |
+ been configured before the Java open() has been called. |
474 |
----------------------------------------------------------*/ |
475 |
|
476 |
void set_java_vars( JNIEnv *env, jobject jobj, int fd ) |
477 |
@@ -570,10 +590,10 @@ |
478 |
|
479 |
|
480 |
switch( ttyset.c_cflag&CSIZE ) { |
481 |
- case CS5: databits = JDATABITS_5; break; |
482 |
- case CS6: databits = JDATABITS_6; break; |
483 |
- case CS7: databits = JDATABITS_7; break; |
484 |
- case CS8: databits = JDATABITS_8; break; |
485 |
+ case CS5: databits = JDATABITS_5; break; |
486 |
+ case CS6: databits = JDATABITS_6; break; |
487 |
+ case CS7: databits = JDATABITS_7; break; |
488 |
+ case CS8: databits = JDATABITS_8; break; |
489 |
} |
490 |
#ifdef CMSPAR |
491 |
switch( ttyset.c_cflag&(PARENB|PARODD|CMSPAR ) ) { |
492 |
@@ -588,9 +608,9 @@ |
493 |
case PARENB | CMSPAR: jparity = JPARITY_SPACE; break; |
494 |
#endif /* CMSPAR */ |
495 |
} |
496 |
- switch( ttyset.c_cflag&(CSTOPB) ) { |
497 |
- case 0: stop_bits = STOPBITS_1; break; |
498 |
- case CSTOPB: |
499 |
+ switch( ttyset.c_cflag&(CSTOPB) ) { |
500 |
+ case 0: stop_bits = STOPBITS_1; break; |
501 |
+ case CSTOPB: |
502 |
if ( (ttyset.c_cflag & CSIZE) == CS5 ) { |
503 |
stop_bits = STOPBITS_1_5; |
504 |
} |
505 |
@@ -598,7 +618,7 @@ |
506 |
stop_bits = STOPBITS_2; |
507 |
} |
508 |
break; |
509 |
- } |
510 |
+ } |
511 |
/* |
512 |
dima writes: |
513 |
|
514 |
@@ -616,9 +636,9 @@ |
515 |
|
516 |
*/ |
517 |
#if defined(CBAUD)/* dima */ |
518 |
- baudrate = ttyset.c_cflag&CBAUD; |
519 |
+ baudrate = ttyset.c_cflag&CBAUD; |
520 |
#else |
521 |
- baudrate = cfgetispeed(&ttyset); |
522 |
+ baudrate = cfgetispeed(&ttyset); |
523 |
#endif |
524 |
(*env)->SetIntField(env, jobj, jfspeed, |
525 |
( jint ) get_java_baudrate(baudrate) ); |
526 |
@@ -629,14 +649,14 @@ |
527 |
/*---------------------------------------------------------- |
528 |
RXTXPort.open |
529 |
|
530 |
- accept: The device to open. ie "/dev/ttyS0" |
531 |
- perform: open the device, set the termios struct to sane settings and |
532 |
- return the filedescriptor |
533 |
- return: fd |
534 |
- exceptions: IOExcepiton |
535 |
- comments: Very often people complain about not being able to get past |
536 |
- this function and it turns out to be permissions on the |
537 |
- device file or bios has the device disabled. |
538 |
+ accept: The device to open. ie "/dev/ttyS0" |
539 |
+ perform: open the device, set the termios struct to sane settings and |
540 |
+ return the filedescriptor |
541 |
+ return: fd |
542 |
+ exceptions: IOExcepiton |
543 |
+ comments: Very often people complain about not being able to get past |
544 |
+ this function and it turns out to be permissions on the |
545 |
+ device file or bios has the device disabled. |
546 |
----------------------------------------------------------*/ |
547 |
JNIEXPORT jint JNICALL RXTXPort(open)( |
548 |
JNIEnv *env, |
549 |
@@ -676,9 +696,10 @@ |
550 |
system_does_not_lock Win32 |
551 |
*/ |
552 |
|
553 |
- ENTER( "RXTXPort:open" ); |
554 |
+ report( "Entering - RXTXPort:open\n" ); |
555 |
if ( LOCK( filename, pid ) ) |
556 |
{ |
557 |
+ memset(&message[0], 0, sizeof(message)); |
558 |
sprintf( message, "open: locking has failed for %s\n", |
559 |
filename ); |
560 |
report( message ); |
561 |
@@ -686,6 +707,7 @@ |
562 |
} |
563 |
else |
564 |
{ |
565 |
+ memset(&message[0], 0, sizeof(message)); |
566 |
sprintf( message, "open: locking worked for %s\n", filename ); |
567 |
report( message ); |
568 |
} |
569 |
@@ -703,36 +725,36 @@ |
570 |
} while (fd < 0 && errno==EINTR); |
571 |
|
572 |
#ifdef OPEN_EXCL |
573 |
- /* |
574 |
- Note that open() follows POSIX semantics: multiple open() calls to |
575 |
- the same file will succeed unless the TIOCEXCL ioctl is issued. |
576 |
- This will prevent additional opens except by root-owned processes. |
577 |
- See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details. |
578 |
- */ |
579 |
- |
580 |
- if (fd >= 0 && (ioctl(fd, TIOCEXCL) == -1)) |
581 |
- { |
582 |
- sprintf( message, "open: exclusive access denied for %s\n", |
583 |
- filename ); |
584 |
- report( message ); |
585 |
- report_error( message ); |
586 |
- |
587 |
- close(fd); |
588 |
- goto fail; |
589 |
- } |
590 |
+ /* |
591 |
+ Note that open() follows POSIX semantics: multiple open() calls to |
592 |
+ the same file will succeed unless the TIOCEXCL ioctl is issued. |
593 |
+ This will prevent additional opens except by root-owned processes. |
594 |
+ See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details. |
595 |
+ */ |
596 |
+ |
597 |
+ if (fd >= 0 && (ioctl(fd, TIOCEXCL) == -1)) |
598 |
+ { |
599 |
+ memset(&message[0], 0, sizeof(message)); |
600 |
+ sprintf( message, "open: exclusive access denied for %s\n", filename ); |
601 |
+ report( message ); |
602 |
+ report_error( message ); |
603 |
+ close(fd); |
604 |
+ goto fail; |
605 |
+ } |
606 |
#endif /* OPEN_EXCL */ |
607 |
|
608 |
if( configure_port( fd ) ) goto fail; |
609 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
610 |
+ memset(&message[0], 0, sizeof(message)); |
611 |
sprintf( message, "open: fd returned is %i\n", fd ); |
612 |
report( message ); |
613 |
- LEAVE( "RXTXPort:open" ); |
614 |
+ report( "Leaving - RXTXPort:open\n" ); |
615 |
report_time_end( ); |
616 |
return (jint)fd; |
617 |
|
618 |
fail: |
619 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
620 |
- LEAVE( "RXTXPort:open" ); |
621 |
+ report( "Leaving - RXTXPort:open\n" ); |
622 |
throw_java_exception( env, PORT_IN_USE_EXCEPTION, "open", |
623 |
strerror( errno ) ); |
624 |
return -1; |
625 |
@@ -741,10 +763,10 @@ |
626 |
/*---------------------------------------------------------- |
627 |
RXTXPort.nativeClose |
628 |
|
629 |
- accept: none |
630 |
- perform: get the fd from the java end and close it |
631 |
- return: none |
632 |
- exceptions: none |
633 |
+ accept: none |
634 |
+ perform: get the fd from the java end and close it |
635 |
+ return: none |
636 |
+ exceptions: none |
637 |
----------------------------------------------------------*/ |
638 |
JNIEXPORT void JNICALL RXTXPort(nativeClose)( JNIEnv *env, |
639 |
jobject jobj,jstring jstr ) |
640 |
@@ -764,7 +786,7 @@ |
641 |
(*env)->ExceptionDescribe( env ); |
642 |
(*env)->ExceptionClear( env ); |
643 |
(*env)->DeleteLocalRef( env, jclazz ); |
644 |
- report("nativeClose: Close not detecting thread pid"); |
645 |
+ report("nativeClose: Close not detecting thread pid\n"); |
646 |
return; |
647 |
} |
648 |
report("<nativeClose: pid\n"); |
649 |
@@ -777,14 +799,14 @@ |
650 |
system_does_not_unlock Win32 |
651 |
*/ |
652 |
|
653 |
- ENTER( "RXTXPort:nativeClose" ); |
654 |
+ report( "Entering - RXTXPort:nativeClose\n" ); |
655 |
if (fd > 0) |
656 |
{ |
657 |
report("nativeClose: discarding remaining data (tcflush)\n"); |
658 |
/* discard any incoming+outgoing data not yet read/sent */ |
659 |
tcflush(fd, TCIOFLUSH); |
660 |
do { |
661 |
- report("nativeClose: calling close\n"); |
662 |
+ report("nativeClose: calling close\n"); |
663 |
result=CLOSE (fd); |
664 |
} while ( result < 0 && errno == EINTR ); |
665 |
UNLOCK( filename, pid ); |
666 |
@@ -793,7 +815,7 @@ |
667 |
(*env)->DeleteLocalRef( env, jclazz ); |
668 |
report("nativeClose: release filename\n"); |
669 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
670 |
- LEAVE( "RXTXPort:nativeClose" ); |
671 |
+ report( "Leaving - RXTXPort:nativeClose\n" ); |
672 |
report_time_end( ); |
673 |
return; |
674 |
} |
675 |
@@ -801,15 +823,15 @@ |
676 |
/*---------------------------------------------------------- |
677 |
RXTXPort.set_port_params |
678 |
|
679 |
- accept: env, fd, speed, data bits, stop bits, parity |
680 |
- perform: set the serial port parameters |
681 |
- return: 1 on error |
682 |
- exceptions: UnsupportedCommOperationException |
683 |
- comments: There is a static method and an instance method that use this |
684 |
- function. The static method gets a fd first. The instance |
685 |
- method can get the fd from the object. |
686 |
+ accept: env, fd, speed, data bits, stop bits, parity |
687 |
+ perform: set the serial port parameters |
688 |
+ return: 1 on error |
689 |
+ exceptions: UnsupportedCommOperationException |
690 |
+ comments: There is a static method and an instance method that use this |
691 |
+ function. The static method gets a fd first. The instance |
692 |
+ method can get the fd from the object. |
693 |
|
694 |
- see: nativeSetSerialPortParams & nativeStaticSerialPortParams |
695 |
+ see: nativeSetSerialPortParams & nativeStaticSerialPortParams |
696 |
----------------------------------------------------------*/ |
697 |
int set_port_params( JNIEnv *env, int fd, int cspeed, int dataBits, |
698 |
int stopBits, int parity ) |
699 |
@@ -864,36 +886,36 @@ |
700 |
ioctl( fd, TIOCMSET, &result ); |
701 |
} |
702 |
/* |
703 |
- B38400 is a special case in Linux for custom baud rates. |
704 |
+ B38400 is a special case in Linux for custom baud rates. |
705 |
|
706 |
- We just treat this as a custom speed for now. If you take this ifdef |
707 |
- out and select baud rates 38400 then 28800 then 38400, you will get |
708 |
- a final baud rate of 28800 because you did not update the divisor. |
709 |
+ We just treat this as a custom speed for now. If you take this ifdef |
710 |
+ out and select baud rates 38400 then 28800 then 38400, you will get |
711 |
+ a final baud rate of 28800 because you did not update the divisor. |
712 |
|
713 |
- See the next ifdef below for the divisor. |
714 |
+ See the next ifdef below for the divisor. |
715 |
*/ |
716 |
#if defined(TIOCGSERIAL) |
717 |
if ( cspeed == B38400 ) |
718 |
cspeed = 38400; |
719 |
#endif /* TIOCGSERIAL */ |
720 |
- if( cfsetispeed( &ttyset, cspeed ) < 0 || |
721 |
+ if( cfsetispeed( &ttyset, cspeed ) < 0 || |
722 |
cfsetospeed( &ttyset, cspeed ) < 0 ) |
723 |
{ |
724 |
/* |
725 |
- Some people need to set the baud rate to ones not defined |
726 |
- in termios.h |
727 |
+ Some people need to set the baud rate to ones not defined |
728 |
+ in termios.h |
729 |
|
730 |
- This includes some baud rates which are supported by CommAPI |
731 |
- in Unix ( 14400, 28800, 128000, 256000 ) |
732 |
+ This includes some baud rates which are supported by CommAPI |
733 |
+ in Unix ( 14400, 28800, 128000, 256000 ) |
734 |
|
735 |
- If the above fails, we assume this is not a defined |
736 |
- baud rate on Unix. With Win32, It is assumed the kernel |
737 |
- will do this for us. |
738 |
+ If the above fails, we assume this is not a defined |
739 |
+ baud rate on Unix. With Win32, It is assumed the kernel |
740 |
+ will do this for us. |
741 |
|
742 |
- The baud_base and desired speed are used to |
743 |
- calculate a custom divisor. |
744 |
+ The baud_base and desired speed are used to |
745 |
+ calculate a custom divisor. |
746 |
|
747 |
- On linux the setserial man page covers this. |
748 |
+ On linux the setserial man page covers this. |
749 |
*/ |
750 |
|
751 |
#if defined(TIOCGSERIAL) |
752 |
@@ -905,7 +927,7 @@ |
753 |
sstruct.custom_divisor = ( sstruct.baud_base/cspeed ); |
754 |
cspeed = B38400; |
755 |
#endif /* TIOCGSERIAL */ |
756 |
- if( cfsetispeed( &ttyset, cspeed ) < 0 || |
757 |
+ if( cfsetispeed( &ttyset, cspeed ) < 0 || |
758 |
cfsetospeed( &ttyset, cspeed ) < 0 ) |
759 |
{ |
760 |
/* OK, we tried everything */ |
761 |
@@ -933,10 +955,10 @@ |
762 |
/*---------------------------------------------------------- |
763 |
RXTXPort.nativeSetSerialPortParams |
764 |
|
765 |
- accept: speed, data bits, stop bits, parity |
766 |
- perform: set the serial port parameters |
767 |
- return: jboolean 1 on error |
768 |
- exceptions: UnsupportedCommOperationException |
769 |
+ accept: speed, data bits, stop bits, parity |
770 |
+ perform: set the serial port parameters |
771 |
+ return: jboolean 1 on error |
772 |
+ exceptions: UnsupportedCommOperationException |
773 |
----------------------------------------------------------*/ |
774 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeSetSerialPortParams)( |
775 |
JNIEnv *env, jobject jobj, jint speed, jint dataBits, jint stopBits, |
776 |
@@ -945,15 +967,15 @@ |
777 |
int fd = get_java_var( env, jobj,"fd","I" ); |
778 |
int cspeed = translate_speed( env, speed ); |
779 |
|
780 |
- ENTER( "RXTXPort:nativeSetSerialPortParams" ); |
781 |
+ report( "Entering - RXTXPort:nativeSetSerialPortParams\n" ); |
782 |
report_time_start( ); |
783 |
|
784 |
if (cspeed < 0 ) |
785 |
{ |
786 |
report(" invalid cspeed\n"); |
787 |
/* |
788 |
- For some reason the native exceptions are not being caught. Moving this |
789 |
- to the Java side fixed the issue. taj. |
790 |
+ For some reason the native exceptions are not being caught. Moving this |
791 |
+ to the Java side fixed the issue. taj. |
792 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
793 |
"", "BaudRate could not be set to the specified value" ); |
794 |
*/ |
795 |
@@ -964,17 +986,17 @@ |
796 |
if( set_port_params( env, fd, cspeed, dataBits, stopBits, parity ) ) |
797 |
{ |
798 |
report("set_port_params failed\n"); |
799 |
- LEAVE( "RXTXPort:nativeSetSerialPortParams" ); |
800 |
+ report( "Leaving - RXTXPort:nativeSetSerialPortParams\n" ); |
801 |
/* |
802 |
- For some reason the native exceptions are not being caught. Moving this |
803 |
- to the Java side fixed the issue. taj. |
804 |
+ For some reason the native exceptions are not being caught. Moving this |
805 |
+ to the Java side fixed the issue. taj. |
806 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
807 |
"nativeSetSerialPortParams", strerror( errno ) ); |
808 |
*/ |
809 |
return(1); |
810 |
} |
811 |
|
812 |
- LEAVE( "RXTXPort:nativeSetSerialPortParams" ); |
813 |
+ report( "Leaving - RXTXPort:nativeSetSerialPortParams\n" ); |
814 |
report_time_end( ); |
815 |
return(0); |
816 |
} |
817 |
@@ -982,17 +1004,17 @@ |
818 |
/*---------------------------------------------------------- |
819 |
translate_speed |
820 |
|
821 |
- accept: speed in bits-per-second |
822 |
- perform: convert bits-per-second to a speed_t constant |
823 |
- return: speed_t constant |
824 |
- exceptions: returns -1 and the calling method throws the exception so |
825 |
- it may be caught in java. |
826 |
- comments: Only the lowest level code should know about |
827 |
- the magic constants. |
828 |
+ accept: speed in bits-per-second |
829 |
+ perform: convert bits-per-second to a speed_t constant |
830 |
+ return: speed_t constant |
831 |
+ exceptions: returns -1 and the calling method throws the exception so |
832 |
+ it may be caught in java. |
833 |
+ comments: Only the lowest level code should know about |
834 |
+ the magic constants. |
835 |
----------------------------------------------------------*/ |
836 |
int translate_speed( JNIEnv *env, jint speed ) |
837 |
{ |
838 |
- LEAVE( "RXTXPort:translate_speed" ); |
839 |
+ report( "Leaving - RXTXPort:translate_speed\n" ); |
840 |
switch( speed ) { |
841 |
case 0: return B0; |
842 |
case 50: return B50; |
843 |
@@ -1072,7 +1094,7 @@ |
844 |
if( speed >= 0 ) return speed; |
845 |
else |
846 |
{ |
847 |
- LEAVE( "RXTXPort:translate_speed: Error condition" ); |
848 |
+ report( "Leaving - RXTXPort:translate_speed: Error condition\n" ); |
849 |
return -1; |
850 |
} |
851 |
} |
852 |
@@ -1080,16 +1102,16 @@ |
853 |
/*---------------------------------------------------------- |
854 |
translate_data_bits |
855 |
|
856 |
- accept: gnu.io.SerialPort.DATABITS_* constant |
857 |
- perform: set proper termios c_cflag bits |
858 |
- return: 1 on error |
859 |
- exceptions: UnsupportedCommOperationException |
860 |
+ accept: gnu.io.SerialPort.DATABITS_* constant |
861 |
+ perform: set proper termios c_cflag bits |
862 |
+ return: 1 on error |
863 |
+ exceptions: UnsupportedCommOperationException |
864 |
----------------------------------------------------------*/ |
865 |
int translate_data_bits( JNIEnv *env, tcflag_t *cflag, jint dataBits ) |
866 |
{ |
867 |
int temp = (*cflag) & ~CSIZE; |
868 |
|
869 |
- ENTER( "translate_date_bits" ); |
870 |
+ report( "Entering - translate_date_bits\n" ); |
871 |
switch( dataBits ) { |
872 |
case JDATABITS_5: |
873 |
(*cflag) = temp | CS5; |
874 |
@@ -1105,10 +1127,10 @@ |
875 |
return 0; |
876 |
} |
877 |
|
878 |
- LEAVE( "RXTXPort:translate_date_bits" ); |
879 |
+ report( "Leaving - RXTXPort:translate_date_bits\n" ); |
880 |
/* |
881 |
- For some reason the native exceptions are not being caught. Moving this |
882 |
- to the Java side fixed the issue. taj. |
883 |
+ For some reason the native exceptions are not being caught. Moving this |
884 |
+ to the Java side fixed the issue. taj. |
885 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
886 |
"", "databit value not supported" ); |
887 |
*/ |
888 |
@@ -1118,20 +1140,20 @@ |
889 |
/*---------------------------------------------------------- |
890 |
translate_stop_bits |
891 |
|
892 |
- accept: gnu.io.SerialPort.STOPBITS_* constant |
893 |
- perform: set proper termios c_cflag bits |
894 |
- return: 1 on error |
895 |
- exceptions: UnsupportedCommOperationException |
896 |
- comments: If you specify 5 data bits and 2 stop bits, the port will |
897 |
- allegedly use 1.5 stop bits. Does anyone care? |
898 |
+ accept: gnu.io.SerialPort.STOPBITS_* constant |
899 |
+ perform: set proper termios c_cflag bits |
900 |
+ return: 1 on error |
901 |
+ exceptions: UnsupportedCommOperationException |
902 |
+ comments: If you specify 5 data bits and 2 stop bits, the port will |
903 |
+ allegedly use 1.5 stop bits. Does anyone care? |
904 |
----------------------------------------------------------*/ |
905 |
int translate_stop_bits( JNIEnv *env, tcflag_t *cflag, jint stopBits ) |
906 |
{ |
907 |
- ENTER( "translate_stop_bits" ); |
908 |
+ report( "Entering - translate_stop_bits\n" ); |
909 |
switch( stopBits ) { |
910 |
case STOPBITS_1: |
911 |
(*cflag) &= ~CSTOPB; |
912 |
- LEAVE( "RXTXPort:translate_stop_bits" ); |
913 |
+ report( "Leaving - RXTXPort:translate_stop_bits\n" ); |
914 |
return 0; |
915 |
/* ok.. lets try putting it in and see if anyone notices */ |
916 |
case STOPBITS_1_5: |
917 |
@@ -1141,14 +1163,14 @@ |
918 |
return 0; |
919 |
case STOPBITS_2: |
920 |
(*cflag) |= CSTOPB; |
921 |
- LEAVE( "RXTXPort:translate_stop_bits" ); |
922 |
+ report( "Leaving - RXTXPort:translate_stop_bits\n" ); |
923 |
return 0; |
924 |
} |
925 |
|
926 |
- LEAVE( "RXTXPort:translate_stop_bits" ); |
927 |
+ report( "Leaving - RXTXPort:translate_stop_bits\n" ); |
928 |
/* |
929 |
- For some reason the native exceptions are not being caught. Moving this |
930 |
- to the Java side fixed the issue. taj. |
931 |
+ For some reason the native exceptions are not being caught. Moving this |
932 |
+ to the Java side fixed the issue. taj. |
933 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
934 |
"", "stopbit value not supported" ); |
935 |
*/ |
936 |
@@ -1181,7 +1203,7 @@ |
937 |
|
938 |
if( tcgetattr( fd, &ttyset ) < 0 ) |
939 |
{ |
940 |
- report("nativeGetParity: tcgetattr failed\n"); |
941 |
+ report("nativeGetParity: tcgetattr failed\n"); |
942 |
return( -1 ); |
943 |
} |
944 |
#ifdef CMSPAR |
945 |
@@ -1215,49 +1237,49 @@ |
946 |
/*---------------------------------------------------------- |
947 |
translate_parity |
948 |
|
949 |
- accept: javax.comm.SerialPort.PARITY_* constant |
950 |
- perform: set proper termios c_cflag bits |
951 |
- return: 1 on error |
952 |
- exceptions: UnsupportedCommOperationException |
953 |
- comments: The CMSPAR bit should be used for 'mark' and 'space' parity, |
954 |
- but it's not in glibc's includes. Oh well, rarely used anyway. |
955 |
+ accept: javax.comm.SerialPort.PARITY_* constant |
956 |
+ perform: set proper termios c_cflag bits |
957 |
+ return: 1 on error |
958 |
+ exceptions: UnsupportedCommOperationException |
959 |
+ comments: The CMSPAR bit should be used for 'mark' and 'space' parity, |
960 |
+ but it's not in glibc's includes. Oh well, rarely used anyway. |
961 |
----------------------------------------------------------*/ |
962 |
int translate_parity( JNIEnv *env, tcflag_t *cflag, jint parity ) |
963 |
{ |
964 |
- ENTER( "translate_parity" ); |
965 |
+ report( "Entering - translate_parity\n" ); |
966 |
#ifdef CMSPAR |
967 |
(*cflag) &= ~(PARENB | PARODD | CMSPAR ); |
968 |
#endif /* CMSPAR */ |
969 |
switch( parity ) { |
970 |
case JPARITY_NONE: |
971 |
- LEAVE( "translate_parity" ); |
972 |
+ report( "Leaving - translate_parity\n" ); |
973 |
return 0; |
974 |
case JPARITY_EVEN: |
975 |
(*cflag) |= PARENB; |
976 |
- LEAVE( "translate_parity" ); |
977 |
+ report( "Leaving - translate_parity\n" ); |
978 |
return 0; |
979 |
case JPARITY_ODD: |
980 |
(*cflag) |= PARENB | PARODD; |
981 |
- LEAVE( "translate_parity" ); |
982 |
+ report( "Leaving - translate_parity\n" ); |
983 |
return 0; |
984 |
#ifdef CMSPAR |
985 |
case JPARITY_MARK: |
986 |
(*cflag) |= PARENB | PARODD | CMSPAR; |
987 |
- LEAVE( "translate_parity" ); |
988 |
+ report( "Leaving - translate_parity\n" ); |
989 |
return 0; |
990 |
case JPARITY_SPACE: |
991 |
(*cflag) |= PARENB | CMSPAR; |
992 |
- LEAVE( "translate_parity" ); |
993 |
+ report( "Leaving - translate_parity\n" ); |
994 |
return 0; |
995 |
#endif /* CMSPAR */ |
996 |
default: |
997 |
printf("Parity missed %i\n", (int) parity ); |
998 |
} |
999 |
|
1000 |
- LEAVE( "translate_parity" ); |
1001 |
+ report( "Leaving - translate_parity\n" ); |
1002 |
/* |
1003 |
- For some reason the native exceptions are not being caught. Moving this |
1004 |
- to the Java side fixed the issue. taj. |
1005 |
+ For some reason the native exceptions are not being caught. Moving this |
1006 |
+ to the Java side fixed the issue. taj. |
1007 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
1008 |
"", "parity value not supported" ); |
1009 |
*/ |
1010 |
@@ -1267,48 +1289,63 @@ |
1011 |
/*---------------------------------------------------------- |
1012 |
drain_loop() |
1013 |
|
1014 |
- accept: |
1015 |
- perform: call tcdrain() and report an event when it succeds |
1016 |
- return: none |
1017 |
- exceptions: |
1018 |
- comments: |
1019 |
+ accept: |
1020 |
+ perform: call tcdrain() and report an event when it succeds |
1021 |
+ return: none |
1022 |
+ exceptions: |
1023 |
+ comments: |
1024 |
----------------------------------------------------------*/ |
1025 |
void *drain_loop( void *arg ) |
1026 |
{ |
1027 |
+ report("Entering - drain_loop\n"); |
1028 |
struct event_info_struct *eis = ( struct event_info_struct * ) arg; |
1029 |
/* char msg[80]; */ |
1030 |
int i; |
1031 |
+ |
1032 |
+ report_verbose("drain_loop: pthread detaching\n"); |
1033 |
pthread_detach( pthread_self() ); |
1034 |
- |
1035 |
+ |
1036 |
+ report_verbose("drain_loop: begining for loop\n"); |
1037 |
for(i=0;;i++) |
1038 |
{ |
1039 |
- report_verbose("drain_loop: looping\n"); |
1040 |
+ report_verbose("drain_loop: looping\n"); |
1041 |
if( eis->eventloop_interrupted ) |
1042 |
{ |
1043 |
+ report_verbose("drain_loop: EventLoop Interrupted\n"); |
1044 |
goto end; |
1045 |
} |
1046 |
-#if defined(__sun__) |
1047 |
- /* FIXME: No time to test on all OS's for production */ |
1048 |
- if (usleep(5000)) { |
1049 |
- report("drain_loop: received EINTR"); |
1050 |
- } |
1051 |
-#else |
1052 |
- if (usleep(1000000)) { |
1053 |
- report("drain_loop: received EINTR"); |
1054 |
- } |
1055 |
-#endif /* __sun__ */ |
1056 |
+ |
1057 |
+ #if defined(__sun__) |
1058 |
+ /* FIXME: No time to test on all OS's for production */ |
1059 |
+ report_verbose("drain_loop: SUN: Sleeping now\n"); |
1060 |
+ if (usleep(5000)) { |
1061 |
+ report("***drain_loop: received EINTR\n"); |
1062 |
+ } |
1063 |
+ #else |
1064 |
+ report_verbose("drain_loop: Sleeping now\n"); |
1065 |
+ if (usleep(1000000)) { |
1066 |
+ report("***drain_loop: received EINTR\n"); |
1067 |
+ } |
1068 |
+ #endif /* __sun__ */ |
1069 |
+ |
1070 |
+ report_verbose("***drain_loop: Out of sleep loop\n"); |
1071 |
/* |
1072 |
system_wait(); |
1073 |
*/ |
1074 |
+ |
1075 |
if( eis->eventloop_interrupted ) |
1076 |
{ |
1077 |
+ report_verbose("*** drain_loop: Interupted\n"); |
1078 |
+ eis->closing = 1; |
1079 |
goto end; |
1080 |
} |
1081 |
+ |
1082 |
if( tcdrain( eis->fd ) == 0 ) |
1083 |
{ |
1084 |
if( eis && eis->writing ) |
1085 |
{ |
1086 |
/* |
1087 |
+ memset(&msg[0], 0, sizeof(msg)); |
1088 |
sprintf(msg, "drain_loop: setting OUTPUT_BUFFER_EMPTY\n" ); |
1089 |
report( msg ); |
1090 |
*/ |
1091 |
@@ -1321,17 +1358,17 @@ |
1092 |
{ |
1093 |
goto end; |
1094 |
} |
1095 |
- report_verbose("drain_loop: writing not set\n"); |
1096 |
+ report_verbose("drain_loop: writing not set\n"); |
1097 |
} |
1098 |
} |
1099 |
else if (errno != EINTR) |
1100 |
{ |
1101 |
- report("drain_loop: tcdrain bad fd\n"); |
1102 |
+ report("drain_loop: tcdrain bad fd\n"); |
1103 |
goto end; |
1104 |
} |
1105 |
else |
1106 |
{ |
1107 |
- report("drain_loop: received EINTR in tcdrain\n"); |
1108 |
+ report("drain_loop: received EINTR in tcdrain\n"); |
1109 |
} |
1110 |
} |
1111 |
end: |
1112 |
@@ -1344,12 +1381,12 @@ |
1113 |
/*---------------------------------------------------------- |
1114 |
finalize_threads( ) |
1115 |
|
1116 |
- accept: event_info_struct used to access java and communicate with |
1117 |
- eventLoop(). |
1118 |
- perform: see comments |
1119 |
- return: none |
1120 |
- exceptions: none |
1121 |
- comments: |
1122 |
+ accept: event_info_struct used to access java and communicate with |
1123 |
+ eventLoop(). |
1124 |
+ perform: see comments |
1125 |
+ return: none |
1126 |
+ exceptions: none |
1127 |
+ comments: |
1128 |
The is the pthread spawned on systems that can't access the |
1129 |
LSR (Line Status Register). Without access to the LSR rxtx |
1130 |
cannot detect when the output buffer is empty in the Monitor |
1131 |
@@ -1361,14 +1398,14 @@ |
1132 |
----------------------------------------------------------*/ |
1133 |
void finalize_threads( struct event_info_struct *eis ) |
1134 |
{ |
1135 |
-#if !defined(TIOCSERGETLSR) && !defined( WIN32 ) |
1136 |
+#if !defined(TIOCSERGETLSR) && !defined( WIN32 ) |
1137 |
/* used to shut down any remaining write threads */ |
1138 |
|
1139 |
eis->output_buffer_empty_flag = 0; |
1140 |
- ENTER("finalize_threads\n"); |
1141 |
+ report("Entering - finalize_threads\n"); |
1142 |
|
1143 |
/* need to clean up again after working events */ |
1144 |
- LEAVE("---------------- finalize_threads ---------------"); |
1145 |
+ report("Leaving - ---------------- finalize_threads ---------------\n"); |
1146 |
#endif /* TIOCSERGETLSR & !WIN32 */ |
1147 |
} |
1148 |
|
1149 |
@@ -1377,6 +1414,8 @@ |
1150 |
{ |
1151 |
/* |
1152 |
char msg[80]; |
1153 |
+ |
1154 |
+ memset(&msg[0], 0, sizeof(msg)); |
1155 |
sprintf( msg, "RXTX Recieved Signal %i\n", signo ); |
1156 |
report_error( msg ); |
1157 |
*/ |
1158 |
@@ -1386,17 +1425,19 @@ |
1159 |
/*---------------------------------------------------------- |
1160 |
init_threads( ) |
1161 |
|
1162 |
- accept: none |
1163 |
- perform: |
1164 |
- return: none |
1165 |
- exceptions: none |
1166 |
- comments: |
1167 |
- this function is called from the event_loop or in other words |
1168 |
- from the monitor thread. On systems !WIN32 and without TIOCSERGETLSR |
1169 |
- it will create a new thread looping a call to tcdrain. |
1170 |
+ accept: none |
1171 |
+ perform: |
1172 |
+ return: none |
1173 |
+ exceptions: none |
1174 |
+ comments: |
1175 |
+ this function is called from the event_loop or in other |
1176 |
+ words from the monitor thread. On systems !WIN32 and |
1177 |
+ without TIOCSERGETLSR it will create a new thread |
1178 |
+ looping a call to tcdrain. |
1179 |
----------------------------------------------------------*/ |
1180 |
int init_threads( struct event_info_struct *eis ) |
1181 |
{ |
1182 |
+ report("Entering - init_threads\n"); |
1183 |
jfieldID jeis; |
1184 |
#if !defined(TIOCSERGETLSR) & !defined(WIN32) |
1185 |
sigset_t newmask, oldmask; |
1186 |
@@ -1404,7 +1445,7 @@ |
1187 |
pthread_t tid; |
1188 |
|
1189 |
report_time_start( ); |
1190 |
- report("init_threads: start\n"); |
1191 |
+ report("init_threads: start\n"); |
1192 |
/* ignore child thread status changes */ |
1193 |
sigemptyset(&newmask); |
1194 |
sigaddset(&newmask, SIGCHLD); |
1195 |
@@ -1412,14 +1453,17 @@ |
1196 |
/* install our own signal hander */ |
1197 |
newaction.sa_handler = warn_sig_abort; |
1198 |
sigemptyset( &newaction.sa_mask ); |
1199 |
-#ifdef SA_INTERRUPT |
1200 |
- newaction.sa_flags = SA_INTERRUPT; |
1201 |
-#endif /* SA_INTERRUPT */ |
1202 |
-#ifdef SA_RESTART |
1203 |
- /* JOE: do not demand restart! we are handling EINTR */ |
1204 |
-/* newaction.sa_flags = SA_RESTART;*/ |
1205 |
-#endif /* SA_RESTART */ |
1206 |
- |
1207 |
+ #ifdef SA_INTERRUPT |
1208 |
+ newaction.sa_flags = SA_INTERRUPT; |
1209 |
+ #endif /* SA_INTERRUPT */ |
1210 |
+ #ifdef SA_RESTART |
1211 |
+ /* JOE: do not demand restart! we are handling EINTR */ |
1212 |
+ /* newaction.sa_flags = SA_RESTART;*/ |
1213 |
+ #endif /* SA_RESTART */ |
1214 |
+ |
1215 |
+ /** |
1216 |
+ * POSIX SIGABRT behaviour not changed in original code!! |
1217 |
+ **/ |
1218 |
sigaction(SIGABRT, &newaction, &oldaction); |
1219 |
sigaction(SIGCHLD, &newaction, &oldaction); |
1220 |
sigaction(SIGALRM, &newaction, &oldaction); |
1221 |
@@ -1443,23 +1487,25 @@ |
1222 |
pthread_detach( tid ); |
1223 |
eis->drain_tid = tid; |
1224 |
#endif /* TIOCSERGETLSR */ |
1225 |
+ |
1226 |
report("init_threads: get eis\n"); |
1227 |
jeis = (*eis->env)->GetFieldID( eis->env, eis->jclazz, "eis", "J" ); |
1228 |
report("init_threads: set eis\n"); |
1229 |
(*eis->env)->SetLongField(eis->env, *eis->jobj, jeis, ( size_t ) eis ); |
1230 |
- report("init_threads: stop\n"); |
1231 |
+ report("init_threads: stop\n"); |
1232 |
report_time_end( ); |
1233 |
+ report("Leaving - init_threads\n"); |
1234 |
return( 1 ); |
1235 |
} |
1236 |
|
1237 |
/*---------------------------------------------------------- |
1238 |
RXTXPort.writeByte |
1239 |
|
1240 |
- accept: byte to write (passed as int) |
1241 |
- jboolean interrupted (no events if true) |
1242 |
- perform: write a single byte to the port |
1243 |
- return: none |
1244 |
- exceptions: IOException |
1245 |
+ accept: byte to write (passed as int) |
1246 |
+ jboolean interrupted (no events if true) |
1247 |
+ perform: write a single byte to the port |
1248 |
+ return: none |
1249 |
+ exceptions: IOException |
1250 |
----------------------------------------------------------*/ |
1251 |
JNIEXPORT void JNICALL RXTXPort(writeByte)( JNIEnv *env, |
1252 |
jobject jobj, jint ji, jboolean interrupted ) |
1253 |
@@ -1476,8 +1522,9 @@ |
1254 |
#endif /* __sun__ */ |
1255 |
|
1256 |
report_time_start(); |
1257 |
- ENTER( "RXTXPort:writeByte" ); |
1258 |
+ report( "Entering - RXTXPort:writeByte\n" ); |
1259 |
do { |
1260 |
+ memset(&msg[0], 0, sizeof(msg)); |
1261 |
sprintf( msg, "writeByte %c>>\n", byte ); |
1262 |
report( msg ); |
1263 |
result=WRITE (fd, (void * ) &byte, sizeof(unsigned char)); |
1264 |
@@ -1506,12 +1553,14 @@ |
1265 |
index->next ) index = index->next; |
1266 |
} |
1267 |
index->writing = 1; |
1268 |
- report( "writeByte: index->writing = 1" ); |
1269 |
+ report( "writeByte: index->writing = 1\n" ); |
1270 |
} |
1271 |
#endif |
1272 |
+ |
1273 |
+ memset(&msg[0], 0, sizeof(msg)); |
1274 |
sprintf( msg, "RXTXPort:writeByte %i\n", result ); |
1275 |
report( msg ); |
1276 |
- LEAVE( "RXTXPort:writeByte" ); |
1277 |
+ report( "Leaving - RXTXPort:writeByte\n" ); |
1278 |
if(result >= 0) |
1279 |
{ |
1280 |
report_time_end(); |
1281 |
@@ -1525,13 +1574,13 @@ |
1282 |
/*---------------------------------------------------------- |
1283 |
RXTXPort.writeArray |
1284 |
|
1285 |
- accept: jbarray: bytes used for writing |
1286 |
- offset: offset in array to start writing |
1287 |
- count: Number of bytes to write |
1288 |
- jboolean interrupted (no events if true) |
1289 |
- perform: write length bytes of jbarray |
1290 |
- return: none |
1291 |
- exceptions: IOException |
1292 |
+ accept: jbarray: bytes used for writing |
1293 |
+ offset: offset in array to start writing |
1294 |
+ count: Number of bytes to write |
1295 |
+ jboolean interrupted (no events if true) |
1296 |
+ perform: write length bytes of jbarray |
1297 |
+ return: none |
1298 |
+ exceptions: IOException |
1299 |
----------------------------------------------------------*/ |
1300 |
JNIEXPORT void JNICALL RXTXPort(writeArray)( JNIEnv *env, |
1301 |
jobject jobj, jbyteArray jbarray, jint offset, jint count, |
1302 |
@@ -1562,9 +1611,10 @@ |
1303 |
/* return; OH CRAP */ |
1304 |
|
1305 |
report_time_start(); |
1306 |
- ENTER( "writeArray" ); |
1307 |
+ report( "Entering - writeArray\n" ); |
1308 |
/* warning Roy Rogers */ |
1309 |
/* |
1310 |
+ memset(&message[0], 0, sizeof(message)); |
1311 |
sprintf( message, "::::RXTXPort:writeArray(%s);\n", (char *) body ); |
1312 |
report_verbose( message ); |
1313 |
*/ |
1314 |
@@ -1600,7 +1650,7 @@ |
1315 |
index->next ) index = index->next; |
1316 |
} |
1317 |
index->writing = 1; |
1318 |
- report( "writeArray: index->writing = 1" ); |
1319 |
+ report( "writeArray: index->writing = 1\n" ); |
1320 |
} |
1321 |
#endif /* TIOCSERGETLSR */ |
1322 |
/* |
1323 |
@@ -1615,7 +1665,7 @@ |
1324 |
|
1325 |
Things just start spinning out of control after that. |
1326 |
*/ |
1327 |
- LEAVE( "RXTXPort:writeArray" ); |
1328 |
+ report( "Leaving - RXTXPort:writeArray\n" ); |
1329 |
report_time_end(); |
1330 |
fail: |
1331 |
if( result < 0 ) throw_java_exception( env, IO_EXCEPTION, |
1332 |
@@ -1625,15 +1675,14 @@ |
1333 |
/*---------------------------------------------------------- |
1334 |
RXTXPort.nativeDrain |
1335 |
|
1336 |
- accept: jboolean interrupted (no events if true) |
1337 |
- perform: wait until all data is transmitted |
1338 |
- return: none |
1339 |
- exceptions: IOException |
1340 |
- comments: java.io.OutputStream.flush() is equivalent to tcdrain, |
1341 |
- not tcflush, which throws away unsent bytes |
1342 |
- |
1343 |
- count logic added to avoid infinite loops when EINTR is |
1344 |
- true... Thread.yeild() was suggested. |
1345 |
+ accept: jboolean interrupted (no events if true) |
1346 |
+ perform: wait until all data is transmitted |
1347 |
+ return: none |
1348 |
+ exceptions: IOException |
1349 |
+ comments: java.io.OutputStream.flush() is equivalent to tcdrain, |
1350 |
+ not tcflush, which throws away unsent bytes |
1351 |
+ count logic added to avoid infinite loops when EINTR is |
1352 |
+ true... Thread.yeild() was suggested. |
1353 |
----------------------------------------------------------*/ |
1354 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeDrain)( JNIEnv *env, |
1355 |
jobject jobj, jboolean interrupted ) |
1356 |
@@ -1644,7 +1693,7 @@ |
1357 |
|
1358 |
char message[80]; |
1359 |
|
1360 |
- ENTER( "SerialImp.c:drain()" ); |
1361 |
+ report( "Entering - SerialImp.c:drain()\n" ); |
1362 |
report_time_start( ); |
1363 |
do { |
1364 |
report_verbose( "nativeDrain: trying tcdrain\n" ); |
1365 |
@@ -1652,13 +1701,15 @@ |
1366 |
count++; |
1367 |
} while (result && errno==EINTR && count <3); |
1368 |
|
1369 |
+ memset(&message[0], 0, sizeof(message)); |
1370 |
sprintf( message, "RXTXPort:drain() returns: %i\n", result ); |
1371 |
report_verbose( message ); |
1372 |
+ |
1373 |
#if defined(__sun__) |
1374 |
/* FIXME: No time to test on all OS's for production */ |
1375 |
return( JNI_TRUE ); |
1376 |
#endif /* __sun__ */ |
1377 |
- LEAVE( "RXTXPort:drain()" ); |
1378 |
+ report( "Leaving - RXTXPort:drain()\n" ); |
1379 |
if( result ) throw_java_exception( env, IO_EXCEPTION, "nativeDrain", |
1380 |
strerror( errno ) ); |
1381 |
if( interrupted ) return( JNI_FALSE ); |
1382 |
@@ -1669,10 +1720,12 @@ |
1383 |
eis->output_buffer_empty_flag = 0; |
1384 |
} |
1385 |
#endif /* !TIOCSERGETLSR !WIN32 */ |
1386 |
+ |
1387 |
if( eis && eis->eventflags[SPE_OUTPUT_BUFFER_EMPTY] ) |
1388 |
{ |
1389 |
- struct event_info_struct myeis = |
1390 |
+ struct event_info_struct myeis = |
1391 |
build_threadsafe_eis( env, &jobj, eis ); |
1392 |
+ |
1393 |
send_event( &myeis, SPE_OUTPUT_BUFFER_EMPTY, 1 ); |
1394 |
} |
1395 |
report_time_end( ); |
1396 |
@@ -1682,29 +1735,29 @@ |
1397 |
/*---------------------------------------------------------- |
1398 |
RXTXPort.sendBreak |
1399 |
|
1400 |
- accept: duration in milliseconds. |
1401 |
- perform: send break for actual time. not less than 0.25 seconds. |
1402 |
- exceptions: none |
1403 |
- comments: not very precise |
1404 |
+ accept: duration in milliseconds. |
1405 |
+ perform: send break for actual time. not less than 0.25 seconds. |
1406 |
+ exceptions: none |
1407 |
+ comments: not very precise |
1408 |
----------------------------------------------------------*/ |
1409 |
JNIEXPORT void JNICALL RXTXPort(sendBreak)( JNIEnv *env, |
1410 |
jobject jobj, jint duration ) |
1411 |
{ |
1412 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1413 |
report_time_start( ); |
1414 |
- ENTER( "RXTXPort:sendBreak()" ); |
1415 |
+ report( "Entering - RXTXPort:sendBreak()\n" ); |
1416 |
tcsendbreak( fd, (int)( duration / 250 ) ); |
1417 |
report_time_end( ); |
1418 |
- LEAVE( "RXTXPort:sendBreak()" ); |
1419 |
+ report( "Leaving - RXTXPort:sendBreak()\n" ); |
1420 |
} |
1421 |
|
1422 |
/*---------------------------------------------------------- |
1423 |
RXTXPort.NativegetReceiveTimeout |
1424 |
|
1425 |
- accept: none |
1426 |
- perform: get termios.c_cc[VTIME] |
1427 |
- return: VTIME |
1428 |
- comments: see NativeEnableReceiveTimeoutThreshold |
1429 |
+ accept: none |
1430 |
+ perform: get termios.c_cc[VTIME] |
1431 |
+ return: VTIME |
1432 |
+ comments: see NativeEnableReceiveTimeoutThreshold |
1433 |
----------------------------------------------------------*/ |
1434 |
JNIEXPORT jint JNICALL RXTXPort(NativegetReceiveTimeout)( |
1435 |
JNIEnv *env, |
1436 |
@@ -1714,12 +1767,12 @@ |
1437 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1438 |
struct termios ttyset; |
1439 |
|
1440 |
- ENTER( "RXTXPort:nativegetRecieveTimeout()" ); |
1441 |
+ report( "Entering - RXTXPort:nativegetRecieveTimeout()\n" ); |
1442 |
if( tcgetattr( fd, &ttyset ) < 0 ) goto fail; |
1443 |
- LEAVE( "RXTXPort:nativegetRecieveTimeout()" ); |
1444 |
+ report( "Leaving - RXTXPort:nativegetRecieveTimeout()\n" ); |
1445 |
return(ttyset.c_cc[ VTIME ] * 100); |
1446 |
fail: |
1447 |
- LEAVE( "RXTXPort:nativegetRecieveTimeout()" ); |
1448 |
+ report( "Leaving - RXTXPort:nativegetRecieveTimeout()\n" ); |
1449 |
throw_java_exception( env, IO_EXCEPTION, "getReceiveTimeout", |
1450 |
strerror( errno ) ); |
1451 |
return -1; |
1452 |
@@ -1728,10 +1781,10 @@ |
1453 |
/*---------------------------------------------------------- |
1454 |
RXTXPort.NativeisReceiveTimeoutEnabled |
1455 |
|
1456 |
- accept: none |
1457 |
- perform: determine if VTIME is none 0 |
1458 |
- return: JNI_TRUE if VTIME > 0 else JNI_FALSE |
1459 |
- comments: see NativeEnableReceiveTimeoutThreshold |
1460 |
+ accept: none |
1461 |
+ perform: determine if VTIME is none 0 |
1462 |
+ return: JNI_TRUE if VTIME > 0 else JNI_FALSE |
1463 |
+ comments: see NativeEnableReceiveTimeoutThreshold |
1464 |
----------------------------------------------------------*/ |
1465 |
JNIEXPORT jboolean JNICALL RXTXPort(NativeisReceiveTimeoutEnabled)( |
1466 |
JNIEnv *env, |
1467 |
@@ -1740,12 +1793,12 @@ |
1468 |
{ |
1469 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1470 |
struct termios ttyset; |
1471 |
- ENTER( "RXTXPort:NativeisRecieveTimeoutEnabled()" ); |
1472 |
+ report( "Entering - RXTXPort:NativeisRecieveTimeoutEnabled()\n" ); |
1473 |
if( tcgetattr( fd, &ttyset ) < 0 ) goto fail; |
1474 |
- LEAVE( "RXTXPort:NativeisRecieveTimeoutEnabled()" ); |
1475 |
+ report( "Leaving - RXTXPort:NativeisRecieveTimeoutEnabled()\n" ); |
1476 |
return(ttyset.c_cc[ VTIME ] > 0 ? JNI_TRUE:JNI_FALSE); |
1477 |
fail: |
1478 |
- LEAVE( "RXTXPort:NativeisRecieveTimeoutEnabled()" ); |
1479 |
+ report( "Leaving - RXTXPort:NativeisRecieveTimeoutEnabled()\n" ); |
1480 |
throw_java_exception( env, IO_EXCEPTION, "isReceiveTimeoutEnabled", |
1481 |
strerror( errno ) ); |
1482 |
return JNI_FALSE; |
1483 |
@@ -1754,12 +1807,12 @@ |
1484 |
/*---------------------------------------------------------- |
1485 |
RXTXPort.isDSR |
1486 |
|
1487 |
- accept: none |
1488 |
- perform: check status of DSR |
1489 |
- return: true if TIOCM_DSR is set |
1490 |
- false if TIOCM_DSR is not set |
1491 |
- exceptions: none |
1492 |
- comments: DSR stands for Data Set Ready |
1493 |
+ accept: none |
1494 |
+ perform: check status of DSR |
1495 |
+ return: true if TIOCM_DSR is set |
1496 |
+ false if TIOCM_DSR is not set |
1497 |
+ exceptions: none |
1498 |
+ comments: DSR stands for Data Set Ready |
1499 |
----------------------------------------------------------*/ |
1500 |
JNIEXPORT jboolean JNICALL RXTXPort(isDSR)( JNIEnv *env, |
1501 |
jobject jobj ) |
1502 |
@@ -1768,11 +1821,13 @@ |
1503 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1504 |
char message[80]; |
1505 |
|
1506 |
- ENTER( "RXTXPort:isDSR" ); |
1507 |
+ report( "Entering - RXTXPort:isDSR\n" ); |
1508 |
ioctl( fd, TIOCMGET, &result ); |
1509 |
+ |
1510 |
+ memset(&message[0], 0, sizeof(message)); |
1511 |
sprintf( message, "RXTXPort:isDSR returns %i\n", result & TIOCM_DSR ); |
1512 |
report( message ); |
1513 |
- LEAVE( "RXTXPort:isDSR" ); |
1514 |
+ report( "Leaving - RXTXPort:isDSR\n" ); |
1515 |
if( result & TIOCM_DSR ) return JNI_TRUE; |
1516 |
else return JNI_FALSE; |
1517 |
} |
1518 |
@@ -1780,15 +1835,15 @@ |
1519 |
/*---------------------------------------------------------- |
1520 |
RXTXPort.isCD |
1521 |
|
1522 |
- accept: none |
1523 |
- perform: check status of CD |
1524 |
- return: true if TIOCM_CD is set |
1525 |
- false if TIOCM_CD is not set |
1526 |
- exceptions: none |
1527 |
- comments: CD stands for Carrier Detect |
1528 |
- The following comment has been made... |
1529 |
- "well, it works, there might ofcourse be a bug, but making DCD |
1530 |
- permanently on fixed it for me so I don't care" |
1531 |
+ accept: none |
1532 |
+ perform: check status of CD |
1533 |
+ return: true if TIOCM_CD is set |
1534 |
+ false if TIOCM_CD is not set |
1535 |
+ exceptions: none |
1536 |
+ comments: CD stands for Carrier Detect |
1537 |
+ The following comment has been made... |
1538 |
+ "well, it works, there might ofcourse be a bug, but making DCD |
1539 |
+ permanently on fixed it for me so I don't care" |
1540 |
|
1541 |
----------------------------------------------------------*/ |
1542 |
JNIEXPORT jboolean JNICALL RXTXPort(isCD)( JNIEnv *env, |
1543 |
@@ -1798,10 +1853,12 @@ |
1544 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1545 |
char message[80]; |
1546 |
|
1547 |
- ENTER( "RXTXPort:isCD" ); |
1548 |
+ report( "Entering - RXTXPort:isCD\n" ); |
1549 |
ioctl( fd, TIOCMGET, &result ); |
1550 |
+ |
1551 |
+ memset(&message[0], 0, sizeof(message)); |
1552 |
sprintf( message, "RXTXPort:isCD returns %i\n", result & TIOCM_CD ); |
1553 |
- LEAVE( "RXTXPort:isCD" ); |
1554 |
+ report( "Leaving - RXTXPort:isCD\n" ); |
1555 |
if( result & TIOCM_CD ) return JNI_TRUE; |
1556 |
else return JNI_FALSE; |
1557 |
} |
1558 |
@@ -1809,12 +1866,12 @@ |
1559 |
/*---------------------------------------------------------- |
1560 |
RXTXPort.isCTS |
1561 |
|
1562 |
- accept: none |
1563 |
- perform: check status of CTS |
1564 |
- return: true if TIOCM_CTS is set |
1565 |
- false if TIOCM_CTS is not set |
1566 |
- exceptions: none |
1567 |
- comments: CTS stands for Clear To Send. |
1568 |
+ accept: none |
1569 |
+ perform: check status of CTS |
1570 |
+ return: true if TIOCM_CTS is set |
1571 |
+ false if TIOCM_CTS is not set |
1572 |
+ exceptions: none |
1573 |
+ comments: CTS stands for Clear To Send. |
1574 |
----------------------------------------------------------*/ |
1575 |
JNIEXPORT jboolean JNICALL RXTXPort(isCTS)( JNIEnv *env, |
1576 |
jobject jobj ) |
1577 |
@@ -1823,11 +1880,13 @@ |
1578 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1579 |
char message[80]; |
1580 |
|
1581 |
- ENTER( "RXTXPort:isCTS" ); |
1582 |
+ report( "Entering - RXTXPort:isCTS\n" ); |
1583 |
ioctl( fd, TIOCMGET, &result ); |
1584 |
+ |
1585 |
+ memset(&message[0], 0, sizeof(message)); |
1586 |
sprintf( message, "RXTXPort:isCTS returns %i\n", result & TIOCM_CTS ); |
1587 |
report( message ); |
1588 |
- LEAVE( "RXTXPort:isCTS" ); |
1589 |
+ report( "Leaving - RXTXPort:isCTS\n" ); |
1590 |
if( result & TIOCM_CTS ) return JNI_TRUE; |
1591 |
else return JNI_FALSE; |
1592 |
} |
1593 |
@@ -1835,12 +1894,12 @@ |
1594 |
/*---------------------------------------------------------- |
1595 |
RXTXPort.isRI |
1596 |
|
1597 |
- accept: none |
1598 |
- perform: check status of RI |
1599 |
- return: true if TIOCM_RI is set |
1600 |
- false if TIOCM_RI is not set |
1601 |
- exceptions: none |
1602 |
- comments: RI stands for Ring Indicator |
1603 |
+ accept: none |
1604 |
+ perform: check status of RI |
1605 |
+ return: true if TIOCM_RI is set |
1606 |
+ false if TIOCM_RI is not set |
1607 |
+ exceptions: none |
1608 |
+ comments: RI stands for Ring Indicator |
1609 |
----------------------------------------------------------*/ |
1610 |
JNIEXPORT jboolean JNICALL RXTXPort(isRI)( JNIEnv *env, |
1611 |
jobject jobj ) |
1612 |
@@ -1849,11 +1908,13 @@ |
1613 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1614 |
char message[80]; |
1615 |
|
1616 |
- ENTER( "RXTXPort:isRI" ); |
1617 |
+ report( "Entering - RXTXPort:isRI\n" ); |
1618 |
ioctl( fd, TIOCMGET, &result ); |
1619 |
+ |
1620 |
+ memset(&message[0], 0, sizeof(message)); |
1621 |
sprintf( message, "RXTXPort:isRI returns %i\n", result & TIOCM_RI ); |
1622 |
report( message ); |
1623 |
- LEAVE( "RXTXPort:isRI" ); |
1624 |
+ report( "Leaving - RXTXPort:isRI\n" ); |
1625 |
if( result & TIOCM_RI ) return JNI_TRUE; |
1626 |
else return JNI_FALSE; |
1627 |
} |
1628 |
@@ -1861,12 +1922,12 @@ |
1629 |
/*---------------------------------------------------------- |
1630 |
RXTXPort.isRTS |
1631 |
|
1632 |
- accept: none |
1633 |
- perform: check status of RTS |
1634 |
- return: true if TIOCM_RTS is set |
1635 |
- false if TIOCM_RTS is not set |
1636 |
- exceptions: none |
1637 |
- comments: tcgetattr with c_cflag CRTS_IFLOW |
1638 |
+ accept: none |
1639 |
+ perform: check status of RTS |
1640 |
+ return: true if TIOCM_RTS is set |
1641 |
+ false if TIOCM_RTS is not set |
1642 |
+ exceptions: none |
1643 |
+ comments: tcgetattr with c_cflag CRTS_IFLOW |
1644 |
----------------------------------------------------------*/ |
1645 |
JNIEXPORT jboolean JNICALL RXTXPort(isRTS)( JNIEnv *env, |
1646 |
jobject jobj ) |
1647 |
@@ -1875,11 +1936,13 @@ |
1648 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1649 |
char message[80]; |
1650 |
|
1651 |
- ENTER( "RXTXPort:isRTS" ); |
1652 |
+ report( "Entering - RXTXPort:isRTS\n" ); |
1653 |
ioctl( fd, TIOCMGET, &result ); |
1654 |
+ |
1655 |
+ memset(&message[0], 0, sizeof(message)); |
1656 |
sprintf( message, "RXTXPort:isRTS returns %i\n", result & TIOCM_RTS ); |
1657 |
report( message ); |
1658 |
- LEAVE( "RXTXPort:isRTS" ); |
1659 |
+ report( "Leaving - RXTXPort:isRTS\n" ); |
1660 |
if( result & TIOCM_RTS ) return JNI_TRUE; |
1661 |
else return JNI_FALSE; |
1662 |
} |
1663 |
@@ -1887,13 +1950,13 @@ |
1664 |
/*---------------------------------------------------------- |
1665 |
RXTXPort.setRTS |
1666 |
|
1667 |
- accept: state flag to set/unset. |
1668 |
- perform: depends on the state flag |
1669 |
- if true TIOCM_RTS is set |
1670 |
- if false TIOCM_RTS is unset |
1671 |
- return: none |
1672 |
- exceptions: none |
1673 |
- comments: tcsetattr with c_cflag CRTS_IFLOW |
1674 |
+ accept: state flag to set/unset. |
1675 |
+ perform: depends on the state flag |
1676 |
+ if true TIOCM_RTS is set |
1677 |
+ if false TIOCM_RTS is unset |
1678 |
+ return: none |
1679 |
+ exceptions: none |
1680 |
+ comments: tcsetattr with c_cflag CRTS_IFLOW |
1681 |
----------------------------------------------------------*/ |
1682 |
JNIEXPORT void JNICALL RXTXPort(setRTS)( JNIEnv *env, |
1683 |
jobject jobj, jboolean state ) |
1684 |
@@ -1902,27 +1965,29 @@ |
1685 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1686 |
char message[80]; |
1687 |
|
1688 |
- ENTER( "RXTXPort:setRTS" ); |
1689 |
+ report( "Entering - RXTXPort:setRTS\n" ); |
1690 |
ioctl( fd, TIOCMGET, &result ); |
1691 |
if( state == JNI_TRUE ) result |= TIOCM_RTS; |
1692 |
else result &= ~TIOCM_RTS; |
1693 |
ioctl( fd, TIOCMSET, &result ); |
1694 |
+ |
1695 |
+ memset(&message[0], 0, sizeof(message)); |
1696 |
sprintf( message, "setRTS( %i )\n", state ); |
1697 |
report( message ); |
1698 |
- LEAVE( "RXTXPort:setRTS" ); |
1699 |
+ report( "Leaving - RXTXPort:setRTS\n" ); |
1700 |
return; |
1701 |
} |
1702 |
|
1703 |
/*---------------------------------------------------------- |
1704 |
RXTXPort.setDSR |
1705 |
|
1706 |
- accept: state flag to set/unset. |
1707 |
- perform: depends on the state flag |
1708 |
- if true TIOCM_DSR is set |
1709 |
- if false TIOCM_DSR is unset |
1710 |
- return: none |
1711 |
- exceptions: none |
1712 |
- comments: tcsetattr with c_cflag CRTS_IFLOW |
1713 |
+ accept: state flag to set/unset. |
1714 |
+ perform: depends on the state flag |
1715 |
+ if true TIOCM_DSR is set |
1716 |
+ if false TIOCM_DSR is unset |
1717 |
+ return: none |
1718 |
+ exceptions: none |
1719 |
+ comments: tcsetattr with c_cflag CRTS_IFLOW |
1720 |
----------------------------------------------------------*/ |
1721 |
JNIEXPORT void JNICALL RXTXPort(setDSR)( JNIEnv *env, |
1722 |
jobject jobj, jboolean state ) |
1723 |
@@ -1931,28 +1996,31 @@ |
1724 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1725 |
char message[80]; |
1726 |
|
1727 |
- ENTER( "RXTXPort:setDSR()" ); |
1728 |
+ report( "Entering - RXTXPort:setDSR()\n" ); |
1729 |
ioctl( fd, TIOCMGET, &result ); |
1730 |
|
1731 |
+ memset(&message[0], 0, sizeof(message)); |
1732 |
sprintf( message, "setDSR( %i )\n", state ); |
1733 |
if( state == JNI_TRUE ) result |= TIOCM_DSR; |
1734 |
else result &= ~TIOCM_DSR; |
1735 |
ioctl( fd, TIOCMSET, &result ); |
1736 |
+ |
1737 |
+ memset(&message[0], 0, sizeof(message)); |
1738 |
sprintf( message, "setDSR( %i )\n", state ); |
1739 |
report( message ); |
1740 |
- LEAVE( "RXTXPort:setDSR()" ); |
1741 |
+ report( "Leaving - RXTXPort:setDSR()\n" ); |
1742 |
return; |
1743 |
} |
1744 |
|
1745 |
/*---------------------------------------------------------- |
1746 |
RXTXPort.isDTR |
1747 |
|
1748 |
- accept: none |
1749 |
- perform: check status of DTR |
1750 |
- return: true if TIOCM_DTR is set |
1751 |
- false if TIOCM_DTR is not set |
1752 |
- exceptions: none |
1753 |
- comments: DTR stands for Data Terminal Ready |
1754 |
+ accept: none |
1755 |
+ perform: check status of DTR |
1756 |
+ return: true if TIOCM_DTR is set |
1757 |
+ false if TIOCM_DTR is not set |
1758 |
+ exceptions: none |
1759 |
+ comments: DTR stands for Data Terminal Ready |
1760 |
----------------------------------------------------------*/ |
1761 |
JNIEXPORT jboolean JNICALL RXTXPort(isDTR)( JNIEnv *env, |
1762 |
jobject jobj ) |
1763 |
@@ -1961,11 +2029,13 @@ |
1764 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1765 |
char message[80]; |
1766 |
|
1767 |
- ENTER( "RXTXPort:isDTR" ); |
1768 |
+ report( "Entering - RXTXPort:isDTR\n" ); |
1769 |
ioctl( fd, TIOCMGET, &result ); |
1770 |
+ |
1771 |
+ memset(&message[0], 0, sizeof(message)); |
1772 |
sprintf( message, "isDTR( ) returns %i\n", result& TIOCM_DTR ); |
1773 |
report( message ); |
1774 |
- LEAVE( "RXTXPort:isDTR" ); |
1775 |
+ report( "Leaving - RXTXPort:isDTR\n" ); |
1776 |
if( result & TIOCM_DTR ) return JNI_TRUE; |
1777 |
else return JNI_FALSE; |
1778 |
} |
1779 |
@@ -1973,12 +2043,12 @@ |
1780 |
/*---------------------------------------------------------- |
1781 |
RXTXPort.setDTR |
1782 |
|
1783 |
- accept: new DTR state |
1784 |
- perform: if state is true, TIOCM_DTR is set |
1785 |
- if state is false, TIOCM_DTR is unset |
1786 |
- return: none |
1787 |
- exceptions: none |
1788 |
- comments: DTR stands for Data Terminal Ready |
1789 |
+ accept: new DTR state |
1790 |
+ perform: if state is true, TIOCM_DTR is set |
1791 |
+ if state is false, TIOCM_DTR is unset |
1792 |
+ return: none |
1793 |
+ exceptions: none |
1794 |
+ comments: DTR stands for Data Terminal Ready |
1795 |
----------------------------------------------------------*/ |
1796 |
JNIEXPORT void JNICALL RXTXPort(setDTR)( JNIEnv *env, |
1797 |
jobject jobj, jboolean state ) |
1798 |
@@ -1987,32 +2057,35 @@ |
1799 |
int fd = get_java_var( env, jobj,"fd","I" ); |
1800 |
char message[80]; |
1801 |
|
1802 |
- ENTER( "RXTXPort:setDTR" ); |
1803 |
+ report( "Entering - RXTXPort:setDTR\n" ); |
1804 |
ioctl( fd, TIOCMGET, &result ); |
1805 |
if( state == JNI_TRUE ) result |= TIOCM_DTR; |
1806 |
else result &= ~TIOCM_DTR; |
1807 |
ioctl( fd, TIOCMSET, &result ); |
1808 |
+ |
1809 |
+ memset(&message[0], 0, sizeof(message)); |
1810 |
sprintf( message, "setDTR( %i )\n", state ); |
1811 |
report( message ); |
1812 |
- LEAVE( "RXTXPort:setDTR" ); |
1813 |
+ report( "Leaving - RXTXPort:setDTR\n" ); |
1814 |
return; |
1815 |
} |
1816 |
/*---------------------------------------------------------- |
1817 |
RXTXPort.static_add_filename |
1818 |
|
1819 |
- accept: filename and fd to save |
1820 |
- perform: add a struct holding the info to a linked list |
1821 |
- return: none |
1822 |
- exceptions: none |
1823 |
- comments: the info is checked on open() if its in the list no |
1824 |
- changes are performed on the file on open() |
1825 |
- |
1826 |
- comments: see |
1827 |
- RXTXPort.nativeStaticSetDSR |
1828 |
- RXTXPort.nativeStaticSetDTR |
1829 |
- RXTXPort.nativeStaticSetRTS |
1830 |
- RXTXPort.nativeStaticSetSerialPortParams |
1831 |
- This is used so people can setDTR low before calling the |
1832 |
+ accept: filename and fd to save |
1833 |
+ perform: add a struct holding the info to a linked list |
1834 |
+ return: none |
1835 |
+ exceptions: none |
1836 |
+ comments: the info is checked on open() if its in the list no |
1837 |
+ changes are performed on the file on open() |
1838 |
+ |
1839 |
+ comments: see |
1840 |
+ RXTXPort.nativeStaticSetDSR |
1841 |
+ RXTXPort.nativeStaticSetDTR |
1842 |
+ RXTXPort.nativeStaticSetRTS |
1843 |
+ RXTXPort.nativeStaticSetSerialPortParams |
1844 |
+ |
1845 |
+ This is used so people can setDTR low before calling the |
1846 |
-----------------------------------------------------------*/ |
1847 |
|
1848 |
void static_add_filename( const char *filename, int fd) |
1849 |
@@ -2055,14 +2128,14 @@ |
1850 |
/*---------------------------------------------------------- |
1851 |
RXTXPort.nativeSetBaudBase |
1852 |
|
1853 |
- accept: The Baud Base for custom speeds |
1854 |
- perform: set the Baud Base |
1855 |
- return: 0 on success |
1856 |
- exceptions: Unsupported Comm Operation on systems not supporting |
1857 |
- TIOCGSERIAL |
1858 |
- comments: |
1859 |
- Set baud rate to 38400 before using this |
1860 |
- First introduced in rxtx-2.1-3 |
1861 |
+ accept: The Baud Base for custom speeds |
1862 |
+ perform: set the Baud Base |
1863 |
+ return: 0 on success |
1864 |
+ exceptions: Unsupported Comm Operation on systems not supporting |
1865 |
+ TIOCGSERIAL |
1866 |
+ comments: |
1867 |
+ Set baud rate to 38400 before using this |
1868 |
+ First introduced in rxtx-2.1-3 |
1869 |
----------------------------------------------------------*/ |
1870 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeSetBaudBase)( |
1871 |
JNIEnv *env, |
1872 |
@@ -2103,13 +2176,13 @@ |
1873 |
/*---------------------------------------------------------- |
1874 |
RXTXPort.nativeGetBaudBase |
1875 |
|
1876 |
- accept: the Baud Base used for custom speeds |
1877 |
- perform: |
1878 |
- return: Baud Base |
1879 |
- exceptions: Unsupported Comm Operation on systems not supporting |
1880 |
- TIOCGSERIAL |
1881 |
- comments: |
1882 |
- First introduced in rxtx-2.1-3 |
1883 |
+ accept: the Baud Base used for custom speeds |
1884 |
+ perform: |
1885 |
+ return: Baud Base |
1886 |
+ exceptions: Unsupported Comm Operation on systems not supporting |
1887 |
+ TIOCGSERIAL |
1888 |
+ comments: |
1889 |
+ First introduced in rxtx-2.1-3 |
1890 |
----------------------------------------------------------*/ |
1891 |
JNIEXPORT jint JNICALL RXTXPort(nativeGetBaudBase)( |
1892 |
JNIEnv *env, |
1893 |
@@ -2141,14 +2214,14 @@ |
1894 |
/*---------------------------------------------------------- |
1895 |
RXTXPort.nativeSetDivisor |
1896 |
|
1897 |
- accept: Divisor for custom speeds |
1898 |
- perform: set the Divisor for custom speeds |
1899 |
- return: 0 on success |
1900 |
- exceptions: Unsupported Comm Operation on systems not supporting |
1901 |
- TIOCGSERIAL |
1902 |
- comments: |
1903 |
- Set baud rate to 38400 before using this |
1904 |
- First introduced in rxtx-2.1-3 |
1905 |
+ accept: Divisor for custom speeds |
1906 |
+ perform: set the Divisor for custom speeds |
1907 |
+ return: 0 on success |
1908 |
+ exceptions: Unsupported Comm Operation on systems not supporting |
1909 |
+ TIOCGSERIAL |
1910 |
+ comments: |
1911 |
+ Set baud rate to 38400 before using this |
1912 |
+ First introduced in rxtx-2.1-3 |
1913 |
----------------------------------------------------------*/ |
1914 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeSetDivisor)( |
1915 |
JNIEnv *env, |
1916 |
@@ -2187,13 +2260,13 @@ |
1917 |
/*---------------------------------------------------------- |
1918 |
RXTXPort.nativeGetDivisor |
1919 |
|
1920 |
- accept: none |
1921 |
- perform: Find the Divisor used for custom speeds |
1922 |
- return: Divisor negative value on error. |
1923 |
- exceptions: Unsupported Comm Operation on systems not supporting |
1924 |
- TIOCGSERIAL |
1925 |
- comments: |
1926 |
- First introduced in rxtx-2.1-3 |
1927 |
+ accept: none |
1928 |
+ perform: Find the Divisor used for custom speeds |
1929 |
+ return: Divisor negative value on error. |
1930 |
+ exceptions: Unsupported Comm Operation on systems not supporting |
1931 |
+ TIOCGSERIAL |
1932 |
+ comments: |
1933 |
+ First introduced in rxtx-2.1-3 |
1934 |
----------------------------------------------------------*/ |
1935 |
JNIEXPORT jint JNICALL RXTXPort(nativeGetDivisor)( |
1936 |
JNIEnv *env, |
1937 |
@@ -2226,18 +2299,18 @@ |
1938 |
/*---------------------------------------------------------- |
1939 |
RXTXPort.nativeStaticSetDSR |
1940 |
|
1941 |
- accept: new RTS state |
1942 |
- perform: if flag is true, TIOCM_DSR is set |
1943 |
- if flag is false, TIOCM_DSR is unset |
1944 |
- return: none |
1945 |
- exceptions: none |
1946 |
- comments: Set the DSR so it does not raise on the next open |
1947 |
- needed for some funky test boards? |
1948 |
+ accept: new RTS state |
1949 |
+ perform: if flag is true, TIOCM_DSR is set |
1950 |
+ if flag is false, TIOCM_DSR is unset |
1951 |
+ return: none |
1952 |
+ exceptions: none |
1953 |
+ comments: Set the DSR so it does not raise on the next open |
1954 |
+ needed for some funky test boards? |
1955 |
|
1956 |
- This is static so we can not call the open() setDSR() |
1957 |
- we dont have the jobject. |
1958 |
+ This is static so we can not call the open() setDSR() |
1959 |
+ we dont have the jobject. |
1960 |
|
1961 |
- First introduced in rxtx-1.5-9 |
1962 |
+ First introduced in rxtx-1.5-9 |
1963 |
----------------------------------------------------------*/ |
1964 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticSetDSR) (JNIEnv *env, |
1965 |
jclass jclazz, jstring jstr, jboolean flag) |
1966 |
@@ -2247,7 +2320,7 @@ |
1967 |
int result; |
1968 |
const char *filename = (*env)->GetStringUTFChars( env, jstr, 0 ); |
1969 |
|
1970 |
- ENTER( "RXTXPort:nativeStaticSetDSR" ); |
1971 |
+ report( "Entering - RXTXPort:nativeStaticSetDSR\n" ); |
1972 |
#ifndef WIN32 |
1973 |
pid = getpid(); |
1974 |
#endif /* WIN32 */ |
1975 |
@@ -2281,29 +2354,29 @@ |
1976 |
|
1977 |
/* dont close the port. Its not clear if the DSR would remain high */ |
1978 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
1979 |
- LEAVE( "RXTXPort:nativeStaticSetDSR" ); |
1980 |
+ report( "Leaving - RXTXPort:nativeStaticSetDSR\n" ); |
1981 |
return( JNI_TRUE ); |
1982 |
fail: |
1983 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
1984 |
- LEAVE( "RXTXPort:nativeStaticSetDSR" ); |
1985 |
+ report( "Leaving - RXTXPort:nativeStaticSetDSR\n" ); |
1986 |
return( JNI_FALSE ); |
1987 |
} |
1988 |
|
1989 |
/*---------------------------------------------------------- |
1990 |
RXTXPort.nativeStaticSetRTS |
1991 |
|
1992 |
- accept: new RTS state |
1993 |
- perform: if flag is true, TIOCM_RTS is set |
1994 |
- if flag is false, TIOCM_RTS is unset |
1995 |
- return: none |
1996 |
- exceptions: none |
1997 |
- comments: Set the RTS so it does not raise on the next open |
1998 |
- needed for some funky test boards? |
1999 |
- |
2000 |
- This is static so we can not call the open() setDTR() |
2001 |
- we dont have the jobject. |
2002 |
- |
2003 |
- First introduced in rxtx-1.5-9 |
2004 |
+ accept: new RTS state |
2005 |
+ perform: if flag is true, TIOCM_RTS is set |
2006 |
+ if flag is false, TIOCM_RTS is unset |
2007 |
+ return: none |
2008 |
+ exceptions: none |
2009 |
+ comments: Set the RTS so it does not raise on the next open |
2010 |
+ needed for some funky test boards? |
2011 |
+ |
2012 |
+ This is static so we can not call the open() setDTR() |
2013 |
+ we dont have the jobject. |
2014 |
+ |
2015 |
+ First introduced in rxtx-1.5-9 |
2016 |
----------------------------------------------------------*/ |
2017 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticSetRTS) (JNIEnv *env, |
2018 |
jclass jclazz, jstring jstr, jboolean flag) |
2019 |
@@ -2313,7 +2386,7 @@ |
2020 |
int result; |
2021 |
const char *filename = (*env)->GetStringUTFChars( env, jstr, 0 ); |
2022 |
|
2023 |
- ENTER( "RXTXPort:nativeStaticSetRTS" ); |
2024 |
+ report( "Entering - RXTXPort:nativeStaticSetRTS\n" ); |
2025 |
#ifndef WIN32 |
2026 |
pid = getpid(); |
2027 |
#endif /* WIN32 */ |
2028 |
@@ -2347,29 +2420,29 @@ |
2029 |
|
2030 |
/* dont close the port. Its not clear if the RTS would remain high */ |
2031 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2032 |
- LEAVE( "RXTXPort:nativeStaticSetRTS" ); |
2033 |
+ report( "Leaving - RXTXPort:nativeStaticSetRTS\n" ); |
2034 |
return( JNI_TRUE ); |
2035 |
fail: |
2036 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2037 |
- LEAVE( "RXTXPort:nativeStaticSetRTS" ); |
2038 |
+ report( "Leaving - RXTXPort:nativeStaticSetRTS\n" ); |
2039 |
return( JNI_FALSE ); |
2040 |
} |
2041 |
|
2042 |
/*---------------------------------------------------------- |
2043 |
RXTXPort.nativeStaticSetSerialPortParams |
2044 |
|
2045 |
- accept: string for the filename, int baudrate, int databits, |
2046 |
- int stopbits, int parity |
2047 |
- perform: set the serial port, set the params, save the fd in a linked |
2048 |
+ accept: string for the filename, int baudrate, int databits, |
2049 |
+ int stopbits, int parity |
2050 |
+ perform: set the serial port, set the params, save the fd in a linked |
2051 |
list. |
2052 |
- return: none |
2053 |
- exceptions: none |
2054 |
- comments: Not set the speed on the next 'open' |
2055 |
+ return: none |
2056 |
+ exceptions: none |
2057 |
+ comments: Not set the speed on the next 'open' |
2058 |
|
2059 |
- This is static so we can not call the open() setDTR() |
2060 |
- we dont have the jobject. |
2061 |
+ This is static so we can not call the open() setDTR() |
2062 |
+ we dont have the jobject. |
2063 |
|
2064 |
- First introduced in rxtx-1.5-9 |
2065 |
+ First introduced in rxtx-1.5-9 |
2066 |
----------------------------------------------------------*/ |
2067 |
JNIEXPORT void JNICALL RXTXPort(nativeStaticSetSerialPortParams) (JNIEnv *env, |
2068 |
jclass jclazz, jstring jstr, jint baudrate, jint dataBits, jint stopBits, jint parity ) |
2069 |
@@ -2380,7 +2453,7 @@ |
2070 |
int cspeed = translate_speed( env, baudrate ); |
2071 |
|
2072 |
|
2073 |
- ENTER( "RXTXPort:nativeStaticSetSerialPortParams" ); |
2074 |
+ report( "Entering - RXTXPort:nativeStaticSetSerialPortParams\n" ); |
2075 |
#ifndef WIN32 |
2076 |
pid = getpid(); |
2077 |
#endif /* WIN32 */ |
2078 |
@@ -2400,7 +2473,7 @@ |
2079 |
if ( fd < 0 ) |
2080 |
{ |
2081 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2082 |
- LEAVE( "RXTXPort:nativeStaticSetSerialPortParams" ); |
2083 |
+ report( "Leaving - RXTXPort:nativeStaticSetSerialPortParams\n" ); |
2084 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
2085 |
"nativeStaticSetSerialPortParams", strerror( errno ) ); |
2086 |
return; |
2087 |
@@ -2410,14 +2483,14 @@ |
2088 |
{ |
2089 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2090 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
2091 |
- "", "BaudRate could not be set to the specified value" ); |
2092 |
+ "", "BaudRate could not be set to the specified value\n" ); |
2093 |
return; |
2094 |
} |
2095 |
|
2096 |
if( set_port_params( env, fd, cspeed, dataBits, stopBits, parity ) ) |
2097 |
{ |
2098 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2099 |
- LEAVE( "RXTXPort:nativeStatic SetSerialPortParams" ); |
2100 |
+ report( "Leaving - RXTXPort:nativeStatic SetSerialPortParams\n" ); |
2101 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
2102 |
"nativeStaticSetSerialPortParams", strerror( errno ) ); |
2103 |
return; |
2104 |
@@ -2431,29 +2504,29 @@ |
2105 |
/* dont close the port. */ |
2106 |
|
2107 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2108 |
- LEAVE( "RXTXPort:nativeStaticSetSerialPortParams" ); |
2109 |
+ report( "Leaving - RXTXPort:nativeStaticSetSerialPortParams\n" ); |
2110 |
return; |
2111 |
fail: |
2112 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2113 |
- LEAVE( "RXTXPort:nativeStaticSetSerialPortParams" ); |
2114 |
+ report( "Leaving - RXTXPort:nativeStaticSetSerialPortParams\n" ); |
2115 |
return; |
2116 |
} |
2117 |
|
2118 |
/*---------------------------------------------------------- |
2119 |
RXTXPort.nativeStaticSetDTR |
2120 |
|
2121 |
- accept: new DTR state |
2122 |
- perform: if flag is true, TIOCM_DTR is set |
2123 |
- if flag is false, TIOCM_DTR is unset |
2124 |
- return: none |
2125 |
- exceptions: none |
2126 |
- comments: Set the DTR so it does not raise on the next open |
2127 |
- needed for some funky test boards? |
2128 |
- |
2129 |
- This is static so we can not call the open() setDTR() |
2130 |
- we dont have the jobject. |
2131 |
- |
2132 |
- First introduced in rxtx-1.5-9 |
2133 |
+ accept: new DTR state |
2134 |
+ perform: if flag is true, TIOCM_DTR is set |
2135 |
+ if flag is false, TIOCM_DTR is unset |
2136 |
+ return: none |
2137 |
+ exceptions: none |
2138 |
+ comments: Set the DTR so it does not raise on the next open |
2139 |
+ needed for some funky test boards? |
2140 |
+ |
2141 |
+ This is static so we can not call the open() setDTR() |
2142 |
+ we dont have the jobject. |
2143 |
+ |
2144 |
+ First introduced in rxtx-1.5-9 |
2145 |
----------------------------------------------------------*/ |
2146 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticSetDTR) (JNIEnv *env, |
2147 |
jclass jclazz, jstring jstr, jboolean flag) |
2148 |
@@ -2463,7 +2536,7 @@ |
2149 |
const char *filename = (*env)->GetStringUTFChars( env, jstr, 0 ); |
2150 |
int result; |
2151 |
|
2152 |
- ENTER( "RXTXPort:nativeStaticSetDTR" ); |
2153 |
+ report( "Entering - RXTXPort:nativeStaticSetDTR\n" ); |
2154 |
#ifndef WIN32 |
2155 |
pid = getpid(); |
2156 |
#endif /* WIN32 */ |
2157 |
@@ -2497,24 +2570,24 @@ |
2158 |
/* dont close the port. Its not clear if the DTR would remain high */ |
2159 |
|
2160 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2161 |
- LEAVE( "RXTXPort:nativeStaticSetDTR" ); |
2162 |
+ report( "Leaving - RXTXPort:nativeStaticSetDTR\n" ); |
2163 |
return( JNI_TRUE ); |
2164 |
fail: |
2165 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2166 |
- LEAVE( "RXTXPort:nativeStaticSetDTR" ); |
2167 |
+ report( "Leaving - RXTXPort:nativeStaticSetDTR\n" ); |
2168 |
return( JNI_FALSE ); |
2169 |
} |
2170 |
|
2171 |
/*---------------------------------------------------------- |
2172 |
RXTXPort.nativeStaticIsRTS |
2173 |
|
2174 |
- accept: filename |
2175 |
- perform: check status of RTS of preopened ports (setting lines/params |
2176 |
- before calling the Java open() |
2177 |
- return: true if TIOCM_RTS is set |
2178 |
- false if TIOCM_RTS is not set |
2179 |
- exceptions: none |
2180 |
- comments: RTS stands for Request to Send |
2181 |
+ accept: filename |
2182 |
+ perform: check status of RTS of preopened ports (setting lines/params |
2183 |
+ before calling the Java open() |
2184 |
+ return: true if TIOCM_RTS is set |
2185 |
+ false if TIOCM_RTS is not set |
2186 |
+ exceptions: none |
2187 |
+ comments: RTS stands for Request to Send |
2188 |
----------------------------------------------------------*/ |
2189 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsRTS)( JNIEnv *env, |
2190 |
jobject jobj, jstring jstr ) |
2191 |
@@ -2524,29 +2597,31 @@ |
2192 |
int fd = find_preopened_ports( filename ); |
2193 |
char message[80]; |
2194 |
|
2195 |
- ENTER( "RXTXPort:nativeStaticIsRTS" ); |
2196 |
+ report( "Entering - RXTXPort:nativeStaticIsRTS\n" ); |
2197 |
if( !fd ) |
2198 |
{ |
2199 |
/* Exception? FIXME */ |
2200 |
return JNI_FALSE; |
2201 |
} |
2202 |
ioctl( fd, TIOCMGET, &result ); |
2203 |
+ |
2204 |
+ memset(&message[0], 0, sizeof(message)); |
2205 |
sprintf( message, "nativeStaticIsRTS( ) returns %i\n", result& TIOCM_RTS ); |
2206 |
report( message ); |
2207 |
- LEAVE( "RXTXPort:nativeStaticIsRTS" ); |
2208 |
+ report( "Leaving - RXTXPort:nativeStaticIsRTS\n" ); |
2209 |
if( result & TIOCM_RTS ) return JNI_TRUE; |
2210 |
else return JNI_FALSE; |
2211 |
} |
2212 |
/*---------------------------------------------------------- |
2213 |
RXTXPort.nativeStaticIsDSR |
2214 |
|
2215 |
- accept: filename |
2216 |
- perform: check status of DSR of preopened ports (setting lines/params |
2217 |
- before calling the Java open() |
2218 |
- return: true if TIOCM_DSR is set |
2219 |
- false if TIOCM_DSR is not set |
2220 |
- exceptions: none |
2221 |
- comments: |
2222 |
+ accept: filename |
2223 |
+ perform: check status of DSR of preopened ports (setting lines/params |
2224 |
+ before calling the Java open() |
2225 |
+ return: true if TIOCM_DSR is set |
2226 |
+ false if TIOCM_DSR is not set |
2227 |
+ exceptions: none |
2228 |
+ comments: |
2229 |
----------------------------------------------------------*/ |
2230 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsDSR)( JNIEnv *env, |
2231 |
jobject jobj, jstring jstr ) |
2232 |
@@ -2556,29 +2631,31 @@ |
2233 |
int fd = find_preopened_ports( filename ); |
2234 |
char message[80]; |
2235 |
|
2236 |
- ENTER( "RXTXPort:nativeStaticIsDSR" ); |
2237 |
+ report( "Entering - RXTXPort:nativeStaticIsDSR\n" ); |
2238 |
if( !fd ) |
2239 |
{ |
2240 |
/* Exception? FIXME */ |
2241 |
return JNI_FALSE; |
2242 |
} |
2243 |
ioctl( fd, TIOCMGET, &result ); |
2244 |
+ |
2245 |
+ memset(&message[0], 0, sizeof(message)); |
2246 |
sprintf( message, "nativeStaticIsDSR( ) returns %i\n", result& TIOCM_DSR ); |
2247 |
report( message ); |
2248 |
- LEAVE( "RXTXPort:nativeStaticIsDSR" ); |
2249 |
+ report( "Leaving - RXTXPort:nativeStaticIsDSR\n" ); |
2250 |
if( result & TIOCM_DSR ) return JNI_TRUE; |
2251 |
else return JNI_FALSE; |
2252 |
} |
2253 |
/*---------------------------------------------------------- |
2254 |
RXTXPort.nativeStaticIsDTR |
2255 |
|
2256 |
- accept: filename |
2257 |
- perform: check status of DTR of preopened ports (setting lines/params |
2258 |
- before calling the Java open() |
2259 |
- return: true if TIOCM_DTR is set |
2260 |
- false if TIOCM_DTR is not set |
2261 |
- exceptions: none |
2262 |
- comments: DTR stands for Data Terminal Ready |
2263 |
+ accept: filename |
2264 |
+ perform: check status of DTR of preopened ports (setting lines/params |
2265 |
+ before calling the Java open() |
2266 |
+ return: true if TIOCM_DTR is set |
2267 |
+ false if TIOCM_DTR is not set |
2268 |
+ exceptions: none |
2269 |
+ comments: DTR stands for Data Terminal Ready |
2270 |
----------------------------------------------------------*/ |
2271 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsDTR)( JNIEnv *env, |
2272 |
jobject jobj, jstring jstr ) |
2273 |
@@ -2588,29 +2665,31 @@ |
2274 |
int fd = find_preopened_ports( filename ); |
2275 |
char message[80]; |
2276 |
|
2277 |
- ENTER( "RXTXPort:nativeStaticIsDTR" ); |
2278 |
+ report( "Entering - RXTXPort:nativeStaticIsDTR\n" ); |
2279 |
if( !fd ) |
2280 |
{ |
2281 |
/* Exception? FIXME */ |
2282 |
return JNI_FALSE; |
2283 |
} |
2284 |
ioctl( fd, TIOCMGET, &result ); |
2285 |
+ |
2286 |
+ memset(&message[0], 0, sizeof(message)); |
2287 |
sprintf( message, "nativeStaticIsDTR( ) returns %i\n", result& TIOCM_DTR ); |
2288 |
report( message ); |
2289 |
- LEAVE( "RXTXPort:nativeStaticIsDTR" ); |
2290 |
+ report( "Leaving - RXTXPort:nativeStaticIsDTR\n" ); |
2291 |
if( result & TIOCM_DTR ) return JNI_TRUE; |
2292 |
else return JNI_FALSE; |
2293 |
} |
2294 |
/*---------------------------------------------------------- |
2295 |
RXTXPort.nativeStaticIsCD |
2296 |
|
2297 |
- accept: filename |
2298 |
- perform: check status of CD of preopened ports (setting lines/params |
2299 |
- before calling the Java open() |
2300 |
- return: true if TIOCM_CD is set |
2301 |
- false if TIOCM_CD is not set |
2302 |
- exceptions: none |
2303 |
- comments: CD stands for carrier detect |
2304 |
+ accept: filename |
2305 |
+ perform: check status of CD of preopened ports (setting lines/params |
2306 |
+ before calling the Java open() |
2307 |
+ return: true if TIOCM_CD is set |
2308 |
+ false if TIOCM_CD is not set |
2309 |
+ exceptions: none |
2310 |
+ comments: CD stands for carrier detect |
2311 |
----------------------------------------------------------*/ |
2312 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsCD)( JNIEnv *env, |
2313 |
jobject jobj, jstring jstr ) |
2314 |
@@ -2620,29 +2699,31 @@ |
2315 |
int fd = find_preopened_ports( filename ); |
2316 |
char message[80]; |
2317 |
|
2318 |
- ENTER( "RXTXPort:nativeStaticIsCD" ); |
2319 |
+ report( "Entering - RXTXPort:nativeStaticIsCD\n" ); |
2320 |
if( !fd ) |
2321 |
{ |
2322 |
/* Exception? FIXME */ |
2323 |
return JNI_FALSE; |
2324 |
} |
2325 |
ioctl( fd, TIOCMGET, &result ); |
2326 |
+ |
2327 |
+ memset(&message[0], 0, sizeof(message)); |
2328 |
sprintf( message, "nativeStaticIsCD( ) returns %i\n", result& TIOCM_CD ); |
2329 |
report( message ); |
2330 |
- LEAVE( "RXTXPort:nativeStaticIsCD" ); |
2331 |
+ report( "Leaving - RXTXPort:nativeStaticIsCD\n" ); |
2332 |
if( result & TIOCM_CD ) return JNI_TRUE; |
2333 |
else return JNI_FALSE; |
2334 |
} |
2335 |
/*---------------------------------------------------------- |
2336 |
RXTXPort.nativeStaticIsCTS |
2337 |
|
2338 |
- accept: filename |
2339 |
- perform: check status of CTS of preopened ports (setting lines/params |
2340 |
- before calling the Java open() |
2341 |
- return: true if TIOCM_CTS is set |
2342 |
- false if TIOCM_CTS is not set |
2343 |
- exceptions: none |
2344 |
- comments: CTS stands for Clear To Send |
2345 |
+ accept: filename |
2346 |
+ perform: check status of CTS of preopened ports (setting lines/params |
2347 |
+ before calling the Java open() |
2348 |
+ return: true if TIOCM_CTS is set |
2349 |
+ false if TIOCM_CTS is not set |
2350 |
+ exceptions: none |
2351 |
+ comments: CTS stands for Clear To Send |
2352 |
----------------------------------------------------------*/ |
2353 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsCTS)( JNIEnv *env, |
2354 |
jobject jobj, jstring jstr ) |
2355 |
@@ -2652,29 +2733,31 @@ |
2356 |
int fd = find_preopened_ports( filename ); |
2357 |
char message[80]; |
2358 |
|
2359 |
- ENTER( "RXTXPort:nativeStaticIsCTS" ); |
2360 |
+ report( "Entering - RXTXPort:nativeStaticIsCTS\n" ); |
2361 |
if( !fd ) |
2362 |
{ |
2363 |
/* Exception? FIXME */ |
2364 |
return JNI_FALSE; |
2365 |
} |
2366 |
ioctl( fd, TIOCMGET, &result ); |
2367 |
+ |
2368 |
+ memset(&message[0], 0, sizeof(message)); |
2369 |
sprintf( message, "nativeStaticIsCTS( ) returns %i\n", result& TIOCM_CTS ); |
2370 |
report( message ); |
2371 |
- LEAVE( "RXTXPort:nativeStaticIsCTS" ); |
2372 |
+ report( "Leaving - RXTXPort:nativeStaticIsCTS\n" ); |
2373 |
if( result & TIOCM_CTS ) return JNI_TRUE; |
2374 |
else return JNI_FALSE; |
2375 |
} |
2376 |
/*---------------------------------------------------------- |
2377 |
RXTXPort.nativeStaticIsRI |
2378 |
|
2379 |
- accept: filename |
2380 |
- perform: check status of RI of preopened ports (setting lines/params |
2381 |
- before calling the Java open() |
2382 |
- return: true if TIOCM_RI is set |
2383 |
- false if TIOCM_RI is not set |
2384 |
- exceptions: none |
2385 |
- comments: RI stands for carrier detect |
2386 |
+ accept: filename |
2387 |
+ perform: check status of RI of preopened ports (setting lines/params |
2388 |
+ before calling the Java open() |
2389 |
+ return: true if TIOCM_RI is set |
2390 |
+ false if TIOCM_RI is not set |
2391 |
+ exceptions: none |
2392 |
+ comments: RI stands for carrier detect |
2393 |
----------------------------------------------------------*/ |
2394 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsRI)( JNIEnv *env, |
2395 |
jobject jobj, jstring jstr ) |
2396 |
@@ -2684,16 +2767,18 @@ |
2397 |
int fd = find_preopened_ports( filename ); |
2398 |
char message[80]; |
2399 |
|
2400 |
- ENTER( "RXTXPort:nativeStaticIsRI" ); |
2401 |
+ report( "Entering - RXTXPort:nativeStaticIsRI\n" ); |
2402 |
if( !fd ) |
2403 |
{ |
2404 |
/* Exception? FIXME */ |
2405 |
return JNI_FALSE; |
2406 |
} |
2407 |
ioctl( fd, TIOCMGET, &result ); |
2408 |
+ |
2409 |
+ memset(&message[0], 0, sizeof(message)); |
2410 |
sprintf( message, "nativeStaticRI( ) returns %i\n", result& TIOCM_RI ); |
2411 |
report( message ); |
2412 |
- LEAVE( "RXTXPort:nativeStaticIsRI" ); |
2413 |
+ report( "Leaving - RXTXPort:nativeStaticIsRI\n" ); |
2414 |
if( result & TIOCM_RI ) return JNI_TRUE; |
2415 |
else return JNI_FALSE; |
2416 |
} |
2417 |
@@ -2701,11 +2786,11 @@ |
2418 |
/*---------------------------------------------------------- |
2419 |
RXTXPort.nativeStaticGetBaudRate |
2420 |
|
2421 |
- accept: filename |
2422 |
- perform: find the baud rate (not all buads are handled yet) |
2423 |
- return: return the baud rate or -1 if not supported yet. |
2424 |
- exceptions: |
2425 |
- comments: simple test for preopened ports |
2426 |
+ accept: filename |
2427 |
+ perform: find the baud rate (not all buads are handled yet) |
2428 |
+ return: return the baud rate or -1 if not supported yet. |
2429 |
+ exceptions: |
2430 |
+ comments: simple test for preopened ports |
2431 |
----------------------------------------------------------*/ |
2432 |
JNIEXPORT jint JNICALL RXTXPort(nativeStaticGetBaudRate)( JNIEnv *env, jobject jobj, jstring jstr ) |
2433 |
{ |
2434 |
@@ -2715,7 +2800,7 @@ |
2435 |
int baudrate; |
2436 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2437 |
|
2438 |
- ENTER( "RXTXPort:nativeStaticGetBaudRate" ); |
2439 |
+ report( "Entering - RXTXPort:nativeStaticGetBaudRate\n" ); |
2440 |
if( !fd ) |
2441 |
{ |
2442 |
/* Exception? FIXME */ |
2443 |
@@ -2743,21 +2828,21 @@ |
2444 |
|
2445 |
*/ |
2446 |
#if defined(CBAUD)/* dima */ |
2447 |
- baudrate = ttyset.c_cflag&CBAUD; |
2448 |
+ baudrate = ttyset.c_cflag&CBAUD; |
2449 |
#else |
2450 |
- if(cfgetispeed(&ttyset) != cfgetospeed(&ttyset)) return -1; |
2451 |
- baudrate = cfgetispeed(&ttyset); |
2452 |
+ if(cfgetispeed(&ttyset) != cfgetospeed(&ttyset)) return -1; |
2453 |
+ baudrate = cfgetispeed(&ttyset); |
2454 |
#endif |
2455 |
return( get_java_baudrate(baudrate) ); |
2456 |
} |
2457 |
/*---------------------------------------------------------- |
2458 |
RXTXPort.nativeStaticGetDataBits |
2459 |
|
2460 |
- accept: filename |
2461 |
- perform: find the data bits (not all buads are handled yet) |
2462 |
- return: return the data bits |
2463 |
- exceptions: |
2464 |
- comments: simple test for preopened ports |
2465 |
+ accept: filename |
2466 |
+ perform: find the data bits (not all buads are handled yet) |
2467 |
+ return: return the data bits |
2468 |
+ exceptions: |
2469 |
+ comments: simple test for preopened ports |
2470 |
----------------------------------------------------------*/ |
2471 |
JNIEXPORT jint JNICALL RXTXPort(nativeStaticGetDataBits)( JNIEnv *env, jobject jobj, jstring jstr ) |
2472 |
{ |
2473 |
@@ -2766,7 +2851,7 @@ |
2474 |
struct termios ttyset; |
2475 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2476 |
|
2477 |
- ENTER( "RXTXPort:nativeStaticGetDataBits" ); |
2478 |
+ report( "Entering - RXTXPort:nativeStaticGetDataBits\n" ); |
2479 |
if( !fd ) |
2480 |
{ |
2481 |
/* Exception? FIXME */ |
2482 |
@@ -2778,21 +2863,21 @@ |
2483 |
return(-1); |
2484 |
} |
2485 |
switch( ttyset.c_cflag&CSIZE ) { |
2486 |
- case CS5: return JDATABITS_5; |
2487 |
- case CS6: return JDATABITS_6; |
2488 |
- case CS7: return JDATABITS_7; |
2489 |
- case CS8: return JDATABITS_8; |
2490 |
- default: return(-1); |
2491 |
+ case CS5: return JDATABITS_5; |
2492 |
+ case CS6: return JDATABITS_6; |
2493 |
+ case CS7: return JDATABITS_7; |
2494 |
+ case CS8: return JDATABITS_8; |
2495 |
+ default: return(-1); |
2496 |
} |
2497 |
} |
2498 |
/*---------------------------------------------------------- |
2499 |
RXTXPort.nativeStaticGetParity |
2500 |
|
2501 |
- accept: filename |
2502 |
- perform: find the parity |
2503 |
- return: return the parity |
2504 |
- exceptions: |
2505 |
- comments: simple test for preopened ports |
2506 |
+ accept: filename |
2507 |
+ perform: find the parity |
2508 |
+ return: return the parity |
2509 |
+ exceptions: |
2510 |
+ comments: simple test for preopened ports |
2511 |
----------------------------------------------------------*/ |
2512 |
JNIEXPORT jint JNICALL RXTXPort(nativeStaticGetParity)( JNIEnv *env, jobject jobj, jstring jstr ) |
2513 |
{ |
2514 |
@@ -2801,7 +2886,7 @@ |
2515 |
struct termios ttyset; |
2516 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2517 |
|
2518 |
- ENTER( "RXTXPort:nativeStaticGetParity" ); |
2519 |
+ report( "Entering - RXTXPort:nativeStaticGetParity\n" ); |
2520 |
if( !fd ) |
2521 |
{ |
2522 |
/* Exception? FIXME */ |
2523 |
@@ -2824,17 +2909,17 @@ |
2524 |
case PARENB | PARODD | CMSPAR: return JPARITY_MARK; |
2525 |
case PARENB | CMSPAR: return JPARITY_SPACE; |
2526 |
#endif /* CMSPAR */ |
2527 |
- default: return(-1); |
2528 |
+ default: return(-1); |
2529 |
} |
2530 |
} |
2531 |
/*---------------------------------------------------------- |
2532 |
RXTXPort.nativeStaticGetStopBits |
2533 |
|
2534 |
- accept: filename |
2535 |
- perform: find the stop bits |
2536 |
- return: return the stop bits |
2537 |
- exceptions: |
2538 |
- comments: simple test for preopened ports |
2539 |
+ accept: filename |
2540 |
+ perform: find the stop bits |
2541 |
+ return: return the stop bits |
2542 |
+ exceptions: |
2543 |
+ comments: simple test for preopened ports |
2544 |
----------------------------------------------------------*/ |
2545 |
JNIEXPORT jint JNICALL RXTXPort(nativeStaticGetStopBits)( JNIEnv *env, jobject jobj, jstring jstr ) |
2546 |
{ |
2547 |
@@ -2843,7 +2928,7 @@ |
2548 |
struct termios ttyset; |
2549 |
(*env)->ReleaseStringUTFChars( env, jstr, filename ); |
2550 |
|
2551 |
- ENTER( "RXTXPort:nativeStaticGetStopBits" ); |
2552 |
+ report( "Entering - RXTXPort:nativeStaticGetStopBits\n" ); |
2553 |
if( !fd ) |
2554 |
{ |
2555 |
/* Exception? FIXME */ |
2556 |
@@ -2872,46 +2957,46 @@ |
2557 |
/*---------------------------------------------------------- |
2558 |
RXTXPort.nativeGetParityErrorChar |
2559 |
|
2560 |
- accept: - |
2561 |
- perform: check the ParityErrorChar |
2562 |
- return: The ParityErrorChar as an jbyte. |
2563 |
- exceptions: UnsupportedCommOperationException if not implemented |
2564 |
- comments: It appears the Parity char is usually \0. The windows |
2565 |
- API allows for this to be changed. I cant find may |
2566 |
- examples of this being done. Maybe for a reason. |
2567 |
- |
2568 |
- Use a direct call to the termios file until we find a |
2569 |
- solution. |
2570 |
+ accept: - |
2571 |
+ perform: check the ParityErrorChar |
2572 |
+ return: The ParityErrorChar as an jbyte. |
2573 |
+ exceptions: UnsupportedCommOperationException if not implemented |
2574 |
+ comments: It appears the Parity char is usually \0. The windows |
2575 |
+ API allows for this to be changed. I cant find may |
2576 |
+ examples of this being done. Maybe for a reason. |
2577 |
+ |
2578 |
+ Use a direct call to the termios file until we find a |
2579 |
+ solution. |
2580 |
----------------------------------------------------------*/ |
2581 |
JNIEXPORT jbyte JNICALL RXTXPort(nativeGetParityErrorChar)( JNIEnv *env, |
2582 |
jobject jobj ) |
2583 |
{ |
2584 |
unsigned int result = 0; |
2585 |
|
2586 |
- ENTER( "nativeGetParityErrorChar" ); |
2587 |
+ report( "Entering - nativeGetParityErrorChar\n" ); |
2588 |
#ifdef WIN32 |
2589 |
result = ( jbyte ) termiosGetParityErrorChar( |
2590 |
get_java_var(env, jobj, "fd", "I" ) ); |
2591 |
#else |
2592 |
/* |
2593 |
- arg! I cant find a way to change it from \0 in Linux. I think |
2594 |
- the frame and parity error characters are hardcoded. |
2595 |
+ arg! I cant find a way to change it from \0 in Linux. I think |
2596 |
+ the frame and parity error characters are hardcoded. |
2597 |
*/ |
2598 |
result = ( jint ) '\0'; |
2599 |
|
2600 |
#endif /* WIN32 */ |
2601 |
- LEAVE( "nativeGetParityErrorChar" ); |
2602 |
+ report( "Leaving - nativeGetParityErrorChar\n" ); |
2603 |
return( ( jbyte ) result ); |
2604 |
} |
2605 |
|
2606 |
/*---------------------------------------------------------- |
2607 |
RXTXPort.nativeGetEndOfInputChar |
2608 |
|
2609 |
- accept: - |
2610 |
- perform: check the EndOf InputChar |
2611 |
- return: the EndOfInputChar as an jbyte. -1 on error |
2612 |
- exceptions: UnsupportedCommOperationException if not implemented |
2613 |
- comments: |
2614 |
+ accept: - |
2615 |
+ perform: check the EndOf InputChar |
2616 |
+ return: the EndOfInputChar as an jbyte. -1 on error |
2617 |
+ exceptions: UnsupportedCommOperationException if not implemented |
2618 |
+ comments: |
2619 |
----------------------------------------------------------*/ |
2620 |
JNIEXPORT jbyte JNICALL RXTXPort(nativeGetEndOfInputChar)( JNIEnv *env, |
2621 |
jobject jobj ) |
2622 |
@@ -2919,12 +3004,12 @@ |
2623 |
int fd = get_java_var( env, jobj,"fd","I" ); |
2624 |
struct termios ttyset; |
2625 |
|
2626 |
- ENTER( "nativeGetEndOfInputChar" ); |
2627 |
+ report( "Entering - nativeGetEndOfInputChar\n" ); |
2628 |
if( tcgetattr( fd, &ttyset ) < 0 ) goto fail; |
2629 |
- LEAVE( "nativeGetEndOfInputChar" ); |
2630 |
+ report( "Leaving - nativeGetEndOfInputChar" ); |
2631 |
return( (jbyte) ttyset.c_cc[VEOF] ); |
2632 |
fail: |
2633 |
- LEAVE( "nativeGetEndOfInputChar" ); |
2634 |
+ report( "Leaving - nativeGetEndOfInputChar\n" ); |
2635 |
report( "nativeGetEndOfInputChar failed\n" ); |
2636 |
return( ( jbyte ) -1 ); |
2637 |
} |
2638 |
@@ -2932,16 +3017,16 @@ |
2639 |
/*---------------------------------------------------------- |
2640 |
RXTXPort.nativeSetParityErrorChar |
2641 |
|
2642 |
- accept: the ParityArrorCharacter as an int. |
2643 |
- perform: Set the ParityErrorChar |
2644 |
- return: JNI_TRUE on success |
2645 |
- exceptions: UnsupportedCommOperationException if not implemented |
2646 |
- comments: It appears the Parity char is usually \0. The windows |
2647 |
- API allows for this to be changed. I cant find may |
2648 |
- examples of this being done. Maybe for a reason. |
2649 |
+ accept: the ParityArrorCharacter as an int. |
2650 |
+ perform: Set the ParityErrorChar |
2651 |
+ return: JNI_TRUE on success |
2652 |
+ exceptions: UnsupportedCommOperationException if not implemented |
2653 |
+ comments: It appears the Parity char is usually \0. The windows |
2654 |
+ API allows for this to be changed. I cant find may |
2655 |
+ examples of this being done. Maybe for a reason. |
2656 |
|
2657 |
- Use a direct call to the termios file until we find a |
2658 |
- solution. |
2659 |
+ Use a direct call to the termios file until we find a |
2660 |
+ solution. |
2661 |
----------------------------------------------------------*/ |
2662 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeSetParityErrorChar)( JNIEnv *env, |
2663 |
jobject jobj, jbyte value ) |
2664 |
@@ -2949,21 +3034,21 @@ |
2665 |
|
2666 |
#ifdef WIN32 |
2667 |
int fd = get_java_var( env, jobj,"fd","I" ); |
2668 |
- ENTER( "nativeSetParityErrorChar" ); |
2669 |
+ report( "Entering - nativeSetParityErrorChar\n" ); |
2670 |
termiosSetParityError( fd, ( char ) value ); |
2671 |
- LEAVE( "nativeSetParityErrorChar" ); |
2672 |
+ report( "Leaving - nativeSetParityErrorChar\n" ); |
2673 |
return( JNI_TRUE ); |
2674 |
#else |
2675 |
- ENTER( "nativeSetParityErrorChar" ); |
2676 |
+ report( "Entering - nativeSetParityErrorChar\n" ); |
2677 |
/* |
2678 |
- arg! I cant find a way to change it from \0 in Linux. I think |
2679 |
- the frame and parity error characters are hardcoded. |
2680 |
+ arg! I cant find a way to change it from \0 in Linux. I think |
2681 |
+ the frame and parity error characters are hardcoded. |
2682 |
*/ |
2683 |
|
2684 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, |
2685 |
"Not implemented... yet", |
2686 |
strerror( errno ) ); |
2687 |
- LEAVE( "nativeSetParityErrorChar" ); |
2688 |
+ report( "Leaving - nativeSetParityErrorChar\n" ); |
2689 |
return( JNI_FALSE ); |
2690 |
#endif /* WIN32 */ |
2691 |
} |
2692 |
@@ -2971,17 +3056,17 @@ |
2693 |
/*---------------------------------------------------------- |
2694 |
RXTXPort.nativeSetEndOfInputChar |
2695 |
|
2696 |
- accept: The EndOfInputChar as an int |
2697 |
- perform: set the EndOfInputChar |
2698 |
- return: JNI_TRUE on success |
2699 |
- exceptions: UnsupportedCommOperationException if not implemented |
2700 |
- comments: This may cause troubles on Windows. |
2701 |
- Lets give it a shot and see what happens. |
2702 |
+ accept: The EndOfInputChar as an int |
2703 |
+ perform: set the EndOfInputChar |
2704 |
+ return: JNI_TRUE on success |
2705 |
+ exceptions: UnsupportedCommOperationException if not implemented |
2706 |
+ comments: This may cause troubles on Windows. |
2707 |
+ Lets give it a shot and see what happens. |
2708 |
|
2709 |
- See termios.c for the windows bits. |
2710 |
+ See termios.c for the windows bits. |
2711 |
|
2712 |
- EofChar = val; |
2713 |
- fBinary = false; winapi docs say always use true. ? |
2714 |
+ EofChar = val; |
2715 |
+ fBinary = false; winapi docs say always use true. ? |
2716 |
----------------------------------------------------------*/ |
2717 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeSetEndOfInputChar)( JNIEnv *env, |
2718 |
jobject jobj, jbyte value ) |
2719 |
@@ -2989,17 +3074,17 @@ |
2720 |
int fd = get_java_var( env, jobj,"fd","I" ); |
2721 |
struct termios ttyset; |
2722 |
|
2723 |
- ENTER( "nativeSetEndOfInputChar" ); |
2724 |
+ report( "Entering - nativeSetEndOfInputChar\n" ); |
2725 |
if( tcgetattr( fd, &ttyset ) < 0 ) goto fail; |
2726 |
ttyset.c_cc[VEOF] = ( char ) value; |
2727 |
if( tcsetattr( fd, TCSANOW, &ttyset ) < 0 ) goto fail; |
2728 |
- LEAVE( "nativeSetEndOfInputChar" ); |
2729 |
+ report( "Leaving - nativeSetEndOfInputChar\n" ); |
2730 |
return( JNI_TRUE ); |
2731 |
fail: |
2732 |
throw_java_exception( env, IO_EXCEPTION, "nativeSetEndOfInputChar", |
2733 |
strerror( errno ) ); |
2734 |
report( "nativeSetEndOfInputChar failed\n" ); |
2735 |
- LEAVE( "nativeSetEndOfInputChar" ); |
2736 |
+ report( "Leaving - nativeSetEndOfInputChar\n" ); |
2737 |
return( JNI_FALSE ); |
2738 |
} |
2739 |
|
2740 |
@@ -3025,28 +3110,31 @@ |
2741 |
/*---------------------------------------------------------- |
2742 |
read_byte_array |
2743 |
|
2744 |
- accept: int fd file descriptor to read from |
2745 |
- unsigned char *buffer buffer to read data into |
2746 |
- int length number of bytes to read |
2747 |
- int timeout milliseconds to wait before returning |
2748 |
- perform: read bytes from the port into a buffer |
2749 |
- return: status of read |
2750 |
- -1 fail (IOException) |
2751 |
- 0 timeout |
2752 |
- >0 number of bytes read |
2753 |
- comments: According to the Communications API spec, a receive threshold |
2754 |
- of 1 is the same as having the threshold disabled. |
2755 |
- |
2756 |
- The nuts and bolts are documented in |
2757 |
- NativeEnableReceiveTimeoutThreshold() |
2758 |
-----------------------------------------------------------*/ |
2759 |
- |
2760 |
-int read_byte_array( JNIEnv *env, |
2761 |
- jobject *jobj, |
2762 |
- int fd, |
2763 |
- unsigned char *buffer, |
2764 |
- int length, |
2765 |
- int timeout ) |
2766 |
+ accept: int fd file descriptor to read from |
2767 |
+ unsigned char *buffer buffer to read data into |
2768 |
+ int length number of bytes to read |
2769 |
+ int timeout milliseconds to wait |
2770 |
+ perform: read bytes from the port into a buffer |
2771 |
+ return: status of read |
2772 |
+ -1 fail (IOException) |
2773 |
+ 0 timeout |
2774 |
+ >0 number of bytes read |
2775 |
+ comments: According to the Communications API spec, a receive |
2776 |
+ threshold of 1 is the same as having the threshold |
2777 |
+ disabled. |
2778 |
+ |
2779 |
+ The nuts and bolts are documented in |
2780 |
+ NativeEnableReceiveTimeoutThreshold() |
2781 |
+----------------------------------------------------------*/ |
2782 |
+ |
2783 |
+int read_byte_array( |
2784 |
+ JNIEnv *env, |
2785 |
+ jobject *jobj, |
2786 |
+ int fd, |
2787 |
+ unsigned char *buffer, |
2788 |
+ int length, |
2789 |
+ int timeout |
2790 |
+) |
2791 |
{ |
2792 |
int ret, left, bytes = 0; |
2793 |
long timeLeft, now = 0, start = 0; |
2794 |
@@ -3062,7 +3150,8 @@ |
2795 |
flag = eis->eventflags[SPE_DATA_AVAILABLE]; |
2796 |
eis->eventflags[SPE_DATA_AVAILABLE] = 0; |
2797 |
/* |
2798 |
- ENTER( "read_byte_array" ); |
2799 |
+ report( "Entering - read_byte_array\n" ); |
2800 |
+ memset(&message[0], 0, sizeof(message)); |
2801 |
sprintf(msg, "read_byte_array requests %i\n", length); |
2802 |
report( msg ); |
2803 |
*/ |
2804 |
@@ -3102,7 +3191,7 @@ |
2805 |
#endif /* WIN32 */ |
2806 |
if (ret == -1){ |
2807 |
report( "read_byte_array: select returned -1\n" ); |
2808 |
- LEAVE( "read_byte_array" ); |
2809 |
+ report( "Leaving - read_byte_array\n" ); |
2810 |
eis->eventflags[SPE_DATA_AVAILABLE] = flag; |
2811 |
return -1; |
2812 |
} |
2813 |
@@ -3111,7 +3200,7 @@ |
2814 |
if ((ret = READ( fd, buffer + bytes, left )) < 0 ){ |
2815 |
if (errno != EINTR && errno != EAGAIN){ |
2816 |
report( "read_byte_array: read returned -1\n" ); |
2817 |
- LEAVE( "read_byte_array" ); |
2818 |
+ report( "Leaving - read_byte_array\n" ); |
2819 |
eis->eventflags[SPE_DATA_AVAILABLE] = flag; |
2820 |
return -1; |
2821 |
} |
2822 |
@@ -3146,9 +3235,10 @@ |
2823 |
"No data available" ); |
2824 |
} |
2825 |
|
2826 |
+ memset(&message[0], 0, sizeof(message)); |
2827 |
sprintf(msg, "read_byte_array returns %i\n", bytes); |
2828 |
report( msg ); |
2829 |
- LEAVE( "read_byte_array" ); |
2830 |
+ report( "Leaving - read_byte_array\n" ); |
2831 |
report_time_end(); |
2832 |
*/ |
2833 |
eis->eventflags[SPE_DATA_AVAILABLE] = flag; |
2834 |
@@ -3168,7 +3258,8 @@ |
2835 |
char msg[80]; |
2836 |
|
2837 |
report_time_start(); |
2838 |
- ENTER( "read_byte_array" ); |
2839 |
+ report( "Entering - read_byte_array\n" ); |
2840 |
+ memset(&message[0], 0, sizeof(message)); |
2841 |
sprintf(msg, "read_byte_array requests %i\n", length); |
2842 |
report( msg ); |
2843 |
left = length; |
2844 |
@@ -3186,15 +3277,16 @@ |
2845 |
if (errno == EINTR) |
2846 |
goto RETRY; |
2847 |
report( "read_byte_array: read returned -1\n" ); |
2848 |
- LEAVE( "read_byte_array" ); |
2849 |
+ report( "Leaving - read_byte_array\n" ); |
2850 |
return -1; |
2851 |
} |
2852 |
bytes += ret; |
2853 |
left -= ret; |
2854 |
} |
2855 |
+ memset(&message[0], 0, sizeof(message)); |
2856 |
sprintf(msg, "read_byte_array returns %i\n", bytes); |
2857 |
report( msg ); |
2858 |
- LEAVE( "read_byte_array" ); |
2859 |
+ report( "Leaving - read_byte_array\n" ); |
2860 |
report_time_end(); |
2861 |
return bytes; |
2862 |
} |
2863 |
@@ -3217,7 +3309,7 @@ |
2864 |
struct timeval *psleep=&sleep; |
2865 |
#endif /* WIN32 */ |
2866 |
|
2867 |
- ENTER( "read_byte_array" ); |
2868 |
+ report( "Entering - read_byte_array\n" ); |
2869 |
left = length; |
2870 |
FD_ZERO( &rfds ); |
2871 |
FD_SET( fd, &rfds ); |
2872 |
@@ -3228,10 +3320,10 @@ |
2873 |
} |
2874 |
while( bytes < length ) |
2875 |
{ |
2876 |
- /* FIXME: In Linux, select updates the timeout automatically, so |
2877 |
- other OSes will need to update it manually if they want to have |
2878 |
- the same behavior. For those OSes, timeouts will occur after no |
2879 |
- data AT ALL is received for the timeout duration. No big deal. */ |
2880 |
+ /* FIXME: In Linux, select updates the timeout automatically, so |
2881 |
+ other OSes will need to update it manually if they want to have |
2882 |
+ the same behavior. For those OSes, timeouts will occur after no |
2883 |
+ data AT ALL is received for the timeout duration. No big deal. */ |
2884 |
#ifndef WIN32 |
2885 |
do { |
2886 |
if( timeout == 0 ) psleep = NULL; |
2887 |
@@ -3239,9 +3331,9 @@ |
2888 |
} while (ret < 0 && errno==EINTR); |
2889 |
#else |
2890 |
/* |
2891 |
- the select() needs some work before the above will |
2892 |
- work on win32. The select code cannot be accessed |
2893 |
- from both the Monitor Thread and the Reading Thread. |
2894 |
+ the select() needs some work before the above will |
2895 |
+ work on win32. The select code cannot be accessed |
2896 |
+ from both the Monitor Thread and the Reading Thread. |
2897 |
|
2898 |
*/ |
2899 |
ret = RXTXPort(nativeavailable)( env, *jobj ); |
2900 |
@@ -3249,44 +3341,44 @@ |
2901 |
if( ret == 0 ) |
2902 |
{ |
2903 |
report( "read_byte_array: select returned 0\n" ); |
2904 |
- LEAVE( "read_byte_array" ); |
2905 |
+ report( "Leaving - read_byte_array\n" ); |
2906 |
break; |
2907 |
} |
2908 |
if( ret < 0 ) |
2909 |
{ |
2910 |
report( "read_byte_array: select returned -1\n" ); |
2911 |
- LEAVE( "read_byte_array" ); |
2912 |
+ report( "Leaving - read_byte_array\n" ); |
2913 |
return -1; |
2914 |
} |
2915 |
ret = READ( fd, buffer + bytes, left ); |
2916 |
if( ret == 0 ) |
2917 |
{ |
2918 |
report( "read_byte_array: read returned 0 bytes\n" ); |
2919 |
- LEAVE( "read_byte_array" ); |
2920 |
+ report( "Leaving - read_byte_array\n" ); |
2921 |
break; |
2922 |
} |
2923 |
else if( ret < 0 ) |
2924 |
{ |
2925 |
report( "read_byte_array: read returned -1\n" ); |
2926 |
- LEAVE( "read_byte_array" ); |
2927 |
+ report( "Leaving - read_byte_array\n" ); |
2928 |
return -1; |
2929 |
} |
2930 |
bytes += ret; |
2931 |
left -= ret; |
2932 |
} |
2933 |
- LEAVE( "read_byte_array" ); |
2934 |
+ report( "Leaving - read_byte_array\n" ); |
2935 |
return bytes; |
2936 |
} |
2937 |
#endif /* asdf */ |
2938 |
|
2939 |
/*---------------------------------------------------------- |
2940 |
NativeEnableReceiveTimeoutThreshold |
2941 |
- accept: int threshold, int vtime,int buffer |
2942 |
- perform: Set c_cc->VMIN to threshold and c_cc=>VTIME to vtime |
2943 |
- return: void |
2944 |
- exceptions: IOException |
2945 |
- comments: This is actually all handled in read with select in |
2946 |
- canonical input mode. |
2947 |
+ accept: int threshold, int vtime,int buffer |
2948 |
+ perform: Set c_cc->VMIN to threshold and c_cc=>VTIME to vtime |
2949 |
+ return: void |
2950 |
+ exceptions: IOException |
2951 |
+ comments: This is actually all handled in read with select in |
2952 |
+ canonical input mode. |
2953 |
----------------------------------------------------------*/ |
2954 |
JNIEXPORT void JNICALL RXTXPort(NativeEnableReceiveTimeoutThreshold)( |
2955 |
JNIEnv *env, jobject jobj, jint vtime, jint threshold, jint buffer) |
2956 |
@@ -3305,16 +3397,16 @@ |
2957 |
timeout = vtime; |
2958 |
} |
2959 |
|
2960 |
- ENTER( "RXTXPort:NativeEnableRecieveTimeoutThreshold" ); |
2961 |
+ report( "Entering - RXTXPort:NativeEnableRecieveTimeoutThreshold\n" ); |
2962 |
if( tcgetattr( fd, &ttyset ) < 0 ) goto fail; |
2963 |
ttyset.c_cc[ VMIN ] = threshold; |
2964 |
ttyset.c_cc[ VTIME ] = timeout/100; |
2965 |
if( tcsetattr( fd, TCSANOW, &ttyset ) < 0 ) goto fail; |
2966 |
|
2967 |
- LEAVE( "RXTXPort:NativeEnableRecieveTimeoutThreshold" ); |
2968 |
+ report( "Leaving - RXTXPort:NativeEnableRecieveTimeoutThreshold\n" ); |
2969 |
return; |
2970 |
fail: |
2971 |
- LEAVE( "RXTXPort:NativeEnableRecieveTimeoutThreshold" ); |
2972 |
+ report( "Leaving - RXTXPort:NativeEnableRecieveTimeoutThreshold\n" ); |
2973 |
throw_java_exception( env, IO_EXCEPTION, "TimeoutThreshold", |
2974 |
strerror( errno ) ); |
2975 |
return; |
2976 |
@@ -3323,16 +3415,16 @@ |
2977 |
/*---------------------------------------------------------- |
2978 |
RXTXPort.readByte |
2979 |
|
2980 |
- accept: none |
2981 |
- perform: Read a single byte from the port. Block unless an exeption |
2982 |
- is thrown, or end of stream. |
2983 |
- return: The byte read |
2984 |
- exceptions: IOException |
2985 |
- comments: |
2986 |
+ accept: none |
2987 |
+ perform: Read a single byte from the port. Block unless an exeption |
2988 |
+ is thrown, or end of stream. |
2989 |
+ return: The byte read |
2990 |
+ exceptions: IOException |
2991 |
+ comments: |
2992 |
|
2993 |
-On Fri, 30 Aug 2002, Bill Smith wrote: |
2994 |
+ On Fri, 30 Aug 2002, Bill Smith wrote: |
2995 |
|
2996 |
-I agree, the documentation isn't the best. No surprises there. |
2997 |
+ I agree, the documentation isn't the best. No surprises there. |
2998 |
|
2999 |
I did do a test using the sun/win32 comm driver with read() and retrieve |
3000 |
timeout enabled. It blocked until the timeout expired, then returned a -1. |
3001 |
@@ -3350,32 +3442,32 @@ |
3002 |
> I have a couple of questions/comments. |
3003 |
> |
3004 |
> 1) I noticed in the thread last night and in the code changes this morning that you |
3005 |
-> now have readByte() (which is called from the input stream read(), to block |
3006 |
-> forever. I pulled the following info from the javax.comm doc for the CommPort class in |
3007 |
-> getInputStream(). |
3008 |
+> now have readByte() (which is called from the input stream read(), to block |
3009 |
+> forever. I pulled the following info from the javax.comm doc for the CommPort class in |
3010 |
+> getInputStream(). |
3011 |
> |
3012 |
-> The way I interpret that is that read() just like read(byte[]), and read(byte[], int, int), |
3013 |
-> show only block indefinitely if timeout is disabled. The sun implementation for win32 (as |
3014 |
-> well as the one we have for vxworks) returns a -1 when it times out. |
3015 |
+> The way I interpret that is that read() just like read(byte[]), and read(byte[], int, int), |
3016 |
+> show only block indefinitely if timeout is disabled. The sun implementation for win32 (as |
3017 |
+> well as the one we have for vxworks) returns a -1 when it times out. |
3018 |
> |
3019 |
|
3020 |
Doing what Sun does is going to the least hassle. The documentation was a |
3021 |
little unclear to me. I assume this is the CommPort.getInputStream |
3022 |
comment that you mention |
3023 |
|
3024 |
- The read behaviour of the input stream returned by getInputStream |
3025 |
- depends on combination of the threshold and timeout values. The |
3026 |
- possible behaviours are described in the table below: ... |
3027 |
+ The read behaviour of the input stream returned by getInputStream |
3028 |
+ depends on combination of the threshold and timeout values. The |
3029 |
+ possible behaviours are described in the table below: ... |
3030 |
|
3031 |
But InputStream is where read(byte) is documented |
3032 |
http://java.sun.com/j2se/1.3/docs/api/java/io/InputStream.html#read() |
3033 |
|
3034 |
- Reads the next byte of data from the input stream. The value byte |
3035 |
- is returned as an int in the range 0 to 255. If no byte is |
3036 |
- available because the end of the stream has been reached, the value |
3037 |
- -1 is returned. This method blocks until input data is |
3038 |
- available, the end of the stream is detected, or an exception is |
3039 |
- thrown |
3040 |
+ Reads the next byte of data from the input stream. The value byte |
3041 |
+ is returned as an int in the range 0 to 255. If no byte is |
3042 |
+ available because the end of the stream has been reached, the value |
3043 |
+ -1 is returned. This method blocks until input data is |
3044 |
+ available, the end of the stream is detected, or an exception is |
3045 |
+ thrown |
3046 |
|
3047 |
If you are sure commapi is doing a timeout and returning -1, I can change |
3048 |
it back and document the issue. |
3049 |
@@ -3383,20 +3475,20 @@ |
3050 |
Because I often grep my own mailbox for details, I'm going to add |
3051 |
these two comments also: |
3052 |
|
3053 |
- public int read(byte[] b) |
3054 |
+ public int read(byte[] b) |
3055 |
) |
3056 |
http://java.sun.com/j2se/1.3/docs/api/java/io/InputStream.html#read(byte[]) |
3057 |
|
3058 |
- Reads some number of bytes from the input stream and stores them |
3059 |
- into the buffer array b. The number of bytes actually read is |
3060 |
- returned as an integer. This method blocks until input data is |
3061 |
- available, end of file is detected, or an exception is thrown. |
3062 |
- |
3063 |
- If b is null, a NullPointerException is thrown. If the length of b |
3064 |
- is zero, then no bytes are read and 0 is returned; otherwise, |
3065 |
- there is an attempt to read at least one byte. If no byte is |
3066 |
- available because the stream is at end of file, the value -1 is |
3067 |
- returned; otherwise, at least one byte is read and stored into b. |
3068 |
+ Reads some number of bytes from the input stream and stores them |
3069 |
+ into the buffer array b. The number of bytes actually read is |
3070 |
+ returned as an integer. This method blocks until input data is |
3071 |
+ available, end of file is detected, or an exception is thrown. |
3072 |
+ |
3073 |
+ If b is null, a NullPointerException is thrown. If the length of b |
3074 |
+ is zero, then no bytes are read and 0 is returned; otherwise, |
3075 |
+ there is an attempt to read at least one byte. If no byte is |
3076 |
+ available because the stream is at end of file, the value -1 is |
3077 |
+ returned; otherwise, at least one byte is read and stored into b. |
3078 |
|
3079 |
So read(byte[] b) is documented as blocking for the first byte. |
3080 |
|
3081 |
@@ -3404,10 +3496,10 @@ |
3082 |
http://java.sun.com/j2se/1.3/docs/api/java/io/InputStream.html#read(byte[], |
3083 |
int, int) |
3084 |
|
3085 |
- Reads up to len bytes of data from the input stream into an array of |
3086 |
- bytes. An attempt is made to read as many as len bytes, but a |
3087 |
- smaller number may be read, possibly zero. The number of bytes |
3088 |
- actually read is returned as an integer. |
3089 |
+ Reads up to len bytes of data from the input stream into an array of |
3090 |
+ bytes. An attempt is made to read as many as len bytes, but a |
3091 |
+ smaller number may be read, possibly zero. The number of bytes |
3092 |
+ actually read is returned as an integer. |
3093 |
|
3094 |
Which makes sense with the timeout documentation. |
3095 |
|
3096 |
@@ -3434,18 +3526,18 @@ |
3097 |
> described in the table below: |
3098 |
> |
3099 |
> |
3100 |
-> Threshold Timeout Read Buffer Read Behaviour |
3101 |
-> State Value State Value Size |
3102 |
+> Threshold Timeout Read Buffer Read Behaviour |
3103 |
+> State Value State Value Size |
3104 |
> |
3105 |
----------------------------------------------------------------------------------- |
3106 |
-> disabled - disabled - n bytes block until any data is available |
3107 |
+> disabled - disabled - n bytes block until any data is available |
3108 |
> |
3109 |
-> enabled m bytes disabled - n bytes block until min(m,n) bytes are available |
3110 |
+> enabled m bytes disabled - n bytes block until min(m,n) bytes are available |
3111 |
> |
3112 |
-> disabled - enabled x ms n bytes block for x ms or |
3113 |
+> disabled - enabled x ms n bytes block for x ms or |
3114 |
until any data is available |
3115 |
> |
3116 |
-> enabled m bytes enabled x ms n bytes block for x ms or |
3117 |
+> enabled m bytes enabled x ms n bytes block for x ms or |
3118 |
until min(m,n) bytes are available |
3119 |
> |
3120 |
> Returns: InputStream object that can be used to read from the port |
3121 |
@@ -3464,18 +3556,19 @@ |
3122 |
/* char msg[80]; */ |
3123 |
|
3124 |
/* |
3125 |
- ENTER( "RXTXPort:readByte" ); |
3126 |
+ report( "Entering - RXTXPort:readByte" ); |
3127 |
report_time_start( ); |
3128 |
*/ |
3129 |
bytes = read_byte_array( env, &jobj, fd, buffer, 1, timeout ); |
3130 |
if( bytes < 0 ) { |
3131 |
- LEAVE( "RXTXPort:readByte" ); |
3132 |
+ report( "Leaving - RXTXPort:readByte\n" ); |
3133 |
throw_java_exception( env, IO_EXCEPTION, "readByte", |
3134 |
strerror( errno ) ); |
3135 |
return -1; |
3136 |
} |
3137 |
/* |
3138 |
- LEAVE( "RXTXPort:readByte" ); |
3139 |
+ report( "Leaving - RXTXPort:readByte\n" ); |
3140 |
+ memset(&message[0], 0, sizeof(message)); |
3141 |
sprintf( msg, "readByte return(%i)\n", bytes ? buffer[ 0 ] : -1 ); |
3142 |
report( msg ); |
3143 |
report_time_end( ); |
3144 |
@@ -3486,14 +3579,14 @@ |
3145 |
/*---------------------------------------------------------- |
3146 |
RXTXPort.readArray |
3147 |
|
3148 |
- accept: offset (offset to start storing data in the jbarray) and |
3149 |
- Length (bytes to read) |
3150 |
- perform: read bytes from the port into a byte array |
3151 |
- return: bytes read on success |
3152 |
- 0 on read timeout |
3153 |
- exceptions: IOException |
3154 |
- comments: throws ArrayIndexOutOfBoundsException if asked to |
3155 |
- read more than SSIZE_MAX bytes |
3156 |
+ accept: offset (offset to start storing data in the jbarray) and |
3157 |
+ * Length (bytes to read) |
3158 |
+ perform: read bytes from the port into a byte array |
3159 |
+ return: bytes read on success |
3160 |
+ * 0 on read timeout |
3161 |
+ exceptions: IOException |
3162 |
+ comments: throws ArrayIndexOutOfBoundsException if asked to |
3163 |
+ * read more than SSIZE_MAX bytes |
3164 |
----------------------------------------------------------*/ |
3165 |
JNIEXPORT jint JNICALL RXTXPort(readArray)( JNIEnv *env, |
3166 |
jobject jobj, jbyteArray jbarray, jint offset, jint length ) |
3167 |
@@ -3505,12 +3598,12 @@ |
3168 |
int timeout = get_java_var( env, jobj, "timeout", "I" ); |
3169 |
|
3170 |
/* |
3171 |
- ENTER( "readArray" ); |
3172 |
+ report( "Entering - readArray\n" ); |
3173 |
report_time_start( ); |
3174 |
*/ |
3175 |
if( (size_t) length > SSIZE_MAX || (size_t) length < 0 ) { |
3176 |
- report( "RXTXPort:readArray length > SSIZE_MAX" ); |
3177 |
- LEAVE( "RXTXPort:readArray" ); |
3178 |
+ report( "RXTXPort:readArray length > SSIZE_MAX\n" ); |
3179 |
+ report( "Leaving - RXTXPort:readArray\n" ); |
3180 |
throw_java_exception( env, ARRAY_INDEX_OUT_OF_BOUNDS, |
3181 |
"readArray", "Invalid length" ); |
3182 |
return -1; |
3183 |
@@ -3519,17 +3612,18 @@ |
3184 |
bytes = read_byte_array( env, &jobj, fd, (unsigned char *)(body+offset), length, timeout );/* dima */ |
3185 |
(*env)->ReleaseByteArrayElements( env, jbarray, body, 0 ); |
3186 |
if( bytes < 0 ) { |
3187 |
- report( "RXTXPort:readArray bytes < 0" ); |
3188 |
- LEAVE( "RXTXPort:readArray" ); |
3189 |
+ report( "RXTXPort:readArray bytes < 0\n" ); |
3190 |
+ report( "Leaving - RXTXPort:readArray\n" ); |
3191 |
throw_java_exception( env, IO_EXCEPTION, "readArray", |
3192 |
strerror( errno ) ); |
3193 |
return -1; |
3194 |
} |
3195 |
/* |
3196 |
+ memset(&message[0], 0, sizeof(message)); |
3197 |
sprintf( msg, "RXTXPort:readArray: %i %i\n", (int) length, bytes); |
3198 |
report( msg ); |
3199 |
report_time_end( ); |
3200 |
- LEAVE( "RXTXPort:readArray" ); |
3201 |
+ report( "Leaving - RXTXPort:readArray\n" ); |
3202 |
*/ |
3203 |
return (bytes); |
3204 |
} |
3205 |
@@ -3537,11 +3631,11 @@ |
3206 |
/*---------------------------------------------------------- |
3207 |
RXTXPort.nativeClearCommInput |
3208 |
|
3209 |
- accept: none |
3210 |
- perform: try to clear the input. |
3211 |
- return: true on success, false on error |
3212 |
- exceptions: none |
3213 |
- comments: This is an extension to commapi. |
3214 |
+ accept: none |
3215 |
+ perform: try to clear the input. |
3216 |
+ return: true on success, false on error |
3217 |
+ exceptions: none |
3218 |
+ comments: This is an extension to commapi. |
3219 |
----------------------------------------------------------*/ |
3220 |
JNIEXPORT jboolean JNICALL RXTXPort(nativeClearCommInput)( JNIEnv *env, |
3221 |
jobject jobj ) |
3222 |
@@ -3554,18 +3648,18 @@ |
3223 |
/*---------------------------------------------------------- |
3224 |
RXTXPort.readTerminatedArray |
3225 |
|
3226 |
- accept: offset (offset to start storing data in the jbarray) and |
3227 |
- Length (bytes to read). Terminator - 2 bytes that we |
3228 |
- dont read past |
3229 |
- perform: read bytes from the port into a byte array |
3230 |
- return: bytes read on success |
3231 |
- 0 on read timeout |
3232 |
- exceptions: IOException |
3233 |
- comments: throws ArrayIndexOutOfBoundsException if asked to |
3234 |
- read more than SSIZE_MAX bytes |
3235 |
- timeout is not properly handled |
3236 |
+ accept: offset (offset to start storing data in the jbarray) and |
3237 |
+ Length (bytes to read). Terminator - 2 bytes that we |
3238 |
+ dont read past |
3239 |
+ perform: read bytes from the port into a byte array |
3240 |
+ return: bytes read on success |
3241 |
+ 0 on read timeout |
3242 |
+ exceptions: IOException |
3243 |
+ comments: throws ArrayIndexOutOfBoundsException if asked to |
3244 |
+ read more than SSIZE_MAX bytes |
3245 |
+ timeout is not properly handled |
3246 |
|
3247 |
- This is an extension to commapi. |
3248 |
+ This is an extension to commapi. |
3249 |
----------------------------------------------------------*/ |
3250 |
JNIEXPORT jint JNICALL RXTXPort(readTerminatedArray)( JNIEnv *env, |
3251 |
jobject jobj, jbyteArray jbarray, jint offset, jint length, |
3252 |
@@ -3578,12 +3672,12 @@ |
3253 |
int timeout = get_java_var( env, jobj, "timeout", "I" ); |
3254 |
|
3255 |
/* |
3256 |
- ENTER( "readArray" ); |
3257 |
+ report( "Entering - readArray\n" ); |
3258 |
report_time_start( ); |
3259 |
*/ |
3260 |
if( (size_t) length > SSIZE_MAX || (size_t) length < 0 ) { |
3261 |
- report( "RXTXPort:readArray length > SSIZE_MAX" ); |
3262 |
- LEAVE( "RXTXPort:readArray" ); |
3263 |
+ report( "RXTXPort:readArray length > SSIZE_MAX\n" ); |
3264 |
+ report( "Leaving - RXTXPort:readArray\n" ); |
3265 |
throw_java_exception( env, ARRAY_INDEX_OUT_OF_BOUNDS, |
3266 |
"readArray", "Invalid length" ); |
3267 |
return -1; |
3268 |
@@ -3595,8 +3689,8 @@ |
3269 |
bytes = read_byte_array( env, &jobj, fd, (unsigned char *)(body+offset + total ), 1 , timeout );/* dima */ |
3270 |
total += bytes; |
3271 |
if( bytes < 0 ) { |
3272 |
- report( "RXTXPort:readArray bytes < 0" ); |
3273 |
- LEAVE( "RXTXPort:readArray" ); |
3274 |
+ report( "RXTXPort:readArray bytes < 0\n" ); |
3275 |
+ report( "Leaving - RXTXPort:readArray\n" ); |
3276 |
throw_java_exception( env, IO_EXCEPTION, "readArray", |
3277 |
strerror( errno ) ); |
3278 |
return -1; |
3279 |
@@ -3612,10 +3706,11 @@ |
3280 |
} while ( bytes > 0 && total < length ); |
3281 |
(*env)->ReleaseByteArrayElements( env, jbarray, body, 0 ); |
3282 |
/* |
3283 |
+ memset(&message[0], 0, sizeof(message)); |
3284 |
sprintf( msg, "RXTXPort:readArray: %i %i\n", (int) length, bytes); |
3285 |
report( msg ); |
3286 |
report_time_end( ); |
3287 |
- LEAVE( "RXTXPort:readArray" ); |
3288 |
+ report( "Leaving - RXTXPort:readArray\n" ); |
3289 |
*/ |
3290 |
return (bytes); |
3291 |
} |
3292 |
@@ -3623,11 +3718,11 @@ |
3293 |
/*---------------------------------------------------------- |
3294 |
RXTXPort.nativeavailable |
3295 |
|
3296 |
- accept: none |
3297 |
- perform: find out the number of bytes available for reading |
3298 |
- return: available bytes |
3299 |
- -1 on error |
3300 |
- exceptions: none |
3301 |
+ accept: none |
3302 |
+ perform: find out the number of bytes available for reading |
3303 |
+ return: available bytes |
3304 |
+ -1 on error |
3305 |
+ exceptions: none |
3306 |
----------------------------------------------------------*/ |
3307 |
JNIEXPORT jint JNICALL RXTXPort(nativeavailable)( JNIEnv *env, |
3308 |
jobject jobj ) |
3309 |
@@ -3638,13 +3733,13 @@ |
3310 |
char message[80]; |
3311 |
|
3312 |
|
3313 |
- ENTER( "RXTXPort:nativeavailable" ); |
3314 |
+ report( "Entering - RXTXPort:nativeavailable\n" ); |
3315 |
|
3316 |
- On SCO OpenServer FIONREAD always fails for serial devices, |
3317 |
- so try ioctl FIORDCHK instead; will only tell us whether |
3318 |
- bytes are available, not how many, but better than nothing. |
3319 |
+ On SCO OpenServer FIONREAD always fails for serial devices, |
3320 |
+ so try ioctl FIORDCHK instead; will only tell us whether |
3321 |
+ bytes are available, not how many, but better than nothing. |
3322 |
|
3323 |
- This turns out to be true on Solaris also. taj. |
3324 |
+ This turns out to be true on Solaris also. taj. |
3325 |
*/ |
3326 |
#ifdef FIORDCHK /* __unixware__ __sun__ probably others */ |
3327 |
result = ioctl(fd, FIORDCHK, 0); |
3328 |
@@ -3658,22 +3753,24 @@ |
3329 |
goto fail; |
3330 |
} |
3331 |
/* |
3332 |
- sprintf(message, " nativeavailable: FIORDCHK result %d, \ |
3333 |
+ memset(&message[0], 0, sizeof(message)); |
3334 |
+ sprintf(message, " nativeavailable: FIORDCHK result %d, \ |
3335 |
errno %d\n", result , result == -1 ? errno : 0); |
3336 |
report_verbose( message ); |
3337 |
if( result ) |
3338 |
{ |
3339 |
- sprintf(message, " nativeavailable: FIORDCHK result %d, \ |
3340 |
+ memset(&message[0], 0, sizeof(message)); |
3341 |
+ sprintf(message, " nativeavailable: FIORDCHK result %d, \ |
3342 |
errno %d\n", result , result == -1 ? errno : 0); |
3343 |
report( message ); |
3344 |
} |
3345 |
- LEAVE( "RXTXPort:nativeavailable" ); |
3346 |
+ report( "Leaving - RXTXPort:nativeavailable\n" ); |
3347 |
*/ |
3348 |
return (jint)result; |
3349 |
fail: |
3350 |
- report("RXTXPort:nativeavailable: ioctl() failed\n"); |
3351 |
+ report("RXTXPort:nativeavailable: ioctl() failed\n"); |
3352 |
/* |
3353 |
- LEAVE( "RXTXPort:nativeavailable" ); |
3354 |
+ report( "Leaving - RXTXPort:nativeavailable\n" ); |
3355 |
*/ |
3356 |
throw_java_exception( env, IO_EXCEPTION, "nativeavailable", |
3357 |
strerror( errno ) ); |
3358 |
@@ -3683,17 +3780,17 @@ |
3359 |
/*---------------------------------------------------------- |
3360 |
RXTXPort.setflowcontrol |
3361 |
|
3362 |
- accept: flowmode |
3363 |
- FLOWCONTROL_NONE none |
3364 |
- FLOWCONTROL_RTSCTS_IN hardware flow control |
3365 |
- FLOWCONTROL_RTSCTS_OUT "" |
3366 |
- FLOWCONTROL_XONXOFF_IN input software flow control |
3367 |
- FLOWCONTROL_XONXOFF_OUT output software flow control |
3368 |
- perform: set flow control to flowmode |
3369 |
- return: none |
3370 |
- exceptions: UnsupportedCommOperationException |
3371 |
- comments: there is no differentiation between input and output hardware |
3372 |
- flow control |
3373 |
+ accept: flowmode |
3374 |
+ FLOWCONTROL_NONE none |
3375 |
+ FLOWCONTROL_RTSCTS_IN hardware flow control |
3376 |
+ FLOWCONTROL_RTSCTS_OUT "" |
3377 |
+ FLOWCONTROL_XONXOFF_IN input software flow control |
3378 |
+ FLOWCONTROL_XONXOFF_OUT output software flow control |
3379 |
+ perform: set flow control to flowmode |
3380 |
+ return: none |
3381 |
+ exceptions: UnsupportedCommOperationException |
3382 |
+ comments: there is no differentiation between input and output hardware |
3383 |
+ flow control |
3384 |
----------------------------------------------------------*/ |
3385 |
JNIEXPORT void JNICALL RXTXPort(setflowcontrol)( JNIEnv *env, |
3386 |
jobject jobj, jint flowmode ) |
3387 |
@@ -3701,7 +3798,7 @@ |
3388 |
struct termios ttyset; |
3389 |
int fd = get_java_var( env, jobj,"fd","I" ); |
3390 |
|
3391 |
- ENTER( "RXTXPort:setflowcontrol" ); |
3392 |
+ report( "Entering - RXTXPort:setflowcontrol\n" ); |
3393 |
if( tcgetattr( fd, &ttyset ) ) goto fail; |
3394 |
|
3395 |
if ( flowmode & ( FLOWCONTROL_RTSCTS_IN | FLOWCONTROL_RTSCTS_OUT ) ) |
3396 |
@@ -3726,10 +3823,10 @@ |
3397 |
else ttyset.c_iflag &= ~IXON; |
3398 |
/* TRENT */ |
3399 |
if( tcsetattr( fd, TCSANOW, &ttyset ) ) goto fail; |
3400 |
- LEAVE( "RXTXPort:setflowcontrol" ); |
3401 |
+ report( "Leaving - RXTXPort:setflowcontrol\n" ); |
3402 |
return; |
3403 |
fail: |
3404 |
- LEAVE( "RXTXPort:setflowcontrol" ); |
3405 |
+ report( "Leaving - RXTXPort:setflowcontrol\n" ); |
3406 |
throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, "", |
3407 |
"flow control type not supported" ); |
3408 |
return; |
3409 |
@@ -3738,30 +3835,32 @@ |
3410 |
/*---------------------------------------------------------- |
3411 |
unlock_monitor_thread |
3412 |
|
3413 |
- accept: event_info_struct |
3414 |
- perform: unlock the monitor thread so event notification can start. |
3415 |
- return: none |
3416 |
- exceptions: none |
3417 |
- comments: Events can be missed otherwise. |
3418 |
+ accept: event_info_struct |
3419 |
+ perform: unlock the monitor thread so event notification can start. |
3420 |
+ return: none |
3421 |
+ exceptions: none |
3422 |
+ comments: Events can be missed otherwise. |
3423 |
----------------------------------------------------------*/ |
3424 |
|
3425 |
void unlock_monitor_thread( struct event_info_struct *eis ) |
3426 |
{ |
3427 |
+ report("Entering - unlock_monitor_thread\n"); |
3428 |
JNIEnv *env = eis->env; |
3429 |
jobject jobj = *(eis->jobj); |
3430 |
|
3431 |
jfieldID jfid = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, jobj ), "MonitorThreadLock", "Z" ); |
3432 |
(*env)->SetBooleanField( env, jobj, jfid, (jboolean) 0 ); |
3433 |
+ report("Leaving - unlock_monitor_thread\n"); |
3434 |
} |
3435 |
|
3436 |
/*---------------------------------------------------------- |
3437 |
check_line_status_register |
3438 |
|
3439 |
- accept: event_info_struct |
3440 |
- perform: check for changes on the LSR |
3441 |
- return: 0 on success |
3442 |
- exceptions: none |
3443 |
- comments: not supported on all devices/drivers. |
3444 |
+ accept: event_info_struct |
3445 |
+ perform: check for changes on the LSR |
3446 |
+ return: 0 on success |
3447 |
+ exceptions: none |
3448 |
+ comments: not supported on all devices/drivers. |
3449 |
----------------------------------------------------------*/ |
3450 |
int check_line_status_register( struct event_info_struct *eis ) |
3451 |
{ |
3452 |
@@ -3771,8 +3870,8 @@ |
3453 |
if( ! eis->eventflags[SPE_OUTPUT_BUFFER_EMPTY] ) |
3454 |
{ |
3455 |
/* This occurs constantly so remove for now |
3456 |
- * report( "check_line_status_registe OUPUT_BUFFER_EMPTY not set\n" ); |
3457 |
- */ |
3458 |
+ * report( "check_line_status_registe OUPUT_BUFFER_EMPTY not set\n" ); |
3459 |
+ */ |
3460 |
return 0; |
3461 |
} |
3462 |
if ( fstat( eis->fd, &fstatbuf ) ) |
3463 |
@@ -3811,16 +3910,17 @@ |
3464 |
/*---------------------------------------------------------- |
3465 |
has_line_status_register_access |
3466 |
|
3467 |
- accept: fd of interest |
3468 |
- perform: check for access to the LSR |
3469 |
- return: 0 if not available |
3470 |
- exceptions: none |
3471 |
- comments: not supported on all devices/drivers. |
3472 |
- JK00: work around for multiport cards without TIOCSERGETLSR |
3473 |
- Cyclades is one of those :-( |
3474 |
+ accept: fd of interest |
3475 |
+ perform: check for access to the LSR |
3476 |
+ return: 0 if not available |
3477 |
+ exceptions: none |
3478 |
+ comments: not supported on all devices/drivers. |
3479 |
+ JK00: work around for multiport cards without TIOCSERGETLSR |
3480 |
+ Cyclades is one of those :-( |
3481 |
----------------------------------------------------------*/ |
3482 |
int has_line_status_register_access( int fd ) |
3483 |
{ |
3484 |
+ report("Entering - has_line_status_register_access\n"); |
3485 |
#if defined(TIOCSERGETLSR) |
3486 |
int change; |
3487 |
|
3488 |
@@ -3835,17 +3935,17 @@ |
3489 |
/*---------------------------------------------------------- |
3490 |
check_cgi_count |
3491 |
|
3492 |
- accept: fd of interest |
3493 |
- perform: check for access to TIOCGICOUNT |
3494 |
- return: 0 if not available |
3495 |
- exceptions: none |
3496 |
- comments: not supported on all devices/drivers. |
3497 |
- * wait for RNG, DSR, CD or CTS but not DataAvailable |
3498 |
- * The drawback here is it never times out so if someone |
3499 |
- * reads there will be no chance to try again. |
3500 |
- * This may make sense if the program does not want to |
3501 |
- * be notified of data available or errors. |
3502 |
- * ret=ioctl(fd,TIOCMIWAIT); |
3503 |
+ accept: fd of interest |
3504 |
+ perform: check for access to TIOCGICOUNT |
3505 |
+ return: 0 if not available |
3506 |
+ exceptions: none |
3507 |
+ comments: not supported on all devices/drivers. |
3508 |
+ wait for RNG, DSR, CD or CTS but not DataAvailable |
3509 |
+ The drawback here is it never times out so if someone |
3510 |
+ reads there will be no chance to try again. |
3511 |
+ This may make sense if the program does not want to |
3512 |
+ be notified of data available or errors. |
3513 |
+ ret=ioctl(fd,TIOCMIWAIT); |
3514 |
----------------------------------------------------------*/ |
3515 |
void check_cgi_count( struct event_info_struct *eis ) |
3516 |
{ |
3517 |
@@ -3885,11 +3985,11 @@ |
3518 |
/*---------------------------------------------------------- |
3519 |
port_has_changed_fionread |
3520 |
|
3521 |
- accept: fd of interest |
3522 |
- perform: check if FIONREAD has changed |
3523 |
- return: 0 if no data available |
3524 |
- exceptions: none |
3525 |
- comments: |
3526 |
+ accept: fd of interest |
3527 |
+ perform: check if FIONREAD has changed |
3528 |
+ return: 0 if no data available |
3529 |
+ exceptions: none |
3530 |
+ comments: |
3531 |
----------------------------------------------------------*/ |
3532 |
int port_has_changed_fionread( struct event_info_struct *eis ) |
3533 |
{ |
3534 |
@@ -3897,17 +3997,19 @@ |
3535 |
char message[80]; |
3536 |
|
3537 |
rc = ioctl( eis->fd, FIONREAD, &change ); |
3538 |
+ memset(&message[0], 0, sizeof(message)); |
3539 |
sprintf( message, "port_has_changed_fionread: change is %i ret is %i\n", change, eis->ret ); |
3540 |
#if defined(__unixware__) || defined(__sun__) |
3541 |
/* |
3542 |
- On SCO OpenServer FIONREAD always fails for serial devices, |
3543 |
- so rely upon select() result to know whether data available. |
3544 |
+ On SCO OpenServer FIONREAD always fails for serial devices, |
3545 |
+ so rely upon select() result to know whether data available. |
3546 |
|
3547 |
- This is true for Solaris, also. taj. |
3548 |
+ This is true for Solaris, also. taj. |
3549 |
*/ |
3550 |
if( (rc != -1 && change) || (rc == -1 && eis->ret > 0) ) |
3551 |
return( 1 ); |
3552 |
#else |
3553 |
+ memset(&message[0], 0, sizeof(message)); |
3554 |
sprintf( message, "port_has_changed_fionread: change is %i\n", change ); |
3555 |
report_verbose( message ); |
3556 |
if( change ) |
3557 |
@@ -3919,11 +4021,11 @@ |
3558 |
/*---------------------------------------------------------- |
3559 |
check_tiocmget_changes |
3560 |
|
3561 |
- accept: event_info_struct |
3562 |
- perform: use TIOCMGET to report events |
3563 |
- return: none |
3564 |
- exceptions: none |
3565 |
- comments: not supported on all devices/drivers. |
3566 |
+ accept: event_info_struct |
3567 |
+ perform: use TIOCMGET to report events |
3568 |
+ return: none |
3569 |
+ exceptions: none |
3570 |
+ comments: not supported on all devices/drivers. |
3571 |
----------------------------------------------------------*/ |
3572 |
void check_tiocmget_changes( struct event_info_struct * eis ) |
3573 |
{ |
3574 |
@@ -3966,11 +4068,11 @@ |
3575 |
/*---------------------------------------------------------- |
3576 |
system_wait |
3577 |
|
3578 |
- accept: |
3579 |
- perform: |
3580 |
- return: |
3581 |
- exceptions: none |
3582 |
- comments: |
3583 |
+ accept: |
3584 |
+ perform: |
3585 |
+ return: |
3586 |
+ exceptions: none |
3587 |
+ comments: |
3588 |
----------------------------------------------------------*/ |
3589 |
void system_wait() |
3590 |
{ |
3591 |
@@ -3987,9 +4089,9 @@ |
3592 |
#else |
3593 |
#ifdef TRENT_IS_HERE_DEBUGGING_THREADS |
3594 |
/* On NT4 The following was observed in a intense test: |
3595 |
- 50000 95% 179 sec |
3596 |
- 200000 95% 193 sec |
3597 |
- 1000000 95% 203 sec some callback failures sometimes. |
3598 |
+ 50000 95% 179 sec |
3599 |
+ 200000 95% 193 sec |
3600 |
+ 1000000 95% 203 sec some callback failures sometimes. |
3601 |
2000000 0-95% callback failures. |
3602 |
*/ |
3603 |
#endif /* TRENT_IS_HERE_DEBUGGING_THREADS */ |
3604 |
@@ -3999,28 +4101,32 @@ |
3605 |
/*---------------------------------------------------------- |
3606 |
driver_has_tiocgicount |
3607 |
|
3608 |
- accept: fd of interest |
3609 |
- perform: check for access to TIOCGICOUNT |
3610 |
- return: 0 if not available |
3611 |
- exceptions: none |
3612 |
- comments: not supported on all devices/drivers. |
3613 |
- Some multiport serial cards do not implement TIOCGICOUNT ... |
3614 |
- So use the 'dumb' mode to enable using them after all! JK00 |
3615 |
+ accept: fd of interest |
3616 |
+ perform: check for access to TIOCGICOUNT |
3617 |
+ return: 0 if not available |
3618 |
+ exceptions: none |
3619 |
+ comments: not supported on all devices/drivers. |
3620 |
+ Some multiport serial cards do not implement TIOCGICOUNT |
3621 |
+ So use the 'dumb' mode to enable using them after all! |
3622 |
+ JK00 |
3623 |
----------------------------------------------------------*/ |
3624 |
int driver_has_tiocgicount( struct event_info_struct * eis ) |
3625 |
{ |
3626 |
+ report("Entering - driver_has_tiocgicount\n"); |
3627 |
#if defined(TIOCGICOUNT) |
3628 |
- |
3629 |
+ report("TIOCGICOUNT is defined\n"); |
3630 |
/* Some multiport serial cards do not implement TIOCGICOUNT ... */ |
3631 |
/* So use the 'dumb' mode to enable using them after all! JK00 */ |
3632 |
|
3633 |
if( ioctl( eis->fd, TIOCGICOUNT, &eis->osis ) < 0 ) { |
3634 |
- report_verbose( " driver_has_tiocgicount: Port does not support TIOCGICOUNT events\n" ); |
3635 |
+ report_verbose( " driver_has_tiocgicount: Port does not support TIOCGICOUNT events\n" ); |
3636 |
return(0); |
3637 |
} |
3638 |
else |
3639 |
+ report("driver_has_tiocgicount: TIOCGICOUNT is implemented\n"); |
3640 |
return(1); |
3641 |
#endif /* TIOCGICOUNT */ |
3642 |
+ report("Leaving - driver_has_tiocgicount\n"); |
3643 |
return(0); |
3644 |
|
3645 |
} |
3646 |
@@ -4028,11 +4134,11 @@ |
3647 |
/*---------------------------------------------------------- |
3648 |
report_serial_events |
3649 |
|
3650 |
- accept: event_info_struct |
3651 |
- perform: send events if they occured |
3652 |
- return: 0 if not available |
3653 |
- exceptions: none |
3654 |
- comments: not supported on all devices/drivers. |
3655 |
+ accept: event_info_struct |
3656 |
+ perform: send events if they occured |
3657 |
+ return: 0 if not available |
3658 |
+ exceptions: none |
3659 |
+ comments: not supported on all devices/drivers. |
3660 |
----------------------------------------------------------*/ |
3661 |
void report_serial_events( struct event_info_struct *eis ) |
3662 |
{ |
3663 |
@@ -4053,7 +4159,7 @@ |
3664 |
{ |
3665 |
report_verbose("report_serial_events: ignoring DATA_AVAILABLE\n"); |
3666 |
/* |
3667 |
- report("."); |
3668 |
+ report(".\n"); |
3669 |
*/ |
3670 |
usleep(20000); |
3671 |
#if !defined(__sun__) |
3672 |
@@ -4078,14 +4184,15 @@ |
3673 |
/*---------------------------------------------------------- |
3674 |
initialise_event_info_struct |
3675 |
|
3676 |
- accept: event_info_struct for this thread. |
3677 |
- perform: initialise or reset the event_info_struct |
3678 |
- return: 1 on success |
3679 |
- exceptions: none |
3680 |
- comments: |
3681 |
+ accept: event_info_struct for this thread. |
3682 |
+ perform: initialise or reset the event_info_struct |
3683 |
+ return: 1 on success |
3684 |
+ exceptions: none |
3685 |
+ comments: |
3686 |
----------------------------------------------------------*/ |
3687 |
int initialise_event_info_struct( struct event_info_struct *eis ) |
3688 |
{ |
3689 |
+ report("Entering - initialise_event_info_struct\n"); |
3690 |
int i; |
3691 |
jobject jobj = *eis->jobj; |
3692 |
JNIEnv *env = eis->env; |
3693 |
@@ -4141,21 +4248,23 @@ |
3694 |
eis->tv_sleep.tv_sec = 0; |
3695 |
eis->tv_sleep.tv_usec = 1000; |
3696 |
eis->initialised = 1; |
3697 |
+ report("Leaving - initialise_event_info_struct\n"); |
3698 |
return( 1 ); |
3699 |
fail: |
3700 |
report_error("initialise_event_info_struct: initialise failed!\n"); |
3701 |
finalize_event_info_struct( eis ); |
3702 |
+ report("Leaving - initialise_event_info_struct\n"); |
3703 |
return( 0 ); |
3704 |
} |
3705 |
|
3706 |
/*---------------------------------------------------------- |
3707 |
finalize_event_info_struct |
3708 |
|
3709 |
- accept: event_info_struct for this thread. |
3710 |
- perform: free resources |
3711 |
- return: none |
3712 |
- exceptions: none |
3713 |
- comments: |
3714 |
+ accept: event_info_struct for this thread. |
3715 |
+ perform: free resources |
3716 |
+ return: none |
3717 |
+ exceptions: none |
3718 |
+ comments: |
3719 |
----------------------------------------------------------*/ |
3720 |
void finalize_event_info_struct( struct event_info_struct *eis ) |
3721 |
{ |
3722 |
@@ -4181,14 +4290,15 @@ |
3723 |
/*---------------------------------------------------------- |
3724 |
RXTXPort.eventLoop |
3725 |
|
3726 |
- accept: none |
3727 |
- perform: periodically check for SerialPortEvents |
3728 |
- return: none |
3729 |
- exceptions: none |
3730 |
- comments: please keep this function clean. |
3731 |
+ accept: none |
3732 |
+ perform: periodically check for SerialPortEvents |
3733 |
+ return: none |
3734 |
+ exceptions: none |
3735 |
+ comments: please keep this function clean. |
3736 |
----------------------------------------------------------*/ |
3737 |
JNIEXPORT void JNICALL RXTXPort(eventLoop)( JNIEnv *env, jobject jobj ) |
3738 |
{ |
3739 |
+ report( "Entering - RXTXPort_eventLoop\n" ); |
3740 |
#ifdef WIN32 |
3741 |
int i = 0; |
3742 |
#endif /* WIN32 */ |
3743 |
@@ -4198,74 +4308,92 @@ |
3744 |
eis.jobj = &jobj; |
3745 |
eis.initialised = 0; |
3746 |
|
3747 |
- ENTER( "eventLoop\n" ); |
3748 |
+ |
3749 |
if ( !initialise_event_info_struct( &eis ) ) goto end; |
3750 |
if ( !init_threads( &eis ) ) goto end; |
3751 |
+ |
3752 |
+ report( "RXTXPort_eventLoop - Unlocking Monitor Thread\n" ); |
3753 |
unlock_monitor_thread( &eis ); |
3754 |
+ |
3755 |
do{ |
3756 |
report_time_eventLoop( ); |
3757 |
do { |
3758 |
/* nothing goes between this call and select */ |
3759 |
if( eis.closing ) |
3760 |
{ |
3761 |
- report("eventLoop: got interrupt\n"); |
3762 |
+ report( "RXTXPort_eventLoop - Got Interupted\n" ); |
3763 |
finalize_threads( &eis ); |
3764 |
finalize_event_info_struct( &eis ); |
3765 |
- LEAVE("eventLoop"); |
3766 |
+ report("Leaving - RXTXPort_eventLoop\n"); |
3767 |
return; |
3768 |
} |
3769 |
-#ifndef WIN32 |
3770 |
- /* report( "." ); */ |
3771 |
- do { |
3772 |
- eis.ret = SELECT( eis.fd + 1, &eis.rfds, NULL, NULL, |
3773 |
- &eis.tv_sleep ); |
3774 |
- } while (eis.ret < 0 && errno==EINTR); |
3775 |
-#else |
3776 |
- /* |
3777 |
- termios.c:serial_select is instable for some |
3778 |
- reason |
3779 |
- |
3780 |
- polling is not blowing up. |
3781 |
- */ |
3782 |
-/* |
3783 |
- usleep(5000); |
3784 |
-*/ |
3785 |
- eis.ret=1; |
3786 |
- while( i++ < 5 ) |
3787 |
- { |
3788 |
- if(eis.eventflags[SPE_DATA_AVAILABLE] ) |
3789 |
+ |
3790 |
+ #ifndef WIN32 |
3791 |
+ |
3792 |
+ /** |
3793 |
+ * report( "." ); |
3794 |
+ **/ |
3795 |
+ |
3796 |
+ do { |
3797 |
+ eis.ret = SELECT( eis.fd + 1, &eis.rfds, NULL, NULL, |
3798 |
+ &eis.tv_sleep ); |
3799 |
+ } while (eis.ret < 0 && errno==EINTR); |
3800 |
+ |
3801 |
+ #else |
3802 |
+ |
3803 |
+ /** |
3804 |
+ * termios.c:serial_select is instable for some |
3805 |
+ * reason |
3806 |
+ * |
3807 |
+ * polling is not blowing up. |
3808 |
+ **/ |
3809 |
+ |
3810 |
+ /** |
3811 |
+ * usleep(5000); |
3812 |
+ **/ |
3813 |
+ |
3814 |
+ eis.ret=1; |
3815 |
+ while( i++ < 5 ) |
3816 |
{ |
3817 |
- if( port_has_changed_fionread( &eis ) ) |
3818 |
+ if(eis.eventflags[SPE_DATA_AVAILABLE] ) |
3819 |
{ |
3820 |
- send_event( &eis, SPE_DATA_AVAILABLE, 1 ); |
3821 |
+ if( port_has_changed_fionread( &eis ) ) |
3822 |
+ { |
3823 |
+ send_event( &eis, SPE_DATA_AVAILABLE, 1 ); |
3824 |
+ } |
3825 |
} |
3826 |
+ usleep(1000); |
3827 |
} |
3828 |
- usleep(1000); |
3829 |
- } |
3830 |
- i = 0; |
3831 |
-#endif /* WIN32 */ |
3832 |
+ i = 0; |
3833 |
+ |
3834 |
+ #endif /* WIN32 */ |
3835 |
} while ( eis.ret < 0 && errno == EINTR ); |
3836 |
+ |
3837 |
+ |
3838 |
+ |
3839 |
if( eis.ret >= 0 ) |
3840 |
{ |
3841 |
report_serial_events( &eis ); |
3842 |
} |
3843 |
+ |
3844 |
initialise_event_info_struct( &eis ); |
3845 |
+ |
3846 |
} while( 1 ); |
3847 |
end: |
3848 |
- LEAVE( "eventLoop: Bailing!\n" ); |
3849 |
+ report( "Leaving - eventLoop: Bailing!\n" ); |
3850 |
} |
3851 |
|
3852 |
/*---------------------------------------------------------- |
3853 |
RXTXVersion.nativeGetVersion |
3854 |
|
3855 |
- accept: none |
3856 |
- perform: return the current version |
3857 |
- return: version |
3858 |
- exceptions: none |
3859 |
- comments: This is used to avoid mixing versions of the .jar and |
3860 |
- native library. |
3861 |
- First introduced in rxtx-1.5-9 |
3862 |
- Moved from RXTXCommDriver to RXTXVersion in rxtx-2.1-7 |
3863 |
+ accept: none |
3864 |
+ perform: return the current version |
3865 |
+ return: version |
3866 |
+ exceptions: none |
3867 |
+ comments: This is used to avoid mixing versions of the .jar and |
3868 |
+ native library. |
3869 |
+ First introduced in rxtx-1.5-9 |
3870 |
+ Moved from RXTXCommDriver to RXTXVersion in rxtx-2.1-7 |
3871 |
|
3872 |
----------------------------------------------------------*/ |
3873 |
JNIEXPORT jstring JNICALL RXTXVersion(nativeGetVersion) (JNIEnv *env, |
3874 |
@@ -4277,13 +4405,13 @@ |
3875 |
/*---------------------------------------------------------- |
3876 |
RXTXCommDriver.testRead |
3877 |
|
3878 |
- accept: tty_name The device to be tested |
3879 |
- perform: test if the device can be read from |
3880 |
- return: JNI_TRUE if the device can be read from |
3881 |
- exceptions: none |
3882 |
- comments: From Wayne Roberts wroberts1@home.com |
3883 |
- check tcget/setattr returns. |
3884 |
- support for non serial ports Trent |
3885 |
+ accept: tty_name The device to be tested |
3886 |
+ perform: test if the device can be read from |
3887 |
+ return: JNI_TRUE if the device can be read from |
3888 |
+ exceptions: none |
3889 |
+ comments: From Wayne Roberts wroberts1@home.com |
3890 |
+ check tcget/setattr returns. |
3891 |
+ support for non serial ports Trent |
3892 |
----------------------------------------------------------*/ |
3893 |
|
3894 |
JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)( |
3895 |
@@ -4293,68 +4421,117 @@ |
3896 |
jint port_type |
3897 |
) |
3898 |
{ |
3899 |
+ |
3900 |
+ const char *name = (*env)->GetStringUTFChars(env, tty_name, 0); |
3901 |
+ |
3902 |
+ char sm[256]; |
3903 |
+ memset(&sm[0], 0, sizeof(sm)); |
3904 |
+ sprintf( sm, "Entering - RXTXPort:testRead(%s, %i)\n", name, port_type ); |
3905 |
+ report( sm ); |
3906 |
+ |
3907 |
struct termios ttyset; |
3908 |
char c; |
3909 |
-#ifdef TRENT_IS_HERE_DEBUGGING_ENUMERATION |
3910 |
- char message[80]; |
3911 |
-#endif /* TRENT_IS_HERE_DEBUGGING_ENUMERATION */ |
3912 |
+ char message[256]; |
3913 |
int fd; |
3914 |
- const char *name = (*env)->GetStringUTFChars(env, tty_name, 0); |
3915 |
+ |
3916 |
int ret = JNI_TRUE; |
3917 |
int pid = -1; |
3918 |
- /* We opened the file in this thread, use this pid to unlock */ |
3919 |
-#ifndef WIN32 |
3920 |
- pid = getpid(); |
3921 |
-#else |
3922 |
- char full_windows_name[80]; |
3923 |
-#endif /* WIN32 */ |
3924 |
- |
3925 |
- ENTER( "RXTXPort:testRead" ); |
3926 |
-#ifdef TRENT_IS_HERE_DEBUGGING_ENUMERATION |
3927 |
- /* vmware lies about which ports are there causing irq conflicts */ |
3928 |
- /* this is for testing only */ |
3929 |
- if( !strcmp( name, "COM1" ) || !strcmp( name, "COM2") ) |
3930 |
- { |
3931 |
- printf("%s is good\n",name); |
3932 |
- sprintf( message, "testRead: %s is good!\n", name ); |
3933 |
- report( message ); |
3934 |
+ |
3935 |
+ /* We open the file in this thread, use this pid to unlock */ |
3936 |
+ #ifndef WIN32 |
3937 |
+ pid = getpid(); |
3938 |
+ #else |
3939 |
+ char full_windows_name[80]; |
3940 |
+ #endif /* WIN32 */ |
3941 |
+ |
3942 |
+ #ifdef TRENT_IS_HERE_DEBUGGING_ENUMERATION |
3943 |
+ char message[80]; |
3944 |
+ /* vmware lies about which ports are there causing irq conflicts */ |
3945 |
+ /* this is for testing only */ |
3946 |
+ if( !strcmp( name, "COM1" ) || !strcmp( name, "COM2") ) |
3947 |
+ { |
3948 |
+ printf("%s is good\n",name); |
3949 |
+ memset(&message[0], 0, sizeof(message)); |
3950 |
+ sprintf( message, "testRead: %s is good!\n", name ); |
3951 |
+ report( message ); |
3952 |
+ (*env)->ReleaseStringUTFChars( env, tty_name, name ); |
3953 |
+ return( JNI_TRUE ); |
3954 |
+ } |
3955 |
(*env)->ReleaseStringUTFChars( env, tty_name, name ); |
3956 |
- return( JNI_TRUE ); |
3957 |
- } |
3958 |
- (*env)->ReleaseStringUTFChars( env, tty_name, name ); |
3959 |
- return( JNI_FALSE ); |
3960 |
-#endif /* TRENT_IS_HERE_DEBUGGING_ENUMERATION */ |
3961 |
-#ifdef WIN32 |
3962 |
- strcpy( full_windows_name, DEVICEDIR ); |
3963 |
- strcat( full_windows_name, name ); |
3964 |
- ret = serial_test((char *) full_windows_name ); |
3965 |
- (*env)->ReleaseStringUTFChars( env, tty_name, name ); |
3966 |
- return(ret); |
3967 |
-#endif /* WIN32 */ |
3968 |
+ return( JNI_FALSE ); |
3969 |
+ #endif /* TRENT_IS_HERE_DEBUGGING_ENUMERATION */ |
3970 |
+ |
3971 |
+ #ifdef WIN32 |
3972 |
+ strcpy( full_windows_name, DEVICEDIR ); |
3973 |
+ strcat( full_windows_name, name ); |
3974 |
+ ret = serial_test((char *) full_windows_name ); |
3975 |
+ (*env)->ReleaseStringUTFChars( env, tty_name, name ); |
3976 |
+ return(ret); |
3977 |
+ #endif /* WIN32 */ |
3978 |
|
3979 |
- /* |
3980 |
- LOCK is one of three functions defined in SerialImp.h |
3981 |
+ /** |
3982 |
+ * LOCK is one of three functions defined in SerialImp.h |
3983 |
+ * uucp_lock Solaris |
3984 |
+ * fhs_lock Linux |
3985 |
+ * system_does_not_lock Win32 |
3986 |
+ **/ |
3987 |
|
3988 |
- uucp_lock Solaris |
3989 |
- fhs_lock Linux |
3990 |
- system_does_not_lock Win32 |
3991 |
- */ |
3992 |
- |
3993 |
- if ( LOCK( name, pid ) ) |
3994 |
+ |
3995 |
+ if ( port_type == PORT_SERIAL ) |
3996 |
{ |
3997 |
- (*env)->ReleaseStringUTFChars(env, tty_name, name); |
3998 |
- LEAVE( "RXTXPort:testRead no lock" ); |
3999 |
- return JNI_FALSE; |
4000 |
- } |
4001 |
+ int lockstate; |
4002 |
+ report( "testRead() checking for lock\n" ); |
4003 |
+ lockstate = LOCK(name, pid); |
4004 |
+ report( "testRead() - lock check complete\n" ); |
4005 |
+ |
4006 |
|
4007 |
- /* |
4008 |
- CLOCAL eliminates open blocking on modem status lines |
4009 |
- -- changed to O_NONBLOCK |
4010 |
- */ |
4011 |
- do { |
4012 |
+ if ( lockstate == 1 ) |
4013 |
+ { |
4014 |
+ (*env)->ReleaseStringUTFChars(env, tty_name, name); |
4015 |
+ report( "Leaving - RXTXPort:testRead no lock\n" ); |
4016 |
+ return JNI_FALSE; |
4017 |
+ } |
4018 |
+ else |
4019 |
+ { |
4020 |
+ memset(&message[0], 0, sizeof(message)); |
4021 |
+ sprintf( message, "testRead() - going to open the file (%i)\n", (int) O_RDWR); |
4022 |
+ report( message ); |
4023 |
+ } |
4024 |
+ } |
4025 |
+ /** |
4026 |
+ * CLOCAL eliminates open blocking on modem status lines |
4027 |
+ * -- changed to O_NONBLOCK |
4028 |
+ **/ |
4029 |
+ |
4030 |
+ /** |
4031 |
+ * FIXME - On FreeBSD the open command on /dev/lpt0 hangs for |
4032 |
+ * about 5 - 30 seconds in FreeBSD v10.1-p9 on i386. |
4033 |
+ * No idea how to resolve yet. Returns errno == EBUSY. |
4034 |
+ **/ |
4035 |
+ |
4036 |
+ do |
4037 |
+ { |
4038 |
fd=OPEN ( name, O_RDWR | O_NOCTTY | O_NONBLOCK ); |
4039 |
} while ( fd < 0 && errno==EINTR ); |
4040 |
|
4041 |
+ /** |
4042 |
+ * Just because a port is busy, doesn't mean that we can't use it, |
4043 |
+ * but shows it is available for future use... |
4044 |
+ * Note: This skips all the permission tests, as it is in use. |
4045 |
+ * |
4046 |
+ * FIXME: Get perms on FreeBSD from STAT command returned results. |
4047 |
+ * |
4048 |
+ * so: |
4049 |
+ **/ |
4050 |
+ if ( errno == EBUSY ) |
4051 |
+ { |
4052 |
+ goto END; |
4053 |
+ } |
4054 |
+ |
4055 |
+ memset(&message[0], 0, sizeof(message)); |
4056 |
+ sprintf( message, "testRead() - open returned(errno = %i, fd = %i)\n", (int) errno, (int) fd); |
4057 |
+ report( message ); |
4058 |
+ |
4059 |
if( fd < 0 ) |
4060 |
{ |
4061 |
report_verbose( "testRead() open failed\n" ); |
4062 |
@@ -4366,12 +4543,14 @@ |
4063 |
{ |
4064 |
int saved_flags; |
4065 |
struct termios saved_termios; |
4066 |
- |
4067 |
+ |
4068 |
+ report_verbose( "testRead() - tcgetattr\n" ); |
4069 |
+ |
4070 |
if (tcgetattr(fd, &ttyset) < 0) { |
4071 |
ret = JNI_FALSE; |
4072 |
goto END; |
4073 |
} |
4074 |
- |
4075 |
+ |
4076 |
/* save, restore later */ |
4077 |
if ( ( saved_flags = fcntl(fd, F_GETFL ) ) < 0 ) |
4078 |
{ |
4079 |
@@ -4379,7 +4558,7 @@ |
4080 |
ret = JNI_FALSE; |
4081 |
goto END; |
4082 |
} |
4083 |
- |
4084 |
+ |
4085 |
memcpy( &saved_termios, &ttyset, sizeof( struct termios ) ); |
4086 |
|
4087 |
if ( fcntl( fd, F_SETFL, O_NONBLOCK ) < 0 ) |
4088 |
@@ -4400,97 +4579,97 @@ |
4089 |
goto END; |
4090 |
} |
4091 |
|
4092 |
-/* |
4093 |
- |
4094 |
- The following may mess up if both EAGAIN and EWOULDBLOCK |
4095 |
- are defined but only EWOULDBLOCK is used |
4096 |
- |
4097 |
- Linux: |
4098 |
- |
4099 |
- man 2 open |
4100 |
- O_NONBLOCK or O_NDELAY |
4101 |
- When possible, the file is opened in non-blocking |
4102 |
- mode. Neither the open nor any subsequent opera� |
4103 |
- tions on the file descriptor which is returned will |
4104 |
- cause the calling process to wait. For the han� |
4105 |
- dling of FIFOs (named pipes), see also fifo(4). |
4106 |
- This mode need not have any effect on files other |
4107 |
- than FIFOs. |
4108 |
- |
4109 |
- man 2 read |
4110 |
- EAGAIN |
4111 |
- Non-blocking I/O has been selected using O_NONBLOCK |
4112 |
- and no data was immediately available for reading. |
4113 |
- |
4114 |
- |
4115 |
- /usr/include/asm/error.h: |
4116 |
- #define EAGAIN 11 / Try again / |
4117 |
- #define EWOULDBLOCK EAGAIN / Operation would block / |
4118 |
- |
4119 |
- looks like the kernel is using EAGAIN |
4120 |
- |
4121 |
- -- should be OK |
4122 |
- |
4123 |
- Solaris: |
4124 |
- |
4125 |
- man 2 open |
4126 |
- EAGAIN The path argument names the slave side of a |
4127 |
- pseudo-terminal device that is locked. |
4128 |
- |
4129 |
- man 2 read |
4130 |
- If O_NONBLOCK is set, read() returns -1 and sets errno |
4131 |
- to EAGAIN. |
4132 |
- |
4133 |
- -- should be OK. |
4134 |
- |
4135 |
- HP-UX |
4136 |
- |
4137 |
- both are defined but EAGAIN is used. |
4138 |
- |
4139 |
- -- should be OK. |
4140 |
- |
4141 |
- Win32 |
4142 |
- |
4143 |
- neither errno is currently set. Comment added to termios.c |
4144 |
- serial_open(). |
4145 |
- |
4146 |
- -- should be OK |
4147 |
- |
4148 |
-Steven's book. Advanced programming in the Unix Environment pg 364 |
4149 |
- |
4150 |
-"A common use for nonblocking I/O is for dealing with a terminal device |
4151 |
-for a network connection and these devices are normally used by one process |
4152 |
-at a time. This means that the change in the BSD semantics normally does 't |
4153 |
-effect us. The different error return, EWOULDBLOCK, instead of POSIX.1 |
4154 |
-EAGAIN, continues to be a portability difference that we must deal with." |
4155 |
- |
4156 |
-*/ |
4157 |
- |
4158 |
+ /** |
4159 |
+ * The following may mess up if both EAGAIN and EWOULDBLOCK |
4160 |
+ * are defined but only EWOULDBLOCK is used |
4161 |
+ * |
4162 |
+ * Linux: |
4163 |
+ * |
4164 |
+ * man 2 open |
4165 |
+ * O_NONBLOCK or O_NDELAY |
4166 |
+ * When possible, the file is opened in non-blocking |
4167 |
+ * mode. Neither the open nor any subsequent opera� |
4168 |
+ * tions on the file descriptor which is returned will |
4169 |
+ * cause the calling process to wait. For the han� |
4170 |
+ * dling of FIFOs (named pipes), see also fifo(4). |
4171 |
+ * This mode need not have any effect on files other |
4172 |
+ * than FIFOs. |
4173 |
+ |
4174 |
+ * man 2 read |
4175 |
+ * EAGAIN |
4176 |
+ * Non-blocking I/O has been selected using O_NONBLOCK |
4177 |
+ * and no data was immediately available for reading. |
4178 |
+ * /usr/include/asm/error.h: |
4179 |
+ * #define EAGAIN 11 / Try again / |
4180 |
+ * #define EWOULDBLOCK EAGAIN / Operation would block / |
4181 |
+ * looks like the kernel is using EAGAIN |
4182 |
+ * -- should be OK |
4183 |
+ |
4184 |
+ * Solaris: |
4185 |
+ * man 2 open |
4186 |
+ * EAGAIN The path argument names the slave side of a |
4187 |
+ * pseudo-terminal device that is locked. |
4188 |
+ * man 2 read |
4189 |
+ * If O_NONBLOCK is set, read() returns -1 and sets errno |
4190 |
+ * to EAGAIN. |
4191 |
+ * -- should be OK. |
4192 |
+ |
4193 |
+ * HP-UX |
4194 |
+ * both are defined but EAGAIN is used. |
4195 |
+ * -- should be OK. |
4196 |
+ |
4197 |
+ * Win32 |
4198 |
+ * neither errno is currently set. Comment added to termios.c |
4199 |
+ * serial_open(). |
4200 |
+ * -- should be OK |
4201 |
+ |
4202 |
+ * Steven's book. Advanced programming in the Unix Environment pg 364 |
4203 |
+ |
4204 |
+ * "A common use for nonblocking I/O is for dealing with a terminal device |
4205 |
+ * for a network connection and these devices are normally used by one process |
4206 |
+ * at a time. This means that the change in the BSD semantics normally does 't |
4207 |
+ * effect us. The different error return, EWOULDBLOCK, instead of POSIX.1 |
4208 |
+ * EAGAIN, continues to be a portability difference that we must deal with." |
4209 |
+ **/ |
4210 |
+ report_verbose( "testRead() - Reading...\n" ); |
4211 |
+ |
4212 |
if ( READ( fd, &c, 1 ) < 0 ) |
4213 |
{ |
4214 |
-#ifdef EAGAIN |
4215 |
- if ( errno != EAGAIN ) { |
4216 |
- report( "testRead() read failed\n" ); |
4217 |
- ret = JNI_FALSE; |
4218 |
- } |
4219 |
-#else |
4220 |
-#ifdef EWOULDBLOCK |
4221 |
- if ( errno != EWOULDBLOCK ) |
4222 |
- { |
4223 |
- report( "testRead() read failed\n" ); |
4224 |
- ret = JNI_FALSE; |
4225 |
- } |
4226 |
-#else |
4227 |
- ret = JNI_FALSE; |
4228 |
-#endif /* EWOULDBLOCK */ |
4229 |
-#endif /* EAGAIN */ |
4230 |
+ #ifdef EAGAIN |
4231 |
+ if ( errno != EAGAIN ) { |
4232 |
+ report( "testRead() read failed\n" ); |
4233 |
+ ret = JNI_FALSE; |
4234 |
+ } |
4235 |
+ #else |
4236 |
+ #ifdef EWOULDBLOCK |
4237 |
+ if ( errno != EWOULDBLOCK ) |
4238 |
+ { |
4239 |
+ report( "testRead() read failed\n" ); |
4240 |
+ ret = JNI_FALSE; |
4241 |
+ } |
4242 |
+ #else |
4243 |
+ ret = JNI_FALSE; |
4244 |
+ #endif /* EWOULDBLOCK */ |
4245 |
+ #endif /* EAGAIN */ |
4246 |
} |
4247 |
- |
4248 |
+ report_verbose( "testRead() - Read Complete\n" ); |
4249 |
+ |
4250 |
/* dont walk over unlocked open devices */ |
4251 |
tcsetattr( fd, TCSANOW, &saved_termios ); |
4252 |
fcntl( fd, F_SETFL, saved_flags ); |
4253 |
} |
4254 |
- |
4255 |
+ else if ( port_type == PORT_PARALLEL ) |
4256 |
+ { |
4257 |
+ /** |
4258 |
+ * Parrellel ports are also sent here for testing. |
4259 |
+ * We should be doing some sort of check... |
4260 |
+ * FIXME - To implement. |
4261 |
+ **/ |
4262 |
+ report( "testRead() This is a parrelle port, skipping\n" ); |
4263 |
+ } |
4264 |
+ |
4265 |
+ |
4266 |
+ |
4267 |
/* |
4268 |
UNLOCK is one of three functions defined in SerialImp.h |
4269 |
|
4270 |
@@ -4500,185 +4679,249 @@ |
4271 |
*/ |
4272 |
|
4273 |
END: |
4274 |
- UNLOCK(name, pid ); |
4275 |
- (*env)->ReleaseStringUTFChars( env, tty_name, name ); |
4276 |
- CLOSE( fd ); |
4277 |
- LEAVE( "RXTXPort:testRead" ); |
4278 |
+ report_verbose( "testRead() - at end\n" ); |
4279 |
+ if ( port_type == PORT_SERIAL ) |
4280 |
+ { |
4281 |
+ report_verbose( "testRead() - unlocking\n" ); |
4282 |
+ UNLOCK(name, pid ); |
4283 |
+ report_verbose( "testRead() - Releasing String Chars\n" ); |
4284 |
+ (*env)->ReleaseStringUTFChars( env, tty_name, name ); |
4285 |
+ report_verbose( "testRead() - Closing...\n" ); |
4286 |
+ CLOSE( fd ); |
4287 |
+ } |
4288 |
+ else |
4289 |
+ { |
4290 |
+ report_verbose( "testRead() - Releasing String Chars\n" ); |
4291 |
+ (*env)->ReleaseStringUTFChars( env, tty_name, name ); |
4292 |
+ } |
4293 |
+ report( "Leaving - RXTXPort:testRead\n" ); |
4294 |
return ret; |
4295 |
} |
4296 |
|
4297 |
#if defined(__APPLE__) |
4298 |
-/*---------------------------------------------------------- |
4299 |
- createSerialIterator() |
4300 |
- accept: |
4301 |
- perform: |
4302 |
- return: |
4303 |
- exceptions: |
4304 |
- comments: |
4305 |
+ |
4306 |
+ /*---------------------------------------------------------- |
4307 |
+ createSerialIterator() |
4308 |
+ accept: |
4309 |
+ perform: |
4310 |
+ return: |
4311 |
+ exceptions: |
4312 |
+ comments: |
4313 |
Code courtesy of Eric Welch at Keyspan, except for the bugs |
4314 |
which are courtesy of Joseph Goldstone (joseph@lp.com) |
4315 |
-----------------------------------------------------------*/ |
4316 |
- |
4317 |
-kern_return_t |
4318 |
-createSerialIterator(io_iterator_t *serialIterator) |
4319 |
-{ |
4320 |
- kern_return_t kernResult; |
4321 |
- mach_port_t masterPort; |
4322 |
- CFMutableDictionaryRef classesToMatch; |
4323 |
- if ((kernResult=IOMasterPort( (int) NULL, &masterPort ) ) != KERN_SUCCESS) |
4324 |
- { |
4325 |
- printf( "IOMasterPort returned %d\n", kernResult); |
4326 |
- return kernResult; |
4327 |
- } |
4328 |
- if ((classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue)) == NULL) |
4329 |
- { |
4330 |
- printf( "IOServiceMatching returned NULL\n" ); |
4331 |
- return kernResult; |
4332 |
- } |
4333 |
- CFDictionarySetValue(classesToMatch, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDAllTypes)); |
4334 |
- kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, serialIterator); |
4335 |
- if (kernResult != KERN_SUCCESS) |
4336 |
- { |
4337 |
- printf( "IOServiceGetMatchingServices returned %d\n", kernResult); |
4338 |
- } |
4339 |
- return kernResult; |
4340 |
-} |
4341 |
+ ----------------------------------------------------------*/ |
4342 |
+ |
4343 |
+ kern_return_t |
4344 |
+ createSerialIterator(io_iterator_t *serialIterator) |
4345 |
+ { |
4346 |
+ kern_return_t kernResult; |
4347 |
+ mach_port_t masterPort; |
4348 |
+ CFMutableDictionaryRef classesToMatch; |
4349 |
+ |
4350 |
+ if ((kernResult=IOMasterPort( (int) NULL, &masterPort ) ) != KERN_SUCCESS) |
4351 |
+ { |
4352 |
+ printf( "IOMasterPort returned %d\n", kernResult); |
4353 |
+ return kernResult; |
4354 |
+ } |
4355 |
+ if ((classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue)) == NULL) |
4356 |
+ { |
4357 |
+ printf( "IOServiceMatching returned NULL\n" ); |
4358 |
+ return kernResult; |
4359 |
+ } |
4360 |
+ |
4361 |
+ CFDictionarySetValue(classesToMatch, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDAllTypes)); |
4362 |
+ |
4363 |
+ kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, serialIterator); |
4364 |
+ |
4365 |
+ if (kernResult != KERN_SUCCESS) |
4366 |
+ { |
4367 |
+ printf( "IOServiceGetMatchingServices returned %d\n", kernResult); |
4368 |
+ } |
4369 |
+ |
4370 |
+ return kernResult; |
4371 |
+ } |
4372 |
|
4373 |
-/*---------------------------------------------------------- |
4374 |
- getRegistryString() |
4375 |
- |
4376 |
- accept: |
4377 |
- perform: |
4378 |
- return: |
4379 |
- exceptions: |
4380 |
- comments: |
4381 |
+ /*---------------------------------------------------------- |
4382 |
+ getRegistryString() |
4383 |
+ |
4384 |
+ accept: |
4385 |
+ perform: |
4386 |
+ return: |
4387 |
+ exceptions: |
4388 |
+ comments: |
4389 |
Code courtesy of Eric Welch at Keyspan, except for the bugs |
4390 |
which are courtesy of Joseph Goldstone (joseph@lp.com) |
4391 |
-----------------------------------------------------------*/ |
4392 |
-char * |
4393 |
-getRegistryString(io_object_t sObj, char *propName) |
4394 |
-{ |
4395 |
- static char resultStr[256]; |
4396 |
- CFTypeRef nameCFstring; |
4397 |
- resultStr[0] = 0; |
4398 |
- nameCFstring = IORegistryEntryCreateCFProperty(sObj, |
4399 |
- CFStringCreateWithCString(kCFAllocatorDefault, propName, kCFStringEncodingASCII), |
4400 |
- kCFAllocatorDefault, 0); |
4401 |
- if (nameCFstring) |
4402 |
- { |
4403 |
- CFStringGetCString(nameCFstring, resultStr, sizeof(resultStr), kCFStringEncodingASCII); |
4404 |
- CFRelease(nameCFstring); |
4405 |
- } |
4406 |
- return resultStr; |
4407 |
-} |
4408 |
+ ----------------------------------------------------------*/ |
4409 |
+ char * |
4410 |
+ getRegistryString(io_object_t sObj, char *propName) |
4411 |
+ { |
4412 |
+ static char resultStr[256]; |
4413 |
+ CFTypeRef nameCFstring; |
4414 |
+ resultStr[0] = 0; |
4415 |
+ nameCFstring = IORegistryEntryCreateCFProperty( |
4416 |
+ sObj, |
4417 |
+ CFStringCreateWithCString |
4418 |
+ ( |
4419 |
+ kCFAllocatorDefault, |
4420 |
+ propName, |
4421 |
+ kCFStringEncodingASCII |
4422 |
+ ), |
4423 |
+ kCFAllocatorDefault, |
4424 |
+ 0 |
4425 |
+ ); |
4426 |
+ if (nameCFstring) |
4427 |
+ { |
4428 |
+ CFStringGetCString(nameCFstring, resultStr, sizeof(resultStr), kCFStringEncodingASCII); |
4429 |
+ CFRelease(nameCFstring); |
4430 |
+ } |
4431 |
+ return resultStr; |
4432 |
+ } |
4433 |
+ |
4434 |
+ /*---------------------------------------------------------- |
4435 |
+ registerKnownSerialPorts() |
4436 |
+ accept: |
4437 |
+ perform: |
4438 |
+ return: |
4439 |
+ exceptions: |
4440 |
+ comments: |
4441 |
+ ----------------------------------------------------------*/ |
4442 |
+ int |
4443 |
+ registerKnownSerialPorts(JNIEnv *env, jobject jobj, jint portType) /* dima */ |
4444 |
+ { |
4445 |
+ io_iterator_t theSerialIterator; |
4446 |
+ io_object_t theObject; |
4447 |
+ int * numPorts = 0;/* dima it should initiated */ |
4448 |
+ |
4449 |
+ if ( |
4450 |
+ ( createSerialIterator( &theSerialIterator ) != KERN_SUCCESS) || |
4451 |
+ ( ! IOIteratorIsValid( theSerialIterator)) |
4452 |
+ ) |
4453 |
+ { |
4454 |
+ /* This also happens when no drivers are installed */ |
4455 |
+ report( "createSerialIterator failed\n" ); |
4456 |
+ return(0); |
4457 |
+ } |
4458 |
+ else |
4459 |
+ { |
4460 |
+ jclass cls; |
4461 |
+ jmethodID mid; |
4462 |
+ cls = (*env)->FindClass(env,"gnu/io/CommPortIdentifier" ); |
4463 |
+ if (cls == 0) |
4464 |
+ { |
4465 |
+ report( "can't find class of gnu/io/CommPortIdentifier\n" ); |
4466 |
+ return numPorts; |
4467 |
+ } |
4468 |
+ mid = (*env)->GetStaticMethodID( |
4469 |
+ env, |
4470 |
+ cls, |
4471 |
+ "addPortName", |
4472 |
+ "(Ljava/lang/String;ILgnu/io/CommDriver;)V" |
4473 |
+ ); |
4474 |
|
4475 |
-/*---------------------------------------------------------- |
4476 |
- registerKnownSerialPorts() |
4477 |
- accept: |
4478 |
- perform: |
4479 |
- return: |
4480 |
- exceptions: |
4481 |
- comments: |
4482 |
-----------------------------------------------------------*/ |
4483 |
-int |
4484 |
-registerKnownSerialPorts(JNIEnv *env, jobject jobj, jint portType) /* dima */ |
4485 |
-{ |
4486 |
- io_iterator_t theSerialIterator; |
4487 |
- io_object_t theObject; |
4488 |
- int numPorts = 0;/* dima it should initiated */ |
4489 |
- |
4490 |
- if (( createSerialIterator( &theSerialIterator ) != KERN_SUCCESS) || |
4491 |
- ( ! IOIteratorIsValid( theSerialIterator))) |
4492 |
- { |
4493 |
- /* This also happens when no drivers are installed */ |
4494 |
- report( "createSerialIterator failed\n" ); |
4495 |
- return(0); |
4496 |
- } else { |
4497 |
- jclass cls; /* dima */ |
4498 |
- jmethodID mid; /* dima */ |
4499 |
- cls = (*env)->FindClass(env,"gnu/io/CommPortIdentifier" ); /* dima */ |
4500 |
- if (cls == 0) { /* dima */ |
4501 |
- report( "can't find class of gnu/io/CommPortIdentifier\n" ); /* dima */ |
4502 |
- return numPorts; /* dima */ |
4503 |
- } /* dima */ |
4504 |
- mid = (*env)->GetStaticMethodID(env, cls, "addPortName", "(Ljava/lang/String;ILgnu/io/CommDriver;)V" ); /* dima */ |
4505 |
- |
4506 |
- if (mid == 0) { |
4507 |
- printf( "getMethodID of CommDriver.addPortName failed\n" ); |
4508 |
- } else { |
4509 |
- while (theObject = IOIteratorNext(theSerialIterator)) |
4510 |
- { |
4511 |
- /* begin dima */ |
4512 |
- jstring tempJstring; |
4513 |
- tempJstring = (*env)->NewStringUTF(env,getRegistryString(theObject, kIODialinDeviceKey)); |
4514 |
- (*env)->CallStaticVoidMethod(env, cls, mid,tempJstring,portType,jobj);/* dima */ |
4515 |
- (*env)->DeleteLocalRef(env,tempJstring); |
4516 |
- numPorts++; |
4517 |
- |
4518 |
- tempJstring = (*env)->NewStringUTF(env,getRegistryString(theObject, kIOCalloutDeviceKey)); |
4519 |
- (*env)->CallStaticVoidMethod(env, cls, mid,tempJstring,portType,jobj);/* dima */ |
4520 |
- (*env)->DeleteLocalRef(env,tempJstring); |
4521 |
- numPorts++; |
4522 |
-/* end dima */ |
4523 |
- } |
4524 |
- } |
4525 |
- } |
4526 |
- return numPorts; |
4527 |
-} |
4528 |
+ if (mid == 0) |
4529 |
+ { |
4530 |
+ printf( "getMethodID of CommDriver.addPortName failed\n" ); |
4531 |
+ } |
4532 |
+ else |
4533 |
+ { |
4534 |
+ while (theObject = IOIteratorNext(theSerialIterator)) |
4535 |
+ { |
4536 |
+ /* begin dima */ |
4537 |
+ jstring tempJstring; |
4538 |
+ tempJstring = (*env)->NewStringUTF(env,getRegistryString(theObject, kIODialinDeviceKey)); |
4539 |
+ (*env)->CallStaticVoidMethod(env, cls, mid,tempJstring,portType,jobj);/* dima */ |
4540 |
+ (*env)->DeleteLocalRef(env,tempJstring); |
4541 |
+ numPorts++; |
4542 |
+ |
4543 |
+ tempJstring = (*env)->NewStringUTF(env,getRegistryString(theObject, kIOCalloutDeviceKey)); |
4544 |
+ (*env)->CallStaticVoidMethod(env, cls, mid,tempJstring,portType,jobj);/* dima */ |
4545 |
+ (*env)->DeleteLocalRef(env,tempJstring); |
4546 |
+ numPorts++; |
4547 |
+ /* end dima */ |
4548 |
+ } |
4549 |
+ } |
4550 |
+ } |
4551 |
+ return numPorts; |
4552 |
+ } |
4553 |
#endif /* __APPLE__ */ |
4554 |
|
4555 |
/*---------------------------------------------------------- |
4556 |
registerKnownPorts |
4557 |
|
4558 |
- accept: the type of port |
4559 |
- perform: register any ports of the desired type a priori known to this OS |
4560 |
- return: JNI_TRUE if any such ports were registered otherwise JNI_FALSE |
4561 |
- exceptions: none |
4562 |
- comments: |
4563 |
+ accept: the type of port |
4564 |
+ perform: register any ports of the desired type a priori known |
4565 |
+ to this OS |
4566 |
+ return: JNI_TRUE if any such ports were registered otherwise |
4567 |
+ JNI_FALSE |
4568 |
+ exceptions: none |
4569 |
+ comments: |
4570 |
----------------------------------------------------------*/ |
4571 |
-JNIEXPORT jboolean JNICALL RXTXCommDriver(registerKnownPorts)(JNIEnv *env, |
4572 |
- jobject jobj, jint portType) |
4573 |
+JNIEXPORT jboolean JNICALL RXTXCommDriver(registerKnownPorts)( |
4574 |
+ JNIEnv *env, |
4575 |
+ jobject jobj, |
4576 |
+ jint portType |
4577 |
+) |
4578 |
{ |
4579 |
- enum {PORT_TYPE_SERIAL = 1, |
4580 |
+ report("Entering - RXTXCommDriver_registerKnownPorts\n"); |
4581 |
+ |
4582 |
+ char strbuf[256]; |
4583 |
+ |
4584 |
+ enum |
4585 |
+ { |
4586 |
+ PORT_TYPE_SERIAL = 1, |
4587 |
PORT_TYPE_PARALLEL, |
4588 |
PORT_TYPE_I2C, |
4589 |
PORT_TYPE_RS485, |
4590 |
- PORT_TYPE_RAW}; |
4591 |
+ PORT_TYPE_RAW |
4592 |
+ }; |
4593 |
+ |
4594 |
jboolean result = JNI_FALSE; |
4595 |
char message[80]; |
4596 |
|
4597 |
- switch(portType) { |
4598 |
+ switch(portType) |
4599 |
+ { |
4600 |
case PORT_TYPE_SERIAL: |
4601 |
-#if defined(__APPLE__) |
4602 |
- if (registerKnownSerialPorts(env, jobj, |
4603 |
- PORT_TYPE_SERIAL) > 0) {/* dima */ |
4604 |
- result = JNI_TRUE; |
4605 |
- } |
4606 |
-#endif |
4607 |
- break; |
4608 |
- case PORT_TYPE_PARALLEL: break; |
4609 |
- case PORT_TYPE_I2C: break; |
4610 |
- case PORT_TYPE_RS485: break; |
4611 |
- case PORT_TYPE_RAW: break; |
4612 |
+ #if defined(__APPLE__) |
4613 |
+ if (registerKnownSerialPorts(env, jobj, PORT_TYPE_SERIAL) > 0) |
4614 |
+ { |
4615 |
+ /* dima */ |
4616 |
+ result = JNI_TRUE; |
4617 |
+ } |
4618 |
+ #endif |
4619 |
+ break; |
4620 |
+ |
4621 |
+ case PORT_TYPE_PARALLEL: |
4622 |
+ break; |
4623 |
+ |
4624 |
+ case PORT_TYPE_I2C: |
4625 |
+ break; |
4626 |
+ |
4627 |
+ case PORT_TYPE_RS485: |
4628 |
+ break; |
4629 |
+ |
4630 |
+ case PORT_TYPE_RAW: |
4631 |
+ break; |
4632 |
+ |
4633 |
default: |
4634 |
- sprintf( message, "unknown portType %d handed to \ |
4635 |
- native RXTXCommDriver.registerKnownPorts() \ |
4636 |
- method.\n", |
4637 |
- (int) portType |
4638 |
- ); |
4639 |
+ memset(&message[0], 0, sizeof(message)); |
4640 |
+ sprintf( message, "RXTXCommDriver_registerKnownPorts Unknown portType %d handed to native RXTXCommDriver.registerKnownPorts() method.\n", (int) portType); |
4641 |
report( message ); |
4642 |
} |
4643 |
+ memset(&strbuf[0], 0, sizeof(strbuf)); |
4644 |
+ sprintf(strbuf, "Leaving - RXTXCommDriver_registerKnownPorts(%i)\n", result); |
4645 |
+ report(strbuf); |
4646 |
+ |
4647 |
return result; |
4648 |
} |
4649 |
|
4650 |
/*---------------------------------------------------------- |
4651 |
isPortPrefixValid |
4652 |
|
4653 |
- accept: a port prefix |
4654 |
- perform: see if the port prefix matches a port that is valid on this OS. |
4655 |
- return: JNI_TRUE if it exists otherwise JNI_FALSE |
4656 |
- exceptions: none |
4657 |
- comments: |
4658 |
+ accept: a port prefix |
4659 |
+ perform: see if the port prefix matches a port that is valid on this OS. |
4660 |
+ return: JNI_TRUE if it exists otherwise JNI_FALSE |
4661 |
+ exceptions: none |
4662 |
+ comments: |
4663 |
----------------------------------------------------------*/ |
4664 |
JNIEXPORT jboolean JNICALL RXTXCommDriver(isPortPrefixValid)(JNIEnv *env, |
4665 |
jobject jobj, jstring tty_name) |
4666 |
@@ -4686,87 +4929,106 @@ |
4667 |
jboolean result; |
4668 |
static struct stat mystat; |
4669 |
char teststring[256]; |
4670 |
+ char strbuf[256]; |
4671 |
int fd,i; |
4672 |
const char *name = (*env)->GetStringUTFChars(env, tty_name, 0); |
4673 |
|
4674 |
- ENTER( "RXTXCommDriver:isPortPrefixValid" ); |
4675 |
- for(i=0;i<64;i++){ |
4676 |
-#if defined(__sun__) |
4677 |
- /* Solaris uses /dev/cua/a instead of /dev/cua0 */ |
4678 |
- if( i > 25 ) break; |
4679 |
- sprintf(teststring,"%s%s%c",DEVICEDIR, name, i + 97 ); |
4680 |
- fprintf(stderr, "testing: %s\n", teststring); |
4681 |
-#else |
4682 |
-#if defined(_GNU_SOURCE) |
4683 |
- snprintf(teststring, 256, "%s%s%i",DEVICEDIR,name, i); |
4684 |
-#else |
4685 |
- sprintf(teststring,"%s%s%i",DEVICEDIR,name, i); |
4686 |
-#endif /* _GNU_SOURCE */ |
4687 |
- stat(teststring,&mystat); |
4688 |
-#endif /* __sun__ */ |
4689 |
-/* XXX the following hoses freebsd when it tries to open the port later on */ |
4690 |
-#ifndef __FreeBSD__ |
4691 |
- if(S_ISCHR(mystat.st_mode)){ |
4692 |
- fd=OPEN(teststring,O_RDONLY|O_NONBLOCK); |
4693 |
- if (fd>0){ |
4694 |
- CLOSE(fd); |
4695 |
- result=JNI_TRUE; |
4696 |
- break; |
4697 |
+ report( "Entering - RXTXCommDriver:isPortPrefixValid\n" ); |
4698 |
+ for(i=0;i<64;i++) |
4699 |
+ { |
4700 |
+ #if defined(__sun__) |
4701 |
+ /* Solaris uses /dev/cua/a instead of /dev/cua0 */ |
4702 |
+ if( i > 25 ) break; |
4703 |
+ sprintf(teststring,"%s%s%c\n",DEVICEDIR, name, i + 97 ); |
4704 |
+ fprintf(stderr, "testing: %s\n", teststring); |
4705 |
+ #else |
4706 |
+ #if defined(_GNU_SOURCE) |
4707 |
+ snprintf(teststring, 256, "%s%s%i\n",DEVICEDIR,name, i); |
4708 |
+ #else |
4709 |
+ sprintf(teststring,"%s%s%i\n",DEVICEDIR,name, i); |
4710 |
+ #endif /* _GNU_SOURCE */ |
4711 |
+ stat(teststring,&mystat); |
4712 |
+ #endif /* __sun__ */ |
4713 |
+ |
4714 |
+ /* XXX the following hoses freebsd when it tries to open the port later on */ |
4715 |
+ #ifndef __FreeBSD__ |
4716 |
+ if(S_ISCHR(mystat.st_mode)) |
4717 |
+ { |
4718 |
+ fd=OPEN(teststring,O_RDONLY|O_NONBLOCK); |
4719 |
+ if (fd>0) |
4720 |
+ { |
4721 |
+ CLOSE(fd); |
4722 |
+ result=JNI_TRUE; |
4723 |
+ break; |
4724 |
+ } |
4725 |
+ else |
4726 |
+ { |
4727 |
+ result=JNI_FALSE; |
4728 |
+ } |
4729 |
} |
4730 |
else |
4731 |
+ { |
4732 |
result=JNI_FALSE; |
4733 |
- } |
4734 |
- else |
4735 |
- result=JNI_FALSE; |
4736 |
-#else |
4737 |
- result=JNI_TRUE; |
4738 |
-#endif /* __FreeBSD __ */ |
4739 |
+ } |
4740 |
+ #else |
4741 |
+ result=JNI_TRUE; |
4742 |
+ #endif /* __FreeBSD __ */ |
4743 |
} |
4744 |
-#if defined(_GNU_SOURCE) |
4745 |
- snprintf(teststring, 256, "%s%s",DEVICEDIR,name); |
4746 |
-#else |
4747 |
- sprintf(teststring,"%s%s",DEVICEDIR,name); |
4748 |
-#endif /* _GNU_SOURCE */ |
4749 |
+ |
4750 |
+ #if defined(_GNU_SOURCE) |
4751 |
+ snprintf(teststring, 256, "%s%s",DEVICEDIR,name); |
4752 |
+ #else |
4753 |
+ sprintf(teststring,"%s%s",DEVICEDIR,name); |
4754 |
+ #endif /* _GNU_SOURCE */ |
4755 |
+ |
4756 |
stat(teststring,&mystat); |
4757 |
- if(S_ISCHR(mystat.st_mode)){ |
4758 |
+ |
4759 |
+ if(S_ISCHR(mystat.st_mode)) |
4760 |
+ { |
4761 |
fd=OPEN(teststring,O_RDONLY|O_NONBLOCK); |
4762 |
- if (fd>0){ |
4763 |
+ if (fd>0) |
4764 |
+ { |
4765 |
CLOSE(fd); |
4766 |
result=JNI_TRUE; |
4767 |
} |
4768 |
} |
4769 |
+ |
4770 |
(*env)->ReleaseStringUTFChars(env, tty_name, name); |
4771 |
- LEAVE( "RXTXCommDriver:isPortPrefixValid" ); |
4772 |
+ |
4773 |
+ memset(&strbuf[0], 0, sizeof(strbuf)); |
4774 |
+ sprintf(strbuf, "Leaving - RXTXCommDriver:isPortPrefixValid(%i)\n", result); |
4775 |
+ report(strbuf); |
4776 |
+ |
4777 |
return(result); |
4778 |
} |
4779 |
|
4780 |
/*---------------------------------------------------------- |
4781 |
getDeviceDirectory |
4782 |
|
4783 |
- accept: |
4784 |
- perform: |
4785 |
- return: the directory containing the device files |
4786 |
- exceptions: |
4787 |
- comments: use this to avoid hard coded "/dev/" |
4788 |
- values are in SerialImp.h |
4789 |
+ accept: |
4790 |
+ perform: |
4791 |
+ return: the directory containing the device files |
4792 |
+ exceptions: |
4793 |
+ comments: use this to avoid hard coded "/dev/" |
4794 |
+ values are in SerialImp.h |
4795 |
----------------------------------------------------------*/ |
4796 |
|
4797 |
JNIEXPORT jstring JNICALL RXTXCommDriver(getDeviceDirectory)(JNIEnv *env, |
4798 |
jobject jobj) |
4799 |
{ |
4800 |
- ENTER( "RXTXCommDriver:getDeviceDirectory" ); |
4801 |
+ report( "Entering - RXTXCommDriver:getDeviceDirectory\n" ); |
4802 |
return (*env)->NewStringUTF(env, DEVICEDIR); |
4803 |
- LEAVE( "RXTXCommDriver:getDeviceDirectory" ); |
4804 |
+ report( "Leaving - RXTXCommDriver:getDeviceDirectory\n" ); |
4805 |
} |
4806 |
|
4807 |
/*---------------------------------------------------------- |
4808 |
setInputBufferSize |
4809 |
|
4810 |
- accept: |
4811 |
- perform: |
4812 |
- return: none |
4813 |
- exceptions: none |
4814 |
- comments: see fopen/fclose/fwrite/fread man pages. |
4815 |
+ accept: |
4816 |
+ perform: |
4817 |
+ return: none |
4818 |
+ exceptions: none |
4819 |
+ comments: see fopen/fclose/fwrite/fread man pages. |
4820 |
----------------------------------------------------------*/ |
4821 |
JNIEXPORT void JNICALL RXTXPort(setInputBufferSize)(JNIEnv *env, |
4822 |
jobject jobj, jint size ) |
4823 |
@@ -4777,11 +5039,11 @@ |
4824 |
/*---------------------------------------------------------- |
4825 |
getIputBufferSize |
4826 |
|
4827 |
- accept: |
4828 |
- perform: |
4829 |
- return: none |
4830 |
- exceptions: none |
4831 |
- comments: see fopen/fclose/fwrite/fread man pages. |
4832 |
+ accept: |
4833 |
+ perform: |
4834 |
+ return: none |
4835 |
+ exceptions: none |
4836 |
+ comments: see fopen/fclose/fwrite/fread man pages. |
4837 |
----------------------------------------------------------*/ |
4838 |
JNIEXPORT jint JNICALL RXTXPort(getInputBufferSize)(JNIEnv *env, |
4839 |
jobject jobj) |
4840 |
@@ -4793,11 +5055,11 @@ |
4841 |
/*---------------------------------------------------------- |
4842 |
setOutputBufferSize |
4843 |
|
4844 |
- accept: |
4845 |
- perform: |
4846 |
- return: none |
4847 |
- exceptions: none |
4848 |
- comments: see fopen/fclose/fwrite/fread man pages. |
4849 |
+ accept: |
4850 |
+ perform: |
4851 |
+ return: none |
4852 |
+ exceptions: none |
4853 |
+ comments: see fopen/fclose/fwrite/fread man pages. |
4854 |
----------------------------------------------------------*/ |
4855 |
JNIEXPORT void JNICALL RXTXPort(setOutputBufferSize)(JNIEnv *env, |
4856 |
jobject jobj, jint size ) |
4857 |
@@ -4808,11 +5070,11 @@ |
4858 |
/*---------------------------------------------------------- |
4859 |
getOutputBufferSize |
4860 |
|
4861 |
- accept: |
4862 |
- perform: |
4863 |
- return: none |
4864 |
- exceptions: none |
4865 |
- comments: see fopen/fclose/fwrite/fread man pages. |
4866 |
+ accept: |
4867 |
+ perform: |
4868 |
+ return: none |
4869 |
+ exceptions: none |
4870 |
+ comments: see fopen/fclose/fwrite/fread man pages. |
4871 |
----------------------------------------------------------*/ |
4872 |
JNIEXPORT jint JNICALL RXTXPort(getOutputBufferSize)(JNIEnv *env, |
4873 |
jobject jobj) |
4874 |
@@ -4824,23 +5086,33 @@ |
4875 |
/*---------------------------------------------------------- |
4876 |
interruptEventLoop |
4877 |
|
4878 |
- accept: nothing |
4879 |
- perform: increment eventloop_interrupted |
4880 |
- return: nothing |
4881 |
- exceptions: none |
4882 |
- comments: all eventloops in this PID will check if their thread |
4883 |
- is interrupted. When all the interrupted threads exit |
4884 |
- they will decrement the var leaving it 0. |
4885 |
- the remaining threads will continue. |
4886 |
+ accept: nothing |
4887 |
+ perform: increment eventloop_interrupted |
4888 |
+ return: nothing |
4889 |
+ exceptions: none |
4890 |
+ comments: all eventloops in this PID will check if their thread |
4891 |
+ is interrupted. When all the interrupted threads exit |
4892 |
+ they will decrement the var leaving it 0. |
4893 |
+ the remaining threads will continue. |
4894 |
----------------------------------------------------------*/ |
4895 |
-JNIEXPORT void JNICALL RXTXPort(interruptEventLoop)(JNIEnv *env, |
4896 |
- jobject jobj) |
4897 |
+JNIEXPORT void JNICALL RXTXPort(interruptEventLoop)( |
4898 |
+ JNIEnv *env, |
4899 |
+ jobject jobj |
4900 |
+) |
4901 |
{ |
4902 |
+ report("Entering - RXTXPort_interruptEventLoop\n"); |
4903 |
+ |
4904 |
struct event_info_struct *index = master_index; |
4905 |
+ |
4906 |
int fd = get_java_var( env, jobj, "fd", "I" ); |
4907 |
+ |
4908 |
int searching = 1; |
4909 |
- |
4910 |
- |
4911 |
+ int waiting = 1; |
4912 |
+ int loop_count = 0; |
4913 |
+ char buff[ 60 ] = ""; |
4914 |
+ |
4915 |
+ report("RXTXPort_interruptEventLoop - Searching...\n"); |
4916 |
+ |
4917 |
while( searching ) |
4918 |
{ |
4919 |
index = master_index; |
4920 |
@@ -4852,63 +5124,161 @@ |
4921 |
} |
4922 |
else |
4923 |
report("x"); |
4924 |
+ |
4925 |
if( searching ) |
4926 |
{ |
4927 |
report("@"); |
4928 |
usleep(1000); |
4929 |
} |
4930 |
} |
4931 |
+ report("RXTXPort_interruptEventLoop - Searched\n"); |
4932 |
+ |
4933 |
+ /** |
4934 |
+ * We now set a flag for the drain_loop thread to jump to it's end. |
4935 |
+ **/ |
4936 |
+ |
4937 |
index->eventloop_interrupted = 1; |
4938 |
- /* |
4939 |
- Many OS's need a thread running to determine if output buffer is |
4940 |
- empty. For Linux and Win32 it is not needed. So closing is used to |
4941 |
- shut down the thread in the write order on OS's that don't have |
4942 |
- kernel support for output buffer empty. |
4943 |
- |
4944 |
- In rxtx TIOCSERGETLSR is defined for win32 and Linux |
4945 |
- */ |
4946 |
-#ifdef TIOCSERGETLSR |
4947 |
- index->closing=1; |
4948 |
-#endif /* TIOCSERGETLSR */ |
4949 |
-#ifdef WIN32 |
4950 |
- termios_interrupt_event_loop( index->fd, 1 ); |
4951 |
-#endif /* WIN32 */ |
4952 |
-#if !defined(TIOCSERGETLSR) && !defined(WIN32) |
4953 |
- /* make sure that the drainloop unblocks from tcdrain */ |
4954 |
- pthread_kill(index->drain_tid, SIGABRT); |
4955 |
- /* TODO use wait/join/SIGCHLD/?? instead of sleep? */ |
4956 |
- usleep(50 * 1000); |
4957 |
- /* |
4958 |
- Under normal conditions, SIGABRT will unblock tcdrain. However |
4959 |
- a non-responding USB device combined with an unclean driver |
4960 |
- may still block. This is very ugly because it may block the call |
4961 |
- to close indefinetly. |
4962 |
- */ |
4963 |
- if (index->closing != 1) { |
4964 |
- /* good bye tcdrain, and thanks for all the fish */ |
4965 |
- report("interruptEventLoop: canceling blocked drain thread\n"); |
4966 |
- pthread_cancel(index->drain_tid); |
4967 |
- index->closing = 1; |
4968 |
- } |
4969 |
-#endif |
4970 |
- report("interruptEventLoop: interrupted\n"); |
4971 |
+ |
4972 |
+ report("RXTXPort_interruptEventLoop - Interrupted\n"); |
4973 |
+ |
4974 |
+ /** |
4975 |
+ * Many OS's need a thread running to determine if output buffer is |
4976 |
+ * empty. For Linux and Win32 it is not needed. So closing is |
4977 |
+ * used to shut down the thread in the write order on OS's that |
4978 |
+ * don't have kernel support for output buffer empty. |
4979 |
+ * |
4980 |
+ * In rxtx TIOCSERGETLSR: |
4981 |
+ * is defined for win32 and Linux |
4982 |
+ * is not defined for FreeBSD 10.1-p9 i386 |
4983 |
+ * Other OSs not tested; not available... |
4984 |
+ * |
4985 |
+ * ( |
4986 |
+ * From looking at the RXTX source code tarball, TIOCSERGETLSR |
4987 |
+ * is only manually defined if on WinCE, unless set / supported |
4988 |
+ * by OS dependant c precompiler... |
4989 |
+ * ) |
4990 |
+ **/ |
4991 |
+ |
4992 |
+ #ifdef TIOCSERGETLSR |
4993 |
+ report("RXTXPort_interruptEventLoop - TIOCSERGETLSR defined\n"); |
4994 |
+ index->closing=1; |
4995 |
+ #endif /* TIOCSERGETLSR */ |
4996 |
+ |
4997 |
+ #ifdef WIN32 |
4998 |
+ report("RXTXPort_interruptEventLoop - WIN32 defined\n"); |
4999 |
+ termios_interrupt_event_loop( index->fd, 1 ); |
5000 |
+ #endif /* WIN32 */ |
5001 |
+ |
5002 |
+ #if !defined(TIOCSERGETLSR) && !defined(WIN32) |
5003 |
+ |
5004 |
+ report("RXTXPort_interruptEventLoop - TIOCSERGETLSR and WIN32 not defined\n"); |
5005 |
+ /* make sure that the drainloop unblocks from tcdrain */ |
5006 |
+ |
5007 |
+ /** |
5008 |
+ * JCE: This was supposed to kill off drain_loop... |
5009 |
+ * CORE DUMP seen with original code on i386 FreeBSD v10.1-p9. |
5010 |
+ * |
5011 |
+ * As eventloop_interrupted is set to 1 above, the attempted |
5012 |
+ * forced closure of the thread is now not needed: the thread |
5013 |
+ * kills its self off politely when it sees the flag. |
5014 |
+ * |
5015 |
+ * Going to wait 1/20th + 1 of the maximum sleep time |
5016 |
+ * (SUN = 5000, ANOs=1000000) and see if it has cancelled. |
5017 |
+ * After 20 iterations we have waited for the entire sleep, |
5018 |
+ * at which point we just get on with it and will be caught by |
5019 |
+ * the good bye tcdrain code block at the end of this function. |
5020 |
+ **/ |
5021 |
+ |
5022 |
+ memset(&buff[0], 0, sizeof(buff)); |
5023 |
+ sprintf( buff, "RXTXPort_interruptEventLoop - Closing State is %i\n", index->closing ); |
5024 |
+ report (buff); |
5025 |
+ |
5026 |
+ report("RXTXPort_interruptEventLoop - Going to wait for thread to say it is closing\n"); |
5027 |
+ |
5028 |
+ loop_count = 0; |
5029 |
+ while( waiting ) |
5030 |
+ { |
5031 |
+ report("RXTXPort_interruptEventLoop - Waiting\n"); |
5032 |
+ usleep(5001); |
5033 |
+ loop_count = loop_count + 1; |
5034 |
+ if ((index->closing) == 1) waiting = 0; |
5035 |
+ if (loop_count > 20) waiting = 0; |
5036 |
+ } |
5037 |
+ |
5038 |
+ memset(&buff[0], 0, sizeof(buff)); |
5039 |
+ sprintf( buff, "RXTXPort_interruptEventLoop - Closing State is now %i\n", index->closing ); |
5040 |
+ report (buff); |
5041 |
+ |
5042 |
+ /** |
5043 |
+ * The command below was being sent to the relevant thread, |
5044 |
+ * however under POSIX spec this abort signal applies to the |
5045 |
+ * whole process, NOT the thread. |
5046 |
+ * |
5047 |
+ * However, if RXTX is being call by something else in Java, |
5048 |
+ * this causes the parent enumaertor and the entire JRE to |
5049 |
+ * SIGABRT, resulting in a Java Core Dump (as requested)! |
5050 |
+ * |
5051 |
+ * Not sure what this call was supposed to achive; Have |
5052 |
+ * included new wait loop above to ensure that we wait for the |
5053 |
+ * thread to pick up that we have asked for it to exit: |
5054 |
+ * |
5055 |
+ * index->eventloop_interrupted = 1; |
5056 |
+ * |
5057 |
+ * No way for checking if an OS is POSIX compliant with |
5058 |
+ * pthread_kill, when TIOCSERGETLSR is not defined? |
5059 |
+ **/ |
5060 |
+ |
5061 |
+ /** |
5062 |
+ * pthread_kill(index->drain_tid, SIGABRT); |
5063 |
+ **/ |
5064 |
+ |
5065 |
+ report("***RXTXPort_interruptEventLoop - Thread Killed\n"); |
5066 |
+ |
5067 |
+ /* TODO use wait/join/SIGCHLD/?? instead of sleep? */ |
5068 |
+ |
5069 |
+ report("RXTXPort_interruptEventLoop - Sleeping now...\n"); |
5070 |
+ usleep(50 * 1000); |
5071 |
+ |
5072 |
+ report("RXTXPort_interruptEventLoop - Waking up...\n"); |
5073 |
+ |
5074 |
+ /** |
5075 |
+ * Under normal conditions, SIGABRT will unblock tcdrain. However |
5076 |
+ * a non-responding USB device combined with an unclean driver |
5077 |
+ * may still block. This is very ugly because it may block the call |
5078 |
+ * to close indefinetly. |
5079 |
+ * |
5080 |
+ * UPDATE to above statement: |
5081 |
+ * SIGABRT does not have the expected results in a |
5082 |
+ * POSIX environment. |
5083 |
+ **/ |
5084 |
+ |
5085 |
+ if (index->closing != 1) { |
5086 |
+ /* good bye tcdrain, and thanks for all the fish */ |
5087 |
+ report("interruptEventLoop: canceling blocked drain thread\n"); |
5088 |
+ pthread_cancel(index->drain_tid); |
5089 |
+ index->closing = 1; |
5090 |
+ } |
5091 |
+ |
5092 |
+ #endif |
5093 |
+ |
5094 |
+ report("Leaving - interruptEventLoop\n"); |
5095 |
} |
5096 |
|
5097 |
/*---------------------------------------------------------- |
5098 |
is_interrupted |
5099 |
|
5100 |
- accept: event_info_struct |
5101 |
- perform: see if the port is being closed. |
5102 |
- return: a positive value if the port is being closed. |
5103 |
- exceptions: none |
5104 |
- comments: |
5105 |
+ accept: event_info_struct |
5106 |
+ perform: see if the port is being closed. |
5107 |
+ return: a positive value if the port is being closed. |
5108 |
+ exceptions: none |
5109 |
+ comments: |
5110 |
----------------------------------------------------------*/ |
5111 |
jboolean is_interrupted( struct event_info_struct *eis ) |
5112 |
{ |
5113 |
int result; |
5114 |
JNIEnv *env = eis->env; |
5115 |
|
5116 |
- ENTER( "is_interrupted" ); |
5117 |
+ report( "Entering - is_interrupted\n" ); |
5118 |
(*env)->ExceptionClear(env); |
5119 |
result = (*env)->CallBooleanMethod( env, *eis->jobj, |
5120 |
eis->checkMonitorThread ); |
5121 |
@@ -4919,18 +5289,18 @@ |
5122 |
(*env)->ExceptionClear(env); |
5123 |
} |
5124 |
#endif /* DEBUG */ |
5125 |
- LEAVE( "RXTXCommDriver:is_interrupted" ); |
5126 |
+ report( "Leaving - RXTXCommDriver:is_interrupted\n" ); |
5127 |
return(result); |
5128 |
} |
5129 |
|
5130 |
/*---------------------------------------------------------- |
5131 |
nativeSetEventFlag |
5132 |
|
5133 |
- accept: fd for finding the struct, event to flag, flag. |
5134 |
- perform: toggle the flag |
5135 |
- return: none |
5136 |
- exceptions: none |
5137 |
- comments: all the logic used to be done in Java but its too noisy |
5138 |
+ accept: fd for finding the struct, event to flag, flag. |
5139 |
+ perform: toggle the flag |
5140 |
+ return: none |
5141 |
+ exceptions: none |
5142 |
+ comments: all the logic used to be done in Java but its too noisy |
5143 |
----------------------------------------------------------*/ |
5144 |
JNIEXPORT void JNICALL RXTXPort(nativeSetEventFlag)( JNIEnv *env, |
5145 |
jobject jobj, |
5146 |
@@ -4964,11 +5334,11 @@ |
5147 |
/*---------------------------------------------------------- |
5148 |
send_event |
5149 |
|
5150 |
- accept: event_info_structure, event type and true/false |
5151 |
- perform: if state is > 0 send a JNI_TRUE event otherwise send JNI_FALSE |
5152 |
- return: a positive value if the port is being closed. |
5153 |
- exceptions: none |
5154 |
- comments: |
5155 |
+ accept: event_info_structure, event type and true/false |
5156 |
+ perform: if state is > 0 send a JNI_TRUE event otherwise send JNI_FALSE |
5157 |
+ return: a positive value if the port is being closed. |
5158 |
+ exceptions: none |
5159 |
+ comments: |
5160 |
----------------------------------------------------------*/ |
5161 |
int send_event( struct event_info_struct *eis, jint type, int flag ) |
5162 |
{ |
5163 |
@@ -4977,7 +5347,7 @@ |
5164 |
if( eis ) env = eis->env; |
5165 |
else return(-1); |
5166 |
|
5167 |
- ENTER( "send_event" ); |
5168 |
+ report( "Entering - send_event\n" ); |
5169 |
if( !eis || eis->eventloop_interrupted > 1 ) |
5170 |
{ |
5171 |
report("event loop interrupted\n"); |
5172 |
@@ -5002,18 +5372,18 @@ |
5173 |
} |
5174 |
#endif /* asdf */ |
5175 |
/* report("e"); */ |
5176 |
- LEAVE( "send_event" ); |
5177 |
+ report( "Leaving - send_event\n" ); |
5178 |
return(result); |
5179 |
} |
5180 |
|
5181 |
/*---------------------------------------------------------- |
5182 |
get_java_var |
5183 |
|
5184 |
- accept: env (keyhole to java) |
5185 |
- jobj (java RXTXPort object) |
5186 |
- return: the fd field from the java object |
5187 |
- exceptions: none |
5188 |
- comments: |
5189 |
+ accept: env (keyhole to java) |
5190 |
+ jobj (java RXTXPort object) |
5191 |
+ return: the fd field from the java object |
5192 |
+ exceptions: none |
5193 |
+ comments: |
5194 |
----------------------------------------------------------*/ |
5195 |
size_t get_java_var( JNIEnv *env, jobject jobj, char *id, char *type ) { |
5196 |
return (size_t) get_java_var_long( env, jobj, id, type ); |
5197 |
@@ -5026,26 +5396,26 @@ |
5198 |
jfieldID jfd = (*env)->GetFieldID( env, jclazz, id, type ); |
5199 |
|
5200 |
/* |
5201 |
- ENTER( "get_java_var" ); |
5202 |
+ report( "Entering - get_java_var\n" ); |
5203 |
*/ |
5204 |
if( !jfd ) { |
5205 |
(*env)->ExceptionDescribe( env ); |
5206 |
(*env)->ExceptionClear( env ); |
5207 |
(*env)->DeleteLocalRef( env, jclazz ); |
5208 |
- LEAVE( "get_java_var" ); |
5209 |
+ report( "Leaving - get_java_var\n" ); |
5210 |
return result; |
5211 |
} |
5212 |
if ( !strcmp( type, "J" ) ) { |
5213 |
- result = (long)( (*env)->GetLongField( env, jobj, jfd ) ); |
5214 |
+ result = (long)( (*env)->GetLongField( env, jobj, jfd ) ); |
5215 |
} else { |
5216 |
- result = (size_t) ( (*env)->GetIntField( env, jobj, jfd ) ); |
5217 |
+ result = (size_t) ( (*env)->GetIntField( env, jobj, jfd ) ); |
5218 |
} |
5219 |
/* ct7 & gel * Added DeleteLocalRef */ |
5220 |
(*env)->DeleteLocalRef( env, jclazz ); |
5221 |
if(!strncmp( "fd",id,2) && result == 0) |
5222 |
report_error( "get_java_var: invalid file descriptor\n" ); |
5223 |
/* |
5224 |
- LEAVE( "get_java_var" ); |
5225 |
+ report( "Leaving - get_java_var\n" ); |
5226 |
*/ |
5227 |
return result; |
5228 |
} |
5229 |
@@ -5053,110 +5423,132 @@ |
5230 |
/*---------------------------------------------------------- |
5231 |
throw_java_exception |
5232 |
|
5233 |
- accept: env (keyhole to java) |
5234 |
- *exc (exception class name) |
5235 |
- *foo (function name) |
5236 |
- *msg (error message) |
5237 |
- perform: Throw a new java exception |
5238 |
- return: none |
5239 |
- exceptions: haha! |
5240 |
- comments: |
5241 |
+ accept: env (keyhole to java) |
5242 |
+ *exc (exception class name) |
5243 |
+ *foo (function name) |
5244 |
+ *msg (error message) |
5245 |
+ perform: Throw a new java exception |
5246 |
+ return: none |
5247 |
+ exceptions: haha! |
5248 |
+ comments: |
5249 |
----------------------------------------------------------*/ |
5250 |
void throw_java_exception( JNIEnv *env, char *exc, char *foo, char *msg ) |
5251 |
{ |
5252 |
char buf[ 60 ]; |
5253 |
jclass clazz = (*env)->FindClass( env, exc ); |
5254 |
- ENTER( "throw_java_exception" ); |
5255 |
+ report( "Entering - throw_java_exception\n" ); |
5256 |
if( !clazz ) { |
5257 |
(*env)->ExceptionDescribe( env ); |
5258 |
(*env)->ExceptionClear( env ); |
5259 |
- LEAVE( "throw_java_exception" ); |
5260 |
+ report( "Leaving - throw_java_exception\n" ); |
5261 |
return; |
5262 |
} |
5263 |
+ memset(&buf[0], 0, sizeof(buf)); |
5264 |
#if defined(_GNU_SOURCE) |
5265 |
- snprintf( buf, 60, "%s in %s", msg, foo ); |
5266 |
+ snprintf( buf, 60, "%s in %s\n", msg, foo ); |
5267 |
#else |
5268 |
- sprintf( buf,"%s in %s", msg, foo ); |
5269 |
+ sprintf( buf,"%s in %s\n", msg, foo ); |
5270 |
#endif /* _GNU_SOURCE */ |
5271 |
(*env)->ThrowNew( env, clazz, buf ); |
5272 |
/* ct7 * Added DeleteLocalRef */ |
5273 |
(*env)->DeleteLocalRef( env, clazz ); |
5274 |
- LEAVE( "throw_java_exception" ); |
5275 |
+ report( "Leaving - throw_java_exception\n" ); |
5276 |
} |
5277 |
|
5278 |
/*---------------------------------------------------------- |
5279 |
report_warning |
5280 |
|
5281 |
- accept: string to send to report as an message |
5282 |
- perform: send the string to stderr or however it needs to be reported. |
5283 |
- return: none |
5284 |
- exceptions: none |
5285 |
- comments: |
5286 |
+ accept: string to send to report as an message |
5287 |
+ perform: send the string to stderr or however it needs to be reported. |
5288 |
+ return: none |
5289 |
+ exceptions: none |
5290 |
+ comments: |
5291 |
----------------------------------------------------------*/ |
5292 |
void report_warning(char *msg) |
5293 |
{ |
5294 |
-#ifndef DEBUG_MW |
5295 |
- fprintf(stderr, msg); |
5296 |
-#else |
5297 |
- mexWarnMsgTxt( (const char *) msg ); |
5298 |
-#endif /* DEBUG_MW */ |
5299 |
+ |
5300 |
+ #if defined(DEBUG_STDOUT) |
5301 |
+ report(msg); |
5302 |
+ #endif |
5303 |
+ |
5304 |
+ #ifdef DEBUG |
5305 |
+ fprintf(stderr, "%s", msg); |
5306 |
+ #endif |
5307 |
+ |
5308 |
} |
5309 |
|
5310 |
/*---------------------------------------------------------- |
5311 |
report_verbose |
5312 |
|
5313 |
- accept: string to send to report as an verbose message |
5314 |
- perform: send the string to stderr or however it needs to be reported. |
5315 |
- return: none |
5316 |
- exceptions: none |
5317 |
- comments: |
5318 |
+ accept: string to send to report as an verbose message |
5319 |
+ perform: send the string to stderr or however it needs to be reported. |
5320 |
+ return: none |
5321 |
+ exceptions: none |
5322 |
+ comments: |
5323 |
----------------------------------------------------------*/ |
5324 |
void report_verbose(char *msg) |
5325 |
{ |
5326 |
-#ifdef DEBUG_VERBOSE |
5327 |
-#ifdef DEBUG_MW |
5328 |
- mexErrMsgTxt( msg ); |
5329 |
-#else |
5330 |
- fprintf(stderr, msg); |
5331 |
-#endif /* DEBUG_MW */ |
5332 |
-#endif /* DEBUG_VERBOSE */ |
5333 |
+ |
5334 |
+ #if defined(DEBUG_STDOUT) |
5335 |
+ report(msg); |
5336 |
+ #endif |
5337 |
+ |
5338 |
+ #ifdef DEBUG |
5339 |
+ fprintf(stderr, "%s", msg); |
5340 |
+ #endif |
5341 |
+ |
5342 |
} |
5343 |
/*---------------------------------------------------------- |
5344 |
report_error |
5345 |
|
5346 |
- accept: string to send to report as an error |
5347 |
- perform: send the string to stderr or however it needs to be reported. |
5348 |
- return: none |
5349 |
- exceptions: none |
5350 |
- comments: |
5351 |
+ accept: string to send to report as an error |
5352 |
+ perform: send the string to stderr or however it needs to be reported. |
5353 |
+ return: none |
5354 |
+ exceptions: none |
5355 |
+ comments: |
5356 |
----------------------------------------------------------*/ |
5357 |
void report_error(char *msg) |
5358 |
{ |
5359 |
-#ifndef DEBUG_MW |
5360 |
- fprintf(stderr, msg); |
5361 |
-#else |
5362 |
- mexWarnMsgTxt( msg ); |
5363 |
-#endif /* DEBUG_MW */ |
5364 |
+ |
5365 |
+ #if defined(DEBUG_STDOUT) |
5366 |
+ report(msg); |
5367 |
+ #endif |
5368 |
+ |
5369 |
+ #ifdef DEBUG |
5370 |
+ fprintf(stderr, "%s", msg); |
5371 |
+ #endif |
5372 |
+ |
5373 |
} |
5374 |
|
5375 |
/*---------------------------------------------------------- |
5376 |
report |
5377 |
|
5378 |
- accept: string to send to stderr |
5379 |
- perform: if DEBUG is defined send the string to stderr. |
5380 |
- return: none |
5381 |
- exceptions: none |
5382 |
- comments: |
5383 |
+ accept: string to send to stderr |
5384 |
+ perform: if DEBUG is defined send the string to stderr. |
5385 |
+ return: none |
5386 |
+ exceptions: none |
5387 |
+ comments: |
5388 |
----------------------------------------------------------*/ |
5389 |
void report(char *msg) |
5390 |
{ |
5391 |
-#ifdef DEBUG |
5392 |
-# ifndef DEBUG_MW |
5393 |
- fprintf(stderr, msg); |
5394 |
-# else |
5395 |
- mexPrintf( msg ); |
5396 |
-# endif /* DEBUG_MW */ |
5397 |
-#endif /* DEBUG */ |
5398 |
+ #if defined(DEBUG_STDOUT) |
5399 |
+ |
5400 |
+ char message[1024] = ""; |
5401 |
+ char fmsg[1024] = ""; |
5402 |
+ |
5403 |
+ memset(&fmsg[0], 0, sizeof(fmsg)); |
5404 |
+ strcat ( fmsg, "SerialImp.c: " ); |
5405 |
+ strcat ( fmsg, msg ); |
5406 |
+ |
5407 |
+ memset(&message[0], 0, sizeof(message)); |
5408 |
+ sprintf( message, "%s", fmsg); |
5409 |
+ fprintf(stdout, "%s", message); |
5410 |
+ |
5411 |
+ #endif |
5412 |
+ |
5413 |
+ #ifdef DEBUG |
5414 |
+ fprintf(stderr, "%s", msg); |
5415 |
+ #endif /* DEBUG */ |
5416 |
} |
5417 |
|
5418 |
#ifndef WIN32 |
5419 |
@@ -5164,12 +5556,12 @@ |
5420 |
/*---------------------------------------------------------- |
5421 |
lfs_lock |
5422 |
|
5423 |
- accept: The name of the device to try to lock |
5424 |
- perform: Create a lock file if there is not one already using a |
5425 |
- lock file server. |
5426 |
- return: 1 on failure 0 on success |
5427 |
- exceptions: none |
5428 |
- comments: |
5429 |
+ accept: The name of the device to try to lock |
5430 |
+ perform: Create a lock file if there is not one already using a |
5431 |
+ lock file server. |
5432 |
+ return: 1 on failure 0 on success |
5433 |
+ exceptions: none |
5434 |
+ comments: |
5435 |
|
5436 |
----------------------------------------------------------*/ |
5437 |
int lfs_lock( const char *filename, int pid ) |
5438 |
@@ -5189,7 +5581,7 @@ |
5439 |
if ( !connect( s, ( struct sockaddr * ) &addr, sizeof( addr ) ) == 0 ) |
5440 |
return 1; |
5441 |
ret=recv( s, buffer, size, 0 ); |
5442 |
- sprintf( buffer, "lock %s %i\n", filename, pid ); |
5443 |
+ sprintf( buffer, "lock %s %i", filename, pid ); |
5444 |
/* printf( "%s", buffer ); */ |
5445 |
send( s, buffer, strlen(buffer), 0 ); |
5446 |
ret=recv( s, buffer, size, 0 ); |
5447 |
@@ -5208,12 +5600,12 @@ |
5448 |
/*---------------------------------------------------------- |
5449 |
lfs_unlock |
5450 |
|
5451 |
- accept: The name of the device to try to unlock |
5452 |
- perform: Remove a lock file if there is one using a |
5453 |
- lock file server. |
5454 |
- return: 1 on failure 0 on success |
5455 |
- exceptions: none |
5456 |
- comments: |
5457 |
+ accept: The name of the device to try to unlock |
5458 |
+ perform: Remove a lock file if there is one using a |
5459 |
+ lock file server. |
5460 |
+ return: 1 on failure 0 on success |
5461 |
+ exceptions: none |
5462 |
+ comments: |
5463 |
|
5464 |
----------------------------------------------------------*/ |
5465 |
int lfs_unlock( const char *filename, int pid ) |
5466 |
@@ -5232,7 +5624,7 @@ |
5467 |
|
5468 |
if ( !connect( s, ( struct sockaddr * ) &addr, sizeof( addr ) ) == 0 ) |
5469 |
return 1; |
5470 |
- sprintf( buffer, "unlock %s %i\n", filename, pid ); |
5471 |
+ sprintf( buffer, "unlock %s %i", filename, pid ); |
5472 |
/* printf( "%s", buffer ); */ |
5473 |
send( s, buffer, strlen(buffer), 0 ); |
5474 |
ret = recv( s, buffer, size, 0 ); |
5475 |
@@ -5251,14 +5643,14 @@ |
5476 |
/*---------------------------------------------------------- |
5477 |
lib_lock_dev_unlock |
5478 |
|
5479 |
- accept: The name of the device to try to unlock |
5480 |
- perform: Remove a lock file if there is one using a |
5481 |
- lock file server. |
5482 |
- return: 1 on failure 0 on success |
5483 |
- exceptions: none |
5484 |
- comments: This is for use with liblockdev which comes with Linux |
5485 |
- distros. I suspect it will be problematic with embeded |
5486 |
- Linux. taj |
5487 |
+ accept: The name of the device to try to unlock |
5488 |
+ perform: Remove a lock file if there is one using a |
5489 |
+ lock file server. |
5490 |
+ return: 1 on failure 0 on success |
5491 |
+ exceptions: none |
5492 |
+ comments: This is for use with liblockdev which comes with Linux |
5493 |
+ distros. I suspect it will be problematic with embeded |
5494 |
+ Linux. taj |
5495 |
|
5496 |
----------------------------------------------------------*/ |
5497 |
#ifdef LIBLOCKDEV |
5498 |
@@ -5276,17 +5668,17 @@ |
5499 |
/*---------------------------------------------------------- |
5500 |
lib_lock_dev_lock |
5501 |
|
5502 |
- accept: The name of the device to try to lock |
5503 |
- termios struct |
5504 |
- perform: Create a lock file if there is not one already. |
5505 |
- return: 1 on failure 0 on success |
5506 |
- exceptions: none |
5507 |
- comments: This is for use with liblockdev which comes with Linux |
5508 |
- distros. I suspect it will be problematic with embeded |
5509 |
- Linux. taj |
5510 |
+ accept: The name of the device to try to lock |
5511 |
+ termios struct |
5512 |
+ perform: Create a lock file if there is not one already. |
5513 |
+ return: 1 on failure 0 on success |
5514 |
+ exceptions: none |
5515 |
+ comments: This is for use with liblockdev which comes with Linux |
5516 |
+ distros. I suspect it will be problematic with embeded |
5517 |
+ Linux. taj |
5518 |
|
5519 |
- One could load the library here rather than link it and |
5520 |
- always try to use this. |
5521 |
+ One could load the library here rather than link it and |
5522 |
+ always try to use this. |
5523 |
|
5524 |
----------------------------------------------------------*/ |
5525 |
#ifdef LIBLOCKDEV |
5526 |
@@ -5301,6 +5693,7 @@ |
5527 |
} |
5528 |
if ( dev_lock( filename ) ) |
5529 |
{ |
5530 |
+ memset(&message[0], 0, sizeof(message)); |
5531 |
sprintf( message, |
5532 |
"RXTX fhs_lock() Error: creating lock file for: %s: %s\n", |
5533 |
filename, strerror(errno) ); |
5534 |
@@ -5314,27 +5707,24 @@ |
5535 |
/*---------------------------------------------------------- |
5536 |
fhs_lock |
5537 |
|
5538 |
- accept: The name of the device to try to lock |
5539 |
- termios struct |
5540 |
- perform: Create a lock file if there is not one already. |
5541 |
- return: 1 on failure 0 on success |
5542 |
- exceptions: none |
5543 |
- comments: This is for linux and freebsd only currently. I see SVR4 does |
5544 |
- this differently and there are other proposed changes to the |
5545 |
- Filesystem Hierachy Standard |
5546 |
- |
5547 |
- more reading: |
5548 |
- |
5549 |
+ accept: The name of the device to try to lock |
5550 |
+ termios struct |
5551 |
+ perform: Create a lock file if there is not one already. |
5552 |
+ return: 1 on failure 0 on success |
5553 |
+ exceptions: none |
5554 |
+ comments: This is for linux and freebsd only currently. I see SVR4 does |
5555 |
+ this differently and there are other proposed changes to the |
5556 |
+ Filesystem Hierachy Standard |
5557 |
----------------------------------------------------------*/ |
5558 |
int fhs_lock( const char *filename, int pid ) |
5559 |
{ |
5560 |
/* |
5561 |
- * There is a zoo of lockdir possibilities |
5562 |
- * Its possible to check for stale processes with most of them. |
5563 |
- * for now we will just check for the lockfile on most |
5564 |
- * Problem lockfiles will be dealt with. Some may not even be in use. |
5565 |
- * |
5566 |
- */ |
5567 |
+ * There is a zoo of lockdir possibilities |
5568 |
+ * Its possible to check for stale processes with most of them. |
5569 |
+ * for now we will just check for the lockfile on most |
5570 |
+ * Problem lockfiles will be dealt with. Some may not even be in use. |
5571 |
+ * |
5572 |
+ */ |
5573 |
int fd,j; |
5574 |
char lockinfo[12], message[80]; |
5575 |
char file[80], *p; |
5576 |
@@ -5342,7 +5732,7 @@ |
5577 |
j = strlen( filename ); |
5578 |
p = ( char * ) filename + j; |
5579 |
/* FIXME need to handle subdirectories /dev/cua/... |
5580 |
- SCO Unix use lowercase all the time |
5581 |
+ SCO Unix use lowercase all the time |
5582 |
taj |
5583 |
*/ |
5584 |
while( *( p - 1 ) != '/' && j-- != 1 ) |
5585 |
@@ -5361,13 +5751,15 @@ |
5586 |
fd = open( file, O_CREAT | O_WRONLY | O_EXCL, 0444 ); |
5587 |
if( fd < 0 ) |
5588 |
{ |
5589 |
+ memset(&message[0], 0, sizeof(message)); |
5590 |
sprintf( message, |
5591 |
"RXTX fhs_lock() Error: creating lock file: %s: %s\n", |
5592 |
file, strerror(errno) ); |
5593 |
report_error( message ); |
5594 |
return 1; |
5595 |
} |
5596 |
- sprintf( lockinfo, "%10d\n",(int) getpid() ); |
5597 |
+ sprintf( lockinfo, "%10d",(int) getpid() ); |
5598 |
+ memset(&message[0], 0, sizeof(message)); |
5599 |
sprintf( message, "fhs_lock: creating lockfile: %s\n", lockinfo ); |
5600 |
report( message ); |
5601 |
write( fd, lockinfo, 11 ); |
5602 |
@@ -5378,11 +5770,12 @@ |
5603 |
/*---------------------------------------------------------- |
5604 |
uucp_lock |
5605 |
|
5606 |
- accept: char * filename. Device to be locked |
5607 |
- perform: Try to get a uucp_lock |
5608 |
- return: int 0 on success |
5609 |
- exceptions: none |
5610 |
- comments: |
5611 |
+ accept: char * filename. Device to be locked |
5612 |
+ perform: Try to get a uucp_lock |
5613 |
+ return: int 0 on success |
5614 |
+ exceptions: none |
5615 |
+ comments: |
5616 |
+ |
5617 |
The File System Hierarchy Standard |
5618 |
http://www.pathname.com/fhs/ |
5619 |
|
5620 |
@@ -5408,9 +5801,9 @@ |
5621 |
/var/lock |
5622 |
4) handle stale locks (done except kermit locks) |
5623 |
5) handle minicom lockfile contents (FSSTND?) |
5624 |
- " 16929 minicom root\n" (done) |
5625 |
+ " 16929 minicom root\n" (done) |
5626 |
6) there are other Lock conventions that use Major and Minor |
5627 |
- numbers... |
5628 |
+ numbers... |
5629 |
7) Stevens recommends LCK..<pid> |
5630 |
|
5631 |
most are caught above. If they turn out to be problematic |
5632 |
@@ -5424,7 +5817,8 @@ |
5633 |
int fd; |
5634 |
struct stat buf; |
5635 |
|
5636 |
- sprintf( message, "uucp_lock( %s );\n", filename ); |
5637 |
+ memset(&message[0], 0, sizeof(message)); |
5638 |
+ sprintf( message, "uucp_lock(%s)\n", filename ); |
5639 |
report( message ); |
5640 |
|
5641 |
if ( check_lock_status( filename ) ) |
5642 |
@@ -5432,55 +5826,75 @@ |
5643 |
report( "RXTX uucp check_lock_status true\n" ); |
5644 |
return 1; |
5645 |
} |
5646 |
+ report("uucp_lock - getting STAT on lock dir\n"); |
5647 |
if ( stat( LOCKDIR, &buf ) != 0 ) |
5648 |
{ |
5649 |
report( "RXTX uucp_lock() could not find lock directory.\n" ); |
5650 |
return 1; |
5651 |
} |
5652 |
+ |
5653 |
+ report("uucp_lock - getting STAT on filename\n"); |
5654 |
if ( stat( filename, &buf ) != 0 ) |
5655 |
{ |
5656 |
+ memset(&message[0], 0, sizeof(message)); |
5657 |
report( "RXTX uucp_lock() could not find device.\n" ); |
5658 |
sprintf( message, "uucp_lock: device was %s\n", name ); |
5659 |
report( message ); |
5660 |
return 1; |
5661 |
} |
5662 |
+ report("uucp_lock - generating lock filename\n"); |
5663 |
sprintf( lockfilename, "%s/LK.%03d.%03d.%03d", |
5664 |
LOCKDIR, |
5665 |
(int) major( buf.st_dev ), |
5666 |
- (int) major( buf.st_rdev ), |
5667 |
+ (int) major( buf.st_rdev ), |
5668 |
(int) minor( buf.st_rdev ) |
5669 |
); |
5670 |
- sprintf( lockinfo, "%10d\n", (int) getpid() ); |
5671 |
+ report("uucp_lock - generating lock info\n"); |
5672 |
+ sprintf( lockinfo, "%10d", (int) getpid() ); |
5673 |
+ |
5674 |
+ report("uucp_lock - getting STAT on lock filename\n"); |
5675 |
if ( stat( lockfilename, &buf ) == 0 ) |
5676 |
{ |
5677 |
+ memset(&message[0], 0, sizeof(message)); |
5678 |
sprintf( message, "RXTX uucp_lock() %s is there\n", |
5679 |
lockfilename ); |
5680 |
report( message ); |
5681 |
report_error( message ); |
5682 |
return 1; |
5683 |
} |
5684 |
+ |
5685 |
+ report("uucp_lock - Opening lock file\n"); |
5686 |
fd = open( lockfilename, O_CREAT | O_WRONLY | O_EXCL, 0444 ); |
5687 |
+ |
5688 |
+ |
5689 |
if( fd < 0 ) |
5690 |
{ |
5691 |
+ memset(&message[0], 0, sizeof(message)); |
5692 |
sprintf( message, |
5693 |
"RXTX uucp_lock() Error: creating lock file: %s\n", |
5694 |
lockfilename ); |
5695 |
report_error( message ); |
5696 |
return 1; |
5697 |
} |
5698 |
+ else |
5699 |
+ { |
5700 |
+ report("uucp_lock - lock file created\n"); |
5701 |
+ } |
5702 |
write( fd, lockinfo,11 ); |
5703 |
+ report("uucp_lock - Writen lockinfo, closing on lock filen\n"); |
5704 |
close( fd ); |
5705 |
+ report("uucp_lock - returning (0)\n"); |
5706 |
return 0; |
5707 |
} |
5708 |
|
5709 |
/*---------------------------------------------------------- |
5710 |
check_lock_status |
5711 |
|
5712 |
- accept: the lock name in question |
5713 |
- perform: Make sure everything is sane |
5714 |
- return: 0 on success |
5715 |
- exceptions: none |
5716 |
- comments: |
5717 |
+ accept: the lock name in question |
5718 |
+ perform: Make sure everything is sane |
5719 |
+ return: 0 on success |
5720 |
+ exceptions: none |
5721 |
+ comments: |
5722 |
----------------------------------------------------------*/ |
5723 |
int check_lock_status( const char *filename ) |
5724 |
{ |
5725 |
@@ -5515,13 +5929,13 @@ |
5726 |
/*---------------------------------------------------------- |
5727 |
fhs_unlock |
5728 |
|
5729 |
- accept: The name of the device to unlock |
5730 |
- perform: delete the lock file |
5731 |
- return: none |
5732 |
- exceptions: none |
5733 |
- comments: This is for linux only currently. I see SVR4 does this |
5734 |
- differently and there are other proposed changes to the |
5735 |
- Filesystem Hierachy Standard |
5736 |
+ accept: The name of the device to unlock |
5737 |
+ perform: delete the lock file |
5738 |
+ return: none |
5739 |
+ exceptions: none |
5740 |
+ comments: This is for linux only currently. I see SVR4 does this |
5741 |
+ differently and there are other proposed changes to the |
5742 |
+ Filesystem Hierachy Standard |
5743 |
----------------------------------------------------------*/ |
5744 |
void fhs_unlock( const char *filename, int openpid ) |
5745 |
{ |
5746 |
@@ -5548,11 +5962,11 @@ |
5747 |
/*---------------------------------------------------------- |
5748 |
uucp_unlock |
5749 |
|
5750 |
- accept: char *filename the device that is locked |
5751 |
- perform: remove the uucp lockfile if it exists |
5752 |
- return: none |
5753 |
- exceptions: none |
5754 |
- comments: http://docs.freebsd.org/info/uucp/uucp.info.UUCP_Lock_Files.html |
5755 |
+ accept: char *filename the device that is locked |
5756 |
+ perform: remove the uucp lockfile if it exists |
5757 |
+ return: none |
5758 |
+ exceptions: none |
5759 |
+ comments: http://docs.freebsd.org/info/uucp/uucp.info.UUCP_Lock_Files.html |
5760 |
----------------------------------------------------------*/ |
5761 |
void uucp_unlock( const char *filename, int openpid ) |
5762 |
{ |
5763 |
@@ -5560,34 +5974,46 @@ |
5764 |
char file[80], message[80]; |
5765 |
/* FIXME */ |
5766 |
|
5767 |
- sprintf( message, "uucp_unlock( %s );\n", filename ); |
5768 |
+ memset(&message[0], 0, sizeof(message)); |
5769 |
+ sprintf( message, "uucp_unlock(%s);\n", filename ); |
5770 |
report( message ); |
5771 |
|
5772 |
if ( stat( filename, &buf ) != 0 ) |
5773 |
{ |
5774 |
/* hmm the file is not there? */ |
5775 |
- report( "uucp_unlock() no such device\n" ); |
5776 |
+ report( "uucp_unlock() - no such device\n" ); |
5777 |
return; |
5778 |
} |
5779 |
+ else |
5780 |
+ { |
5781 |
+ report( "uucp_unlock() - device exists\n" ); |
5782 |
+ } |
5783 |
+ |
5784 |
sprintf( file, LOCKDIR"/LK.%03d.%03d.%03d", |
5785 |
(int) major( buf.st_dev ), |
5786 |
- (int) major( buf.st_rdev ), |
5787 |
+ (int) major( buf.st_rdev ), |
5788 |
(int) minor( buf.st_rdev ) |
5789 |
); |
5790 |
+ |
5791 |
+ report( "uucp_unlock() - going to stat\n" ); |
5792 |
if ( stat( file, &buf ) != 0 ) |
5793 |
{ |
5794 |
/* hmm the file is not there? */ |
5795 |
report( "uucp_unlock no such lockfile\n" ); |
5796 |
return; |
5797 |
} |
5798 |
+ report( "uucp_unlock() - going to check lock pid\n" ); |
5799 |
if( !check_lock_pid( file, openpid ) ) |
5800 |
{ |
5801 |
+ memset(&message[0], 0, sizeof(message)); |
5802 |
sprintf( message, "uucp_unlock: unlinking %s\n", file ); |
5803 |
report( message ); |
5804 |
unlink(file); |
5805 |
+ report( "uucp_unlock() - Unlink completed\n" ); |
5806 |
} |
5807 |
else |
5808 |
{ |
5809 |
+ memset(&message[0], 0, sizeof(message)); |
5810 |
sprintf( message, "uucp_unlock: unlinking failed %s\n", file ); |
5811 |
report( message ); |
5812 |
} |
5813 |
@@ -5596,11 +6022,11 @@ |
5814 |
/*---------------------------------------------------------- |
5815 |
check_lock_pid |
5816 |
|
5817 |
- accept: the name of the lockfile |
5818 |
- perform: make sure the lock file is ours. |
5819 |
- return: 0 on success |
5820 |
- exceptions: none |
5821 |
- comments: |
5822 |
+ accept: the name of the lockfile |
5823 |
+ perform: make sure the lock file is ours. |
5824 |
+ return: 0 on success |
5825 |
+ exceptions: none |
5826 |
+ comments: |
5827 |
----------------------------------------------------------*/ |
5828 |
int check_lock_pid( const char *file, int openpid ) |
5829 |
{ |
5830 |
@@ -5624,6 +6050,7 @@ |
5831 |
/* Native threads JVM's have multiple pids */ |
5832 |
if ( lockpid != getpid() && lockpid != getppid() && lockpid != openpid ) |
5833 |
{ |
5834 |
+ memset(&message[0], 0, sizeof(message)); |
5835 |
sprintf(message, "check_lock_pid: lock = %s pid = %i gpid=%i openpid=%i\n", |
5836 |
pid_buffer, (int) getpid(), (int) getppid(), openpid ); |
5837 |
report( message ); |
5838 |
@@ -5635,16 +6062,17 @@ |
5839 |
/*---------------------------------------------------------- |
5840 |
check_group_uucp |
5841 |
|
5842 |
- accept: none |
5843 |
- perform: check if the user is root or in group uucp |
5844 |
- return: 0 on success |
5845 |
- exceptions: none |
5846 |
- comments: |
5847 |
+ accept: none |
5848 |
+ perform: check if the user is root or in group uucp |
5849 |
+ return: 0 on success |
5850 |
+ exceptions: none |
5851 |
+ comments: |
5852 |
This checks if the effective user is in group uucp so we can |
5853 |
create lock files. If not we give them a warning and bail. |
5854 |
If its root we just skip the test. |
5855 |
|
5856 |
- if someone really wants to override this they can use the USER_LOCK_DIRECTORY --not recommended. |
5857 |
+ if someone really wants to override this they can use the |
5858 |
+ USER_LOCK_DIRECTORY --not recommended. |
5859 |
|
5860 |
In a recent change RedHat 7.2 decided to use group lock. |
5861 |
In order to get around this we just check the group id |
5862 |
@@ -5674,7 +6102,7 @@ |
5863 |
+ strlen(testLockFileName) + 2, sizeof(char)); |
5864 |
if ( NULL == testLockAbsFileName ) |
5865 |
{ |
5866 |
- report_error("check_group_uucp(): Insufficient memory"); |
5867 |
+ report_error("check_group_uucp(): Insufficient memory\n"); |
5868 |
return 1; |
5869 |
} |
5870 |
strcat(testLockAbsFileName, testLockFileDirName); |
5871 |
@@ -5683,16 +6111,14 @@ |
5872 |
if ( NULL == mktemp(testLockAbsFileName) ) |
5873 |
{ |
5874 |
free(testLockAbsFileName); |
5875 |
- report_error("check_group_uucp(): mktemp malformed string - \ |
5876 |
- should not happen"); |
5877 |
+ report_error("check_group_uucp(): mktemp malformed string - should not happen\n"); |
5878 |
|
5879 |
return 1; |
5880 |
} |
5881 |
testLockFile = fopen (testLockAbsFileName, "w+"); |
5882 |
if (NULL == testLockFile) |
5883 |
{ |
5884 |
- report_error("check_group_uucp(): error testing lock file " |
5885 |
- "creation Error details:"); |
5886 |
+ report_error("check_group_uucp(): error testing lock file creation Error details:\n"); |
5887 |
report_error(strerror(errno)); |
5888 |
free(testLockAbsFileName); |
5889 |
return 1; |
5890 |
@@ -5717,7 +6143,8 @@ |
5891 |
|
5892 |
if( stat( LOCKDIR, &buf) ) |
5893 |
{ |
5894 |
- sprintf( msg, "check_group_uucp: Can not find Lock Directory: %s\n", LOCKDIR ); |
5895 |
+ memset(&msg[0], 0, sizeof(msg)); |
5896 |
+ sprintf( msg, "check_group_uucp: Can not find Lock Directory: %s\n", LOCKDIR ); |
5897 |
report_error( msg ); |
5898 |
return( 1 ); |
5899 |
} |
5900 |
@@ -5741,6 +6168,7 @@ |
5901 |
} |
5902 |
if( buf.st_gid == list[ group_count ] ) |
5903 |
return 0; |
5904 |
+ memset(&msg[0], 0, sizeof(msg)); |
5905 |
sprintf( msg, "%i %i\n", buf.st_gid, list[ group_count ] ); |
5906 |
report_error( msg ); |
5907 |
report_error( UUCP_ERROR ); |
5908 |
@@ -5776,7 +6204,7 @@ |
5909 |
for information. |
5910 |
|
5911 |
* realpath() doesn't exist on all of the systems my code has to run |
5912 |
- on (HP-UX 9.x, specifically) |
5913 |
+ on (HP-UX 9.x, specifically) |
5914 |
---------------------------------------------------------- |
5915 |
int different_from_LOCKDIR(const char* ld) |
5916 |
{ |
5917 |
@@ -5798,13 +6226,13 @@ |
5918 |
/*---------------------------------------------------------- |
5919 |
is_device_locked |
5920 |
|
5921 |
- accept: char * filename. The device in question including the path. |
5922 |
- perform: see if one of the many possible lock files is aready there |
5923 |
- if there is a stale lock, remove it. |
5924 |
- return: 1 if the device is locked or somethings wrong. |
5925 |
- 0 if its possible to create our own lock file. |
5926 |
- exceptions: none |
5927 |
- comments: check if the device is already locked |
5928 |
+ accept: char * filename. The device in question including the path. |
5929 |
+ perform: see if one of the many possible lock files is aready there |
5930 |
+ if there is a stale lock, remove it. |
5931 |
+ return: 1 if the device is locked or somethings wrong. |
5932 |
+ 0 if its possible to create our own lock file. |
5933 |
+ exceptions: none |
5934 |
+ comments: check if the device is already locked |
5935 |
----------------------------------------------------------*/ |
5936 |
int is_device_locked( const char *port_filename ) |
5937 |
{ |
5938 |
@@ -5828,12 +6256,12 @@ |
5939 |
while( lockdirs[i] ) |
5940 |
{ |
5941 |
/* |
5942 |
- Look for lockfiles in all known places other than the |
5943 |
- defined lock directory for this system |
5944 |
- report any unexpected lockfiles. |
5945 |
+ Look for lockfiles in all known places other than the |
5946 |
+ defined lock directory for this system |
5947 |
+ report any unexpected lockfiles. |
5948 |
|
5949 |
- Is the suspect lockdir there? |
5950 |
- if it is there is it not the expected lock dir? |
5951 |
+ Is the suspect lockdir there? |
5952 |
+ if it is there is it not the expected lock dir? |
5953 |
*/ |
5954 |
if( !stat( lockdirs[i], &buf2 ) && |
5955 |
buf2.st_ino != lockbuf.st_ino && |
5956 |
@@ -5842,7 +6270,7 @@ |
5957 |
j = strlen( port_filename ); |
5958 |
p = ( char * ) port_filename + j; |
5959 |
/* |
5960 |
- SCO Unix use lowercase all the time |
5961 |
+ SCO Unix use lowercase all the time |
5962 |
taj |
5963 |
*/ |
5964 |
while( *( p - 1 ) != '/' && j-- != 1 ) |
5965 |
@@ -5860,7 +6288,8 @@ |
5966 |
lockprefixes[k], p ); |
5967 |
if( stat( file, &buf ) == 0 ) |
5968 |
{ |
5969 |
- sprintf( message, UNEXPECTED_LOCK_FILE, |
5970 |
+ memset(&message[0], 0, sizeof(message)); |
5971 |
+ sprintf( message, "%s%s\n", UNEXPECTED_LOCK_FILE, |
5972 |
file ); |
5973 |
report_warning( message ); |
5974 |
return 1; |
5975 |
@@ -5877,7 +6306,8 @@ |
5976 |
); |
5977 |
if( stat( file, &buf ) == 0 ) |
5978 |
{ |
5979 |
- sprintf( message, UNEXPECTED_LOCK_FILE, |
5980 |
+ memset(&message[0], 0, sizeof(message)); |
5981 |
+ sprintf( message, "%s%s\n", UNEXPECTED_LOCK_FILE, |
5982 |
file ); |
5983 |
report_warning( message ); |
5984 |
return 1; |
5985 |
@@ -5934,13 +6364,15 @@ |
5986 |
|
5987 |
if( kill( (pid_t) pid, 0 ) && errno==ESRCH ) |
5988 |
{ |
5989 |
+ memset(&message[0], 0, sizeof(message)); |
5990 |
sprintf( message, |
5991 |
- "RXTX Warning: Removing stale lock file. %s\n", |
5992 |
+ "RXTX Warning: Removing stale lock file. %s\n", |
5993 |
file ); |
5994 |
report_warning( message ); |
5995 |
if( unlink( file ) != 0 ) |
5996 |
{ |
5997 |
- snprintf( message, 80, "RXTX Error: Unable to \ |
5998 |
+ memset(&message[0], 0, sizeof(message)); |
5999 |
+ snprintf( message, 80, "RXTX Error: Unable to \ |
6000 |
remove stale lock file: %s\n", |
6001 |
file |
6002 |
); |
6003 |
@@ -5956,11 +6388,11 @@ |
6004 |
/*---------------------------------------------------------- |
6005 |
system_does_not_lock |
6006 |
|
6007 |
- accept: the filename the system thinks should be locked. |
6008 |
- perform: avoid trying to create lock files on systems that dont use them |
6009 |
- return: 0 for success ;) |
6010 |
- exceptions: none |
6011 |
- comments: OS's like Win32 may not have lock files. |
6012 |
+ accept: the filename the system thinks should be locked. |
6013 |
+ perform: avoid trying to create lock files on systems that dont use them |
6014 |
+ return: 0 for success ;) |
6015 |
+ exceptions: none |
6016 |
+ comments: OS's like Win32 may not have lock files. |
6017 |
----------------------------------------------------------*/ |
6018 |
int system_does_not_lock( const char * filename, int pid ) |
6019 |
{ |
6020 |
@@ -5970,11 +6402,11 @@ |
6021 |
/*---------------------------------------------------------- |
6022 |
system_does_not_unlock |
6023 |
|
6024 |
- accept: the filename the system thinks should be locked. |
6025 |
- perform: avoid trying to create lock files on systems that dont use them |
6026 |
- return: none |
6027 |
- exceptions: none |
6028 |
- comments: OS's like Win32 may not have lock files. |
6029 |
+ accept: the filename the system thinks should be locked. |
6030 |
+ perform: avoid trying to create lock files on systems that dont use them |
6031 |
+ return: none |
6032 |
+ exceptions: none |
6033 |
+ comments: OS's like Win32 may not have lock files. |
6034 |
----------------------------------------------------------*/ |
6035 |
void system_does_not_unlock( const char * filename, int openpid ) |
6036 |
{ |
6037 |
@@ -5984,12 +6416,12 @@ |
6038 |
/*---------------------------------------------------------- |
6039 |
dump_termios |
6040 |
|
6041 |
- accept: string to indicate where this was called. |
6042 |
- termios struct |
6043 |
- perform: print the termios struct to stderr. |
6044 |
- return: none |
6045 |
- exceptions: none |
6046 |
- comments: used to debug the termios struct. |
6047 |
+ accept: string to indicate where this was called. |
6048 |
+ termios struct |
6049 |
+ perform: print the termios struct to stderr. |
6050 |
+ return: none |
6051 |
+ exceptions: none |
6052 |
+ comments: used to debug the termios struct. |
6053 |
----------------------------------------------------------*/ |
6054 |
void dump_termios(char *foo,struct termios *ttyset) |
6055 |
{ |
6056 |
@@ -6012,12 +6444,12 @@ |
6057 |
/*---------------------------------------------------------- |
6058 |
get_java_environment |
6059 |
|
6060 |
- accept: pointer to the virtual machine |
6061 |
- flag to know if we are attached |
6062 |
- return: pointer to the Java Environment |
6063 |
- exceptions: none |
6064 |
- comments: see JNI_OnLoad. For getting the JNIEnv in the thread |
6065 |
- used to monitor for output buffer empty. |
6066 |
+ accept: pointer to the virtual machine |
6067 |
+ flag to know if we are attached |
6068 |
+ return: pointer to the Java Environment |
6069 |
+ exceptions: none |
6070 |
+ comments: see JNI_OnLoad. For getting the JNIEnv in the thread |
6071 |
+ used to monitor for output buffer empty. |
6072 |
----------------------------------------------------------*/ |
6073 |
JNIEnv *get_java_environment(JavaVM *java_vm, jboolean *was_attached){ |
6074 |
void **env = NULL; |
6075 |
@@ -6045,15 +6477,15 @@ |
6076 |
/*---------------------------------------------------------- |
6077 |
JNI_OnLoad |
6078 |
|
6079 |
- accept: JavaVM pointer to the Vertial Machine |
6080 |
- void * reserved ??? |
6081 |
- return: jint JNI version used. |
6082 |
- exceptions: none |
6083 |
- comments: http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html |
6084 |
- http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html |
6085 |
- grab the Java VM pointer when the library loads for later use |
6086 |
- in the drain thread. Also lets Java know we are using the |
6087 |
- 1.4 API so we can get pointers later. |
6088 |
+ accept: JavaVM pointer to the Vertial Machine |
6089 |
+ void * reserved ??? |
6090 |
+ return: jint JNI version used. |
6091 |
+ exceptions: none |
6092 |
+ comments: http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html |
6093 |
+ http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html |
6094 |
+ grab the Java VM pointer when the library loads for later use |
6095 |
+ in the drain thread. Also lets Java know we are using the |
6096 |
+ 1.4 API so we can get pointers later. |
6097 |
----------------------------------------------------------*/ |
6098 |
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *java_vm, void *reserved) |
6099 |
{ |
6100 |
@@ -6065,28 +6497,28 @@ |
6101 |
/*---------------------------------------------------------- |
6102 |
JNI_OnUnload |
6103 |
|
6104 |
- accept: JavaVM pointer to the Vertial Machine |
6105 |
- void * reserved ??? |
6106 |
- return: none |
6107 |
- exceptions: none |
6108 |
- comments: http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html |
6109 |
- http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html |
6110 |
- final library cleanup here. |
6111 |
+ accept: JavaVM pointer to the Vertial Machine |
6112 |
+ void * reserved ??? |
6113 |
+ return: none |
6114 |
+ exceptions: none |
6115 |
+ comments: http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html |
6116 |
+ http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html |
6117 |
+ final library cleanup here. |
6118 |
----------------------------------------------------------*/ |
6119 |
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) |
6120 |
{ |
6121 |
/* never called it appears */ |
6122 |
- printf("Experimental: JNI_OnUnload called.\n"); |
6123 |
+ printf("Experimental: JNI_OnUnload called.\n"); |
6124 |
} |
6125 |
|
6126 |
#ifdef asdf |
6127 |
/*---------------------------------------------------------- |
6128 |
printj |
6129 |
|
6130 |
- accept: like vwprintf() |
6131 |
- return: number of jchars written or -1 |
6132 |
- exceptions: none |
6133 |
- comments: prints data using System.out.print() |
6134 |
+ accept: like vwprintf() |
6135 |
+ return: number of jchars written or -1 |
6136 |
+ exceptions: none |
6137 |
+ comments: prints data using System.out.print() |
6138 |
----------------------------------------------------------*/ |
6139 |
int printj(JNIEnv *env, wchar_t *fmt, ...) |
6140 |
{ |
6141 |
@@ -6158,4 +6590,3 @@ |
6142 |
(*env)->CallStaticVoidMethod(env, cls, mid, 1); |
6143 |
*/ |
6144 |
#endif /* asdf */ |
6145 |
- |