2
0

stream.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef STREAM_H
  2. #define STREAM_H
  3. #include "qom/object.h"
  4. #define TYPE_STREAM_SINK "stream-sink"
  5. typedef struct StreamSinkClass StreamSinkClass;
  6. DECLARE_CLASS_CHECKERS(StreamSinkClass, STREAM_SINK,
  7. TYPE_STREAM_SINK)
  8. #define STREAM_SINK(obj) \
  9. INTERFACE_CHECK(StreamSink, (obj), TYPE_STREAM_SINK)
  10. typedef struct StreamSink StreamSink;
  11. typedef void (*StreamCanPushNotifyFn)(void *opaque);
  12. struct StreamSinkClass {
  13. InterfaceClass parent;
  14. /**
  15. * can push - determine if a stream sink is capable of accepting at least
  16. * one byte of data. Returns false if cannot accept. If not implemented, the
  17. * sink is assumed to always be capable of receiving.
  18. * @notify: Optional callback that the sink will call when the sink is
  19. * capable of receiving again. Only called if false is returned.
  20. * @notify_opaque: opaque data to pass to notify call.
  21. */
  22. bool (*can_push)(StreamSink *obj, StreamCanPushNotifyFn notify,
  23. void *notify_opaque);
  24. /**
  25. * push - push data to a Stream sink. The number of bytes pushed is
  26. * returned. If the sink short returns, the master must wait before trying
  27. * again, the sink may continue to just return 0 waiting for the vm time to
  28. * advance. The can_push() function can be used to trap the point in time
  29. * where the sink is ready to receive again, otherwise polling on a QEMU
  30. * timer will work.
  31. * @obj: Stream sink to push to
  32. * @buf: Data to write
  33. * @len: Maximum number of bytes to write
  34. * @eop: End of packet flag
  35. */
  36. size_t (*push)(StreamSink *obj, unsigned char *buf, size_t len, bool eop);
  37. };
  38. size_t
  39. stream_push(StreamSink *sink, uint8_t *buf, size_t len, bool eop);
  40. bool
  41. stream_can_push(StreamSink *sink, StreamCanPushNotifyFn notify,
  42. void *notify_opaque);
  43. #endif /* STREAM_H */