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
*ctx G_GNUC_UNUSED
,
132 IOHandler
*io_read G_GNUC_UNUSED
,
133 IOHandler
*io_write G_GNUC_UNUSED
,
134 void *opaque G_GNUC_UNUSED
)
140 qio_channel_null_source_prepare(GSource
*source G_GNUC_UNUSED
,
150 qio_channel_null_source_check(GSource
*source G_GNUC_UNUSED
)
157 qio_channel_null_source_dispatch(GSource
*source
,
158 GSourceFunc callback
,
161 QIOChannelFunc func
= (QIOChannelFunc
)callback
;
162 QIOChannelNullSource
*ssource
= (QIOChannelNullSource
*)source
;
164 return (*func
)(ssource
->ioc
,
171 qio_channel_null_source_finalize(GSource
*source
)
173 QIOChannelNullSource
*ssource
= (QIOChannelNullSource
*)source
;
175 object_unref(OBJECT(ssource
->ioc
));
179 GSourceFuncs qio_channel_null_source_funcs
= {
180 qio_channel_null_source_prepare
,
181 qio_channel_null_source_check
,
182 qio_channel_null_source_dispatch
,
183 qio_channel_null_source_finalize
188 qio_channel_null_create_watch(QIOChannel
*ioc
,
189 GIOCondition condition
)
192 QIOChannelNullSource
*ssource
;
194 source
= g_source_new(&qio_channel_null_source_funcs
,
195 sizeof(QIOChannelNullSource
));
196 ssource
= (QIOChannelNullSource
*)source
;
199 object_ref(OBJECT(ioc
));
201 ssource
->condition
= condition
;
208 qio_channel_null_class_init(ObjectClass
*klass
,
209 void *class_data G_GNUC_UNUSED
)
211 QIOChannelClass
*ioc_klass
= QIO_CHANNEL_CLASS(klass
);
213 ioc_klass
->io_writev
= qio_channel_null_writev
;
214 ioc_klass
->io_readv
= qio_channel_null_readv
;
215 ioc_klass
->io_set_blocking
= qio_channel_null_set_blocking
;
216 ioc_klass
->io_seek
= qio_channel_null_seek
;
217 ioc_klass
->io_close
= qio_channel_null_close
;
218 ioc_klass
->io_create_watch
= qio_channel_null_create_watch
;
219 ioc_klass
->io_set_aio_fd_handler
= qio_channel_null_set_aio_fd_handler
;
223 static const TypeInfo qio_channel_null_info
= {
224 .parent
= TYPE_QIO_CHANNEL
,
225 .name
= TYPE_QIO_CHANNEL_NULL
,
226 .instance_size
= sizeof(QIOChannelNull
),
227 .instance_init
= qio_channel_null_init
,
228 .class_init
= qio_channel_null_class_init
,
233 qio_channel_null_register_types(void)
235 type_register_static(&qio_channel_null_info
);
238 type_init(qio_channel_null_register_types
);