char-device: Add a read method to simplify reading data

Avoid to pass throught SpiceCharDeviceInterface.
When data is read from device the device get marked as active.
This is coherent with what is done in red_char_device_read_from_device.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
This commit is contained in:
Frediano Ziglio 2020-05-07 12:36:44 +01:00
parent 3c8037d39f
commit 66dacecda9
2 changed files with 16 additions and 0 deletions

View File

@ -947,3 +947,14 @@ RedCharDevice::RedCharDevice(RedsState *reds, SpiceCharDeviceInstance *sin,
g_queue_init(&priv->write_queue);
}
int RedCharDevice::read(uint8_t *buf, int len)
{
auto sif = spice_char_device_get_interface(priv->sin);
int ret = sif->read(priv->sin, buf, len);
if (ret > 0) {
priv->active = true;
}
return ret;
}

View File

@ -174,6 +174,11 @@ public:
SpiceCharDeviceInstance *get_device_instance();
/**
* Read data from device
*/
int read(uint8_t *buf, int len);
red::unique_link<RedCharDevicePrivate> priv;
//protected: