]> git.proxmox.com Git - qemu.git/commitdiff
qmp: add pull_event function
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 18 Oct 2012 14:49:29 +0000 (16:49 +0200)
committerKevin Wolf <kwolf@redhat.com>
Wed, 24 Oct 2012 08:26:22 +0000 (10:26 +0200)
This function is unlike get_events in that it makes it easy to process
one event at a time.  This is useful in the mirroring test cases, where
we want to process just one event (BLOCK_JOB_ERROR) and leave the others
to a helper function.

Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
QMP/qmp.py

index 32510a176a268d5a31398be834b27f467aec765c..c551df1ed7fec581c76d552540d83cd197e4fb5b 100644 (file)
@@ -136,6 +136,26 @@ class QEMUMonitorProtocol:
             raise Exception(ret['error']['desc'])
         return ret['return']
 
+    def pull_event(self, wait=False):
+        """
+        Get and delete the first available QMP event.
+
+        @param wait: block until an event is available (bool)
+        """
+        self.__sock.setblocking(0)
+        try:
+            self.__json_read()
+        except socket.error, err:
+            if err[0] == errno.EAGAIN:
+                # No data available
+                pass
+        self.__sock.setblocking(1)
+        if not self.__events and wait:
+            self.__json_read(only_event=True)
+        event = self.__events[0]
+        del self.__events[0]
+        return event
+
     def get_events(self, wait=False):
         """
         Get a list of available QMP events.