From patchwork Wed Jun 1 15:54:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 98282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 69DE4B6F8F for ; Thu, 2 Jun 2011 08:20:33 +1000 (EST) Received: from localhost ([::1]:49129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRtmA-0004o1-0w for incoming@patchwork.ozlabs.org; Wed, 01 Jun 2011 18:20:30 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39670) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRtaB-0002l7-3F for qemu-devel@nongnu.org; Wed, 01 Jun 2011 18:08:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QRta8-0007IW-RD for qemu-devel@nongnu.org; Wed, 01 Jun 2011 18:08:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRnke-000711-30 for qemu-devel@nongnu.org; Wed, 01 Jun 2011 11:54:32 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p51FsUXi011977 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 1 Jun 2011 11:54:30 -0400 Received: from localhost (ovpn-113-123.phx2.redhat.com [10.3.113.123]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p51FsSr3032294; Wed, 1 Jun 2011 11:54:29 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Wed, 1 Jun 2011 12:54:04 -0300 Message-Id: <1306943645-20313-5-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1306943645-20313-1-git-send-email-lcapitulino@redhat.com> References: <1306943645-20313-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , armbru@redhat.com Subject: [Qemu-devel] [PATCH 4/5] QMP: add get_events(wait=True) option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stefan Hajnoczi 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 Signed-off-by: Luiz Capitulino --- 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):