Debian Codegraph @

CNI/SerialImp.h

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*-------------------------------------------------------------------------
2 | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface.
3 | RXTX is a native interface to serial ports in java.
4 | Copyright 1997-2007 by Trent Jarvi [email protected] and others who
5 | actually wrote it. See individual source files for more information.
6 |
7 | A copy of the LGPL v 2.1 may be found at
8 | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is
9 | here for your convenience.
10 |
11 | This library is free software; you can redistribute it and/or
12 | modify it under the terms of the GNU Lesser General Public
13 | License as published by the Free Software Foundation; either
14 | version 2.1 of the License, or (at your option) any later version.
15 |
16 | This library is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 | Lesser General Public License for more details.
20 |
21 | An executable that contains no derivative of any portion of RXTX, but
22 | is designed to work with RXTX by being dynamically linked with it,
23 | is considered a "work that uses the Library" subject to the terms and
24 | conditions of the GNU Lesser General Public License.
25 |
26 | The following has been added to the RXTX License to remove
27 | any confusion about linking to RXTX. We want to allow in part what
28 | section 5, paragraph 2 of the LGPL does not permit in the special
29 | case of linking over a controlled interface. The intent is to add a
30 | Java Specification Request or standards body defined interface in the
31 | future as another exception but one is not currently available.
32 |
33 | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
34 |
35 | As a special exception, the copyright holders of RXTX give you
36 | permission to link RXTX with independent modules that communicate with
37 | RXTX solely through the Sun Microsytems CommAPI interface version 2,
38 | regardless of the license terms of these independent modules, and to copy
39 | and distribute the resulting combined work under terms of your choice,
40 | provided that every copy of the combined work is accompanied by a complete
41 | copy of the source code of RXTX (the version of RXTX used to produce the
42 | combined work), being distributed under the terms of the GNU Lesser General
43 | Public License plus this exception. An independent module is a
44 | module which is not derived from or based on RXTX.
45 |
46 | Note that people who make modified versions of RXTX are not obligated
47 | to grant this special exception for their modified versions; it is
48 | their choice whether to do so. The GNU Lesser General Public License
49 | gives permission to release a modified version without this exception; this
50 | exception also makes it possible to release a modified version which
51 | carries forward this exception.
52 |
53 | You should have received a copy of the GNU Lesser General Public
54 | License along with this library; if not, write to the Free
55 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
56 | All trademarks belong to their respective owners.
57 --------------------------------------------------------------------------*/
58 /* gnu.io.SerialPort constants */
59 #ifdef WIN32
60 #include "win32termios.h"
61 #endif /* WIN32 */
62 #define JDATABITS_5 5
63 #define JDATABITS_6 6
64 #define JDATABITS_7 7
65 #define JDATABITS_8 8
66 #define JPARITY_NONE 0
67 #define JPARITY_ODD 1
68 #define JPARITY_EVEN 2
69 #define JPARITY_MARK 3
70 #define JPARITY_SPACE 4
71 #define STOPBITS_1 1
72 #define STOPBITS_2 2
73 #define STOPBITS_1_5 3
74 #define FLOWCONTROL_NONE 0
75 #define FLOWCONTROL_RTSCTS_IN 1
76 #define FLOWCONTROL_RTSCTS_OUT 2
77 #define FLOWCONTROL_XONXOFF_IN 4
78 #define FLOWCONTROL_XONXOFF_OUT 8
79
80 /* gnu.io.SerialPortEvent constants */
81 #define SPE_DATA_AVAILABLE 1
82 #define SPE_OUTPUT_BUFFER_EMPTY 2
83 #define SPE_CTS 3
84 #define SPE_DSR 4
85 #define SPE_RI 5
86 #define SPE_CD 6
87 #define SPE_OE 7
88 #define SPE_PE 8
89 #define SPE_FE 9
90 #define SPE_BI 10
91
92 #define PORT_SERIAL 1
93 #define PORT_PARALLEL 2
94 #define PORT_I2C 3
95 #define PORT_RS485 4
96 #define PORT_RAW 5
97
98 /* glue for unsupported linux speeds see also win32termios.h */
99
100 #if !defined(__APPLE__) && !defined(__FreeBSD__) /* dima */
101 /* this is now handled in SerialImp.c
102 #define B14400 1010001
103 #define B28800 1010002
104 #define B128000 1010003
105 #define B256000 1010004
106 */
107 #endif /* dima */
108
109 struct preopened
110 {
111 char filename[40];
112 int fd;
113 struct preopened *next;
114 struct preopened *prev;
115 };
116
117 struct event_info_struct
118 {
119 int fd;
120 /* flags for events */
121 int eventflags[11];
122
123 int initialised;
124 int ret, change;
125 unsigned int omflags;
126 char message[80];
127 int has_tiocsergetlsr;
128 int has_tiocgicount;
129 int eventloop_interrupted;
130 /*
131 JNIEnv *env;
132 jobject *jobj;
133 jclass jclazz;
134 jmethodID send_event;
135 jmethodID checkMonitorThread;
136 */
137 struct event_info_struct *next, *prev;
138 fd_set rfds;
139 struct timeval tv_sleep;
140 int closing;
141 #if !defined(TIOCSERGETLSR) && !defined(WIN32)
142 int writing;
143 int output_buffer_empty_flag;
144 #endif /* !TIOCSERGETLSR !WIN32 */
145 # if defined(TIOCGICOUNT)
146 struct serial_icounter_struct osis;
147 #endif /* TIOCGICOUNT */
148 };
149
150 /* Ports known on the OS */
151 #if defined(__linux__)
152 # define DEVICEDIR "/dev/"
153 # define LOCKDIR "/var/lock"
154 # define LOCKFILEPREFIX "LCK.."
155 # define FHS
156 #endif /* __linux__ */
157 #if defined(__QNX__)
158 # define DEVICEDIR "/dev/"
159 # define LOCKDIR ""
160 # define LOCKFILEPREFIX ""
161 #endif /* qnx */
162 #if defined(__sgi__) || defined(sgi)
163 # define DEVICEDIR "/dev/"
164 # define LOCKDIR "/usr/spool/uucp"
165 # define LOCKFILEPREFIX "LK."
166 # define UUCP
167 #endif /* __sgi__ || sgi */
168 #if defined(__FreeBSD__)
169 # define DEVICEDIR "/dev/"
170 # define LOCKDIR "/var/spool/uucp"
171 # define LOCKFILEPREFIX "LK."
172 # define UUCP
173 #endif
174 #if defined(__APPLE__)
175 # define DEVICEDIR "/dev/"
176 # define LOCKDIR "/var/spool/uucp"
177 # define LOCKFILEPREFIX "LK."
178 # define UUCP
179 #endif /* __FreeBSD__ */
180 #if defined(__NetBSD__)
181 # define DEVICEDIR "/dev/"
182 # define LOCKDIR "/usr/spool/uucp"
183 # define LOCKFILEPREFIX "LK."
184 # define UUCP
185 #endif /* __NetBSD__ */
186 #if defined(__unixware__)
187 # define DEVICEDIR "/dev/"
188 /* really this only fully works for OpenServer */
189 # define LOCKDIR "/var/spool/uucp/"
190 # define LOCKFILEPREFIX "LK."
191 /*
192 this needs work....
193
194 Jonathan Schilling <[email protected]> writes:
195
196 This is complicated because as I said in my previous mail, there are
197 two kinds of SCO operating systems.
198
199 The one that most people want gnu.io for, including the guy who
200 asked the mailing list about SCO support a few days ago, is Open Server
201 (a/k/a "SCO UNIX"), which is SVR3-based. This uses old-style uucp locks,
202 of the form LCK..tty0a. That's what I implemented in the RXTX port I did,
203 and it works correctly.
204
205 The other SCO/Caldera OS, UnixWare/Open UNIX, uses the new-style
206 SVR4 locks, of the form LK.123.123.123. These OSes are a lot like
207 Solaris (UnixWare/Open UNIX come from AT&T SVR4 which had a joint
208
209 The other SCO/Caldera OS, UnixWare/Open UNIX, uses the new-style
210 SVR4 locks, of the form LK.123.123.123. These OSes are a lot like
211 Solaris (UnixWare/Open UNIX come from AT&T SVR4 which had a joint
212 heritage with Sun way back when). I saw that you added support
213 for this form of lock by RXTX 1.4-10 ... but it gets messy because,
214 as I said before, we use the same binary gnu.io files for both
215 UnixWare/Open UNIX and OpenServer. Thus we can't #ifdef one or the
216 other; it would have to be a runtime test. Your code and your macros
217 aren't set up for doing this (understandably!). So I didn't implement
218 these; the gnu.io locks won't fully work on UnixWare/Open UNIX
219 as a result, which I mentioned in the Release Notes.
220
221
222 What I would suggest is that you merge in the old-style LCK..tty0a lock
223 code that I used, since this will satisfy 90% of the SCO users. Then
224 I'll work on some way of getting UnixWare/Open UNIX locking to work
225 correctly, and give you those changes at a later date.
226
227 Jonathan
228
229 FIXME The lock type could be passed with -DOLDUUCP or -DUUCP based on
230 os.name in configure.in or perhaps system defines could determine the lock
231 type.
232
233 Trent
234 */
235 # define OLDUUCP
236 #endif
237 #if defined(__hpux__)
238 /* modif cath */
239 # define DEVICEDIR "/dev/"
240 # define LOCKDIR "/var/spool/uucp"
241 # define LOCKFILEPREFIX "LCK."
242 # define UUCP
243 #endif /* __hpux__ */
244 #if defined(__osf__) /* Digital Unix */
245 # define DEVICEDIR "/dev/"
246 # define LOCKDIR ""
247 # define LOCKFILEPREFIX "LK."
248 # define UUCP
249 #endif /* __osf__ */
250 #if defined(__sun__) /* Solaris */
251 # define DEVICEDIR "/dev/"
252 # define LOCKDIR "/var/spool/locks"
253 # define LOCKFILEPREFIX "LK."
254 /*
255 # define UUCP
256 */
257 #endif /* __sun__ */
258 #if defined(__BEOS__)
259 # define DEVICEDIR "/dev/ports/"
260 # define LOCKDIR ""
261 # define LOCKFILEPREFIX ""
262 # define UUCP
263 #endif /* __BEOS__ */
264 #if defined(WIN32)
265 # define DEVICEDIR "//./"
266 # define LOCKDIR ""
267 # define LOCKFILEPREFIX ""
268 # define OPEN serial_open
269 # define CLOSE serial_close
270 # define WRITE serial_write
271 # define READ serial_read
272 # define SELECT serial_select
273 #else /* use the system calls for Unix */
274 # define OPEN open
275 # define CLOSE close
276 # define WRITE write
277 # define READ read
278 # define SELECT select
279 struct timeval snow, enow, seloop, eeloop;
280 #define report_time_start_rs( ) \
281 { \
282 gettimeofday(&snow, NULL); \
283 }
284 #define report_time_end_rs( ) \
285 { \
286 gettimeofday(&enow, NULL); \
287 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); \
288 }
289 #ifdef DEBUG_TIMING
290 struct timeval snow, enow, seloop, eeloop;
291 #define report_time_eventLoop( ) { \
292 if ( seloop.tv_sec == eeloop.tv_sec && seloop.tv_usec == eeloop.tv_usec ) \
293 { \
294 gettimeofday(&eeloop, NULL); \
295 seloop.tv_sec = eeloop.tv_sec; \
296 seloop.tv_usec = eeloop.tv_usec; \
297 mexPrintf("%8i sec : %8i usec\n", eeloop.tv_sec - seloop.tv_sec, eeloop.tv_usec - seloop.tv_usec); \
298 } \
299 }
300 #define report_time( ) \
301 { \
302 struct timeval now; \
303 gettimeofday(&now, NULL); \
304 mexPrintf("%8s : %5i : %8i sec : %8i usec\n", __TIME__, __LINE__, now.tv_sec, now.tv_usec); \
305 }
306 #define report_time_start( ) \
307 { \
308 gettimeofday(&snow, NULL); \
309 mexPrintf("%8s : %5i : %8i sec : %8i usec", __TIME__, __LINE__, snow.tv_sec, snow.tv_usec); \
310 }
311 #define report_time_end( ) \
312 { \
313 gettimeofday(&enow, NULL); \
314 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); \
315 }
316 #else
317 #define report_time_eventLoop( ){};
318 #define report_time( ) {}
319 #define report_time_start( ) {}
320 #define report_time_end( ) {}
321
322 #endif /* DEBUG_TIMING */
323
324 /* #define TRACE */
325 #ifdef TRACE
326 #define ENTER(x) report("entering "x" \n");
327 #define LEAVE(x) report("leaving "x" \n");
328 #else
329 #define ENTER(x)
330 #define LEAVE(x)
331 #endif /* TRACE */
332
333 #endif /* WIN32 */
334
335 /* allow people to override the directories */
336 /* #define USER_LOCK_DIRECTORY "/home/tjarvi/1.5/build" */
337 #ifdef USER_LOCK_DIRECTORY
338 # define LOCKDIR USER_LOCK_DIRECTORY
339 #endif /* USER_LOCK_DIRECTORY */
340
341 #ifdef DISABLE_LOCKFILES
342 #undef UUCP
343 #undef FHS
344 #undef OLDUUCP
345 #endif /* DISABLE_LOCKFILES */
346
347 /* That should be all you need to look at in this file for porting */
348 #ifdef LFS /* Use a Lock File Server */
349 # define LOCK lfs_lock
350 # define UNLOCK lfs_unlock
351 #elif defined(UUCP)
352 # define LOCK uucp_lock
353 # define UNLOCK uucp_unlock
354 #elif defined(OLDUUCP)
355 /*
356 We can handle the old style if needed here see __unixware__ above.
357 defaulting to rxtx-1.4-8 behavior for now.
358
359 see also __sco__ in SerialImp.c when changing this for a possible
360 bug
361
362 FIXME
363 */
364 # define LOCK fhs_lock
365 # define UNLOCK fhs_unlock
366 #elif defined(FHS)
367 # define LOCK fhs_lock
368 # define UNLOCK fhs_unlock
369 #else
370 # define LOCK system_does_not_lock
371 # define UNLOCK system_does_not_unlock
372 #endif /* UUCP */
373
374 /* java exception class names */
375 //#define UNSUPPORTED_COMM_OPERATION "gnu/io/UnsupportedCommOperationException"
376 #define UNSUPPORTED_COMM_OPERATION "UnsupportedCommOperationException"
377 #define ARRAY_INDEX_OUT_OF_BOUNDS "java/lang/ArrayIndexOutOfBoundsException"
378 #define OUT_OF_MEMORY "java/lang/OutOfMemoryError"
379 #define IO_EXCEPTION "java/io/IOException"
380 #define PORT_IN_USE_EXCEPTION "gnu/io/PortInUseException"
381
382 /* some popular releases of Slackware do not have SSIZE_MAX */
383
384 #ifndef SSIZE_MAX
385 # if defined(INT_MAX)
386 # define SSIZE_MAX INT_MAX
387 # elif defined(MAXINT)
388 # define SSIZE_MAX MAXINT
389 # else
390 # define SSIZE_MAX 2147483647 /* ugh */
391 # endif
392 #endif
393
394 /*
395 Flow Control defines inspired by reading how mgetty by Gert Doering does it
396 */
397
398 #ifdef CRTSCTS
399 #define HARDWARE_FLOW_CONTROL CRTSCTS
400 #else
401 # ifdef CCTS_OFLOW
402 # define HARDWARE_FLOW_CONTROL CCTS_OFLOW|CRST_IFLOW
403 # else
404 # ifdef RTSFLOW
405 # define HARDWARE_FLOW_CONTROL RTSFLOW|CTSFLOW
406 # else
407 # ifdef CRTSFL
408 # define HARDWARE_FLOW_CONTROL CRTSFL
409 # else
410 # ifdef CTSCD
411 # define HARDWARE_FLOW_CONTROL CTSCD
412 # else
413 # define HARDWARE_FLOW_CONTROL 0
414 # endif
415 # endif
416 # endif
417 # endif
418 #endif
419
420 /* PROTOTYPES */
421 #ifdef DEBUG_MW
422 extern void mexWarnMsgTxt( const char * );
423 extern void mexErrMsgTxt( const char * );
424 #ifndef __APPLE__
425 extern int mexPrintf( const char *, ... );
426 # define printf mexPrintf
427 #endif
428 #endif /* DEBUG_MW */
429
430 #ifdef __APPLE__
431 # define mexPrintf printf
432 #endif
433
434 #ifdef __BEOS__
435 struct tpid_info_struct *add_tpid( struct tpid_info_struct * );
436 data_rate translate_speed( jint );
437 int translate_data_bits( data_bits *, jint );
438 int translate_stop_bits( stop_bits *, jint );
439 int translate_parity( parity_mode *, jint );
440 #else
441 int spawn_write_thread( int, char *, int );
442 int translate_speed( jint );
443 int translate_data_bits( tcflag_t *, jint );
444 int translate_stop_bits( tcflag_t *, jint );
445 int translate_parity( tcflag_t *, jint );
446 #endif
447 void system_wait();
448 void finalize_event_info_struct( struct event_info_struct * );
449 int read_byte_array( int, unsigned char *, int, int );
450 int get_java_var( char *, char * );
451 jboolean is_interrupted( struct event_info_struct * );
452 int send_event(gnu::io::RXTXPort *, struct event_info_struct *, jint, int );
453 void dump_termios(char *,struct termios *);
454 void report_verbose(char *);
455 void report_error(char *);
456 void report_warning(char *);
457 void report(char *);
458 void throw_java_exception( char *, char *, char * );
459 int lock_device( const char * );
460 void unlock_device( const char * );
461 int is_device_locked( const char * );
462 int check_lock_status( const char * );
463 int lfs_unlock(const char *, int );
464 int lfs_lock( const char *, int);
465 void fhs_unlock(const char *, int );
466 int fhs_lock( const char *, int);
467 void uucp_unlock( const char *, int );
468 int uucp_lock( const char *, int );
469 int system_does_not_lock( const char *, int );
470 void system_does_not_unlock( const char *, int );
471 int check_group_uucp();
472 int check_lock_pid( const char *, int );
473 int printj(wchar_t *fmt, ...);
474
475 #define UNEXPECTED_LOCK_FILE "RXTX Error: Unexpected lock file: %s\n Please report to the RXTX developers\n"
476 #define LINUX_KERNEL_VERSION_ERROR "\n\n\nRXTX WARNING: This library was compiled to run with OS release %s and you are currently running OS release %s. In some cases this can be a problem. Try recompiling RXTX if you notice strange behavior. If you just compiled RXTX make sure /usr/include/linux is a symbolic link to the include files that came with the kernel source and not an older copy.\n\n\npress enter to continue\n"
477 #define UUCP_ERROR "\n\n\nRXTX WARNING: This library requires the user running applications to be in\ngroup uucp. Please consult the INSTALL documentation. More information is\navaiable under the topic 'How can I use Lock Files with rxtx?'\n"