diff --git a/src/bluetooth.c b/src/bluetooth.c index b55bf86..088d027 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -99,18 +99,18 @@ static const dc_iterator_vtable_t dc_bluetooth_iterator_vtable = { static const dc_iostream_vtable_t dc_bluetooth_vtable = { sizeof(dc_socket_t), dc_socket_set_timeout, /* set_timeout */ - dc_socket_set_latency, /* set_latency */ - dc_socket_set_break, /* set_break */ - dc_socket_set_dtr, /* set_dtr */ - dc_socket_set_rts, /* set_rts */ - dc_socket_get_lines, /* get_lines */ - dc_socket_get_available, /* get_received */ - dc_socket_configure, /* configure */ + NULL, /* set_latency */ + NULL, /* set_break */ + NULL, /* set_dtr */ + NULL, /* set_rts */ + NULL, /* get_lines */ + dc_socket_get_available, /* get_available */ + NULL, /* configure */ dc_socket_read, /* read */ dc_socket_write, /* write */ - dc_socket_flush, /* flush */ - dc_socket_purge, /* purge */ - dc_socket_sleep, /* sleep */ + NULL, /* flush */ + NULL, /* purge */ + NULL, /* sleep */ dc_socket_close, /* close */ }; diff --git a/src/custom.c b/src/custom.c index 1e03aa7..8db276b 100644 --- a/src/custom.c +++ b/src/custom.c @@ -58,7 +58,7 @@ static const dc_iostream_vtable_t dc_custom_vtable = { dc_custom_set_dtr, /* set_dtr */ dc_custom_set_rts, /* set_rts */ dc_custom_get_lines, /* get_lines */ - dc_custom_get_available, /* get_received */ + dc_custom_get_available, /* get_available */ dc_custom_configure, /* configure */ dc_custom_read, /* read */ dc_custom_write, /* write */ @@ -99,7 +99,7 @@ dc_custom_set_timeout (dc_iostream_t *abstract, int timeout) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.set_timeout == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.set_timeout (custom->userdata, timeout); } @@ -110,7 +110,7 @@ dc_custom_set_latency (dc_iostream_t *abstract, unsigned int value) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.set_latency == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.set_latency (custom->userdata, value); } @@ -121,7 +121,7 @@ dc_custom_set_break (dc_iostream_t *abstract, unsigned int value) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.set_break == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.set_break (custom->userdata, value); } @@ -132,7 +132,7 @@ dc_custom_set_dtr (dc_iostream_t *abstract, unsigned int value) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.set_dtr == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.set_dtr (custom->userdata, value); } @@ -143,7 +143,7 @@ dc_custom_set_rts (dc_iostream_t *abstract, unsigned int value) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.set_rts == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.set_rts (custom->userdata, value); } @@ -154,7 +154,7 @@ dc_custom_get_lines (dc_iostream_t *abstract, unsigned int *value) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.get_lines == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.get_lines (custom->userdata, value); } @@ -165,7 +165,7 @@ dc_custom_get_available (dc_iostream_t *abstract, size_t *value) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.get_available == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.get_available (custom->userdata, value); } @@ -176,7 +176,7 @@ dc_custom_configure (dc_iostream_t *abstract, unsigned int baudrate, unsigned in dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.configure == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.configure (custom->userdata, baudrate, databits, parity, stopbits, flowcontrol); } @@ -187,7 +187,7 @@ dc_custom_read (dc_iostream_t *abstract, void *data, size_t size, size_t *actual dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.read == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.read (custom->userdata, data, size, actual); } @@ -198,7 +198,7 @@ dc_custom_write (dc_iostream_t *abstract, const void *data, size_t size, size_t dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.write == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.write (custom->userdata, data, size, actual); } @@ -209,7 +209,7 @@ dc_custom_flush (dc_iostream_t *abstract) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.flush == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.flush (custom->userdata); } @@ -220,7 +220,7 @@ dc_custom_purge (dc_iostream_t *abstract, dc_direction_t direction) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.purge == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.purge (custom->userdata, direction); } @@ -231,7 +231,7 @@ dc_custom_sleep (dc_iostream_t *abstract, unsigned int milliseconds) dc_custom_t *custom = (dc_custom_t *) abstract; if (custom->callbacks.sleep == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; return custom->callbacks.sleep (custom->userdata, milliseconds); } @@ -239,12 +239,10 @@ dc_custom_sleep (dc_iostream_t *abstract, unsigned int milliseconds) static dc_status_t dc_custom_close (dc_iostream_t *abstract) { - dc_status_t status = DC_STATUS_SUCCESS; dc_custom_t *custom = (dc_custom_t *) abstract; - if (custom->callbacks.close) { - status = custom->callbacks.close (custom->userdata); - } + if (custom->callbacks.close == NULL) + return DC_STATUS_SUCCESS; - return status; + return custom->callbacks.close (custom->userdata); } diff --git a/src/iostream.c b/src/iostream.c index 9681d02..e0ba7fc 100644 --- a/src/iostream.c +++ b/src/iostream.c @@ -25,6 +25,7 @@ #include "iostream-private.h" #include "context-private.h" +#include "platform.h" dc_iostream_t * dc_iostream_allocate (dc_context_t *context, const dc_iostream_vtable_t *vtable, dc_transport_t transport) @@ -77,7 +78,7 @@ dc_status_t dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout) { if (iostream == NULL || iostream->vtable->set_timeout == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; INFO (iostream->context, "Timeout: value=%i", timeout); @@ -88,7 +89,7 @@ dc_status_t dc_iostream_set_latency (dc_iostream_t *iostream, unsigned int value) { if (iostream == NULL || iostream->vtable->set_latency == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; INFO (iostream->context, "Latency: value=%i", value); @@ -99,7 +100,7 @@ dc_status_t dc_iostream_set_break (dc_iostream_t *iostream, unsigned int value) { if (iostream == NULL || iostream->vtable->set_break == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; INFO (iostream->context, "Break: value=%i", value); @@ -110,7 +111,7 @@ dc_status_t dc_iostream_set_dtr (dc_iostream_t *iostream, unsigned int value) { if (iostream == NULL || iostream->vtable->set_dtr == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; INFO (iostream->context, "DTR: value=%i", value); @@ -121,7 +122,7 @@ dc_status_t dc_iostream_set_rts (dc_iostream_t *iostream, unsigned int value) { if (iostream == NULL || iostream->vtable->set_rts == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; INFO (iostream->context, "RTS: value=%i", value); @@ -131,26 +132,50 @@ dc_iostream_set_rts (dc_iostream_t *iostream, unsigned int value) dc_status_t dc_iostream_get_lines (dc_iostream_t *iostream, unsigned int *value) { - if (iostream == NULL || iostream->vtable->get_lines == NULL) - return DC_STATUS_UNSUPPORTED; + dc_status_t status = DC_STATUS_SUCCESS; + unsigned int lines = 0; - return iostream->vtable->get_lines (iostream, value); + if (iostream == NULL || iostream->vtable->get_lines == NULL) { + goto out; + } + + status = iostream->vtable->get_lines (iostream, &lines); + + INFO (iostream->context, "Lines: value=%u", lines); + +out: + if (value) + *value = lines; + + return status; } dc_status_t dc_iostream_get_available (dc_iostream_t *iostream, size_t *value) { - if (iostream == NULL || iostream->vtable->get_available == NULL) - return DC_STATUS_UNSUPPORTED; + dc_status_t status = DC_STATUS_SUCCESS; + size_t available = 0; - return iostream->vtable->get_available (iostream, value); + if (iostream == NULL || iostream->vtable->get_available == NULL) { + goto out; + } + + status = iostream->vtable->get_available (iostream, &available); + + INFO (iostream->context, "Available: value=" DC_PRINTF_SIZE, available); + +out: + if (value) + *value = available; + + return status; } dc_status_t dc_iostream_configure (dc_iostream_t *iostream, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol) { if (iostream == NULL || iostream->vtable->configure == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; INFO (iostream->context, "Configure: baudrate=%i, databits=%i, parity=%i, stopbits=%i, flowcontrol=%i", baudrate, databits, parity, stopbits, flowcontrol); @@ -165,7 +190,6 @@ dc_iostream_read (dc_iostream_t *iostream, void *data, size_t size, size_t *actu size_t nbytes = 0; if (iostream == NULL || iostream->vtable->read == NULL) { - status = DC_STATUS_UNSUPPORTED; goto out; } @@ -187,7 +211,6 @@ dc_iostream_write (dc_iostream_t *iostream, const void *data, size_t size, size_ size_t nbytes = 0; if (iostream == NULL || iostream->vtable->read == NULL) { - status = DC_STATUS_UNSUPPORTED; goto out; } @@ -206,7 +229,7 @@ dc_status_t dc_iostream_flush (dc_iostream_t *iostream) { if (iostream == NULL || iostream->vtable->flush == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; INFO (iostream->context, "Flush: none"); @@ -217,7 +240,7 @@ dc_status_t dc_iostream_purge (dc_iostream_t *iostream, dc_direction_t direction) { if (iostream == NULL || iostream->vtable->purge == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; INFO (iostream->context, "Purge: direction=%u", direction); @@ -228,7 +251,7 @@ dc_status_t dc_iostream_sleep (dc_iostream_t *iostream, unsigned int milliseconds) { if (iostream == NULL || iostream->vtable->sleep == NULL) - return DC_STATUS_UNSUPPORTED; + return DC_STATUS_SUCCESS; INFO (iostream->context, "Sleep: value=%u", milliseconds); diff --git a/src/irda.c b/src/irda.c index a5cf803..eedb703 100644 --- a/src/irda.c +++ b/src/irda.c @@ -91,18 +91,18 @@ static const dc_iterator_vtable_t dc_irda_iterator_vtable = { static const dc_iostream_vtable_t dc_irda_vtable = { sizeof(dc_socket_t), dc_socket_set_timeout, /* set_timeout */ - dc_socket_set_latency, /* set_latency */ - dc_socket_set_break, /* set_break */ - dc_socket_set_dtr, /* set_dtr */ - dc_socket_set_rts, /* set_rts */ - dc_socket_get_lines, /* get_lines */ - dc_socket_get_available, /* get_received */ - dc_socket_configure, /* configure */ + NULL, /* set_latency */ + NULL, /* set_break */ + NULL, /* set_dtr */ + NULL, /* set_rts */ + NULL, /* get_lines */ + dc_socket_get_available, /* get_available */ + NULL, /* configure */ dc_socket_read, /* read */ dc_socket_write, /* write */ - dc_socket_flush, /* flush */ - dc_socket_purge, /* purge */ - dc_socket_sleep, /* sleep */ + NULL, /* flush */ + NULL, /* purge */ + NULL, /* sleep */ dc_socket_close, /* close */ }; #endif diff --git a/src/serial_posix.c b/src/serial_posix.c index ff954ef..46ec3de 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -121,7 +121,7 @@ static const dc_iostream_vtable_t dc_serial_vtable = { dc_serial_set_dtr, /* set_dtr */ dc_serial_set_rts, /* set_rts */ dc_serial_get_lines, /* get_lines */ - dc_serial_get_available, /* get_received */ + dc_serial_get_available, /* get_available */ dc_serial_configure, /* configure */ dc_serial_read, /* read */ dc_serial_write, /* write */ diff --git a/src/serial_win32.c b/src/serial_win32.c index ff52b41..124857a 100644 --- a/src/serial_win32.c +++ b/src/serial_win32.c @@ -91,7 +91,7 @@ static const dc_iostream_vtable_t dc_serial_vtable = { dc_serial_set_dtr, /* set_dtr */ dc_serial_set_rts, /* set_rts */ dc_serial_get_lines, /* get_lines */ - dc_serial_get_available, /* get_received */ + dc_serial_get_available, /* get_available */ dc_serial_configure, /* configure */ dc_serial_read, /* read */ dc_serial_write, /* write */ diff --git a/src/socket.c b/src/socket.c index 1842a75..948aa46 100644 --- a/src/socket.c +++ b/src/socket.c @@ -163,39 +163,6 @@ dc_socket_set_timeout (dc_iostream_t *abstract, int timeout) return DC_STATUS_SUCCESS; } -dc_status_t -dc_socket_set_latency (dc_iostream_t *iostream, unsigned int value) -{ - return DC_STATUS_SUCCESS; -} - -dc_status_t -dc_socket_set_break (dc_iostream_t *iostream, unsigned int value) -{ - return DC_STATUS_SUCCESS; -} - -dc_status_t -dc_socket_set_dtr (dc_iostream_t *iostream, unsigned int value) -{ - return DC_STATUS_SUCCESS; -} - -dc_status_t -dc_socket_set_rts (dc_iostream_t *iostream, unsigned int value) -{ - return DC_STATUS_SUCCESS; -} - -dc_status_t -dc_socket_get_lines (dc_iostream_t *iostream, unsigned int *value) -{ - if (value) - *value = 0; - - return DC_STATUS_SUCCESS; -} - dc_status_t dc_socket_get_available (dc_iostream_t *abstract, size_t *value) { @@ -219,12 +186,6 @@ dc_socket_get_available (dc_iostream_t *abstract, size_t *value) return DC_STATUS_SUCCESS; } -dc_status_t -dc_socket_configure (dc_iostream_t *abstract, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol) -{ - return DC_STATUS_SUCCESS; -} - dc_status_t dc_socket_read (dc_iostream_t *abstract, void *data, size_t size, size_t *actual) { @@ -332,21 +293,3 @@ out: return status; } - -dc_status_t -dc_socket_flush (dc_iostream_t *abstract) -{ - return DC_STATUS_SUCCESS; -} - -dc_status_t -dc_socket_purge (dc_iostream_t *abstract, dc_direction_t direction) -{ - return DC_STATUS_SUCCESS; -} - -dc_status_t -dc_socket_sleep (dc_iostream_t *abstract, unsigned int timeout) -{ - return DC_STATUS_SUCCESS; -} diff --git a/src/socket.h b/src/socket.h index 626003c..5f5421d 100644 --- a/src/socket.h +++ b/src/socket.h @@ -104,42 +104,15 @@ dc_socket_connect (dc_iostream_t *iostream, const struct sockaddr *addr, s_sockl dc_status_t dc_socket_set_timeout (dc_iostream_t *iostream, int timeout); -dc_status_t -dc_socket_set_latency (dc_iostream_t *iostream, unsigned int value); - -dc_status_t -dc_socket_set_break (dc_iostream_t *iostream, unsigned int value); - -dc_status_t -dc_socket_set_dtr (dc_iostream_t *iostream, unsigned int value); - -dc_status_t -dc_socket_set_rts (dc_iostream_t *iostream, unsigned int value); - -dc_status_t -dc_socket_get_lines (dc_iostream_t *iostream, unsigned int *value); - dc_status_t dc_socket_get_available (dc_iostream_t *iostream, size_t *value); -dc_status_t -dc_socket_configure (dc_iostream_t *iostream, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol); - dc_status_t dc_socket_read (dc_iostream_t *iostream, void *data, size_t size, size_t *actual); dc_status_t dc_socket_write (dc_iostream_t *iostream, const void *data, size_t size, size_t *actual); -dc_status_t -dc_socket_flush (dc_iostream_t *iostream); - -dc_status_t -dc_socket_purge (dc_iostream_t *iostream, dc_direction_t direction); - -dc_status_t -dc_socket_sleep (dc_iostream_t *iostream, unsigned int milliseconds); - dc_status_t dc_socket_close (dc_iostream_t *iostream); diff --git a/src/usbhid.c b/src/usbhid.c index 0338bfe..a3ddc74 100644 --- a/src/usbhid.c +++ b/src/usbhid.c @@ -142,7 +142,7 @@ static const dc_iostream_vtable_t dc_usbhid_vtable = { NULL, /* set_dtr */ NULL, /* set_rts */ NULL, /* get_lines */ - NULL, /* get_received */ + NULL, /* get_available */ NULL, /* configure */ dc_usbhid_read, /* read */ dc_usbhid_write, /* write */