2012-08-10 05:16:11 +02:00
|
|
|
#ifndef STREAM_H
|
2016-06-29 15:29:06 +02:00
|
|
|
#define STREAM_H
|
2012-08-10 05:16:11 +02:00
|
|
|
|
2012-12-17 18:19:50 +01:00
|
|
|
#include "qom/object.h"
|
2012-08-10 05:16:11 +02:00
|
|
|
|
2020-09-10 09:01:27 +02:00
|
|
|
#define TYPE_STREAM_SINK "stream-sink"
|
2012-08-10 05:16:11 +02:00
|
|
|
|
2020-09-10 09:01:27 +02:00
|
|
|
typedef struct StreamSinkClass StreamSinkClass;
|
|
|
|
DECLARE_CLASS_CHECKERS(StreamSinkClass, STREAM_SINK,
|
|
|
|
TYPE_STREAM_SINK)
|
|
|
|
#define STREAM_SINK(obj) \
|
|
|
|
INTERFACE_CHECK(StreamSink, (obj), TYPE_STREAM_SINK)
|
2012-08-10 05:16:11 +02:00
|
|
|
|
2020-09-10 09:01:27 +02:00
|
|
|
typedef struct StreamSink StreamSink;
|
2012-08-10 05:16:11 +02:00
|
|
|
|
2013-04-16 02:27:16 +02:00
|
|
|
typedef void (*StreamCanPushNotifyFn)(void *opaque);
|
|
|
|
|
2020-09-10 09:01:27 +02:00
|
|
|
struct StreamSinkClass {
|
2012-08-10 05:16:11 +02:00
|
|
|
InterfaceClass parent;
|
2013-04-16 02:27:16 +02:00
|
|
|
/**
|
2020-09-10 09:01:27 +02:00
|
|
|
* can push - determine if a stream sink is capable of accepting at least
|
2013-04-16 02:27:16 +02:00
|
|
|
* one byte of data. Returns false if cannot accept. If not implemented, the
|
2020-09-10 09:01:27 +02:00
|
|
|
* sink is assumed to always be capable of receiving.
|
|
|
|
* @notify: Optional callback that the sink will call when the sink is
|
2013-04-28 11:49:57 +02:00
|
|
|
* capable of receiving again. Only called if false is returned.
|
2013-04-16 02:27:16 +02:00
|
|
|
* @notify_opaque: opaque data to pass to notify call.
|
|
|
|
*/
|
2020-09-10 09:01:27 +02:00
|
|
|
bool (*can_push)(StreamSink *obj, StreamCanPushNotifyFn notify,
|
2013-04-16 02:27:16 +02:00
|
|
|
void *notify_opaque);
|
|
|
|
/**
|
2020-09-10 09:01:27 +02:00
|
|
|
* push - push data to a Stream sink. The number of bytes pushed is
|
|
|
|
* returned. If the sink short returns, the master must wait before trying
|
|
|
|
* again, the sink may continue to just return 0 waiting for the vm time to
|
2013-04-16 02:27:16 +02:00
|
|
|
* advance. The can_push() function can be used to trap the point in time
|
2020-09-10 09:01:27 +02:00
|
|
|
* where the sink is ready to receive again, otherwise polling on a QEMU
|
2013-04-16 02:27:16 +02:00
|
|
|
* timer will work.
|
2020-09-10 09:01:27 +02:00
|
|
|
* @obj: Stream sink to push to
|
2013-04-16 02:27:16 +02:00
|
|
|
* @buf: Data to write
|
|
|
|
* @len: Maximum number of bytes to write
|
2020-05-06 10:25:09 +02:00
|
|
|
* @eop: End of packet flag
|
2013-04-16 02:27:16 +02:00
|
|
|
*/
|
2020-09-10 09:01:27 +02:00
|
|
|
size_t (*push)(StreamSink *obj, unsigned char *buf, size_t len, bool eop);
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2012-08-10 05:16:11 +02:00
|
|
|
|
2013-04-16 02:27:16 +02:00
|
|
|
size_t
|
2020-09-10 09:01:27 +02:00
|
|
|
stream_push(StreamSink *sink, uint8_t *buf, size_t len, bool eop);
|
2012-08-10 05:16:11 +02:00
|
|
|
|
2013-04-16 02:27:16 +02:00
|
|
|
bool
|
2020-09-10 09:01:27 +02:00
|
|
|
stream_can_push(StreamSink *sink, StreamCanPushNotifyFn notify,
|
2013-04-16 02:27:16 +02:00
|
|
|
void *notify_opaque);
|
|
|
|
|
|
|
|
|
2012-08-10 05:16:11 +02:00
|
|
|
#endif /* STREAM_H */
|