2 * This file is part of the libvirt-go project
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * Copyright (c) 2013 Alex Zorin
23 * Copyright (C) 2016 Red Hat, Inc.
35 #cgo pkg-config: libvirt
36 #include "secret_events_wrapper.h"
40 type SecretEventLifecycle struct {
41 Event SecretEventLifecycleType
42 // TODO: we can make Detail typesafe somehow ?
46 type SecretEventLifecycleCallback func(c *Connect, n *Secret, event *SecretEventLifecycle)
48 type SecretEventGenericCallback func(c *Connect, n *Secret)
50 //export secretEventLifecycleCallback
51 func secretEventLifecycleCallback(c C.virConnectPtr, n C.virSecretPtr,
52 event int, detail int,
55 secret := &Secret{ptr: n}
56 connection := &Connect{ptr: c}
58 eventDetails := &SecretEventLifecycle{
59 Event: SecretEventLifecycleType(event),
63 callbackFunc := getCallbackId(goCallbackId)
64 callback, ok := callbackFunc.(SecretEventLifecycleCallback)
66 panic("Inappropriate callback type called")
68 callback(connection, secret, eventDetails)
71 //export secretEventGenericCallback
72 func secretEventGenericCallback(c C.virConnectPtr, n C.virSecretPtr,
75 secret := &Secret{ptr: n}
76 connection := &Connect{ptr: c}
78 callbackFunc := getCallbackId(goCallbackId)
79 callback, ok := callbackFunc.(SecretEventGenericCallback)
81 panic("Inappropriate callback type called")
83 callback(connection, secret)
86 func (c *Connect) SecretEventLifecycleRegister(secret *Secret, callback SecretEventLifecycleCallback) (int, error) {
87 goCallBackId := registerCallbackId(callback)
88 if C.LIBVIR_VERSION_NUMBER < 3000000 {
89 return 0, makeNotImplementedError("virConnectSecretEventRegisterAny")
92 callbackPtr := unsafe.Pointer(C.secretEventLifecycleCallbackHelper)
93 var csecret C.virSecretPtr
98 ret := C.virConnectSecretEventRegisterAnyWrapper(c.ptr, csecret,
99 C.VIR_SECRET_EVENT_ID_LIFECYCLE,
100 C.virConnectSecretEventGenericCallback(callbackPtr),
101 C.long(goCallBackId), &err)
103 freeCallbackId(goCallBackId)
104 return 0, makeError(&err)
109 func (c *Connect) SecretEventValueChangedRegister(secret *Secret, callback SecretEventGenericCallback) (int, error) {
110 goCallBackId := registerCallbackId(callback)
111 if C.LIBVIR_VERSION_NUMBER < 3000000 {
112 return 0, makeNotImplementedError("virConnectSecretEventRegisterAny")
115 callbackPtr := unsafe.Pointer(C.secretEventGenericCallbackHelper)
116 var csecret C.virSecretPtr
121 ret := C.virConnectSecretEventRegisterAnyWrapper(c.ptr, csecret,
122 C.VIR_SECRET_EVENT_ID_VALUE_CHANGED,
123 C.virConnectSecretEventGenericCallback(callbackPtr),
124 C.long(goCallBackId), &err)
126 freeCallbackId(goCallBackId)
127 return 0, makeError(&err)
132 func (c *Connect) SecretEventDeregister(callbackId int) error {
133 if C.LIBVIR_VERSION_NUMBER < 3000000 {
134 return makeNotImplementedError("virConnectSecretEventDeregisterAny")
136 // Deregister the callback
138 ret := int(C.virConnectSecretEventDeregisterAnyWrapper(c.ptr, C.int(callbackId), &err))
140 return makeError(&err)
145 func (e SecretEventLifecycle) String() string {
148 case SECRET_EVENT_DEFINED:
151 case SECRET_EVENT_UNDEFINED:
158 return fmt.Sprintf("Secret event=%q", event)