2 * QEMU Random Number Generator Backend
4 * Copyright IBM, Corp. 2012
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 #include "qapi/qmp/qerror.h"
16 void rng_backend_request_entropy(RngBackend *s, size_t size,
17 EntropyReceiveFunc *receive_entropy,
20 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
22 if (k->request_entropy) {
23 k->request_entropy(s, size, receive_entropy, opaque);
27 void rng_backend_cancel_requests(RngBackend *s)
29 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
31 if (k->cancel_requests) {
32 k->cancel_requests(s);
36 static bool rng_backend_prop_get_opened(Object *obj, Error **errp)
38 RngBackend *s = RNG_BACKEND(obj);
43 void rng_backend_open(RngBackend *s, Error **errp)
45 object_property_set_bool(OBJECT(s), true, "opened", errp);
48 static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
50 RngBackend *s = RNG_BACKEND(obj);
51 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
53 if (value == s->opened) {
57 if (!value && s->opened) {
58 error_set(errp, QERR_PERMISSION_DENIED);
66 if (!error_is_set(errp)) {
71 static void rng_backend_init(Object *obj)
73 object_property_add_bool(obj, "opened",
74 rng_backend_prop_get_opened,
75 rng_backend_prop_set_opened,
79 static const TypeInfo rng_backend_info = {
80 .name = TYPE_RNG_BACKEND,
81 .parent = TYPE_OBJECT,
82 .instance_size = sizeof(RngBackend),
83 .instance_init = rng_backend_init,
84 .class_size = sizeof(RngBackendClass),
88 static void register_types(void)
90 type_register_static(&rng_backend_info);
93 type_init(register_types);