Commit d434c373 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Add support for virConnectDomainQemuMonitorEvent APIs

Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent 47dd82a1
......@@ -38,6 +38,7 @@ package libvirt
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "qemu_compat.h"
#include "qemu_cfuncs.h"
*/
import "C"
......@@ -73,6 +74,13 @@ const (
DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN)
)
type DomainQemuMonitorEventFlags int
const (
CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX = DomainQemuMonitorEventFlags(C.VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX)
CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE = DomainQemuMonitorEventFlags(C.VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE)
)
func (d *Domain) QemuMonitorCommand(command string, flags DomainQemuMonitorCommandFlags) (string, error) {
var cResult *C.char
cCommand := C.CString(command)
......@@ -110,3 +118,65 @@ func (c *Connect) DomainQemuAttach(pid uint32, flags uint32) (*Domain, error) {
}
return &Domain{ptr: ptr}, nil
}
type DomainQemuMonitorEvent struct {
Event string
Seconds int64
Micros uint
Details string
}
type DomainQemuMonitorEventCallback func(c *Connect, d *Domain, event *DomainQemuMonitorEvent)
//export domainQemuMonitorEventCallback
func domainQemuMonitorEventCallback(c C.virConnectPtr, d C.virDomainPtr,
event *C.char, seconds C.longlong, micros C.uint, details *C.char, goCallbackId int) {
domain := &Domain{ptr: d}
connection := &Connect{ptr: c}
eventDetails := &DomainQemuMonitorEvent{
Event: C.GoString(event),
Seconds: int64(seconds),
Micros: uint(micros),
Details: C.GoString(details),
}
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(DomainQemuMonitorEventCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(connection, domain, eventDetails)
}
func (c *Connect) DomainQemuMonitorEventRegister(dom *Domain, event string, callback DomainQemuMonitorEventCallback, flags DomainQemuMonitorEventFlags) (int, error) {
cEvent := C.CString(event)
defer C.free(unsafe.Pointer(cEvent))
goCallBackId := registerCallbackId(callback)
callbackPtr := unsafe.Pointer(C.domainQemuMonitorEventCallback_cgo)
var cdom C.virDomainPtr
if dom != nil {
cdom = dom.ptr
}
ret := C.virConnectDomainQemuMonitorEventRegister_cgo(c.ptr, cdom,
cEvent,
C.virConnectDomainEventGenericCallback(callbackPtr),
C.long(goCallBackId),
C.uint(flags))
if ret == -1 {
freeCallbackId(goCallBackId)
return 0, GetLastError()
}
return int(ret), nil
}
func (c *Connect) DomainQemuEventDeregister(callbackId int) error {
// Deregister the callback
if i := int(C.virConnectDomainQemuMonitorEventDeregister(c.ptr, C.int(callbackId))); i != 0 {
return GetLastError()
}
return nil
}
/*
* This file is part of the libvirt-go project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Copyright (c) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
// Can't rely on pkg-config for libvirt-qemu since it was not
// installed until 2.6.0 onwards
#cgo LDFLAGS: -lvirt-qemu
#include <libvirt/libvirt.h>
#include <libvirt/libvirt-qemu.h>
#include <libvirt/virterror.h>
#include "qemu_cfuncs.h"
#include "callbacks_cfuncs.h"
#include <stdint.h>
extern void domainQemuMonitorEventCallback(virConnectPtr, virDomainPtr, const char *, long long, unsigned int, const char *, int);
void domainQemuMonitorEventCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *event, long long secs,
unsigned int micros, const char *details, void *data)
{
domainQemuMonitorEventCallback(c, d, event, secs, micros, details, (int)(intptr_t)data);
}
int virConnectDomainQemuMonitorEventRegister_cgo(virConnectPtr c, virDomainPtr d,
const char *event, virConnectDomainQemuMonitorEventCallback cb,
long goCallbackId, unsigned int flags) {
void* id = (void*)goCallbackId;
return virConnectDomainQemuMonitorEventRegister(c, d, event, cb, id, freeGoCallback_cgo, flags);
}
*/
import "C"
/*
* This file is part of the libvirt-go project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Copyright (c) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_DOMAIN_EVENTS_CFUNCS_H__
#define LIBVIRT_GO_DOMAIN_EVENTS_CFUNCS_H__
void domainQemuMonitorEventCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *event, long long secs,
unsigned int micros, const char *details, void *data);
int virConnectDomainQemuMonitorEventRegister_cgo(virConnectPtr c, virDomainPtr d,
const char *event, virConnectDomainQemuMonitorEventCallback cb,
long goCallbackId, unsigned int flags);
#endif /* LIBVIRT_GO_DOMAIN_EVENTS_CFUNCS_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment