diff options
| author | Richard Purdie <richard@openedhand.com> | 2008-09-30 15:08:33 +0000 |
|---|---|---|
| committer | Richard Purdie <richard@openedhand.com> | 2008-09-30 15:08:33 +0000 |
| commit | c30eddb243e7e65f67f656e62848a033cf6f2e5c (patch) | |
| tree | 110dd95788b76f55d31cb8d30aac2de8400b6f4a /bitbake-dev/lib/bb/ui/uievent.py | |
| parent | 5ef0510474004eeb2ae8a99b64e2febb1920e077 (diff) | |
| download | poky-c30eddb243e7e65f67f656e62848a033cf6f2e5c.tar.gz | |
Add bitbake-dev to allow ease of testing and development of bitbake trunk
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@5337 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake-dev/lib/bb/ui/uievent.py')
| -rw-r--r-- | bitbake-dev/lib/bb/ui/uievent.py | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/ui/uievent.py b/bitbake-dev/lib/bb/ui/uievent.py new file mode 100644 index 0000000000..9d724d7fc5 --- /dev/null +++ b/bitbake-dev/lib/bb/ui/uievent.py | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | # | ||
| 4 | # Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer | ||
| 5 | # Copyright (C) 2006 - 2007 Richard Purdie | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License version 2 as | ||
| 9 | # published by the Free Software Foundation. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | |||
| 20 | |||
| 21 | """ | ||
| 22 | Use this class to fork off a thread to recieve event callbacks from the bitbake | ||
| 23 | server and queue them for the UI to process. This process must be used to avoid | ||
| 24 | client/server deadlocks. | ||
| 25 | """ | ||
| 26 | |||
| 27 | import sys, socket, threading | ||
| 28 | from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler | ||
| 29 | |||
| 30 | class BBUIEventQueue: | ||
| 31 | def __init__(self, BBServer): | ||
| 32 | |||
| 33 | self.eventQueue = [] | ||
| 34 | self.eventQueueLock = threading.Lock() | ||
| 35 | self.eventQueueNotify = threading.Event() | ||
| 36 | |||
| 37 | self.BBServer = BBServer | ||
| 38 | |||
| 39 | self.t = threading.Thread() | ||
| 40 | self.t.setDaemon(True) | ||
| 41 | self.t.run = self.startCallbackHandler | ||
| 42 | self.t.start() | ||
| 43 | |||
| 44 | def getEvent(self): | ||
| 45 | |||
| 46 | self.eventQueueLock.acquire() | ||
| 47 | |||
| 48 | if len(self.eventQueue) == 0: | ||
| 49 | self.eventQueueLock.release() | ||
| 50 | return None | ||
| 51 | |||
| 52 | item = self.eventQueue.pop(0) | ||
| 53 | |||
| 54 | if len(self.eventQueue) == 0: | ||
| 55 | self.eventQueueNotify.clear() | ||
| 56 | |||
| 57 | self.eventQueueLock.release() | ||
| 58 | |||
| 59 | return item | ||
| 60 | |||
| 61 | def waitEvent(self, delay): | ||
| 62 | self.eventQueueNotify.wait(delay) | ||
| 63 | return self.getEvent() | ||
| 64 | |||
| 65 | def queue_event(self, event): | ||
| 66 | |||
| 67 | self.eventQueueLock.acquire() | ||
| 68 | self.eventQueue.append(event) | ||
| 69 | self.eventQueueNotify.set() | ||
| 70 | self.eventQueueLock.release() | ||
| 71 | |||
| 72 | def startCallbackHandler(self): | ||
| 73 | |||
| 74 | server = UIXMLRPCServer() | ||
| 75 | self.host, self.port = server.socket.getsockname() | ||
| 76 | |||
| 77 | server.register_function( self.system_quit, "event.quit" ) | ||
| 78 | server.register_function( self.queue_event, "event.send" ) | ||
| 79 | server.socket.settimeout(1) | ||
| 80 | |||
| 81 | self.EventHandle = self.BBServer.registerEventHandler(self.host, self.port) | ||
| 82 | |||
| 83 | self.server = server | ||
| 84 | while not server.quit: | ||
| 85 | server.handle_request() | ||
| 86 | server.server_close() | ||
| 87 | |||
| 88 | def system_quit( self ): | ||
| 89 | """ | ||
| 90 | Shut down the callback thread | ||
| 91 | """ | ||
| 92 | try: | ||
| 93 | self.BBServer.unregisterEventHandler(self.EventHandle) | ||
| 94 | except: | ||
| 95 | pass | ||
| 96 | self.server.quit = True | ||
| 97 | |||
| 98 | class UIXMLRPCServer (SimpleXMLRPCServer): | ||
| 99 | |||
| 100 | def __init__( self, interface = ("localhost", 0) ): | ||
| 101 | self.quit = False | ||
| 102 | SimpleXMLRPCServer.__init__( self, | ||
| 103 | interface, | ||
| 104 | requestHandler=SimpleXMLRPCRequestHandler, | ||
| 105 | logRequests=False, allow_none=True) | ||
| 106 | |||
| 107 | def get_request(self): | ||
| 108 | while not self.quit: | ||
| 109 | try: | ||
| 110 | sock, addr = self.socket.accept() | ||
| 111 | sock.settimeout(1) | ||
| 112 | return (sock, addr) | ||
| 113 | except socket.timeout: | ||
| 114 | pass | ||
| 115 | return (None,None) | ||
| 116 | |||
| 117 | def close_request(self, request): | ||
| 118 | if request is None: | ||
| 119 | return | ||
| 120 | SimpleXMLRPCServer.close_request(self, request) | ||
| 121 | |||
| 122 | def process_request(self, request, client_address): | ||
| 123 | if request is None: | ||
| 124 | return | ||
| 125 | SimpleXMLRPCServer.process_request(self, request, client_address) | ||
| 126 | |||
| 127 | |||
