summaryrefslogtreecommitdiffstats
path: root/bitbake-dev/lib/bb/server/none.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake-dev/lib/bb/server/none.py')
-rw-r--r--bitbake-dev/lib/bb/server/none.py164
1 files changed, 100 insertions, 64 deletions
diff --git a/bitbake-dev/lib/bb/server/none.py b/bitbake-dev/lib/bb/server/none.py
index ef061bc5dd..ebda111582 100644
--- a/bitbake-dev/lib/bb/server/none.py
+++ b/bitbake-dev/lib/bb/server/none.py
@@ -1,5 +1,5 @@
1# 1#
2# BitBake XMLRPC Server 2# BitBake 'dummy' Passthrough Server
3# 3#
4# Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer 4# Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer
5# Copyright (C) 2006 - 2008 Richard Purdie 5# Copyright (C) 2006 - 2008 Richard Purdie
@@ -31,8 +31,11 @@
31 in the server's main loop. 31 in the server's main loop.
32""" 32"""
33 33
34import time
34import bb 35import bb
36from bb.ui import uievent
35import xmlrpclib 37import xmlrpclib
38import pickle
36 39
37DEBUG = False 40DEBUG = False
38 41
@@ -44,31 +47,19 @@ class BitBakeServerCommands():
44 self.cooker = cooker 47 self.cooker = cooker
45 self.server = server 48 self.server = server
46 49
47 def registerEventHandler(self, host, port):
48 """
49 Register a remote UI Event Handler
50 """
51 s = xmlrpclib.Server("http://%s:%d" % (host, port), allow_none=True)
52 return bb.event.register_UIHhandler(s)
53
54 def unregisterEventHandler(self, handlerNum):
55 """
56 Unregister a remote UI Event Handler
57 """
58 return bb.event.unregister_UIHhandler(handlerNum)
59
60 def runCommand(self, command): 50 def runCommand(self, command):
61 """ 51 """
62 Run a cooker command on the server 52 Run a cooker command on the server
63 """ 53 """
54 #print "Running Command %s" % command
64 return self.cooker.command.runCommand(command) 55 return self.cooker.command.runCommand(command)
65 56
66 def terminateServer(self): 57 def terminateServer(self):
67 """ 58 """
68 Trigger the server to quit 59 Trigger the server to quit
69 """ 60 """
70 self.server.quit = True 61 self.server.server_exit()
71 print "Server (cooker) exitting" 62 #print "Server (cooker) exitting"
72 return 63 return
73 64
74 def ping(self): 65 def ping(self):
@@ -77,63 +68,84 @@ class BitBakeServerCommands():
77 """ 68 """
78 return True 69 return True
79 70
80class BitBakeXMLRPCServer(SimpleXMLRPCServer): 71eventQueue = []
72
73class BBUIEventQueue:
74 class event:
75 def __init__(self, parent):
76 self.parent = parent
77 @staticmethod
78 def send(event):
79 bb.server.none.eventQueue.append(pickle.loads(event))
80 @staticmethod
81 def quit():
82 return
83
84 def __init__(self, BBServer):
85 self.eventQueue = bb.server.none.eventQueue
86 self.BBServer = BBServer
87 self.EventHandle = bb.event.register_UIHhandler(self)
88
89 def getEvent(self):
90 if len(self.eventQueue) == 0:
91 return None
92
93 return self.eventQueue.pop(0)
94
95 def waitEvent(self, delay):
96 event = self.getEvent()
97 if event:
98 return event
99 self.BBServer.idle_commands(delay)
100 return self.getEvent()
101
102 def queue_event(self, event):
103 self.eventQueue.append(event)
104
105 def system_quit( self ):
106 bb.event.unregister_UIHhandler(self.EventHandle)
107
108class BitBakeServer():
81 # remove this when you're done with debugging 109 # remove this when you're done with debugging
82 # allow_reuse_address = True 110 # allow_reuse_address = True
83 111
84 def __init__(self, cooker, interface = ("localhost", 0)): 112 def __init__(self, cooker):
85 """
86 Constructor
87 """
88 SimpleXMLRPCServer.__init__(self, interface,
89 requestHandler=SimpleXMLRPCRequestHandler,
90 logRequests=False, allow_none=True)
91 self._idlefuns = {} 113 self._idlefuns = {}
92 self.host, self.port = self.socket.getsockname() 114 self.commands = BitBakeServerCommands(self, cooker)
93 #self.register_introspection_functions()
94 commands = BitBakeServerCommands(self, cooker)
95 self.autoregister_all_functions(commands, "")
96
97 def autoregister_all_functions(self, context, prefix):
98 """
99 Convenience method for registering all functions in the scope
100 of this class that start with a common prefix
101 """
102 methodlist = inspect.getmembers(context, inspect.ismethod)
103 for name, method in methodlist:
104 if name.startswith(prefix):
105 self.register_function(method, name[len(prefix):])
106 115
107 def register_idle_function(self, function, data): 116 def register_idle_function(self, function, data):
108 """Register a function to be called while the server is idle""" 117 """Register a function to be called while the server is idle"""
109 assert callable(function) 118 assert callable(function)
110 self._idlefuns[function] = data 119 self._idlefuns[function] = data
111 120
112 def serve_forever(self): 121 def idle_commands(self, delay):
113 """ 122 #print "Idle queue length %s" % len(self._idlefuns)
114 Serve Requests. Overloaded to honor a quit command 123 #print "Idle timeout, running idle functions"
115 """ 124 #if len(self._idlefuns) == 0:
116 self.quit = False 125 nextsleep = delay
117 while not self.quit: 126 for function, data in self._idlefuns.items():
118 #print "Idle queue length %s" % len(self._idlefuns) 127 try:
119 if len(self._idlefuns) == 0: 128 retval = function(self, data, False)
120 self.timeout = None 129 #print "Idle function returned %s" % (retval)
121 else: 130 if retval is False:
122 self.timeout = 0 131 del self._idlefuns[function]
123 self.handle_request() 132 elif retval is True:
124 #print "Idle timeout, running idle functions" 133 nextsleep = None
125 for function, data in self._idlefuns.items(): 134 elif nextsleep is None:
126 try: 135 continue
127 retval = function(self, data, False) 136 elif retval < nextsleep:
128 if not retval: 137 nextsleep = retval
129 del self._idlefuns[function] 138 except SystemExit:
130 except SystemExit: 139 raise
131 raise 140 except:
132 except: 141 import traceback
133 import traceback 142 traceback.print_exc()
134 traceback.print_exc() 143 pass
135 pass 144 if nextsleep is not None:
145 #print "Sleeping for %s (%s)" % (nextsleep, delay)
146 time.sleep(nextsleep)
136 147
148 def server_exit(self):
137 # Tell idle functions we're exiting 149 # Tell idle functions we're exiting
138 for function, data in self._idlefuns.items(): 150 for function, data in self._idlefuns.items():
139 try: 151 try:
@@ -141,5 +153,29 @@ class BitBakeXMLRPCServer(SimpleXMLRPCServer):
141 except: 153 except:
142 pass 154 pass
143 155
144 self.server_close() 156class BitbakeServerInfo():
145 return 157 def __init__(self, server):
158 self.server = server
159 self.commands = server.commands
160
161class BitBakeServerFork():
162 def __init__(self, serverinfo, command, logfile):
163 serverinfo.forkCommand = command
164 serverinfo.logfile = logfile
165
166class BitBakeServerConnection():
167 def __init__(self, serverinfo):
168 self.server = serverinfo.server
169 self.connection = serverinfo.commands
170 self.events = bb.server.none.BBUIEventQueue(self.server)
171
172 def terminate(self):
173 try:
174 self.events.system_quit()
175 except:
176 pass
177 try:
178 self.connection.terminateServer()
179 except:
180 pass
181