forked from rgbkrk/libvirt-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
321 lines (253 loc) · 7.62 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
package libvirt
import (
"unsafe"
)
/*
#cgo LDFLAGS: -lvirt -ldl
#include <libvirt/libvirt.h>
*/
import "C"
type DomainLifecycleEvent struct {
Event int
Detail int
}
type DomainRTCChangeEvent struct {
Utcoffset int64
}
type DomainWatchdogEvent struct {
Action int
}
type DomainIOErrorEvent struct {
SrcPath string
DevAlias string
Action int
}
type DomainEventGraphicsAddress struct {
Family int
Node string
Service string
}
type DomainEventGraphicsSubjectIdentity struct {
Type string
Name string
}
type DomainGraphicsEvent struct {
Phase int
Local DomainEventGraphicsAddress
Remote DomainEventGraphicsAddress
AuthScheme string
Subject []DomainEventGraphicsSubjectIdentity
}
type DomainIOErrorReasonEvent struct {
DomainIOErrorEvent
Reason string
}
type DomainBlockJobEvent struct {
Disk string
Type int
Status int
}
type DomainDiskChangeEvent struct {
OldSrcPath string
NewSrcPath string
DevAlias string
Reason int
}
type DomainTrayChangeEvent struct {
DevAlias string
Reason int
}
type DomainReasonEvent struct {
Reason int
}
type DomainBalloonChangeEvent struct {
Actual uint64
}
type DomainDeviceRemovedEvent struct {
DevAlias string
}
//export domainEventLifecycleCallback
func domainEventLifecycleCallback(c C.virConnectPtr, d C.virDomainPtr,
event int, detail int,
opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainLifecycleEvent{
Event: event,
Detail: detail,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventGenericCallback
func domainEventGenericCallback(c C.virConnectPtr, d C.virDomainPtr,
opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
return (*context.cb)(&connection, &domain, nil, context.f)
}
//export domainEventRTCChangeCallback
func domainEventRTCChangeCallback(c C.virConnectPtr, d C.virDomainPtr,
utcoffset int64, opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainRTCChangeEvent{
Utcoffset: utcoffset,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventWatchdogCallback
func domainEventWatchdogCallback(c C.virConnectPtr, d C.virDomainPtr,
action int, opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainWatchdogEvent{
Action: action,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventIOErrorCallback
func domainEventIOErrorCallback(c C.virConnectPtr, d C.virDomainPtr,
srcPath string, devAlias string, action int, opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainIOErrorEvent{
SrcPath: srcPath,
DevAlias: devAlias,
Action: action,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventGraphicsCallback
func domainEventGraphicsCallback(c C.virConnectPtr, d C.virDomainPtr,
phase int,
local C.virDomainEventGraphicsAddressPtr,
remote C.virDomainEventGraphicsAddressPtr,
authScheme string,
subject C.virDomainEventGraphicsSubjectPtr,
opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
subjectGo := make([]DomainEventGraphicsSubjectIdentity, subject.nidentity)
nidentities := int(subject.nidentity)
identities := (*[1 << 30]C.virDomainEventGraphicsSubjectIdentity)(unsafe.Pointer(&subject.identities))[:nidentities:nidentities]
for _, identity := range identities {
subjectGo = append(subjectGo,
DomainEventGraphicsSubjectIdentity{
Type: C.GoString(identity._type),
Name: C.GoString(identity.name),
},
)
}
eventDetails := DomainGraphicsEvent{
Phase: phase,
Local: DomainEventGraphicsAddress{
Family: int(local.family),
Node: C.GoString(local.node),
Service: C.GoString(local.service),
},
Remote: DomainEventGraphicsAddress{
Family: int(remote.family),
Node: C.GoString(remote.node),
Service: C.GoString(remote.service),
},
AuthScheme: authScheme,
Subject: subjectGo,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventIOErrorReasonCallback
func domainEventIOErrorReasonCallback(c C.virConnectPtr, d C.virDomainPtr,
srcPath string, devAlias string, action int, reason string,
opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainIOErrorReasonEvent{
DomainIOErrorEvent: DomainIOErrorEvent{
SrcPath: srcPath,
DevAlias: devAlias,
Action: action,
},
Reason: reason,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventBlockJobCallback
func domainEventBlockJobCallback(c C.virConnectPtr, d C.virDomainPtr,
disk string, _type int, status int, opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainBlockJobEvent{
Disk: disk,
Type: _type,
Status: status,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventDiskChangeCallback
func domainEventDiskChangeCallback(c C.virConnectPtr, d C.virDomainPtr,
oldSrcPath string, newSrcPath string, devAlias string,
reason int, opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainDiskChangeEvent{
OldSrcPath: oldSrcPath,
NewSrcPath: newSrcPath,
DevAlias: devAlias,
Reason: reason,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventTrayChangeCallback
func domainEventTrayChangeCallback(c C.virConnectPtr, d C.virDomainPtr,
devAlias string, reason int, opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainTrayChangeEvent{
DevAlias: devAlias,
Reason: reason,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventReasonCallback
func domainEventReasonCallback(c C.virConnectPtr, d C.virDomainPtr,
reason int, opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainReasonEvent{
Reason: reason,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventBalloonChangeCallback
func domainEventBalloonChangeCallback(c C.virConnectPtr, d C.virDomainPtr,
actual uint64, opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainBalloonChangeEvent{
Actual: actual,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}
//export domainEventDeviceRemovedCallback
func domainEventDeviceRemovedCallback(c C.virConnectPtr, d C.virDomainPtr,
devAlias string, opaque unsafe.Pointer) int {
context := *(*domainCallbackContext)(opaque)
domain := VirDomain{ptr: d}
connection := VirConnection{ptr: c}
eventDetails := DomainDeviceRemovedEvent{
DevAlias: devAlias,
}
return (*context.cb)(&connection, &domain, eventDetails, context.f)
}