]>
Commit | Line | Data |
---|---|---|
669b4983 | 1 | #ifndef STREAM_H |
175de524 | 2 | #define STREAM_H |
669b4983 | 3 | |
14cccb61 | 4 | #include "qom/object.h" |
669b4983 PC |
5 | |
6 | /* stream slave. Used until qdev provides a generic way. */ | |
7 | #define TYPE_STREAM_SLAVE "stream-slave" | |
8 | ||
db1015e9 | 9 | typedef struct StreamSlaveClass StreamSlaveClass; |
669b4983 PC |
10 | #define STREAM_SLAVE_CLASS(klass) \ |
11 | OBJECT_CLASS_CHECK(StreamSlaveClass, (klass), TYPE_STREAM_SLAVE) | |
12 | #define STREAM_SLAVE_GET_CLASS(obj) \ | |
13 | OBJECT_GET_CLASS(StreamSlaveClass, (obj), TYPE_STREAM_SLAVE) | |
14 | #define STREAM_SLAVE(obj) \ | |
15 | INTERFACE_CHECK(StreamSlave, (obj), TYPE_STREAM_SLAVE) | |
16 | ||
aa1b35b9 | 17 | typedef struct StreamSlave StreamSlave; |
669b4983 | 18 | |
35e60bfd PC |
19 | typedef void (*StreamCanPushNotifyFn)(void *opaque); |
20 | ||
db1015e9 | 21 | struct StreamSlaveClass { |
669b4983 | 22 | InterfaceClass parent; |
35e60bfd PC |
23 | /** |
24 | * can push - determine if a stream slave is capable of accepting at least | |
25 | * one byte of data. Returns false if cannot accept. If not implemented, the | |
805a2505 | 26 | * slave is assumed to always be capable of receiving. |
35e60bfd | 27 | * @notify: Optional callback that the slave will call when the slave is |
805a2505 | 28 | * capable of receiving again. Only called if false is returned. |
35e60bfd PC |
29 | * @notify_opaque: opaque data to pass to notify call. |
30 | */ | |
31 | bool (*can_push)(StreamSlave *obj, StreamCanPushNotifyFn notify, | |
32 | void *notify_opaque); | |
33 | /** | |
34 | * push - push data to a Stream slave. The number of bytes pushed is | |
35 | * returned. If the slave short returns, the master must wait before trying | |
36 | * again, the slave may continue to just return 0 waiting for the vm time to | |
37 | * advance. The can_push() function can be used to trap the point in time | |
805a2505 | 38 | * where the slave is ready to receive again, otherwise polling on a QEMU |
35e60bfd PC |
39 | * timer will work. |
40 | * @obj: Stream slave to push to | |
41 | * @buf: Data to write | |
42 | * @len: Maximum number of bytes to write | |
51b19950 | 43 | * @eop: End of packet flag |
35e60bfd | 44 | */ |
51b19950 | 45 | size_t (*push)(StreamSlave *obj, unsigned char *buf, size_t len, bool eop); |
db1015e9 | 46 | }; |
669b4983 | 47 | |
35e60bfd | 48 | size_t |
51b19950 | 49 | stream_push(StreamSlave *sink, uint8_t *buf, size_t len, bool eop); |
669b4983 | 50 | |
35e60bfd PC |
51 | bool |
52 | stream_can_push(StreamSlave *sink, StreamCanPushNotifyFn notify, | |
53 | void *notify_opaque); | |
54 | ||
55 | ||
669b4983 | 56 | #endif /* STREAM_H */ |