Re-implement the set_latency function as an ioctl
The set_latency function is the perfect example of a feature that should be implemented as an ioctl: it's only implemented by a single driver, and the functionality is also highly platform specific.
This commit is contained in:
parent
0359a57fdc
commit
c205299c02
@ -32,7 +32,6 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct dc_custom_cbs_t {
|
typedef struct dc_custom_cbs_t {
|
||||||
dc_status_t (*set_timeout) (void *userdata, int timeout);
|
dc_status_t (*set_timeout) (void *userdata, int timeout);
|
||||||
dc_status_t (*set_latency) (void *userdata, unsigned int value);
|
|
||||||
dc_status_t (*set_break) (void *userdata, unsigned int value);
|
dc_status_t (*set_break) (void *userdata, unsigned int value);
|
||||||
dc_status_t (*set_dtr) (void *userdata, unsigned int value);
|
dc_status_t (*set_dtr) (void *userdata, unsigned int value);
|
||||||
dc_status_t (*set_rts) (void *userdata, unsigned int value);
|
dc_status_t (*set_rts) (void *userdata, unsigned int value);
|
||||||
|
|||||||
@ -123,22 +123,6 @@ dc_iostream_get_transport (dc_iostream_t *iostream);
|
|||||||
dc_status_t
|
dc_status_t
|
||||||
dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout);
|
dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout);
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the receive latency.
|
|
||||||
*
|
|
||||||
* The effect of this setting is highly platform and driver specific. On
|
|
||||||
* Windows it does nothing at all, on Linux it controls the low latency
|
|
||||||
* flag (e.g. only zero vs non-zero latency), and on Mac OS X it sets
|
|
||||||
* the receive latency as requested.
|
|
||||||
*
|
|
||||||
* @param[in] iostream A valid I/O stream.
|
|
||||||
* @param[in] value The latency in milliseconds.
|
|
||||||
* @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code
|
|
||||||
* on failure.
|
|
||||||
*/
|
|
||||||
dc_status_t
|
|
||||||
dc_iostream_set_latency (dc_iostream_t *iostream, unsigned int value);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the state of the break condition.
|
* Set the state of the break condition.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
#include "iostream.h"
|
#include "iostream.h"
|
||||||
#include "iterator.h"
|
#include "iterator.h"
|
||||||
#include "descriptor.h"
|
#include "descriptor.h"
|
||||||
|
#include "ioctl.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -77,6 +78,16 @@ dc_serial_iterator_new (dc_iterator_t **iterator, dc_context_t *context, dc_desc
|
|||||||
dc_status_t
|
dc_status_t
|
||||||
dc_serial_open (dc_iostream_t **iostream, dc_context_t *context, const char *name);
|
dc_serial_open (dc_iostream_t **iostream, dc_context_t *context, const char *name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the receive latency in milliseconds.
|
||||||
|
*
|
||||||
|
* The effect of this setting is highly platform and driver specific. On
|
||||||
|
* Windows it does nothing at all, on Linux it controls the low latency
|
||||||
|
* flag (e.g. only zero vs non-zero latency), and on Mac OS X it sets
|
||||||
|
* the receive latency as requested.
|
||||||
|
*/
|
||||||
|
#define DC_IOCTL_SERIAL_SET_LATENCY DC_IOCTL_IOW('s', 0, sizeof(unsigned int))
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|||||||
@ -99,7 +99,6 @@ static const dc_iterator_vtable_t dc_bluetooth_iterator_vtable = {
|
|||||||
static const dc_iostream_vtable_t dc_bluetooth_vtable = {
|
static const dc_iostream_vtable_t dc_bluetooth_vtable = {
|
||||||
sizeof(dc_socket_t),
|
sizeof(dc_socket_t),
|
||||||
dc_socket_set_timeout, /* set_timeout */
|
dc_socket_set_timeout, /* set_timeout */
|
||||||
NULL, /* set_latency */
|
|
||||||
NULL, /* set_break */
|
NULL, /* set_break */
|
||||||
NULL, /* set_dtr */
|
NULL, /* set_dtr */
|
||||||
NULL, /* set_rts */
|
NULL, /* set_rts */
|
||||||
|
|||||||
13
src/custom.c
13
src/custom.c
@ -28,7 +28,6 @@
|
|||||||
#include "context-private.h"
|
#include "context-private.h"
|
||||||
|
|
||||||
static dc_status_t dc_custom_set_timeout (dc_iostream_t *abstract, int timeout);
|
static dc_status_t dc_custom_set_timeout (dc_iostream_t *abstract, int timeout);
|
||||||
static dc_status_t dc_custom_set_latency (dc_iostream_t *abstract, unsigned int value);
|
|
||||||
static dc_status_t dc_custom_set_break (dc_iostream_t *abstract, unsigned int value);
|
static dc_status_t dc_custom_set_break (dc_iostream_t *abstract, unsigned int value);
|
||||||
static dc_status_t dc_custom_set_dtr (dc_iostream_t *abstract, unsigned int value);
|
static dc_status_t dc_custom_set_dtr (dc_iostream_t *abstract, unsigned int value);
|
||||||
static dc_status_t dc_custom_set_rts (dc_iostream_t *abstract, unsigned int value);
|
static dc_status_t dc_custom_set_rts (dc_iostream_t *abstract, unsigned int value);
|
||||||
@ -55,7 +54,6 @@ typedef struct dc_custom_t {
|
|||||||
static const dc_iostream_vtable_t dc_custom_vtable = {
|
static const dc_iostream_vtable_t dc_custom_vtable = {
|
||||||
sizeof(dc_custom_t),
|
sizeof(dc_custom_t),
|
||||||
dc_custom_set_timeout, /* set_timeout */
|
dc_custom_set_timeout, /* set_timeout */
|
||||||
dc_custom_set_latency, /* set_latency */
|
|
||||||
dc_custom_set_break, /* set_break */
|
dc_custom_set_break, /* set_break */
|
||||||
dc_custom_set_dtr, /* set_dtr */
|
dc_custom_set_dtr, /* set_dtr */
|
||||||
dc_custom_set_rts, /* set_rts */
|
dc_custom_set_rts, /* set_rts */
|
||||||
@ -108,17 +106,6 @@ dc_custom_set_timeout (dc_iostream_t *abstract, int timeout)
|
|||||||
return custom->callbacks.set_timeout (custom->userdata, timeout);
|
return custom->callbacks.set_timeout (custom->userdata, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static dc_status_t
|
|
||||||
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_SUCCESS;
|
|
||||||
|
|
||||||
return custom->callbacks.set_latency (custom->userdata, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static dc_status_t
|
static dc_status_t
|
||||||
dc_custom_set_break (dc_iostream_t *abstract, unsigned int value)
|
dc_custom_set_break (dc_iostream_t *abstract, unsigned int value)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -43,8 +43,6 @@ struct dc_iostream_vtable_t {
|
|||||||
|
|
||||||
dc_status_t (*set_timeout) (dc_iostream_t *iostream, int timeout);
|
dc_status_t (*set_timeout) (dc_iostream_t *iostream, int timeout);
|
||||||
|
|
||||||
dc_status_t (*set_latency) (dc_iostream_t *iostream, unsigned int value);
|
|
||||||
|
|
||||||
dc_status_t (*set_break) (dc_iostream_t *iostream, unsigned int value);
|
dc_status_t (*set_break) (dc_iostream_t *iostream, unsigned int value);
|
||||||
|
|
||||||
dc_status_t (*set_dtr) (dc_iostream_t *iostream, unsigned int value);
|
dc_status_t (*set_dtr) (dc_iostream_t *iostream, unsigned int value);
|
||||||
|
|||||||
@ -87,17 +87,6 @@ dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout)
|
|||||||
return iostream->vtable->set_timeout (iostream, timeout);
|
return iostream->vtable->set_timeout (iostream, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
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_SUCCESS;
|
|
||||||
|
|
||||||
INFO (iostream->context, "Latency: value=%i", value);
|
|
||||||
|
|
||||||
return iostream->vtable->set_latency (iostream, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
dc_status_t
|
dc_status_t
|
||||||
dc_iostream_set_break (dc_iostream_t *iostream, unsigned int value)
|
dc_iostream_set_break (dc_iostream_t *iostream, unsigned int value)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -91,7 +91,6 @@ static const dc_iterator_vtable_t dc_irda_iterator_vtable = {
|
|||||||
static const dc_iostream_vtable_t dc_irda_vtable = {
|
static const dc_iostream_vtable_t dc_irda_vtable = {
|
||||||
sizeof(dc_socket_t),
|
sizeof(dc_socket_t),
|
||||||
dc_socket_set_timeout, /* set_timeout */
|
dc_socket_set_timeout, /* set_timeout */
|
||||||
NULL, /* set_latency */
|
|
||||||
NULL, /* set_break */
|
NULL, /* set_break */
|
||||||
NULL, /* set_dtr */
|
NULL, /* set_dtr */
|
||||||
NULL, /* set_rts */
|
NULL, /* set_rts */
|
||||||
|
|||||||
@ -36,7 +36,6 @@ dc_descriptor_get_transports
|
|||||||
|
|
||||||
dc_iostream_get_transport
|
dc_iostream_get_transport
|
||||||
dc_iostream_set_timeout
|
dc_iostream_set_timeout
|
||||||
dc_iostream_set_latency
|
|
||||||
dc_iostream_set_break
|
dc_iostream_set_break
|
||||||
dc_iostream_set_dtr
|
dc_iostream_set_dtr
|
||||||
dc_iostream_set_rts
|
dc_iostream_set_rts
|
||||||
|
|||||||
@ -67,7 +67,6 @@ static dc_status_t dc_serial_iterator_next (dc_iterator_t *iterator, void *item)
|
|||||||
static dc_status_t dc_serial_iterator_free (dc_iterator_t *iterator);
|
static dc_status_t dc_serial_iterator_free (dc_iterator_t *iterator);
|
||||||
|
|
||||||
static dc_status_t dc_serial_set_timeout (dc_iostream_t *iostream, int timeout);
|
static dc_status_t dc_serial_set_timeout (dc_iostream_t *iostream, int timeout);
|
||||||
static dc_status_t dc_serial_set_latency (dc_iostream_t *iostream, unsigned int value);
|
|
||||||
static dc_status_t dc_serial_set_break (dc_iostream_t *iostream, unsigned int value);
|
static dc_status_t dc_serial_set_break (dc_iostream_t *iostream, unsigned int value);
|
||||||
static dc_status_t dc_serial_set_dtr (dc_iostream_t *iostream, unsigned int value);
|
static dc_status_t dc_serial_set_dtr (dc_iostream_t *iostream, unsigned int value);
|
||||||
static dc_status_t dc_serial_set_rts (dc_iostream_t *iostream, unsigned int value);
|
static dc_status_t dc_serial_set_rts (dc_iostream_t *iostream, unsigned int value);
|
||||||
@ -118,7 +117,6 @@ static const dc_iterator_vtable_t dc_serial_iterator_vtable = {
|
|||||||
static const dc_iostream_vtable_t dc_serial_vtable = {
|
static const dc_iostream_vtable_t dc_serial_vtable = {
|
||||||
sizeof(dc_serial_t),
|
sizeof(dc_serial_t),
|
||||||
dc_serial_set_timeout, /* set_timeout */
|
dc_serial_set_timeout, /* set_timeout */
|
||||||
dc_serial_set_latency, /* set_latency */
|
|
||||||
dc_serial_set_break, /* set_break */
|
dc_serial_set_break, /* set_break */
|
||||||
dc_serial_set_dtr, /* set_dtr */
|
dc_serial_set_dtr, /* set_dtr */
|
||||||
dc_serial_set_rts, /* set_rts */
|
dc_serial_set_rts, /* set_rts */
|
||||||
@ -854,7 +852,12 @@ out:
|
|||||||
static dc_status_t
|
static dc_status_t
|
||||||
dc_serial_ioctl (dc_iostream_t *abstract, unsigned int request, void *data, size_t size)
|
dc_serial_ioctl (dc_iostream_t *abstract, unsigned int request, void *data, size_t size)
|
||||||
{
|
{
|
||||||
return DC_STATUS_UNSUPPORTED;
|
switch (request) {
|
||||||
|
case DC_IOCTL_SERIAL_SET_LATENCY:
|
||||||
|
return dc_serial_set_latency (abstract, *(unsigned int *) data);
|
||||||
|
default:
|
||||||
|
return DC_STATUS_UNSUPPORTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static dc_status_t
|
static dc_status_t
|
||||||
|
|||||||
@ -36,7 +36,6 @@ static dc_status_t dc_serial_iterator_next (dc_iterator_t *iterator, void *item)
|
|||||||
static dc_status_t dc_serial_iterator_free (dc_iterator_t *iterator);
|
static dc_status_t dc_serial_iterator_free (dc_iterator_t *iterator);
|
||||||
|
|
||||||
static dc_status_t dc_serial_set_timeout (dc_iostream_t *iostream, int timeout);
|
static dc_status_t dc_serial_set_timeout (dc_iostream_t *iostream, int timeout);
|
||||||
static dc_status_t dc_serial_set_latency (dc_iostream_t *iostream, unsigned int value);
|
|
||||||
static dc_status_t dc_serial_set_break (dc_iostream_t *iostream, unsigned int value);
|
static dc_status_t dc_serial_set_break (dc_iostream_t *iostream, unsigned int value);
|
||||||
static dc_status_t dc_serial_set_dtr (dc_iostream_t *iostream, unsigned int value);
|
static dc_status_t dc_serial_set_dtr (dc_iostream_t *iostream, unsigned int value);
|
||||||
static dc_status_t dc_serial_set_rts (dc_iostream_t *iostream, unsigned int value);
|
static dc_status_t dc_serial_set_rts (dc_iostream_t *iostream, unsigned int value);
|
||||||
@ -93,7 +92,6 @@ static const dc_iterator_vtable_t dc_serial_iterator_vtable = {
|
|||||||
static const dc_iostream_vtable_t dc_serial_vtable = {
|
static const dc_iostream_vtable_t dc_serial_vtable = {
|
||||||
sizeof(dc_serial_t),
|
sizeof(dc_serial_t),
|
||||||
dc_serial_set_timeout, /* set_timeout */
|
dc_serial_set_timeout, /* set_timeout */
|
||||||
dc_serial_set_latency, /* set_latency */
|
|
||||||
dc_serial_set_break, /* set_break */
|
dc_serial_set_break, /* set_break */
|
||||||
dc_serial_set_dtr, /* set_dtr */
|
dc_serial_set_dtr, /* set_dtr */
|
||||||
dc_serial_set_rts, /* set_rts */
|
dc_serial_set_rts, /* set_rts */
|
||||||
@ -546,12 +544,6 @@ dc_serial_set_timeout (dc_iostream_t *abstract, int timeout)
|
|||||||
return DC_STATUS_SUCCESS;
|
return DC_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dc_status_t
|
|
||||||
dc_serial_set_latency (dc_iostream_t *abstract, unsigned int value)
|
|
||||||
{
|
|
||||||
return DC_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static dc_status_t
|
static dc_status_t
|
||||||
dc_serial_poll (dc_iostream_t *abstract, int timeout)
|
dc_serial_poll (dc_iostream_t *abstract, int timeout)
|
||||||
{
|
{
|
||||||
@ -687,7 +679,12 @@ out:
|
|||||||
static dc_status_t
|
static dc_status_t
|
||||||
dc_serial_ioctl (dc_iostream_t *abstract, unsigned int request, void *data, size_t size)
|
dc_serial_ioctl (dc_iostream_t *abstract, unsigned int request, void *data, size_t size)
|
||||||
{
|
{
|
||||||
return DC_STATUS_UNSUPPORTED;
|
switch (request) {
|
||||||
|
case DC_IOCTL_SERIAL_SET_LATENCY:
|
||||||
|
return DC_STATUS_SUCCESS;
|
||||||
|
default:
|
||||||
|
return DC_STATUS_UNSUPPORTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static dc_status_t
|
static dc_status_t
|
||||||
|
|||||||
@ -139,7 +139,6 @@ static const dc_iterator_vtable_t dc_usbhid_iterator_vtable = {
|
|||||||
static const dc_iostream_vtable_t dc_usbhid_vtable = {
|
static const dc_iostream_vtable_t dc_usbhid_vtable = {
|
||||||
sizeof(dc_usbhid_t),
|
sizeof(dc_usbhid_t),
|
||||||
dc_usbhid_set_timeout, /* set_timeout */
|
dc_usbhid_set_timeout, /* set_timeout */
|
||||||
NULL, /* set_latency */
|
|
||||||
NULL, /* set_break */
|
NULL, /* set_break */
|
||||||
NULL, /* set_dtr */
|
NULL, /* set_dtr */
|
||||||
NULL, /* set_rts */
|
NULL, /* set_rts */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user