1 | /* |
---|
2 | * Copyright (c) 2006-2007, XenSource Inc. |
---|
3 | * |
---|
4 | * This library is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU Lesser General Public |
---|
6 | * License as published by the Free Software Foundation; either |
---|
7 | * version 2.1 of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This library is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
12 | * Lesser General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU Lesser General Public |
---|
15 | * License along with this library; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | #include <stddef.h> |
---|
21 | #include <stdlib.h> |
---|
22 | |
---|
23 | #include "xen_event_operation_internal.h" |
---|
24 | #include "xen_internal.h" |
---|
25 | #include <xen/api/xen_common.h> |
---|
26 | #include <xen/api/xen_event.h> |
---|
27 | |
---|
28 | |
---|
29 | XEN_ALLOC(xen_event_record) |
---|
30 | XEN_SET_ALLOC_FREE(xen_event_record) |
---|
31 | |
---|
32 | |
---|
33 | static const struct_member xen_event_record_struct_members[] = |
---|
34 | { |
---|
35 | { .key = "id", |
---|
36 | .type = &abstract_type_int, |
---|
37 | .offset = offsetof(xen_event_record, id) }, |
---|
38 | { .key = "timestamp", |
---|
39 | .type = &abstract_type_datetime, |
---|
40 | .offset = offsetof(xen_event_record, timestamp) }, |
---|
41 | { .key = "class", |
---|
42 | .type = &abstract_type_string, |
---|
43 | .offset = offsetof(xen_event_record, class) }, |
---|
44 | { .key = "operation", |
---|
45 | .type = &xen_event_operation_abstract_type_, |
---|
46 | .offset = offsetof(xen_event_record, operation) }, |
---|
47 | { .key = "ref", |
---|
48 | .type = &abstract_type_string, |
---|
49 | .offset = offsetof(xen_event_record, ref) }, |
---|
50 | { .key = "obj_uuid", |
---|
51 | .type = &abstract_type_string, |
---|
52 | .offset = offsetof(xen_event_record, obj_uuid) } |
---|
53 | }; |
---|
54 | |
---|
55 | const abstract_type xen_event_record_abstract_type_ = |
---|
56 | { |
---|
57 | .typename = STRUCT, |
---|
58 | .struct_size = sizeof(xen_event_record), |
---|
59 | .member_count = |
---|
60 | sizeof(xen_event_record_struct_members) / sizeof(struct_member), |
---|
61 | .members = xen_event_record_struct_members |
---|
62 | }; |
---|
63 | |
---|
64 | |
---|
65 | const abstract_type xen_event_record_set_abstract_type_ = |
---|
66 | { |
---|
67 | .typename = SET, |
---|
68 | .child = &xen_event_record_abstract_type_ |
---|
69 | }; |
---|
70 | |
---|
71 | |
---|
72 | void |
---|
73 | xen_event_record_free(xen_event_record *record) |
---|
74 | { |
---|
75 | if (record == NULL) |
---|
76 | { |
---|
77 | return; |
---|
78 | } |
---|
79 | free(record->class); |
---|
80 | free(record->ref); |
---|
81 | free(record->obj_uuid); |
---|
82 | free(record); |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | bool |
---|
87 | xen_event_register(xen_session *session, struct xen_string_set *classes) |
---|
88 | { |
---|
89 | abstract_value param_values[] = |
---|
90 | { |
---|
91 | { .type = &abstract_type_string_set, |
---|
92 | .u.set_val = (arbitrary_set *)classes } |
---|
93 | }; |
---|
94 | |
---|
95 | xen_call_(session, "event.register", param_values, 1, NULL, NULL); |
---|
96 | return session->ok; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | bool |
---|
101 | xen_event_unregister(xen_session *session, struct xen_string_set *classes) |
---|
102 | { |
---|
103 | abstract_value param_values[] = |
---|
104 | { |
---|
105 | { .type = &abstract_type_string_set, |
---|
106 | .u.set_val = (arbitrary_set *)classes } |
---|
107 | }; |
---|
108 | |
---|
109 | xen_call_(session, "event.unregister", param_values, 1, NULL, NULL); |
---|
110 | return session->ok; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | bool |
---|
115 | xen_event_next(xen_session *session, struct xen_event_record_set **result) |
---|
116 | { |
---|
117 | |
---|
118 | abstract_type result_type = xen_event_record_set_abstract_type_; |
---|
119 | |
---|
120 | *result = NULL; |
---|
121 | xen_call_(session, "event.next", NULL, 0, &result_type, result); |
---|
122 | return session->ok; |
---|
123 | } |
---|