qemu/include/hw/stream.h
<<
>>
Prefs
   1#ifndef STREAM_H
   2#define STREAM_H
   3
   4#include "qemu-common.h"
   5#include "qom/object.h"
   6
   7/* stream slave. Used until qdev provides a generic way.  */
   8#define TYPE_STREAM_SLAVE "stream-slave"
   9
  10#define STREAM_SLAVE_CLASS(klass) \
  11     OBJECT_CLASS_CHECK(StreamSlaveClass, (klass), TYPE_STREAM_SLAVE)
  12#define STREAM_SLAVE_GET_CLASS(obj) \
  13    OBJECT_GET_CLASS(StreamSlaveClass, (obj), TYPE_STREAM_SLAVE)
  14#define STREAM_SLAVE(obj) \
  15     INTERFACE_CHECK(StreamSlave, (obj), TYPE_STREAM_SLAVE)
  16
  17#define STREAM_ATTR_EOP      (1 << 0)   /* Signal End-Of-Packet.  */
  18
  19typedef struct StreamSlave {
  20    Object Parent;
  21} StreamSlave;
  22
  23typedef void (*StreamCanPushNotifyFn)(void *opaque);
  24
  25typedef struct StreamSlaveClass {
  26    InterfaceClass parent;
  27    /**
  28     * can push - determine if a stream slave is capable of accepting at least
  29     * one byte of data. Returns false if cannot accept. If not implemented, the
  30     * slave is assumed to always be capable of receiving.
  31     * @notify: Optional callback that the slave will call when the slave is
  32     * capable of receiving again. Only called if false is returned.
  33     * @notify_opaque: opaque data to pass to notify call.
  34     */
  35    bool (*can_push)(StreamSlave *obj, StreamCanPushNotifyFn notify,
  36                     void *notify_opaque);
  37    /**
  38     * push - push data to a Stream slave. The number of bytes pushed is
  39     * returned. If the slave short returns, the master must wait before trying
  40     * again, the slave may continue to just return 0 waiting for the vm time to
  41     * advance. The can_push() function can be used to trap the point in time
  42     * where the slave is ready to receive again, otherwise polling on a QEMU
  43     * timer will work.
  44     * @obj: Stream slave to push to
  45     * @buf: Data to write
  46     * @len: Maximum number of bytes to write
  47     * @attr: Attributes.
  48     */
  49    size_t (*push)(StreamSlave *obj, unsigned char *buf, size_t len,
  50                   uint32_t attr);
  51} StreamSlaveClass;
  52
  53size_t
  54stream_push(StreamSlave *sink, uint8_t *buf, size_t len, uint32_t attr);
  55
  56bool
  57stream_can_push(StreamSlave *sink, StreamCanPushNotifyFn notify,
  58                void *notify_opaque);
  59
  60static inline bool stream_attr_has_eop(uint32_t attr)
  61{
  62    return (attr & STREAM_ATTR_EOP) != 0;
  63}
  64
  65
  66#endif /* STREAM_H */
  67