qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: aliguori@us.ibm.com
Cc: qemu-devel@nongnu.org,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	armbru@redhat.com
Subject: [Qemu-devel] [PATCH 4/5] QMP: add get_events(wait=True) option
Date: Wed,  1 Jun 2011 12:54:04 -0300	[thread overview]
Message-ID: <1306943645-20313-5-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1306943645-20313-1-git-send-email-lcapitulino@redhat.com>

From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

The get_events() function polls for new QMP events and then returns.  It
can be useful to wait for the next QMP event so add the boolean 'wait'
keyword argument.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 QMP/qmp.py |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/QMP/qmp.py b/QMP/qmp.py
index 14ce8b0..2565508 100644
--- a/QMP/qmp.py
+++ b/QMP/qmp.py
@@ -43,7 +43,7 @@ class QEMUMonitorProtocol:
             family = socket.AF_UNIX
         return socket.socket(family, socket.SOCK_STREAM)
 
-    def __json_read(self):
+    def __json_read(self, only_event=False):
         while True:
             data = self.__sockfile.readline()
             if not data:
@@ -51,7 +51,8 @@ class QEMUMonitorProtocol:
             resp = json.loads(data)
             if 'event' in resp:
                 self.__events.append(resp)
-                continue
+                if not only_event:
+                    continue
             return resp
 
     error = socket.error
@@ -106,9 +107,11 @@ class QEMUMonitorProtocol:
             qmp_cmd['id'] = id
         return self.cmd_obj(qmp_cmd)
 
-    def get_events(self):
+    def get_events(self, wait=False):
         """
         Get a list of available QMP events.
+
+        @param wait: block until an event is available (bool)
         """
         self.__sock.setblocking(0)
         try:
@@ -118,6 +121,8 @@ class QEMUMonitorProtocol:
                 # No data available
                 pass
         self.__sock.setblocking(1)
+        if not self.__events and wait:
+            self.__json_read(only_event=True)
         return self.__events
 
     def clear_events(self):
-- 
1.7.4.4

  parent reply	other threads:[~2011-06-01 22:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-01 15:54 [Qemu-devel] [PULL 0/5]: Monitor queue Luiz Capitulino
2011-06-01 15:54 ` [Qemu-devel] [PATCH 1/5] QMP: QError: New QERR_UNSUPPORTED Luiz Capitulino
2011-06-01 15:54 ` [Qemu-devel] [PATCH 2/5] QMP: add inject-nmi qmp command Luiz Capitulino
2011-06-04  8:34   ` Blue Swirl
2011-06-06 14:17     ` Luiz Capitulino
2011-06-12 21:22       ` Blue Swirl
2011-06-01 15:54 ` [Qemu-devel] [PATCH 3/5] HMP: Use QMP inject nmi implementation Luiz Capitulino
2011-06-01 15:54 ` Luiz Capitulino [this message]
2011-06-01 15:54 ` [Qemu-devel] [PATCH 5/5] QMP: add server mode to QEMUMonitorProtocol Luiz Capitulino
2011-06-02  2:19   ` Brad Hards
2011-06-02  9:02     ` Daniel P. Berrange
2011-06-09 12:40 ` [Qemu-devel] [PULL 0/5]: Monitor queue Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1306943645-20313-5-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).