2 * QEMU I/O channels null driver
4 * Copyright (c) 2022 Red Hat, Inc.
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.1 of the License, or (at your option) any later version.
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.
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/>.
21 #include "qemu/osdep.h"
22 #include "io/channel-null.h"
23 #include "io/channel-watch.h"
24 #include "qapi/error.h"
28 typedef struct QIOChannelNullSource QIOChannelNullSource;
29 struct QIOChannelNullSource {
32 GIOCondition condition;
37 qio_channel_null_new(void)
41 ioc = QIO_CHANNEL_NULL(object_new(TYPE_QIO_CHANNEL_NULL));
43 trace_qio_channel_null_new(ioc);
50 qio_channel_null_init(Object *obj)
52 QIOChannelNull *ioc = QIO_CHANNEL_NULL(obj);
58 qio_channel_null_readv(QIOChannel *ioc,
59 const struct iovec *iov,
61 int **fds G_GNUC_UNUSED,
62 size_t *nfds G_GNUC_UNUSED,
66 QIOChannelNull *nioc = QIO_CHANNEL_NULL(ioc);
69 error_setg_errno(errp, EINVAL,
79 qio_channel_null_writev(QIOChannel *ioc,
80 const struct iovec *iov,
82 int *fds G_GNUC_UNUSED,
83 size_t nfds G_GNUC_UNUSED,
84 int flags G_GNUC_UNUSED,
87 QIOChannelNull *nioc = QIO_CHANNEL_NULL(ioc);
90 error_setg_errno(errp, EINVAL,
95 return iov_size(iov, niov);
100 qio_channel_null_set_blocking(QIOChannel *ioc G_GNUC_UNUSED,
101 bool enabled G_GNUC_UNUSED,
102 Error **errp G_GNUC_UNUSED)
109 qio_channel_null_seek(QIOChannel *ioc G_GNUC_UNUSED,
110 off_t offset G_GNUC_UNUSED,
111 int whence G_GNUC_UNUSED,
112 Error **errp G_GNUC_UNUSED)
119 qio_channel_null_close(QIOChannel *ioc,
120 Error **errp G_GNUC_UNUSED)
122 QIOChannelNull *nioc = QIO_CHANNEL_NULL(ioc);
130 qio_channel_null_set_aio_fd_handler(QIOChannel *ioc G_GNUC_UNUSED,
131 AioContext *read_ctx G_GNUC_UNUSED,
132 IOHandler *io_read G_GNUC_UNUSED,
133 AioContext *write_ctx G_GNUC_UNUSED,
134 IOHandler *io_write G_GNUC_UNUSED,
135 void *opaque G_GNUC_UNUSED)
141 qio_channel_null_source_prepare(GSource *source G_GNUC_UNUSED,
151 qio_channel_null_source_check(GSource *source G_GNUC_UNUSED)
158 qio_channel_null_source_dispatch(GSource *source,
159 GSourceFunc callback,
162 QIOChannelFunc func = (QIOChannelFunc)callback;
163 QIOChannelNullSource *ssource = (QIOChannelNullSource *)source;
165 return (*func)(ssource->ioc,
172 qio_channel_null_source_finalize(GSource *source)
174 QIOChannelNullSource *ssource = (QIOChannelNullSource *)source;
176 object_unref(OBJECT(ssource->ioc));
180 GSourceFuncs qio_channel_null_source_funcs = {
181 qio_channel_null_source_prepare,
182 qio_channel_null_source_check,
183 qio_channel_null_source_dispatch,
184 qio_channel_null_source_finalize
189 qio_channel_null_create_watch(QIOChannel *ioc,
190 GIOCondition condition)
193 QIOChannelNullSource *ssource;
195 source = g_source_new(&qio_channel_null_source_funcs,
196 sizeof(QIOChannelNullSource));
197 ssource = (QIOChannelNullSource *)source;
200 object_ref(OBJECT(ioc));
202 ssource->condition = condition;
209 qio_channel_null_class_init(ObjectClass *klass,
210 void *class_data G_GNUC_UNUSED)
212 QIOChannelClass *ioc_klass = QIO_CHANNEL_CLASS(klass);
214 ioc_klass->io_writev = qio_channel_null_writev;
215 ioc_klass->io_readv = qio_channel_null_readv;
216 ioc_klass->io_set_blocking = qio_channel_null_set_blocking;
217 ioc_klass->io_seek = qio_channel_null_seek;
218 ioc_klass->io_close = qio_channel_null_close;
219 ioc_klass->io_create_watch = qio_channel_null_create_watch;
220 ioc_klass->io_set_aio_fd_handler = qio_channel_null_set_aio_fd_handler;
224 static const TypeInfo qio_channel_null_info = {
225 .parent = TYPE_QIO_CHANNEL,
226 .name = TYPE_QIO_CHANNEL_NULL,
227 .instance_size = sizeof(QIOChannelNull),
228 .instance_init = qio_channel_null_init,
229 .class_init = qio_channel_null_class_init,
234 qio_channel_null_register_types(void)
236 type_register_static(&qio_channel_null_info);
239 type_init(qio_channel_null_register_types);