qemu/include/io/channel-buffer.h
<<
>>
Prefs
   1/*
   2 * QEMU I/O channels memory buffer driver
   3 *
   4 * Copyright (c) 2015 Red Hat, Inc.
   5 *
   6 * This library is free software; you can redistribute it and/or
   7 * modify it under the terms of the GNU Lesser General Public
   8 * License as published by the Free Software Foundation; either
   9 * version 2 of the License, or (at your option) any later version.
  10 *
  11 * This library is distributed in the hope that it will be useful,
  12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14 * Lesser General Public License for more details.
  15 *
  16 * You should have received a copy of the GNU Lesser General Public
  17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18 *
  19 */
  20
  21#ifndef QIO_CHANNEL_BUFFER_H__
  22#define QIO_CHANNEL_BUFFER_H__
  23
  24#include "io/channel.h"
  25
  26#define TYPE_QIO_CHANNEL_BUFFER "qio-channel-buffer"
  27#define QIO_CHANNEL_BUFFER(obj)                                     \
  28    OBJECT_CHECK(QIOChannelBuffer, (obj), TYPE_QIO_CHANNEL_BUFFER)
  29
  30typedef struct QIOChannelBuffer QIOChannelBuffer;
  31
  32/**
  33 * QIOChannelBuffer:
  34 *
  35 * The QIOChannelBuffer object provides a channel implementation
  36 * that is able to perform I/O to/from a memory buffer.
  37 *
  38 */
  39
  40struct QIOChannelBuffer {
  41    QIOChannel parent;
  42    size_t capacity; /* Total allocated memory */
  43    size_t usage;    /* Current size of data */
  44    size_t offset;   /* Offset for future I/O ops */
  45    uint8_t *data;
  46};
  47
  48
  49/**
  50 * qio_channel_buffer_new:
  51 * @capacity: the initial buffer capacity to allocate
  52 *
  53 * Allocate a new buffer which is initially empty
  54 *
  55 * Returns: the new channel object
  56 */
  57QIOChannelBuffer *
  58qio_channel_buffer_new(size_t capacity);
  59
  60#endif /* QIO_CHANNEL_BUFFER_H__ */
  61