10d09e41aSPaolo Bonzini #ifndef STREAM_H 2175de524SMarkus Armbruster #define STREAM_H 30d09e41aSPaolo Bonzini 40d09e41aSPaolo Bonzini #include "qom/object.h" 50d09e41aSPaolo Bonzini 6*cfbef3f4SPhilippe Mathieu-Daudé #define TYPE_STREAM_SINK "stream-sink" 70d09e41aSPaolo Bonzini 8*cfbef3f4SPhilippe Mathieu-Daudé typedef struct StreamSinkClass StreamSinkClass; 9*cfbef3f4SPhilippe Mathieu-Daudé DECLARE_CLASS_CHECKERS(StreamSinkClass, STREAM_SINK, 10*cfbef3f4SPhilippe Mathieu-Daudé TYPE_STREAM_SINK) 11*cfbef3f4SPhilippe Mathieu-Daudé #define STREAM_SINK(obj) \ 12*cfbef3f4SPhilippe Mathieu-Daudé INTERFACE_CHECK(StreamSink, (obj), TYPE_STREAM_SINK) 130d09e41aSPaolo Bonzini 14*cfbef3f4SPhilippe Mathieu-Daudé typedef struct StreamSink StreamSink; 150d09e41aSPaolo Bonzini 1635e60bfdSPeter Crosthwaite typedef void (*StreamCanPushNotifyFn)(void *opaque); 1735e60bfdSPeter Crosthwaite 18*cfbef3f4SPhilippe Mathieu-Daudé struct StreamSinkClass { 190d09e41aSPaolo Bonzini InterfaceClass parent; 2035e60bfdSPeter Crosthwaite /** 21*cfbef3f4SPhilippe Mathieu-Daudé * can push - determine if a stream sink is capable of accepting at least 2235e60bfdSPeter Crosthwaite * one byte of data. Returns false if cannot accept. If not implemented, the 23*cfbef3f4SPhilippe Mathieu-Daudé * sink is assumed to always be capable of receiving. 24*cfbef3f4SPhilippe Mathieu-Daudé * @notify: Optional callback that the sink will call when the sink is 25805a2505SStefan Weil * capable of receiving again. Only called if false is returned. 2635e60bfdSPeter Crosthwaite * @notify_opaque: opaque data to pass to notify call. 2735e60bfdSPeter Crosthwaite */ 28*cfbef3f4SPhilippe Mathieu-Daudé bool (*can_push)(StreamSink *obj, StreamCanPushNotifyFn notify, 2935e60bfdSPeter Crosthwaite void *notify_opaque); 3035e60bfdSPeter Crosthwaite /** 31*cfbef3f4SPhilippe Mathieu-Daudé * push - push data to a Stream sink. The number of bytes pushed is 32*cfbef3f4SPhilippe Mathieu-Daudé * returned. If the sink short returns, the master must wait before trying 33*cfbef3f4SPhilippe Mathieu-Daudé * again, the sink may continue to just return 0 waiting for the vm time to 3435e60bfdSPeter Crosthwaite * advance. The can_push() function can be used to trap the point in time 35*cfbef3f4SPhilippe Mathieu-Daudé * where the sink is ready to receive again, otherwise polling on a QEMU 3635e60bfdSPeter Crosthwaite * timer will work. 37*cfbef3f4SPhilippe Mathieu-Daudé * @obj: Stream sink to push to 3835e60bfdSPeter Crosthwaite * @buf: Data to write 3935e60bfdSPeter Crosthwaite * @len: Maximum number of bytes to write 4051b19950SEdgar E. Iglesias * @eop: End of packet flag 4135e60bfdSPeter Crosthwaite */ 42*cfbef3f4SPhilippe Mathieu-Daudé size_t (*push)(StreamSink *obj, unsigned char *buf, size_t len, bool eop); 43db1015e9SEduardo Habkost }; 440d09e41aSPaolo Bonzini 4535e60bfdSPeter Crosthwaite size_t 46*cfbef3f4SPhilippe Mathieu-Daudé stream_push(StreamSink *sink, uint8_t *buf, size_t len, bool eop); 470d09e41aSPaolo Bonzini 4835e60bfdSPeter Crosthwaite bool 49*cfbef3f4SPhilippe Mathieu-Daudé stream_can_push(StreamSink *sink, StreamCanPushNotifyFn notify, 5035e60bfdSPeter Crosthwaite void *notify_opaque); 5135e60bfdSPeter Crosthwaite 5235e60bfdSPeter Crosthwaite 530d09e41aSPaolo Bonzini #endif /* STREAM_H */ 54