func (c *VirConnection) UnregisterCloseCallback() error { connData := getConnectionData(c) if connData.closeCallbackId == nil { return nil } callbackPtr := unsafe.Pointer(C.closeCallback_cgo) res := C.virConnectUnregisterCloseCallback(c.ptr, C.virConnectCloseFunc(callbackPtr)) if res != 0 { return GetLastError() } connData.closeCallbackId = nil return nil }
// Register a close callback for the given destination. Only one // callback per connection is allowed. Setting a callback will remove // the previous one. func (c *VirConnection) RegisterCloseCallback(cb CloseCallback, opaque func()) error { c.UnregisterCloseCallback() context := &closeContext{ cb: cb, f: opaque, } goCallbackId := registerCallbackId(context) callbackPtr := unsafe.Pointer(C.closeCallback_cgo) res := C.virConnectRegisterCloseCallback_cgo(c.ptr, C.virConnectCloseFunc(callbackPtr), C.long(goCallbackId)) if res != 0 { freeCallbackId(goCallbackId) return GetLastError() } connData := getConnectionData(c) connData.closeCallbackId = &goCallbackId return nil }