[PATCH libvirt-python v2 06/22] event-test.py: Merge livecycle callbacks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Registering the same function twice using the old domainEventRegister()
interface would not work, as the function reference is used for
un-registering.

But it is not a problem with the new interface domainEventRegisterAn(),
as that returns a unique ID.

While at it also demonstrate the 'opaque' mechanism.

Signed-off-by: Philipp Hahn <hahn@xxxxxxxxxxxxx>
---
 examples/event-test.py | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index ab1da4a..2dcdee3 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -499,15 +499,11 @@ def agentLifecycleReasonToString(reason):
     agentReasons = ( "unknown", "domain started", "channel event", )
     return agentReasons[reason]
 
-def myDomainEventCallback1 (conn, dom, event, detail, opaque):
-    print("myDomainEventCallback1 EVENT: Domain %s(%s) %s %s" % (dom.name(), dom.ID(),
-                                                                 domEventToString(event),
-                                                                 domDetailToString(event, detail)))
 
-def myDomainEventCallback2 (conn, dom, event, detail, opaque):
-    print("myDomainEventCallback2 EVENT: Domain %s(%s) %s %s" % (dom.name(), dom.ID(),
-                                                                 domEventToString(event),
-                                                                 domDetailToString(event, detail)))
+def myDomainEventCallback(conn, dom, event, detail, opaque):
+    print("myDomainEventCallback%d EVENT: Domain %s(%s) %s %s" % (
+        opaque, dom.name(), dom.ID(), domEventToString(event), domDetailToString(event, detail)))
+
 
 def myDomainEventRebootCallback(conn, dom, opaque):
     print("myDomainEventRebootCallback: Domain %s(%s)" % (dom.name(), dom.ID()))
@@ -725,9 +721,9 @@ def main():
     vc.registerCloseCallback(myConnectionCloseCallback, None)
 
     #Add 2 lifecycle callbacks to prove this works with more than just one
-    vc.domainEventRegister(myDomainEventCallback1,None)
+    vc.domainEventRegister(myDomainEventCallback, 1)
     domcallbacks = []
-    domcallbacks.append(vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, myDomainEventCallback2, None))
+    domcallbacks.append(vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, myDomainEventCallback, 2))
     domcallbacks.append(vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_REBOOT, myDomainEventRebootCallback, None))
     domcallbacks.append(vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_RTC_CHANGE, myDomainEventRTCChangeCallback, None))
     domcallbacks.append(vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG, myDomainEventWatchdogCallback, None))
@@ -784,7 +780,7 @@ def main():
     if not run:
         return
 
-    vc.domainEventDeregister(myDomainEventCallback1)
+    vc.domainEventDeregister(myDomainEventCallback)
 
     for id in seccallbacks:
         vc.secretEventDeregisterAny(id)
-- 
2.11.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux