Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 1 | #ifndef STREAM_H |
Markus Armbruster | 175de52 | 2016-06-29 15:29:06 +0200 | [diff] [blame] | 2 | #define STREAM_H |
Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 3 | |
Paolo Bonzini | 14cccb6 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 4 | #include "qom/object.h" |
Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 5 | |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 6 | #define TYPE_STREAM_SINK "stream-sink" |
Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 7 | |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 8 | typedef struct StreamSinkClass StreamSinkClass; |
| 9 | DECLARE_CLASS_CHECKERS(StreamSinkClass, STREAM_SINK, |
| 10 | TYPE_STREAM_SINK) |
| 11 | #define STREAM_SINK(obj) \ |
| 12 | INTERFACE_CHECK(StreamSink, (obj), TYPE_STREAM_SINK) |
Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 13 | |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 14 | typedef struct StreamSink StreamSink; |
Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 15 | |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 16 | typedef void (*StreamCanPushNotifyFn)(void *opaque); |
| 17 | |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 18 | struct StreamSinkClass { |
Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 19 | InterfaceClass parent; |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 20 | /** |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 21 | * can push - determine if a stream sink is capable of accepting at least |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 22 | * one byte of data. Returns false if cannot accept. If not implemented, the |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 23 | * sink is assumed to always be capable of receiving. |
| 24 | * @notify: Optional callback that the sink will call when the sink is |
Stefan Weil | 805a250 | 2013-04-28 11:49:57 +0200 | [diff] [blame] | 25 | * capable of receiving again. Only called if false is returned. |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 26 | * @notify_opaque: opaque data to pass to notify call. |
| 27 | */ |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 28 | bool (*can_push)(StreamSink *obj, StreamCanPushNotifyFn notify, |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 29 | void *notify_opaque); |
| 30 | /** |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 31 | * push - push data to a Stream sink. The number of bytes pushed is |
| 32 | * returned. If the sink short returns, the master must wait before trying |
| 33 | * again, the sink may continue to just return 0 waiting for the vm time to |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 34 | * advance. The can_push() function can be used to trap the point in time |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 35 | * where the sink is ready to receive again, otherwise polling on a QEMU |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 36 | * timer will work. |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 37 | * @obj: Stream sink to push to |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 38 | * @buf: Data to write |
| 39 | * @len: Maximum number of bytes to write |
Edgar E. Iglesias | 51b1995 | 2020-05-06 10:25:09 +0200 | [diff] [blame] | 40 | * @eop: End of packet flag |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 41 | */ |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 42 | size_t (*push)(StreamSink *obj, unsigned char *buf, size_t len, bool eop); |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 43 | }; |
Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 44 | |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 45 | size_t |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 46 | stream_push(StreamSink *sink, uint8_t *buf, size_t len, bool eop); |
Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 47 | |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 48 | bool |
Philippe Mathieu-Daudé | cfbef3f | 2020-09-10 09:01:27 +0200 | [diff] [blame] | 49 | stream_can_push(StreamSink *sink, StreamCanPushNotifyFn notify, |
Peter Crosthwaite | 35e60bf | 2013-04-16 10:27:16 +1000 | [diff] [blame] | 50 | void *notify_opaque); |
| 51 | |
| 52 | |
Peter A. G. Crosthwaite | 669b498 | 2012-08-10 13:16:11 +1000 | [diff] [blame] | 53 | #endif /* STREAM_H */ |