[Mono.Debugger.Soft] Make CommandException public
[mono.git] / support / serial.c
index a8bd7dad436681cd0f071d7c405e3e40e7e504f9..36b902defb93b9f12fe77e1c64afe5859db074df 100644 (file)
@@ -9,9 +9,13 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
+#include <errno.h>
+#if defined(__APPLE__)
+#include "fakepoll.h"
+#else
 #include <sys/poll.h>
+#endif
 #include <sys/ioctl.h>
-#include <errno.h>
 
 #include <glib.h>
 
@@ -60,8 +64,28 @@ typedef enum {
        Rts = 16  /* Request to send */
 } MonoSerialSignal;
 
+/*
+ * Silence the compiler, we do not need these prototypes to be public, since these are only
+ * used by P/Invoke
+ */
+
+int              open_serial (char *devfile);
+int              close_serial (int unix_fd);
+guint32          read_serial (int fd, guchar *buffer, int offset, int count);
+int              write_serial (int fd, guchar *buffer, int offset, int count, int timeout);
+int              discard_buffer (int fd, gboolean input);
+gint32           get_bytes_in_buffer (int fd, gboolean input);
+gboolean         is_baud_rate_legal (int baud_rate);
+int              setup_baud_rate (int baud_rate);
+gboolean         set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake);
+MonoSerialSignal get_signals (int fd, gint32 *error);
+gint32           set_signal (int fd, MonoSerialSignal signal, gboolean value);
+int              breakprop (int fd);
+gboolean         poll_serial (int fd, gint32 *error, int timeout);
+void            *list_serial_devices (void);
+
 int
-open_serial (chardevfile)
+open_serial (char *devfile)
 {
        int fd;
        fd = open (devfile, O_RDWR | O_NOCTTY | O_NONBLOCK);
@@ -100,7 +124,7 @@ write_serial (int fd, guchar *buffer, int offset, int count, int timeout)
 
        while (n > 0)
        {
-               size_t t;
+               ssize_t t;
                        
                if (timeout != 0) {
                        int c;
@@ -144,22 +168,22 @@ get_bytes_in_buffer (int fd, gboolean input)
 }
 
 gboolean
-set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake)
+is_baud_rate_legal (int baud_rate)
 {
-       struct termios newtio;
-
-       if (tcgetattr (fd, &newtio) == -1)
-               return FALSE;
-
-       newtio.c_cflag |=  (CLOCAL | CREAD);
-       newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN );
-       newtio.c_oflag &= ~(OPOST);
-       newtio.c_iflag = IGNBRK;
+       return setup_baud_rate (baud_rate) != -1;
+}
 
-       /* setup baudrate */
+int
+setup_baud_rate (int baud_rate)
+{
        switch (baud_rate)
        {
-/*This is not defined on OSX and *BSD */
+/*Some values are not defined on OSX and *BSD */
+#if defined(B921600)
+       case 921600:
+           baud_rate = B921600;
+           break;
+#endif
 #if defined(B460800)
        case 460800:
            baud_rate = B460800;
@@ -219,9 +243,27 @@ set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStop
        case 50:
        case 0:
        default:
-           baud_rate = B9600;
+           baud_rate = -1;
                break;
        }
+       return baud_rate;
+}
+
+gboolean
+set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake)
+{
+       struct termios newtio;
+
+       if (tcgetattr (fd, &newtio) == -1)
+               return FALSE;
+
+       newtio.c_cflag |=  (CLOCAL | CREAD);
+       newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN );
+       newtio.c_oflag &= ~(OPOST);
+       newtio.c_iflag = IGNBRK;
+
+       /* setup baudrate */
+       baud_rate = setup_baud_rate (baud_rate);
 
        /* char lenght */
        newtio.c_cflag &= ~CSIZE;