blob: f166facb090a7853992be6bbacba037f24bd7183 [file] [log] [blame]
Peter A. G. Crosthwaite669b4982012-08-10 13:16:11 +10001#ifndef STREAM_H
Markus Armbruster175de522016-06-29 15:29:06 +02002#define STREAM_H
Peter A. G. Crosthwaite669b4982012-08-10 13:16:11 +10003
Paolo Bonzini14cccb62012-12-17 18:19:50 +01004#include "qom/object.h"
Peter A. G. Crosthwaite669b4982012-08-10 13:16:11 +10005
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +02006#define TYPE_STREAM_SINK "stream-sink"
Peter A. G. Crosthwaite669b4982012-08-10 13:16:11 +10007
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +02008typedef struct StreamSinkClass StreamSinkClass;
9DECLARE_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. Crosthwaite669b4982012-08-10 13:16:11 +100013
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020014typedef struct StreamSink StreamSink;
Peter A. G. Crosthwaite669b4982012-08-10 13:16:11 +100015
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100016typedef void (*StreamCanPushNotifyFn)(void *opaque);
17
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020018struct StreamSinkClass {
Peter A. G. Crosthwaite669b4982012-08-10 13:16:11 +100019 InterfaceClass parent;
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100020 /**
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020021 * can push - determine if a stream sink is capable of accepting at least
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100022 * one byte of data. Returns false if cannot accept. If not implemented, the
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020023 * sink is assumed to always be capable of receiving.
24 * @notify: Optional callback that the sink will call when the sink is
Stefan Weil805a2502013-04-28 11:49:57 +020025 * capable of receiving again. Only called if false is returned.
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100026 * @notify_opaque: opaque data to pass to notify call.
27 */
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020028 bool (*can_push)(StreamSink *obj, StreamCanPushNotifyFn notify,
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100029 void *notify_opaque);
30 /**
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020031 * 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 Crosthwaite35e60bf2013-04-16 10:27:16 +100034 * advance. The can_push() function can be used to trap the point in time
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020035 * where the sink is ready to receive again, otherwise polling on a QEMU
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100036 * timer will work.
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020037 * @obj: Stream sink to push to
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100038 * @buf: Data to write
39 * @len: Maximum number of bytes to write
Edgar E. Iglesias51b19952020-05-06 10:25:09 +020040 * @eop: End of packet flag
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100041 */
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020042 size_t (*push)(StreamSink *obj, unsigned char *buf, size_t len, bool eop);
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040043};
Peter A. G. Crosthwaite669b4982012-08-10 13:16:11 +100044
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100045size_t
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020046stream_push(StreamSink *sink, uint8_t *buf, size_t len, bool eop);
Peter A. G. Crosthwaite669b4982012-08-10 13:16:11 +100047
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100048bool
Philippe Mathieu-Daudécfbef3f2020-09-10 09:01:27 +020049stream_can_push(StreamSink *sink, StreamCanPushNotifyFn notify,
Peter Crosthwaite35e60bf2013-04-16 10:27:16 +100050 void *notify_opaque);
51
52
Peter A. G. Crosthwaite669b4982012-08-10 13:16:11 +100053#endif /* STREAM_H */