2012-08-10 11:16:11 +08:00
|
|
|
#ifndef STREAM_H
|
|
|
|
#define STREAM_H 1
|
|
|
|
|
|
|
|
#include "qemu-common.h"
|
2012-12-18 01:19:50 +08:00
|
|
|
#include "qom/object.h"
|
2012-08-10 11:16:11 +08:00
|
|
|
|
|
|
|
/* stream slave. Used until qdev provides a generic way. */
|
|
|
|
#define TYPE_STREAM_SLAVE "stream-slave"
|
|
|
|
|
|
|
|
#define STREAM_SLAVE_CLASS(klass) \
|
|
|
|
OBJECT_CLASS_CHECK(StreamSlaveClass, (klass), TYPE_STREAM_SLAVE)
|
|
|
|
#define STREAM_SLAVE_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(StreamSlaveClass, (obj), TYPE_STREAM_SLAVE)
|
|
|
|
#define STREAM_SLAVE(obj) \
|
|
|
|
INTERFACE_CHECK(StreamSlave, (obj), TYPE_STREAM_SLAVE)
|
|
|
|
|
|
|
|
typedef struct StreamSlave {
|
|
|
|
Object Parent;
|
|
|
|
} StreamSlave;
|
|
|
|
|
2013-04-16 08:27:16 +08:00
|
|
|
typedef void (*StreamCanPushNotifyFn)(void *opaque);
|
|
|
|
|
2012-08-10 11:16:11 +08:00
|
|
|
typedef struct StreamSlaveClass {
|
|
|
|
InterfaceClass parent;
|
2013-04-16 08:27:16 +08: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 17:49:57 +08:00
|
|
|
* slave is assumed to always be capable of receiving.
|
2013-04-16 08:27:16 +08:00
|
|
|
* @notify: Optional callback that the slave will call when the slave is
|
2013-04-28 17:49:57 +08:00
|
|
|
* capable of receiving again. Only called if false is returned.
|
2013-04-16 08:27:16 +08: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 17:49:57 +08:00
|
|
|
* where the slave is ready to receive again, otherwise polling on a QEMU
|
2013-04-16 08:27:16 +08:00
|
|
|
* timer will work.
|
|
|
|
* @obj: Stream slave to push to
|
|
|
|
* @buf: Data to write
|
|
|
|
* @len: Maximum number of bytes to write
|
|
|
|
*/
|
2013-04-16 08:28:35 +08:00
|
|
|
size_t (*push)(StreamSlave *obj, unsigned char *buf, size_t len);
|
2012-08-10 11:16:11 +08:00
|
|
|
} StreamSlaveClass;
|
|
|
|
|
2013-04-16 08:27:16 +08:00
|
|
|
size_t
|
2013-04-16 08:28:35 +08:00
|
|
|
stream_push(StreamSlave *sink, uint8_t *buf, size_t len);
|
2012-08-10 11:16:11 +08:00
|
|
|
|
2013-04-16 08:27:16 +08:00
|
|
|
bool
|
|
|
|
stream_can_push(StreamSlave *sink, StreamCanPushNotifyFn notify,
|
|
|
|
void *notify_opaque);
|
|
|
|
|
|
|
|
|
2012-08-10 11:16:11 +08:00
|
|
|
#endif /* STREAM_H */
|