From d3960d3748e7b83f3ad18fa226ed88c7a5b01941 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Thu, 27 Mar 2014 18:28:11 +0100 Subject: restructure jvm side for use of direct buffers --- flow/src/main/native/include/flow.h | 40 +++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'flow/src/main/native/include/flow.h') diff --git a/flow/src/main/native/include/flow.h b/flow/src/main/native/include/flow.h index ebb845a..d6a173e 100644 --- a/flow/src/main/native/include/flow.h +++ b/flow/src/main/native/include/flow.h @@ -2,9 +2,14 @@ #define FLOW_H #include +#include + +#ifdef _cplusplus +extern "C" { +#endif //general error codes that are returned by functions -#define E_IO -1 //I/O error (port should be closed) +#define E_IO -1 //IO error #define E_ACCESS_DENIED -2 //access denied #define E_BUSY -3 // port is busy #define E_INVALID_SETTINGS -4 // some port settings are invalid @@ -15,7 +20,7 @@ #define PARITY_ODD 1 #define PARITY_EVEN 2 -/** Represents an open serial port. */ +/** Contains internal configuration of an open serial port. */ struct serial_config; /**Opens a serial port and allocates memory for storing configuration. Note: if this function fails, @@ -30,15 +35,15 @@ struct serial_config; * @return E_NO_PORT if the given port does not exist * @return E_ACCESS_DENIED if permissions are not sufficient to open port * @return E_BUSY if port is already in use - * @return E_INVALID_SETTINGS if any of the specified settings are not supported + * @return E_INVALID_SETTINGS if any of the specified settings are invalid * @return E_IO on other error */ int serial_open( - const char* port_name, - int baud, - int char_size, - bool two_stop_bits, - int parity, - struct serial_config** serial); + const char* port_name, + int baud, + int char_size, + bool two_stop_bits, + int parity, + struct serial_config** const serial); /**Closes a previously opened serial port and frees memory containing the configuration. Note: after a call to * this function, the 'serial' pointer will become invalid, make sure you only call it once. This function is NOT @@ -47,23 +52,24 @@ int serial_open( * @param serial pointer to serial configuration that is to be closed (and freed) * @return 0 on success * @return E_IO on error */ -int serial_close(struct serial_config* serial); +int serial_close(struct serial_config* const serial); /**Starts a read from a previously opened serial port. The read is blocking, however it may be - * interrupted by calling 'serial_interrupt' on the given serial port. + * interrupted by calling 'serial_cancel_read' on the given serial port. * @param serial pointer to serial configuration from which to read * @param buffer buffer into which data is read * @param size maximum buffer size * @return n>0 the number of bytes read into buffer * @return E_INTERRUPT if the call to this function was interrupted * @return E_IO on IO error */ -int serial_read(struct serial_config* serial, unsigned char* buffer, size_t size); +int serial_read(struct serial_config* const serial, unsigned char* const buffer, size_t size); -/**Interrupts a blocked read call. +/**Cancels a blocked read call. This function is thread safe, i.e. it may be called from a thread even + * while another thread is blocked in a read call. * @param serial_config the serial port to interrupt * @return 0 on success * @return E_IO on error */ -int serial_interrupt(struct serial_config* serial); +int serial_cancel_read(struct serial_config* const serial); /**Writes data to a previously opened serial port. Non bocking. * @param serial pointer to serial configuration to which to write @@ -71,10 +77,14 @@ int serial_interrupt(struct serial_config* serial); * @param size number of bytes to write from data * @return n>0 the number of bytes written * @return E_IO on IO error */ -int serial_write(struct serial_config* serial, unsigned char* data, size_t size); +int serial_write(struct serial_config* const serial, unsigned char* const data, size_t size); /**Sets debugging option. If debugging is enabled, detailed error message are printed from method calls. */ void serial_debug(bool value); +#ifdef __cplusplus +} +#endif + #endif /* FLOW_H */ -- cgit v1.2.3