svn commit: r390725 - in head/comms/rxtx: . files

Philip M. Gollucci pgollucci at FreeBSD.org
Sat Jun 27 19:34:44 UTC 2015


Author: pgollucci
Date: Sat Jun 27 19:34:42 2015
New Revision: 390725
URL: https://svnweb.freebsd.org/changeset/ports/390725

Log:
  comms/rxtx: mutiple fixes
  Makefile
  1) Missing dependancy on plibthread.so.1
  
  Java code base
  2) Added commandline debug output in multiple Java files
  
  3) Tided comment statements, tabulation and white space to aid reading
  of sections of the original source code
  
  4) Added additional debug statements to aid diagnosis in multiple Java
  files
  
  5) Moved error logging from Zystem to be local in the RXTXPort.java
  file (was never firing from Zystem); now common with rest of codebase
  
  6) Ensured that RXTX only outputs debug level information when
  requested.
  
  7) Only enumerate the local ports on initialisation once (use of
  init_clean), rather than three times.
  
  8) Updated ports lists to reflect current usage pre FreeBSD v10 and post
  v10.
  
  9) Debug identifier inserted before all calls
  
  10) correctly read the properties file when there are multiple java
  library paths
  
  11) Enabled the skipping of parrellel ports during scans where they are
  not used by the invoking java parent base to RXTX (Still allows them to
  be manually specified in gn.io.parellel env arg)
  
  SerialImp.c
  12) Tidied code indentation (where needed, it is a medium length file
  and doesn't provide benifit on areas that work)
  
  13) Added standard out debug support to allow for assessment of
  interaction with Java code that can be compiled in (DEBUG_STDOUT)
  
  14) Added entry and exist debug statement for key functions
  
  15) where sprintf is being used, ensure that the existing ptr refers to
  an empty string (uses memset to sizeof)
  
  16) cleared up display tabulation of function headers in entire file (on
  second enumeration strings contained garbage)
  
  17) Remove LEAVE and ENTRY functions as not working as expected in
  header.
  
  18) Made sure all debug statements are null pointer terminated (note
  sprintf is not solely used for debug message formatting)
  
  19) Added condition so that a port that is in use during testread() is
  still reported as selectable. (If you attempt to open it after the port
  scan and it is still EBUSY the behaviour is unaltered and will throw a
  suitable error back)
  
  20) Disabled uucp for lpt ports, as uucp only applies to tty on
  FreeBSD (so says the Handbook...)
  
  21) RXTXPort:interruptEventLoop - resolved SIGABRT call to
  process (intended to kill off thread not entire JRE)...
  
  22) RXTXPort:interruptEventLoop now waits for timer in child thread to
  expire before attempting to closing the thread (delay between 0 and
  1000000 sleeps)
  
  23) All debug streams for FreeBSD now forward to same function for
  uniform formatting.
  
  This fixes two downstream issues in the arduino port, which results in
  missing dependancies, a core dump when uploading, or very slow port
  enumeration (up to 30s in some cases) when the arduino IDE is first
  started.
  
  PR:                  200179
  Submitted by:        james at elstone.net
  Approved by:         maintainer timeout (mirror176 at cox.net ; 45 days)

Added:
  head/comms/rxtx/files/patch-src-SerialImp.c   (contents, props changed)
  head/comms/rxtx/files/patch-src-gnu-io-CommPort.java   (contents, props changed)
  head/comms/rxtx/files/patch-src-gnu-io-CommPortEnumerator.java   (contents, props changed)
  head/comms/rxtx/files/patch-src-gnu-io-CommPortIdentifier.java   (contents, props changed)
  head/comms/rxtx/files/patch-src-gnu-io-Configure.java   (contents, props changed)
  head/comms/rxtx/files/patch-src-gnu-io-LPRPort.java   (contents, props changed)
  head/comms/rxtx/files/patch-src-gnu-io-NoSuchPortException.java   (contents, props changed)
  head/comms/rxtx/files/patch-src-gnu-io-RXTXPort.java   (contents, props changed)
  head/comms/rxtx/files/patch-src-gnu-io-SerialPortEvent.java   (contents, props changed)
Modified:
  head/comms/rxtx/Makefile
  head/comms/rxtx/files/patch-src-ParallelImp.c   (contents, props changed)
  head/comms/rxtx/files/patch-src-gnu-io-RXTXCommDriver.java   (contents, props changed)

Modified: head/comms/rxtx/Makefile
==============================================================================
--- head/comms/rxtx/Makefile	Sat Jun 27 19:32:38 2015	(r390724)
+++ head/comms/rxtx/Makefile	Sat Jun 27 19:34:42 2015	(r390725)
@@ -14,6 +14,8 @@ MAINTAINER=	mirror176 at cox.net
 COMMENT=	Native interface to serial ports in Java
 
 USES=		gmake libtool zip
+USE_LINUX=	c6
+
 USE_JAVA=	yes
 JAVA_VERSION=	1.6+
 JAVA_OS=	native

Modified: head/comms/rxtx/files/patch-src-ParallelImp.c
==============================================================================
--- head/comms/rxtx/files/patch-src-ParallelImp.c	Sat Jun 27 19:32:38 2015	(r390724)
+++ head/comms/rxtx/files/patch-src-ParallelImp.c	Sat Jun 27 19:34:42 2015	(r390725)
@@ -1,8 +1,6 @@
-$FreeBSD: /tmp/pcvs/ports/comms/rxtx/files/patch-src-ParallelImp.c,v 1.1 2011-09-17 14:55:56 pawel Exp $
-
---- src/ParallelImp.c.orig	Fri Apr  9 23:31:09 2004
-+++ src/ParallelImp.c	Fri Apr  9 23:35:01 2004
-@@ -222,9 +222,6 @@
+--- src/ParallelImp.c.orig	2008-11-27 20:01:48.000000000 +0000
++++ src/ParallelImp.c	2015-05-11 16:52:36.000000000 +0100
+@@ -265,9 +265,6 @@
  #if defined(__linux__)
  	return( status & LP_BUSY ? JNI_TRUE : JNI_FALSE );
  #endif

Added: head/comms/rxtx/files/patch-src-SerialImp.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/comms/rxtx/files/patch-src-SerialImp.c	Sat Jun 27 19:34:42 2015	(r390725)
@@ -0,0 +1,6145 @@
+--- src/SerialImp.c.orig	2009-02-04 22:06:16.000000000 +0000
++++ src/SerialImp.c	2015-05-11 16:52:36.000000000 +0100
+@@ -1,60 +1,79 @@
+ /*-------------------------------------------------------------------------
+-|   RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface.
+-|   RXTX is a native interface to serial ports in java.
+-|   Copyright 1997-2009 by Trent Jarvi tjarvi at qbang.org and others who
+-|   actually wrote it.  See individual source files for more information.
++|	RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface.
++|	RXTX is a native interface to serial ports in java.
++|	Copyright 1997-2009 by Trent Jarvi tjarvi at qbang.org and others who
++|	actually wrote it.  See individual source files for more information.
+ |
+-|   A copy of the LGPL v 2.1 may be found at
+-|   http://www.gnu.org/licenses/lgpl.txt on March 4th 2007.  A copy is
+-|   here for your convenience.
++|	A copy of the LGPL v 2.1 may be found at
++|	http://www.gnu.org/licenses/lgpl.txt on March 4th 2007.  A copy is
++|	here for your convenience.
+ |
+-|   This library is free software; you can redistribute it and/or
+-|   modify it under the terms of the GNU Lesser General Public
+-|   License as published by the Free Software Foundation; either
+-|   version 2.1 of the License, or (at your option) any later version.
++|	This library is free software; you can redistribute it and/or
++|	modify it under the terms of the GNU Lesser General Public
++|	License as published by the Free Software Foundation; either
++|	version 2.1 of the License, or (at your option) any later version.
+ |
+-|   This library is distributed in the hope that it will be useful,
+-|   but WITHOUT ANY WARRANTY; without even the implied warranty of
+-|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+-|   Lesser General Public License for more details.
++|	This library is distributed in the hope that it will be useful,
++|	but WITHOUT ANY WARRANTY; without even the implied warranty of
++|	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++|	Lesser General Public License for more details.
+ |
+-|   An executable that contains no derivative of any portion of RXTX, but
+-|   is designed to work with RXTX by being dynamically linked with it,
+-|   is considered a "work that uses the Library" subject to the terms and
+-|   conditions of the GNU Lesser General Public License.
++|	An executable that contains no derivative of any portion of RXTX, but
++|	is designed to work with RXTX by being dynamically linked with it,
++|	is considered a "work that uses the Library" subject to the terms and
++|	conditions of the GNU Lesser General Public License.
+ |
+-|   The following has been added to the RXTX License to remove
+-|   any confusion about linking to RXTX.   We want to allow in part what
+-|   section 5, paragraph 2 of the LGPL does not permit in the special
+-|   case of linking over a controlled interface.  The intent is to add a
+-|   Java Specification Request or standards body defined interface in the
+-|   future as another exception but one is not currently available.
++|	The following has been added to the RXTX License to remove
++|	any confusion about linking to RXTX.	We want to allow in part what
++|	section 5, paragraph 2 of the LGPL does not permit in the special
++|	case of linking over a controlled interface.  The intent is to add a
++|	Java Specification Request or standards body defined interface in the
++|	future as another exception but one is not currently available.
+ |
+-|   http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
++|	http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
+ |
+-|   As a special exception, the copyright holders of RXTX give you
+-|   permission to link RXTX with independent modules that communicate with
+-|   RXTX solely through the Sun Microsytems CommAPI interface version 2,
+-|   regardless of the license terms of these independent modules, and to copy
+-|   and distribute the resulting combined work under terms of your choice,
+-|   provided that every copy of the combined work is accompanied by a complete
+-|   copy of the source code of RXTX (the version of RXTX used to produce the
+-|   combined work), being distributed under the terms of the GNU Lesser General
+-|   Public License plus this exception.  An independent module is a
+-|   module which is not derived from or based on RXTX.
++|	As a special exception, the copyright holders of RXTX give you
++|	permission to link RXTX with independent modules that communicate with
++|	RXTX solely through the Sun Microsytems CommAPI interface version 2,
++|	regardless of the license terms of these independent modules, and to copy
++|	and distribute the resulting combined work under terms of your choice,
++|	provided that every copy of the combined work is accompanied by a complete
++|	copy of the source code of RXTX (the version of RXTX used to produce the
++|	combined work), being distributed under the terms of the GNU Lesser General
++|	Public License plus this exception.  An independent module is a
++|	module which is not derived from or based on RXTX.
+ |
+-|   Note that people who make modified versions of RXTX are not obligated
+-|   to grant this special exception for their modified versions; it is
+-|   their choice whether to do so.  The GNU Lesser General Public License
+-|   gives permission to release a modified version without this exception; this
+-|   exception also makes it possible to release a modified version which
+-|   carries forward this exception.
++|	Note that people who make modified versions of RXTX are not obligated
++|	to grant this special exception for their modified versions; it is
++|	their choice whether to do so.  The GNU Lesser General Public License
++|	gives permission to release a modified version without this exception; this
++|	exception also makes it possible to release a modified version which
++|	carries forward this exception.
+ |
+-|   You should have received a copy of the GNU Lesser General Public
+-|   License along with this library; if not, write to the Free
+-|   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+-|   All trademarks belong to their respective owners.
++|	You should have received a copy of the GNU Lesser General Public
++|	License along with this library; if not, write to the Free
++|	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++|	All trademarks belong to their respective owners.
+ --------------------------------------------------------------------------*/
++/**
++ *	9th May 2015 - james.c.elstone (at) ntlworld.com:
++ *		
++ *		Added STDOUT debug stream, so can see when used with OpenJDK in
++ *		console terminal.  Useful for seeing events interleaved, with OS
++ *		activity.  Just put '#define DEBUG_STDOUT' just below...
++ *		
++ *		Altered behaviour of SIGABRT in RXTXPort(interruptEventLoop)
++ *		to prevent Core Dump from being performed on POSIX compliant OS.
++ * 
++ * 		Sorted out null termination on all debug strings!
++ * 		
++ *		Clearing of char array for sprintfs, driver enumerated multilpe
++ *		times, leaving the content behind in places.
++ *		
++ **/
++
++//#define DEBUG_STDOUT
++
+ #if defined(__MWERKS__) /* dima */
+ #include "RXTXPort.h" /* dima */
+ #else  /* dima */
+@@ -64,7 +83,7 @@
+ #include "gnu_io_RXTXPort.h"
+ #endif /* dima */
+ #ifdef __LCC__ /* windows lcc compiler for fd_set. probably wrong */
+-#   include<winsock.h>
++#	include<winsock.h>
+ #endif /* __LCC__ */
+ #include <time.h>
+ #include <stdio.h>
+@@ -91,23 +110,23 @@
+ #ifdef HAVE_TERMIOS_H
+ #	include <termios.h>
+ #endif /* HAVE_TERMIOS_H */
+-#   include <signal.h>
++#	include <signal.h>
+ #ifdef HAVE_SIGNAL_H
+-#   include <signal.h>
++#	include <signal.h>
+ #endif /* HAVE_SIGNAL_H */
+ #ifdef HAVE_SYS_SIGNAL_H
+-#   include <sys/signal.h>
++#	include <sys/signal.h>
+ #endif /* HAVE_SYS_SIGNAL_H */
+ #include <sys/types.h>
+ #ifdef HAVE_SYS_TIME_H
+-#   include <sys/time.h>
++#	include <sys/time.h>
+ #endif /* HAVE_SYS_TIME_H */
+-#   include <fcntl.h>
++#	include <fcntl.h>
+ #ifdef HAVE_SYS_FCNTL_H
+-#   include <sys/fcntl.h>
++#	include <sys/fcntl.h>
+ #endif /* HAVE_SYS_FCNTL_H */
+ #ifdef HAVE_SYS_FILE_H
+-#   include <sys/file.h>
++#	include <sys/file.h>
+ #endif /* HAVE_SYS_FILE_H */
+ #ifdef LFS  /* File Lock Server */
+ #	include <sys/socket.h>
+@@ -167,59 +186,59 @@
+ /*----------------------------------------------------------
+ cfmakeraw
+ 
+-   accept:      termios to be set to raw
+-   perform:     initializes the termios structure.
+-   return:      int 0 on success
+-   exceptions:  none
+-   comments:    this is how linux cfmakeraw works.
+-		termios(3) manpage
++	accept:		termios to be set to raw
++	perform:	initializes the termios structure.
++	return:		int 0 on success
++	exceptions: none
++	comments:	this is how linux cfmakeraw works.
++				termios(3) manpage
+ ----------------------------------------------------------*/
+ 
+ int cfmakeraw ( struct termios *term )
+ {
+-	ENTER( "cfmakeraw" );
++	report( "Entering - cfmakeraw\n" );
+ 	term->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
+ 	term->c_oflag &= ~OPOST;
+ 	term->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+ 	term->c_cflag &= ~(CSIZE|PARENB);
+ 	term->c_cflag |= CS8;
+-	LEAVE( "cfmakeraw" );
++	report( "Leaving - cfmakeraw\n" );
+ 	return( 0 );
+ }
+ #endif /* __sun__  || __hpux__ */
+ 
+ #ifdef DEBUG_TIMING
+-struct timeval snow, enow, seloop, eeloop;
+-#define report_time_eventLoop( ) { \
+-	if ( seloop.tv_sec == eeloop.tv_sec && seloop.tv_usec == eeloop.tv_usec ) \
++	struct timeval snow, enow, seloop, eeloop;
++	#define report_time_eventLoop( ) { \
++		if ( seloop.tv_sec == eeloop.tv_sec && seloop.tv_usec == eeloop.tv_usec ) \
++		{ \
++			gettimeofday(&eeloop, NULL); \
++			seloop.tv_sec = eeloop.tv_sec; \
++			seloop.tv_usec = eeloop.tv_usec; \
++			printf("%8i sec : %8i usec\n", eeloop.tv_sec - seloop.tv_sec, eeloop.tv_usec - seloop.tv_usec); \
++		} \
++	}
++	#define report_time( ) \
+ 	{ \
+-		gettimeofday(&eeloop, NULL); \
+-		seloop.tv_sec = eeloop.tv_sec; \
+-		seloop.tv_usec = eeloop.tv_usec; \
+-		printf("%8i sec : %8i usec\n", eeloop.tv_sec - seloop.tv_sec, eeloop.tv_usec - seloop.tv_usec); \
+-	} \
+-}
+-#define report_time( ) \
+-{ \
+-	struct timeval now; \
+-	gettimeofday(&now, NULL); \
+-	mexPrintf("%8s : %5i : %8i sec : %8i usec\n", __TIME__, __LINE__, now.tv_sec, now.tv_usec); \
+-}
+-#define report_time_start( ) \
+-{ \
+-	gettimeofday(&snow, NULL); \
+-	mexPrintf("%8s : %5i : %8i sec : %8i usec", __TIME__, __LINE__, snow.tv_sec, snow.tv_usec); \
+-}
+-#define report_time_end( ) \
+-{ \
+-	gettimeofday(&enow, NULL); \
+-	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); \
+-}
++		struct timeval now; \
++		gettimeofday(&now, NULL); \
++		mexPrintf("%8s : %5i : %8i sec : %8i usec\n", __TIME__, __LINE__, now.tv_sec, now.tv_usec); \
++	}
++	#define report_time_start( ) \
++	{ \
++		gettimeofday(&snow, NULL); \
++		mexPrintf("%8s : %5i : %8i sec : %8i usec", __TIME__, __LINE__, snow.tv_sec, snow.tv_usec); \
++	}
++	#define report_time_end( ) \
++	{ \
++		gettimeofday(&enow, NULL); \
++		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); \
++	}
+ #else
+-#define report_time_eventLoop( ){};
+-#define report_time( ) {}
+-#define report_time_start( ) {}
+-#define report_time_end( ) {}
++	#define report_time_eventLoop( ){};
++	#define report_time( ) {}
++	#define report_time_start( ) {}
++	#define report_time_end( ) {}
+ #endif /* DEBUG_TIMING */
+ 
+ 
+@@ -229,16 +248,16 @@
+ /*----------------------------------------------------------
+ RXTXPort.Initialize
+ 
+-   accept:      The JNIEnv and jobj of the thread, the original eis.
+-   perform:     fill in the needed variables with this threads values
+-   return:      none
+-   exceptions:  none
+-   comments:    java variables (especially JNIEnv) should not be shared
+-		between threads.  Right now we build a local struct with
+-		the thread's info before using the variabls.  This is
+-		especially true for send_event.
+-
+-		See also JNI_OnLoad() if the thread does not have the values
++	accept:		The JNIEnv and jobj of the thread, the original eis.
++	perform:	fill in the needed variables with this threads values
++	return:		none
++	exceptions: none
++	comments:	java variables (especially JNIEnv) should not be shared
++				between threads.  Right now we build a local struct with
++				the thread's info before using the variabls.  This is
++				especially true for send_event.
++				
++	See also JNI_OnLoad() if the thread does not have the values
+ ----------------------------------------------------------*/
+ struct event_info_struct build_threadsafe_eis(
+ 	JNIEnv *env,
+@@ -264,13 +283,13 @@
+ /*----------------------------------------------------------
+ RXTXPort.Initialize
+ 
+-   accept:      none
+-   perform:     Initialize the native library
+-   return:      none
+-   exceptions:  none
+-   comments:    Basically this just causes rxtx to ignore signals.  signal
+-		handlers where tried but the VM (circa 1.1) did not like it.
+-
++	accept:		none
++	perform:	Initialize the native library
++	return:		none
++	exceptions:	none
++	comments:	Basically this just causes rxtx to ignore signals.  signal
++				handlers where tried but the VM (circa 1.1) did not like it.
++				
+ 		It also allows for some sanity checks on linux boxes if DEBUG
+ 		is enabled.
+ ----------------------------------------------------------*/
+@@ -284,9 +303,9 @@
+ 	char message[80];
+ #endif /* DEBUG && __linux__ */
+ 	/* This bit of code checks to see if there is a signal handler installed
+-	   for SIGIO, and installs SIG_IGN if there is not.  This is necessary
+-	   for the native threads jdk, but we don't want to do it with green
+-	   threads, because it slows things down.  Go figure. */
++		for SIGIO, and installs SIG_IGN if there is not.  This is necessary
++		for the native threads jdk, but we don't want to do it with green
++		threads, because it slows things down.  Go figure. */
+ 
+ 	/* POSIX signal handling functions */
+ #if !defined(WIN32)
+@@ -306,7 +325,7 @@
+ 		sigaction(SIGIO, &new_action, NULL);
+ 	}
+ #endif /* !WIN32 */
+-	ENTER( "RXTXPort:Initialize" );
++	report( "Entering - RXTXPort:Initialize\n" );
+ #ifdef PRERELEASE
+ 	/*  this is just for avoiding confusion while testing new libraries */
+ #ifdef DEBUG_MW
+@@ -322,32 +341,33 @@
+ 	/* Lets let people who upgraded kernels know they may have problems */
+ 	if (uname (&name) == -1)
+ 	{
+-		report( "RXTX WARNING:  cannot get system name\n" );
+-		LEAVE( "RXTXPort:Initialize" );
++		report( "RXTX WARNING:	cannot get system name\n" );
++		report( "Leaving - RXTXPort:Initialize\n" );
+ 		return;
+ 	}
+ 	if(strcmp(name.release,UTS_RELEASE)!=0)
+ 	{
+-		sprintf( message, LINUX_KERNEL_VERSION_ERROR, UTS_RELEASE,
++		memset(&message[0], 0, sizeof(message));
++		sprintf( message, "%s%s%s\n", LINUX_KERNEL_VERSION_ERROR, UTS_RELEASE,
+ 			name.release );
+ 		report( message );
+ 		getchar();
+ 	}
+-	LEAVE( "RXTXPort:Initialize" );
++	report( "Leaving - RXTXPort:Initialize\n" );
+ #endif /* DEBUG && __linux__ */
+ }
+ 
+ /*----------------------------------------------------------
+ RXTXPort.find_preopened_ports
+-   accept:      The device to find if preopened.  ie "/dev/ttyS0"
+-   perform:     find the filedescriptor if preopened
+-   return:      fd
+-   exceptions:  none
+-   comments:    see
+-			RXTXPort.nativeStaticSetDSR
+-			RXTXPort.nativeStaticSetDTR
+-			RXTXPort.nativeStaticSetRTS
+-			RXTXPort.nativeStaticSetSerialPortParams
++	accept:		The device to find if preopened.  ie "/dev/ttyS0"
++	perform:	find the filedescriptor if preopened
++	return:		fd
++	exceptions:	none
++	comments:	see
++				RXTXPort.nativeStaticSetDSR
++				RXTXPort.nativeStaticSetDTR
++				RXTXPort.nativeStaticSetRTS
++				RXTXPort.nativeStaticSetSerialPortParams
+ 		This is used so people can setDTR low before calling the
+ 		Java open().
+ ----------------------------------------------------------*/
+@@ -401,13 +421,13 @@
+ /*----------------------------------------------------------
+ configure_port
+ 
+-   accept:      env, file descriptor
+-   perform:     set the termios struct to sane settings and
+-   return:      0 on success
+-   exceptions:  IOExcepiton
+-   comments:    Very often people complain about not being able to get past
+-                this function and it turns out to be permissions on the
+-                device file or bios has the device disabled.
++	accept:		Env, file descriptor
++	perform:	set the termios struct to sane settings and
++	return:		0 on success
++	exceptions:	IOExcepiton
++	comments:	Very often people complain about not being able to get past
++				this function and it turns out to be permissions on the
++				device file or bios has the device disabled.
+ ----------------------------------------------------------*/
+ int configure_port( int fd )
+ {
+@@ -446,31 +466,31 @@
+ /*----------------------------------------------------------
+ get_java_baudrate
+ 
+-   accept:      the native speed setting
+-   perform:     translate the native speed to a Java speed
+-   return:      the Java speed
+-   exceptions:  none
+-   comments:    This is used by open() (indirectly) and
+-		nativeStaticGetBaudRate()
++	accept:		the native speed setting
++	perform:	translate the native speed to a Java speed
++	return:		the Java speed
++	exceptions:	none
++	comments:	This is used by open() (indirectly) and
++				nativeStaticGetBaudRate()
+ ----------------------------------------------------------*/
+ int get_java_baudrate( int native_speed )
+ {
+ 	switch( native_speed )
+ 	{
+-		case B0:     return 0;
+-		case B50:    return 50;
+-		case B75:    return 75;
+-		case B110:   return 110;
+-		case B134:   return 134;
+-		case B150:   return 150;
+-		case B200:   return 200;
+-		case B300:   return 300;
+-		case B600:   return 600;
+-		case B1200:  return 1200;
+-		case B1800:  return 1800;
+-		case B2400:  return 2400;
+-		case B4800:  return 4800;
+-		case B9600:  return 9600;
++		case B0:	return 0;
++		case B50:	return 50;
++		case B75:	return 75;
++		case B110:	return 110;
++		case B134:	return 134;
++		case B150:	return 150;
++		case B200:	return 200;
++		case B300:	return 300;
++		case B600:	return 600;
++		case B1200:	return 1200;
++		case B1800:	return 1800;
++		case B2400:	return 2400;
++		case B4800:	return 4800;
++		case B9600:	return 9600;
+ #ifdef B14400
+ 		case B14400: return 14400;
+ #endif /* B14400 */
+@@ -536,13 +556,13 @@
+ /*----------------------------------------------------------
+ set_java_vars
+ 
+-   accept:      fd of the preopened device
+-   perform:     Now that the object is instatiated, set the Java variables
+-		to the preopened states.
+-   return:      none
+-   exceptions:  none
+-   comments:    preopened refers to the fact that the serial port has
+-		been configured before the Java open() has been called.
++	accept:		fd of the preopened device
++	perform:	Now that the object is instatiated, set the Java variables
++				to the preopened states.
++	return:		none
++	exceptions:	none
++	comments:	preopened refers to the fact that the serial port has
++				been configured before the Java open() has been called.
+ ----------------------------------------------------------*/
+ 
+ void set_java_vars( JNIEnv *env, jobject jobj, int fd )
+@@ -570,10 +590,10 @@
+ 
+ 
+ 	switch( ttyset.c_cflag&CSIZE ) {
+-		case CS5:  databits = JDATABITS_5; break;
+-		case CS6:  databits = JDATABITS_6; break;
+-		case CS7:  databits = JDATABITS_7; break;
+-		case CS8:  databits = JDATABITS_8; break;
++		case CS5:	databits = JDATABITS_5; break;
++		case CS6:	databits = JDATABITS_6; break;
++		case CS7:	databits = JDATABITS_7; break;
++		case CS8:	databits = JDATABITS_8; break;
+ 	}
+ #ifdef CMSPAR
+ 	switch( ttyset.c_cflag&(PARENB|PARODD|CMSPAR ) ) {
+@@ -588,9 +608,9 @@
+ 		case PARENB | CMSPAR: jparity = JPARITY_SPACE; break;
+ #endif /* CMSPAR */
+ 	}
+-        switch( ttyset.c_cflag&(CSTOPB) ) {
+-                case 0: stop_bits = STOPBITS_1; break;
+-                case CSTOPB:
++	 switch( ttyset.c_cflag&(CSTOPB) ) {
++			case 0: stop_bits = STOPBITS_1; break;
++			case CSTOPB:
+ 			if ( (ttyset.c_cflag & CSIZE) ==  CS5 ) {
+ 				stop_bits = STOPBITS_1_5;
+ 			}
+@@ -598,7 +618,7 @@
+ 				stop_bits = STOPBITS_2;
+ 			}
+ 			break;
+-        }
++	 }
+ /*
+ dima writes:
+ 
+@@ -616,9 +636,9 @@
+ 
+ */
+ #if defined(CBAUD)/* dima */
+-    	baudrate = ttyset.c_cflag&CBAUD;
++		baudrate = ttyset.c_cflag&CBAUD;
+ #else
+-    	baudrate = cfgetispeed(&ttyset);
++		baudrate = cfgetispeed(&ttyset);
+ #endif
+ 	(*env)->SetIntField(env, jobj, jfspeed,
+ 		( jint ) get_java_baudrate(baudrate) );
+@@ -629,14 +649,14 @@
+ /*----------------------------------------------------------
+ RXTXPort.open
+ 
+-   accept:      The device to open.  ie "/dev/ttyS0"
+-   perform:     open the device, set the termios struct to sane settings and
+-                return the filedescriptor
+-   return:      fd
+-   exceptions:  IOExcepiton
+-   comments:    Very often people complain about not being able to get past
+-                this function and it turns out to be permissions on the
+-                device file or bios has the device disabled.
++	accept:		The device to open.  ie "/dev/ttyS0"
++	perform:	open the device, set the termios struct to sane settings and
++				return the filedescriptor
++	return:		fd
++	exceptions:	IOExcepiton
++	comments:	Very often people complain about not being able to get past
++				this function and it turns out to be permissions on the
++				device file or bios has the device disabled.
+ ----------------------------------------------------------*/
+ JNIEXPORT jint JNICALL RXTXPort(open)(
+ 	JNIEnv *env,
+@@ -676,9 +696,10 @@
+ 			system_does_not_lock	Win32
+ 	*/
+ 
+-	ENTER( "RXTXPort:open" );
++	report( "Entering - RXTXPort:open\n" );
+ 	if ( LOCK( filename, pid ) )
+ 	{
++		memset(&message[0], 0, sizeof(message));
+ 		sprintf( message, "open: locking has failed for %s\n",
+ 			filename );
+ 		report( message );
+@@ -686,6 +707,7 @@
+ 	}
+ 	else
+ 	{
++		memset(&message[0], 0, sizeof(message));
+ 		sprintf( message, "open: locking worked for %s\n", filename );
+ 		report( message );
+ 	}
+@@ -703,36 +725,36 @@
+ 	}  while (fd < 0 && errno==EINTR);
+ 
+ #ifdef OPEN_EXCL
+-       /*
+-       Note that open() follows POSIX semantics: multiple open() calls to
+-       the same file will succeed unless the TIOCEXCL ioctl is issued.
+-       This will prevent additional opens except by root-owned processes.
+-       See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details.
+-       */
+-
+-       if (fd >= 0 && (ioctl(fd, TIOCEXCL) == -1))
+-       {
+-               sprintf( message, "open: exclusive access denied for %s\n",
+-                       filename );
+-               report( message );
+-               report_error( message );
+-
+-               close(fd);
+-               goto fail;
+-       }
++	/*
++	Note that open() follows POSIX semantics: multiple open() calls to
++	the same file will succeed unless the TIOCEXCL ioctl is issued.
++	This will prevent additional opens except by root-owned processes.
++	See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details.
++	*/
++
++	if (fd >= 0 && (ioctl(fd, TIOCEXCL) == -1))
++	{
++			memset(&message[0], 0, sizeof(message));
++			sprintf( message, "open: exclusive access denied for %s\n", filename );
++			report( message );
++			report_error( message );
++			close(fd);
++			goto fail;
++	}
+ #endif /* OPEN_EXCL */
+ 
+ 	if( configure_port( fd ) ) goto fail;
+ 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
++	memset(&message[0], 0, sizeof(message));
+ 	sprintf( message, "open: fd returned is %i\n", fd );
+ 	report( message );
+-	LEAVE( "RXTXPort:open" );
++	report( "Leaving - RXTXPort:open\n" );
+ 	report_time_end( );
+ 	return (jint)fd;
+ 
+ fail:
+ 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
+-	LEAVE( "RXTXPort:open" );
++	report( "Leaving - RXTXPort:open\n" );
+ 	throw_java_exception( env, PORT_IN_USE_EXCEPTION, "open",
+ 		strerror( errno ) );
+ 	return -1;
+@@ -741,10 +763,10 @@
+ /*----------------------------------------------------------
+ RXTXPort.nativeClose
+ 
+-   accept:      none
+-   perform:     get the fd from the java end and close it
+-   return:      none
+-   exceptions:  none
++	accept:		none
++	perform:	get the fd from the java end and close it
++	return:		none
++	exceptions:	none
+ ----------------------------------------------------------*/
+ JNIEXPORT void JNICALL RXTXPort(nativeClose)( JNIEnv *env,
+ 	jobject jobj,jstring jstr )
+@@ -764,7 +786,7 @@
+ 		(*env)->ExceptionDescribe( env );
+ 		(*env)->ExceptionClear( env );
+ 		(*env)->DeleteLocalRef( env, jclazz );
+-		report("nativeClose: Close not detecting thread pid");
++		report("nativeClose: Close not detecting thread pid\n");
+ 		return;
+ 	}
+ 	report("<nativeClose: pid\n");
+@@ -777,14 +799,14 @@
+ 			system_does_not_unlock	Win32
+ 	*/
+ 
+-	ENTER( "RXTXPort:nativeClose" );
++	report( "Entering - RXTXPort:nativeClose\n" );
+ 	if (fd > 0)
+ 	{
+ 		report("nativeClose: discarding remaining data (tcflush)\n");
+ 		/* discard any incoming+outgoing data not yet read/sent */
+ 		tcflush(fd, TCIOFLUSH);
+  		do {
+-			report("nativeClose:  calling close\n");
++			report("nativeClose:	calling close\n");
+ 			result=CLOSE (fd);
+ 		}  while ( result < 0 && errno == EINTR );
+ 		UNLOCK( filename, pid );
+@@ -793,7 +815,7 @@
+ 	(*env)->DeleteLocalRef( env, jclazz );
+ 	report("nativeClose: release filename\n");
+ 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
+-	LEAVE( "RXTXPort:nativeClose" );
++	report( "Leaving - RXTXPort:nativeClose\n" );
+ 	report_time_end( );
+ 	return;
+ }
+@@ -801,15 +823,15 @@
+ /*----------------------------------------------------------
+  RXTXPort.set_port_params
+ 
+-   accept:     env, fd, speed, data bits, stop bits, parity
+-   perform:    set the serial port parameters
+-   return:     1 on error
+-   exceptions: UnsupportedCommOperationException
+-   comments:   There is a static method and an instance method that use this
+-		function.  The static method gets a fd first.  The instance
+-		method can get the fd from the object.
++	accept:		env, fd, speed, data bits, stop bits, parity
++	perform:	set the serial port parameters
++	return:		1 on error
++	exceptions: UnsupportedCommOperationException
++	comments:	There is a static method and an instance method that use this
++				function.  The static method gets a fd first.  The instance
++				method can get the fd from the object.
+ 
+-		see:  nativeSetSerialPortParams & nativeStaticSerialPortParams
++	see:		nativeSetSerialPortParams & nativeStaticSerialPortParams
+ ----------------------------------------------------------*/
+ int set_port_params( JNIEnv *env, int fd, int cspeed, int dataBits,
+ 			int stopBits, int parity )
+@@ -864,36 +886,36 @@
+ 		ioctl( fd, TIOCMSET, &result );
+ 	}
+ 	/*
+-	   B38400 is a special case in Linux for custom baud rates.
++		B38400 is a special case in Linux for custom baud rates.
+ 
+-	   We just treat this as a custom speed for now.  If you take this ifdef
+-	   out and select baud rates 38400 then 28800 then 38400, you will get
+-	   a final baud rate of 28800 because you did not update the divisor.
++		We just treat this as a custom speed for now.  If you take this ifdef
++		out and select baud rates 38400 then 28800 then 38400, you will get
++		a final baud rate of 28800 because you did not update the divisor.
+ 
+-	   See the next ifdef below for the divisor.
++		See the next ifdef below for the divisor.
+ 	*/
+ #if defined(TIOCGSERIAL)
+ 	if ( cspeed == B38400 )
+ 		cspeed = 38400;
+ #endif /* TIOCGSERIAL */
+-	if(     cfsetispeed( &ttyset, cspeed ) < 0 ||
++	if(	cfsetispeed( &ttyset, cspeed ) < 0 ||
+ 		cfsetospeed( &ttyset, cspeed ) < 0 )
+ 	{
+ 		/*
+-		    Some people need to set the baud rate to ones not defined
+-		    in termios.h
++			Some people need to set the baud rate to ones not defined
++			in termios.h
+ 
+-		    This includes some baud rates which are supported by CommAPI
+-		    in Unix ( 14400, 28800, 128000, 256000 )
++			This includes some baud rates which are supported by CommAPI
++			in Unix ( 14400, 28800, 128000, 256000 )
+ 
+-		    If the above fails, we assume this is not a defined
+-		    baud rate on Unix.  With Win32, It is assumed the kernel
+-		    will do this for us.
++			If the above fails, we assume this is not a defined
++			baud rate on Unix.  With Win32, It is assumed the kernel
++			will do this for us.
+ 
+-		    The baud_base and desired speed are used to
+-		    calculate a custom divisor.
++			The baud_base and desired speed are used to
++			calculate a custom divisor.
+ 
+-		    On linux the setserial man page covers this.
++			On linux the setserial man page covers this.
+ 		*/
+ 
+ #if defined(TIOCGSERIAL)
+@@ -905,7 +927,7 @@
+ 		sstruct.custom_divisor = ( sstruct.baud_base/cspeed );
+ 		cspeed = B38400;
+ #endif /* TIOCGSERIAL */
+-		if(     cfsetispeed( &ttyset, cspeed ) < 0 ||
++		if(	cfsetispeed( &ttyset, cspeed ) < 0 ||
+ 			cfsetospeed( &ttyset, cspeed ) < 0 )
+ 		{
+ 			/* OK, we tried everything */
+@@ -933,10 +955,10 @@
+ /*----------------------------------------------------------
+  RXTXPort.nativeSetSerialPortParams
+ 
+-   accept:     speed, data bits, stop bits, parity
+-   perform:    set the serial port parameters
+-   return:     jboolean 1 on error
+-   exceptions: UnsupportedCommOperationException
++	accept:		speed, data bits, stop bits, parity
++	perform:	set the serial port parameters
++	return:		jboolean 1 on error
++	exceptions: UnsupportedCommOperationException
+ ----------------------------------------------------------*/
+ JNIEXPORT jboolean JNICALL RXTXPort(nativeSetSerialPortParams)(
+ 	JNIEnv *env, jobject jobj, jint speed, jint dataBits, jint stopBits,
+@@ -945,15 +967,15 @@
+ 	int fd = get_java_var( env, jobj,"fd","I" );
+ 	int cspeed = translate_speed( env, speed );
+ 
+-	ENTER( "RXTXPort:nativeSetSerialPortParams" );
++	report( "Entering - RXTXPort:nativeSetSerialPortParams\n" );
+ 	report_time_start( );
+ 
+ 	if (cspeed < 0 )
+ 	{
+ 		report(" invalid cspeed\n");
+ /*
+-    For some reason the native exceptions are not being caught.  Moving this
+-    to the Java side fixed the issue.  taj.
++	For some reason the native exceptions are not being caught.  Moving this
++	to the Java side fixed the issue.  taj.
+ 		throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
+ 			"", "BaudRate could not be set to the specified value" );
+ */
+@@ -964,17 +986,17 @@
+ 	if( set_port_params( env, fd, cspeed, dataBits, stopBits, parity ) )
+ 	{
+ 		report("set_port_params failed\n");
+-		LEAVE( "RXTXPort:nativeSetSerialPortParams" );
++		report( "Leaving - RXTXPort:nativeSetSerialPortParams\n" );
+ /*
+-    For some reason the native exceptions are not being caught.  Moving this
+-    to the Java side fixed the issue.  taj.
++	For some reason the native exceptions are not being caught.  Moving this
++	to the Java side fixed the issue.  taj.
+ 		throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
+ 			"nativeSetSerialPortParams", strerror( errno ) );
+ */
+ 		return(1);
+ 	}
+ 
+-	LEAVE( "RXTXPort:nativeSetSerialPortParams" );
++	report( "Leaving - RXTXPort:nativeSetSerialPortParams\n" );
+ 	report_time_end( );
+ 	return(0);
+ }
+@@ -982,17 +1004,17 @@
+ /*----------------------------------------------------------
+  translate_speed
+ 
+-   accept:     speed in bits-per-second
+-   perform:    convert bits-per-second to a speed_t constant
+-   return:     speed_t constant
+-   exceptions: returns -1 and the calling method throws the exception so
+-	       it may be caught in java.
+-   comments:   Only the lowest level code should know about
+-               the magic constants.
++	accept:		speed in bits-per-second
++	perform:	convert bits-per-second to a speed_t constant
++	return:		speed_t constant
++	exceptions: returns -1 and the calling method throws the exception so
++				it may be caught in java.
++	comments:	Only the lowest level code should know about
++				the magic constants.
+ ----------------------------------------------------------*/
+ int translate_speed( JNIEnv *env, jint speed )
+ {
+-	LEAVE( "RXTXPort:translate_speed" );
++	report( "Leaving - RXTXPort:translate_speed\n" );
+ 	switch( speed ) {
+ 		case 0:		return B0;
+ 		case 50:	return B50;
+@@ -1072,7 +1094,7 @@
+ 	if( speed >= 0 ) return speed;
+ 	else
+ 	{
+-		LEAVE( "RXTXPort:translate_speed: Error condition" );
++		report( "Leaving - RXTXPort:translate_speed: Error condition\n" );
+ 		return -1;
+ 	}
+ }
+@@ -1080,16 +1102,16 @@
+ /*----------------------------------------------------------
+  translate_data_bits
+ 
+-   accept:     gnu.io.SerialPort.DATABITS_* constant
+-   perform:    set proper termios c_cflag bits
+-   return:     1 on error
+-   exceptions: UnsupportedCommOperationException
++	accept:		gnu.io.SerialPort.DATABITS_* constant
++	perform:	set proper termios c_cflag bits
++	return:		1 on error
++	exceptions: UnsupportedCommOperationException
+ ----------------------------------------------------------*/
+ int translate_data_bits( JNIEnv *env, tcflag_t *cflag, jint dataBits )
+ {
+ 	int temp = (*cflag) & ~CSIZE;
+ 
+-	ENTER( "translate_date_bits" );
++	report( "Entering - translate_date_bits\n" );
+ 	switch( dataBits ) {
+ 		case JDATABITS_5:
+ 			(*cflag) = temp | CS5;
+@@ -1105,10 +1127,10 @@
+ 			return 0;
+ 	}
+ 
+-	LEAVE( "RXTXPort:translate_date_bits" );
++	report( "Leaving - RXTXPort:translate_date_bits\n" );
+ /*
+-    For some reason the native exceptions are not being caught.  Moving this
+-    to the Java side fixed the issue.  taj.
++	For some reason the native exceptions are not being caught.  Moving this
++	to the Java side fixed the issue.  taj.
+ 	throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
+ 		"", "databit value not supported" );
+ */
+@@ -1118,20 +1140,20 @@
+ /*----------------------------------------------------------
+  translate_stop_bits
+ 
+-   accept:     gnu.io.SerialPort.STOPBITS_* constant
+-   perform:    set proper termios c_cflag bits
+-   return:     1 on error
+-   exceptions: UnsupportedCommOperationException
+-   comments:   If you specify 5 data bits and 2 stop bits, the port will
+-               allegedly use 1.5 stop bits.  Does anyone care?
++	accept:		gnu.io.SerialPort.STOPBITS_* constant
++	perform:	set proper termios c_cflag bits
++	return:		1 on error
++	exceptions: UnsupportedCommOperationException
++	comments:	If you specify 5 data bits and 2 stop bits, the port will
++				allegedly use 1.5 stop bits.  Does anyone care?
+ ----------------------------------------------------------*/
+ int translate_stop_bits( JNIEnv *env, tcflag_t *cflag, jint stopBits )
+ {
+-	ENTER( "translate_stop_bits" );
++	report( "Entering - translate_stop_bits\n" );
+ 	switch( stopBits ) {
+ 		case STOPBITS_1:
+ 			(*cflag) &= ~CSTOPB;
+-			LEAVE( "RXTXPort:translate_stop_bits" );
++			report( "Leaving - RXTXPort:translate_stop_bits\n" );
+ 			return 0;
+ 		/*  ok.. lets try putting it in and see if anyone notices */
+ 		case STOPBITS_1_5:
+@@ -1141,14 +1163,14 @@
+ 			return 0;
+ 		case STOPBITS_2:
+ 			(*cflag) |= CSTOPB;
+-			LEAVE( "RXTXPort:translate_stop_bits" );
++			report( "Leaving - RXTXPort:translate_stop_bits\n" );
+ 			return 0;
+ 	}
+ 
+-	LEAVE( "RXTXPort:translate_stop_bits" );
++	report( "Leaving - RXTXPort:translate_stop_bits\n" );
+ /*
+-    For some reason the native exceptions are not being caught.  Moving this
+-    to the Java side fixed the issue.  taj.
++	For some reason the native exceptions are not being caught.  Moving this
++	to the Java side fixed the issue.  taj.
+ 	throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
+ 		"", "stopbit value not supported" );
+ */
+@@ -1181,7 +1203,7 @@
+ 
+ 	if( tcgetattr( fd, &ttyset ) < 0 )
+ 	{
+-		report("nativeGetParity:  tcgetattr failed\n");
++		report("nativeGetParity:	tcgetattr failed\n");
+ 		return( -1 );
+ 	}
+ #ifdef  CMSPAR
+@@ -1215,49 +1237,49 @@
+ /*----------------------------------------------------------
+  translate_parity
+ 
+-   accept:     javax.comm.SerialPort.PARITY_* constant
+-   perform:    set proper termios c_cflag bits
+-   return:     1 on error
+-   exceptions: UnsupportedCommOperationException
+-   comments:   The CMSPAR bit should be used for 'mark' and 'space' parity,
+-               but it's not in glibc's includes.  Oh well, rarely used anyway.
++	accept:		javax.comm.SerialPort.PARITY_* constant
++	perform:	set proper termios c_cflag bits
++	return:		1 on error
++	exceptions:	UnsupportedCommOperationException
++	comments:	The CMSPAR bit should be used for 'mark' and 'space' parity,
++				but it's not in glibc's includes.  Oh well, rarely used anyway.
+ ----------------------------------------------------------*/
+ int translate_parity( JNIEnv *env, tcflag_t *cflag, jint parity )
+ {
+-	ENTER( "translate_parity" );
++	report( "Entering - translate_parity\n" );
+ #ifdef CMSPAR
+ 	(*cflag) &= ~(PARENB | PARODD | CMSPAR );
+ #endif /* CMSPAR */
+ 	switch( parity ) {
+ 		case JPARITY_NONE:
+-			LEAVE( "translate_parity" );
++			report( "Leaving - translate_parity\n" );

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-ports-head mailing list