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