Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- storage_pool_events.go | 40 ++++++++++++++++++++++++++++++++++++++++ storage_pool_events_cfuncs.go | 7 +++++++ storage_pool_events_cfuncs.h | 2 ++ 3 files changed, 49 insertions(+) diff --git a/storage_pool_events.go b/storage_pool_events.go index 14f36cd..d9112d4 100644 --- a/storage_pool_events.go +++ b/storage_pool_events.go @@ -47,6 +47,8 @@ type StoragePoolEventLifecycle struct { type StoragePoolEventLifecycleCallback func(c *Connect, n *StoragePool, event *StoragePoolEventLifecycle) +type StoragePoolEventGenericCallback func(c *Connect, n *StoragePool) + //export storagePoolEventLifecycleCallback func storagePoolEventLifecycleCallback(c C.virConnectPtr, s C.virStoragePoolPtr, event int, detail int, @@ -68,6 +70,21 @@ func storagePoolEventLifecycleCallback(c C.virConnectPtr, s C.virStoragePoolPtr, callback(connection, storage_pool, eventDetails) } +//export storagePoolEventGenericCallback +func storagePoolEventGenericCallback(c C.virConnectPtr, s C.virStoragePoolPtr, + goCallbackId int) { + + storage_pool := &StoragePool{ptr: s} + connection := &Connect{ptr: c} + + callbackFunc := getCallbackId(goCallbackId) + callback, ok := callbackFunc.(StoragePoolEventGenericCallback) + if !ok { + panic("Inappropriate callback type called") + } + callback(connection, storage_pool) +} + func (c *Connect) StoragePoolEventLifecycleRegister(pool *StoragePool, callback StoragePoolEventLifecycleCallback) (int, error) { if C.LIBVIR_VERSION_NUMBER < 2000000 { return 0, GetNotImplementedError() @@ -91,6 +108,29 @@ func (c *Connect) StoragePoolEventLifecycleRegister(pool *StoragePool, callback return int(ret), nil } +func (c *Connect) StoragePoolEventRefreshRegister(pool *StoragePool, callback StoragePoolEventGenericCallback) (int, error) { + if C.LIBVIR_VERSION_NUMBER < 2000000 { + return 0, GetNotImplementedError() + } + + goCallBackId := registerCallbackId(callback) + + callbackPtr := unsafe.Pointer(C.storagePoolEventGenericCallback_cgo) + var cpool C.virStoragePoolPtr + if pool != nil { + cpool = pool.ptr + } + ret := C.virConnectStoragePoolEventRegisterAny_cgo(c.ptr, cpool, + C.VIR_STORAGE_POOL_EVENT_ID_REFRESH, + C.virConnectStoragePoolEventGenericCallback(callbackPtr), + C.long(goCallBackId)) + if ret == -1 { + freeCallbackId(goCallBackId) + return 0, GetLastError() + } + return int(ret), nil +} + func (c *Connect) StoragePoolEventDeregister(callbackId int) error { if C.LIBVIR_VERSION_NUMBER < 2000000 { return GetNotImplementedError() diff --git a/storage_pool_events_cfuncs.go b/storage_pool_events_cfuncs.go index 8b1ab10..52ec553 100644 --- a/storage_pool_events_cfuncs.go +++ b/storage_pool_events_cfuncs.go @@ -43,6 +43,13 @@ void storagePoolEventLifecycleCallback_cgo(virConnectPtr c, virStoragePoolPtr d, storagePoolEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data); } +extern void storagePoolEventGenericCallback(virConnectPtr, virStoragePoolPtr, int); +void storagePoolEventGenericCallback_cgo(virConnectPtr c, virStoragePoolPtr d, + void *data) +{ + storagePoolEventGenericCallback(c, d, (int)(intptr_t)data); +} + int virConnectStoragePoolEventRegisterAny_cgo(virConnectPtr c, virStoragePoolPtr d, int eventID, virConnectStoragePoolEventGenericCallback cb, long goCallbackId) { diff --git a/storage_pool_events_cfuncs.h b/storage_pool_events_cfuncs.h index faa209d..0087d6f 100644 --- a/storage_pool_events_cfuncs.h +++ b/storage_pool_events_cfuncs.h @@ -29,6 +29,8 @@ void storagePoolEventLifecycleCallback_cgo(virConnectPtr c, virStoragePoolPtr d, int event, int detail, void* data); +void storagePoolEventGenericCallback_cgo(virConnectPtr c, virStoragePoolPtr d, + void* data); int virConnectStoragePoolEventRegisterAny_cgo(virConnectPtr c, virStoragePoolPtr d, int eventID, virConnectStoragePoolEventGenericCallback cb, -- 2.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list