2012-08-10 07:16:11 +04:00
|
|
|
#ifndef STREAM_H
|
2016-06-29 16:29:06 +03:00
|
|
|
#define STREAM_H
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2012-12-17 21:19:50 +04:00
|
|
|
#include "qom/object.h"
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2020-09-10 10:01:27 +03:00
|
|
|
#define TYPE_STREAM_SINK "stream-sink"
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2020-09-10 10:01:27 +03: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 07:16:11 +04:00
|
|
|
|
2020-09-10 10:01:27 +03:00
|
|
|
typedef struct StreamSink StreamSink;
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2013-04-16 04:27:16 +04:00
|
|
|
typedef void (*StreamCanPushNotifyFn)(void *opaque);
|
|
|
|
|
2020-09-10 10:01:27 +03:00
|
|
|
struct StreamSinkClass {
|
2012-08-10 07:16:11 +04:00
|
|
|
InterfaceClass parent;
|
2013-04-16 04:27:16 +04:00
|
|
|
/**
|
2020-09-10 10:01:27 +03:00
|
|
|
* can push - determine if a stream sink is capable of accepting at least
|
2013-04-16 04:27:16 +04:00
|
|
|
* one byte of data. Returns false if cannot accept. If not implemented, the
|
2020-09-10 10:01:27 +03: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 13:49:57 +04:00
|
|
|
* capable of receiving again. Only called if false is returned.
|
2013-04-16 04:27:16 +04:00
|
|
|
* @notify_opaque: opaque data to pass to notify call.
|
|
|
|
*/
|
2020-09-10 10:01:27 +03:00
|
|
|
bool (*can_push)(StreamSink *obj, StreamCanPushNotifyFn notify,
|
2013-04-16 04:27:16 +04:00
|
|
|
void *notify_opaque);
|
|
|
|
/**
|
2020-09-10 10:01:27 +03: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 04:27:16 +04:00
|
|
|
* advance. The can_push() function can be used to trap the point in time
|
2020-09-10 10:01:27 +03:00
|
|
|
* where the sink is ready to receive again, otherwise polling on a QEMU
|
2013-04-16 04:27:16 +04:00
|
|
|
* timer will work.
|
2020-09-10 10:01:27 +03:00
|
|
|
* @obj: Stream sink to push to
|
2013-04-16 04:27:16 +04:00
|
|
|
* @buf: Data to write
|
|
|
|
* @len: Maximum number of bytes to write
|
2020-05-06 11:25:09 +03:00
|
|
|
* @eop: End of packet flag
|
2013-04-16 04:27:16 +04:00
|
|
|
*/
|
2020-09-10 10:01:27 +03:00
|
|
|
size_t (*push)(StreamSink *obj, unsigned char *buf, size_t len, bool eop);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2013-04-16 04:27:16 +04:00
|
|
|
size_t
|
2020-09-10 10:01:27 +03:00
|
|
|
stream_push(StreamSink *sink, uint8_t *buf, size_t len, bool eop);
|
2012-08-10 07:16:11 +04:00
|
|
|
|
2013-04-16 04:27:16 +04:00
|
|
|
bool
|
2020-09-10 10:01:27 +03:00
|
|
|
stream_can_push(StreamSink *sink, StreamCanPushNotifyFn notify,
|
2013-04-16 04:27:16 +04:00
|
|
|
void *notify_opaque);
|
|
|
|
|
|
|
|
|
2012-08-10 07:16:11 +04:00
|
|
|
#endif /* STREAM_H */
|