2012-08-10 07:16:11 +04:00
|
|
|
#ifndef STREAM_H
|
2016-06-29 16:29:06 +03:00
|
|
|
#define STREAM_H
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2012-12-17 21:19:50 +04:00
|
|
|
#include "qom/object.h"
|
2012-08-10 07:16:11 +04:00
|
|
|
|
|
|
|
/* stream slave. Used until qdev provides a generic way. */
|
|
|
|
#define TYPE_STREAM_SLAVE "stream-slave"
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
typedef struct StreamSlaveClass StreamSlaveClass;
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_CLASS_CHECKERS(StreamSlaveClass, STREAM_SLAVE,
|
|
|
|
TYPE_STREAM_SLAVE)
|
2012-08-10 07:16:11 +04:00
|
|
|
#define STREAM_SLAVE(obj) \
|
|
|
|
INTERFACE_CHECK(StreamSlave, (obj), TYPE_STREAM_SLAVE)
|
|
|
|
|
2018-12-04 17:20:06 +03:00
|
|
|
typedef struct StreamSlave StreamSlave;
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2013-04-16 04:27:16 +04:00
|
|
|
typedef void (*StreamCanPushNotifyFn)(void *opaque);
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct StreamSlaveClass {
|
2012-08-10 07:16:11 +04:00
|
|
|
InterfaceClass parent;
|
2013-04-16 04:27:16 +04:00
|
|
|
/**
|
|
|
|
* can push - determine if a stream slave is capable of accepting at least
|
|
|
|
* one byte of data. Returns false if cannot accept. If not implemented, the
|
2013-04-28 13:49:57 +04:00
|
|
|
* slave is assumed to always be capable of receiving.
|
2013-04-16 04:27:16 +04:00
|
|
|
* @notify: Optional callback that the slave will call when the slave is
|
2013-04-28 13:49:57 +04:00
|
|
|
* capable of receiving again. Only called if false is returned.
|
2013-04-16 04:27:16 +04:00
|
|
|
* @notify_opaque: opaque data to pass to notify call.
|
|
|
|
*/
|
|
|
|
bool (*can_push)(StreamSlave *obj, StreamCanPushNotifyFn notify,
|
|
|
|
void *notify_opaque);
|
|
|
|
/**
|
|
|
|
* push - push data to a Stream slave. The number of bytes pushed is
|
|
|
|
* returned. If the slave short returns, the master must wait before trying
|
|
|
|
* again, the slave may continue to just return 0 waiting for the vm time to
|
|
|
|
* advance. The can_push() function can be used to trap the point in time
|
2013-04-28 13:49:57 +04:00
|
|
|
* where the slave is ready to receive again, otherwise polling on a QEMU
|
2013-04-16 04:27:16 +04:00
|
|
|
* timer will work.
|
|
|
|
* @obj: Stream slave to push to
|
|
|
|
* @buf: Data to write
|
|
|
|
* @len: Maximum number of bytes to write
|
2020-05-06 11:25:09 +03:00
|
|
|
* @eop: End of packet flag
|
2013-04-16 04:27:16 +04:00
|
|
|
*/
|
2020-05-06 11:25:09 +03:00
|
|
|
size_t (*push)(StreamSlave *obj, unsigned char *buf, size_t len, bool eop);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2013-04-16 04:27:16 +04:00
|
|
|
size_t
|
2020-05-06 11:25:09 +03:00
|
|
|
stream_push(StreamSlave *sink, uint8_t *buf, size_t len, bool eop);
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2013-04-16 04:27:16 +04:00
|
|
|
bool
|
|
|
|
stream_can_push(StreamSlave *sink, StreamCanPushNotifyFn notify,
|
|
|
|
void *notify_opaque);
|
|
|
|
|
|
|
|
|
2012-08-10 07:16:11 +04:00
|
|
|
#endif /* STREAM_H */
|