Merge remote-tracking branch 'remotes/berrange/tags/pull-io-channel-vnc-2015-12-18...
[qemu/ar7.git] / backends / rng.c
blob5065fdc1550b52ae432ab1bfa154536feaecedce
1 /*
2 * QEMU Random Number Generator Backend
4 * Copyright IBM, Corp. 2012
6 * Authors:
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.
13 #include "sysemu/rng.h"
14 #include "qapi/qmp/qerror.h"
15 #include "qom/object_interfaces.h"
17 void rng_backend_request_entropy(RngBackend *s, size_t size,
18 EntropyReceiveFunc *receive_entropy,
19 void *opaque)
21 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
23 if (k->request_entropy) {
24 k->request_entropy(s, size, receive_entropy, opaque);
28 void rng_backend_cancel_requests(RngBackend *s)
30 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
32 if (k->cancel_requests) {
33 k->cancel_requests(s);
37 static bool rng_backend_prop_get_opened(Object *obj, Error **errp)
39 RngBackend *s = RNG_BACKEND(obj);
41 return s->opened;
44 static void rng_backend_complete(UserCreatable *uc, Error **errp)
46 object_property_set_bool(OBJECT(uc), true, "opened", errp);
49 static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
51 RngBackend *s = RNG_BACKEND(obj);
52 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
53 Error *local_err = NULL;
55 if (value == s->opened) {
56 return;
59 if (!value && s->opened) {
60 error_setg(errp, QERR_PERMISSION_DENIED);
61 return;
64 if (k->opened) {
65 k->opened(s, &local_err);
66 if (local_err) {
67 error_propagate(errp, local_err);
68 return;
72 s->opened = true;
75 static void rng_backend_init(Object *obj)
77 object_property_add_bool(obj, "opened",
78 rng_backend_prop_get_opened,
79 rng_backend_prop_set_opened,
80 NULL);
83 static void rng_backend_class_init(ObjectClass *oc, void *data)
85 UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
87 ucc->complete = rng_backend_complete;
90 static const TypeInfo rng_backend_info = {
91 .name = TYPE_RNG_BACKEND,
92 .parent = TYPE_OBJECT,
93 .instance_size = sizeof(RngBackend),
94 .instance_init = rng_backend_init,
95 .class_size = sizeof(RngBackendClass),
96 .class_init = rng_backend_class_init,
97 .abstract = true,
98 .interfaces = (InterfaceInfo[]) {
99 { TYPE_USER_CREATABLE },
104 static void register_types(void)
106 type_register_static(&rng_backend_info);
109 type_init(register_types);