iostream: add 'get_name()' function
Some of the transport types have meaningful names. The BLE transport has a device name that was exposed during device discovery, for example, and some back-ends (ok, right now only the Aqualung i300C and i770R) need to know what that device name was in order to handshake with the device properly. Other transports, like the USBSTORAGE one, could usefully use this to get the basename of the path to the storage, although right now that transport makes do with simply doing a "dc_iostream_read()" on the transport instead. For now, this is just the infrastructure, ready to get hooked into. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
65ef99981f
commit
54ba49b1b3
@ -45,6 +45,7 @@ typedef struct dc_custom_cbs_t {
|
||||
dc_status_t (*purge) (void *userdata, dc_direction_t direction);
|
||||
dc_status_t (*sleep) (void *userdata, unsigned int milliseconds);
|
||||
dc_status_t (*close) (void *userdata);
|
||||
const char *(*get_name) (void *userdata);
|
||||
} dc_custom_cbs_t;
|
||||
|
||||
/**
|
||||
|
||||
@ -283,6 +283,19 @@ dc_iostream_sleep (dc_iostream_t *iostream, unsigned int milliseconds);
|
||||
dc_status_t
|
||||
dc_iostream_close (dc_iostream_t *iostream);
|
||||
|
||||
/**
|
||||
* Get the name of the device
|
||||
*
|
||||
* @param[in] iostream A valid I/O stream.
|
||||
* @returns a NUL-terminated constant C string that has a lifetime
|
||||
* until the close of the iostream, or NUL if no name exists.
|
||||
*
|
||||
* The name depends on the iostream transport. For a BLE device, it
|
||||
* is the name of the device during device discovery.
|
||||
*/
|
||||
const char *
|
||||
dc_iostream_get_name (dc_iostream_t *iostream);
|
||||
|
||||
dc_status_t
|
||||
dc_usb_storage_open (dc_iostream_t **out, dc_context_t *context, const char *name);
|
||||
|
||||
|
||||
13
src/custom.c
13
src/custom.c
@ -41,6 +41,7 @@ static dc_status_t dc_custom_flush (dc_iostream_t *abstract);
|
||||
static dc_status_t dc_custom_purge (dc_iostream_t *abstract, dc_direction_t direction);
|
||||
static dc_status_t dc_custom_sleep (dc_iostream_t *abstract, unsigned int milliseconds);
|
||||
static dc_status_t dc_custom_close (dc_iostream_t *abstract);
|
||||
static const char *dc_custom_get_name (dc_iostream_t *abstract);
|
||||
|
||||
typedef struct dc_custom_t {
|
||||
/* Base class. */
|
||||
@ -66,6 +67,7 @@ static const dc_iostream_vtable_t dc_custom_vtable = {
|
||||
dc_custom_purge, /* purge */
|
||||
dc_custom_sleep, /* sleep */
|
||||
dc_custom_close, /* close */
|
||||
dc_custom_get_name, /* get_name */
|
||||
};
|
||||
|
||||
dc_status_t
|
||||
@ -246,3 +248,14 @@ dc_custom_close (dc_iostream_t *abstract)
|
||||
|
||||
return custom->callbacks.close (custom->userdata);
|
||||
}
|
||||
|
||||
static const char *
|
||||
dc_custom_get_name (dc_iostream_t *abstract)
|
||||
{
|
||||
dc_custom_t *custom = (dc_custom_t *) abstract;
|
||||
|
||||
if (custom->callbacks.get_name == NULL)
|
||||
return NULL;
|
||||
|
||||
return custom->callbacks.get_name (custom->userdata);
|
||||
}
|
||||
|
||||
@ -68,6 +68,8 @@ struct dc_iostream_vtable_t {
|
||||
dc_status_t (*sleep) (dc_iostream_t *iostream, unsigned int milliseconds);
|
||||
|
||||
dc_status_t (*close) (dc_iostream_t *iostream);
|
||||
|
||||
const char *(*get_name) (dc_iostream_t *iostream);
|
||||
};
|
||||
|
||||
dc_iostream_t *
|
||||
|
||||
@ -305,3 +305,15 @@ dc_iostream_close (dc_iostream_t *iostream)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
const char *
|
||||
dc_iostream_get_name (dc_iostream_t *iostream)
|
||||
{
|
||||
if (iostream == NULL)
|
||||
return NULL;
|
||||
|
||||
if (iostream->vtable->get_name)
|
||||
return iostream->vtable->get_name (iostream);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user