NeuronRobotics / nrjavaserial

A Java Serial Port system. This is a fork of the RXTX project that uses in jar loading of the native code.
Other
344 stars 142 forks source link

Deduplicate native flow control getters/setters #203

Open MrDOS opened 3 years ago

MrDOS commented 3 years ago

RXTXPort.setDTR()/isDTR()/setRTS()/isRTS()/isCTS()/setDSR()/isDSR()/isRI()/isCD() are all wrappers around TIOCMSET/TIOCMGET ioctl calls. They all follow the same pattern: the setters retrieve the current control bits and set or clear the relevant bit, then set the new control bits; and the getters retrieve the current control bits, mask out the relevant one, and return a boolean based on whether it's set. These methods are largely copy/pasted, and could be easily deduplicated into a setter function which takes the FD, the bit to set, and the desired state of that bit; and a getter function which takes the FD and the bit, and returns the state of that bit. The JNI functions would then just be thin wrappers around those functions.