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
,
65 QIOChannelNull
*nioc
= QIO_CHANNEL_NULL(ioc
);
68 error_setg_errno(errp
, EINVAL
,
78 qio_channel_null_writev(QIOChannel
*ioc
,
79 const struct iovec
*iov
,
81 int *fds G_GNUC_UNUSED
,
82 size_t nfds G_GNUC_UNUSED
,
83 int flags G_GNUC_UNUSED
,
86 QIOChannelNull
*nioc
= QIO_CHANNEL_NULL(ioc
);
89 error_setg_errno(errp
, EINVAL
,
94 return iov_size(iov
, niov
);
99 qio_channel_null_set_blocking(QIOChannel
*ioc G_GNUC_UNUSED
,
100 bool enabled G_GNUC_UNUSED
,
101 Error
**errp G_GNUC_UNUSED
)
108 qio_channel_null_seek(QIOChannel
*ioc G_GNUC_UNUSED
,
109 off_t offset G_GNUC_UNUSED
,
110 int whence G_GNUC_UNUSED
,
111 Error
**errp G_GNUC_UNUSED
)
118 qio_channel_null_close(QIOChannel
*ioc
,
119 Error
**errp G_GNUC_UNUSED
)
121 QIOChannelNull
*nioc
= QIO_CHANNEL_NULL(ioc
);
129 qio_channel_null_set_aio_fd_handler(QIOChannel
*ioc G_GNUC_UNUSED
,
130 AioContext
*ctx G_GNUC_UNUSED
,
131 IOHandler
*io_read G_GNUC_UNUSED
,
132 IOHandler
*io_write G_GNUC_UNUSED
,
133 void *opaque G_GNUC_UNUSED
)
139 qio_channel_null_source_prepare(GSource
*source G_GNUC_UNUSED
,
149 qio_channel_null_source_check(GSource
*source G_GNUC_UNUSED
)
156 qio_channel_null_source_dispatch(GSource
*source
,
157 GSourceFunc callback
,
160 QIOChannelFunc func
= (QIOChannelFunc
)callback
;
161 QIOChannelNullSource
*ssource
= (QIOChannelNullSource
*)source
;
163 return (*func
)(ssource
->ioc
,
170 qio_channel_null_source_finalize(GSource
*source
)
172 QIOChannelNullSource
*ssource
= (QIOChannelNullSource
*)source
;
174 object_unref(OBJECT(ssource
->ioc
));
178 GSourceFuncs qio_channel_null_source_funcs
= {
179 qio_channel_null_source_prepare
,
180 qio_channel_null_source_check
,
181 qio_channel_null_source_dispatch
,
182 qio_channel_null_source_finalize
187 qio_channel_null_create_watch(QIOChannel
*ioc
,
188 GIOCondition condition
)
191 QIOChannelNullSource
*ssource
;
193 source
= g_source_new(&qio_channel_null_source_funcs
,
194 sizeof(QIOChannelNullSource
));
195 ssource
= (QIOChannelNullSource
*)source
;
198 object_ref(OBJECT(ioc
));
200 ssource
->condition
= condition
;
207 qio_channel_null_class_init(ObjectClass
*klass
,
208 void *class_data G_GNUC_UNUSED
)
210 QIOChannelClass
*ioc_klass
= QIO_CHANNEL_CLASS(klass
);
212 ioc_klass
->io_writev
= qio_channel_null_writev
;
213 ioc_klass
->io_readv
= qio_channel_null_readv
;
214 ioc_klass
->io_set_blocking
= qio_channel_null_set_blocking
;
215 ioc_klass
->io_seek
= qio_channel_null_seek
;
216 ioc_klass
->io_close
= qio_channel_null_close
;
217 ioc_klass
->io_create_watch
= qio_channel_null_create_watch
;
218 ioc_klass
->io_set_aio_fd_handler
= qio_channel_null_set_aio_fd_handler
;
222 static const TypeInfo qio_channel_null_info
= {
223 .parent
= TYPE_QIO_CHANNEL
,
224 .name
= TYPE_QIO_CHANNEL_NULL
,
225 .instance_size
= sizeof(QIOChannelNull
),
226 .instance_init
= qio_channel_null_init
,
227 .class_init
= qio_channel_null_class_init
,
232 qio_channel_null_register_types(void)
234 type_register_static(&qio_channel_null_info
);
237 type_init(qio_channel_null_register_types
);