summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/server/xmlrpc.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2013-05-31 12:06:46 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-06-07 14:13:18 +0100
commit748e3c13c80f698f8396bbc55e42ac3ee6a2a81e (patch)
tree23152dd616209720267647d8a5f36730896983f9 /bitbake/lib/bb/server/xmlrpc.py
parenta62aed41f2d8f874f7ae24d0e5be5dbc66ea2199 (diff)
downloadpoky-748e3c13c80f698f8396bbc55e42ac3ee6a2a81e.tar.gz
bitbake: bitbake server: create common server infrastructure
In an attempt to minimize code duplication, create clear interfaces, and maximize code reuse through OOP, bb.server adds base classes for the BitBakeServer, BitBakeServerConnection and actual server implementations instructed in particular server types. These classes document the minimum interfaces that the derived classes must implement, and provide boilerplate code. Changes to None, Process and XMLRPC servers as to use the common server infrastructure. (Bitbake rev: 6db4a64cef20f8d0aba804db4c4e1eec7b112b46) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/server/xmlrpc.py')
-rw-r--r--bitbake/lib/bb/server/xmlrpc.py64
1 files changed, 25 insertions, 39 deletions
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py
index 56a643c576..2747ed8bf8 100644
--- a/bitbake/lib/bb/server/xmlrpc.py
+++ b/bitbake/lib/bb/server/xmlrpc.py
@@ -49,6 +49,8 @@ DEBUG = False
49from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler 49from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
50import inspect, select 50import inspect, select
51 51
52from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer
53
52if sys.hexversion < 0x020600F0: 54if sys.hexversion < 0x020600F0:
53 print("Sorry, python 2.6 or later is required for bitbake's XMLRPC mode") 55 print("Sorry, python 2.6 or later is required for bitbake's XMLRPC mode")
54 sys.exit(1) 56 sys.exit(1)
@@ -286,7 +288,6 @@ class BitBakeXMLRPCEventServerController(SimpleXMLRPCServer):
286 """ 288 """
287 Register a remote UI Event Handler 289 Register a remote UI Event Handler
288 """ 290 """
289 print "registering handler %s:%s" % (host,port)
290 connection = xmlrpclib.ServerProxy("http://%s:%d/" % (host, port), allow_none=True) 291 connection = xmlrpclib.ServerProxy("http://%s:%d/" % (host, port), allow_none=True)
291 client_hash = "%s:%d" % (host, port) 292 client_hash = "%s:%d" % (host, port)
292 if self.clients.has_key(client_hash): 293 if self.clients.has_key(client_hash):
@@ -301,7 +302,6 @@ class BitBakeXMLRPCEventServerController(SimpleXMLRPCServer):
301 """ 302 """
302 Unregister a remote UI Event Handler 303 Unregister a remote UI Event Handler
303 """ 304 """
304 print "unregistering handler %s:%s" % (host,port)
305 client_thread = self.clients[client_hash] 305 client_thread = self.clients[client_hash]
306 if client_thread: 306 if client_thread:
307 bb.event.unregister_UIHhandler(self.clients_ui_ids[client_hash]) 307 bb.event.unregister_UIHhandler(self.clients_ui_ids[client_hash])
@@ -323,7 +323,16 @@ class BitBakeXMLRPCEventServerController(SimpleXMLRPCServer):
323 self.handle_request() 323 self.handle_request()
324 self.server_close() 324 self.server_close()
325 325
326class BitBakeXMLRPCServer(SimpleXMLRPCServer): 326
327class XMLRPCProxyServer(BaseImplServer):
328 """ not a real working server, but a stub for a proxy server connection
329
330 """
331 def __init__(self, host, port):
332 self.host = host
333 self.port = port
334
335class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer):
327 # remove this when you're done with debugging 336 # remove this when you're done with debugging
328 # allow_reuse_address = True 337 # allow_reuse_address = True
329 338
@@ -331,10 +340,10 @@ class BitBakeXMLRPCServer(SimpleXMLRPCServer):
331 """ 340 """
332 Constructor 341 Constructor
333 """ 342 """
343 BaseImplServer.__init__(self)
334 SimpleXMLRPCServer.__init__(self, interface, 344 SimpleXMLRPCServer.__init__(self, interface,
335 requestHandler=BitBakeXMLRPCRequestHandler, 345 requestHandler=BitBakeXMLRPCRequestHandler,
336 logRequests=False, allow_none=True) 346 logRequests=False, allow_none=True)
337 self._idlefuns = {}
338 self.host, self.port = self.socket.getsockname() 347 self.host, self.port = self.socket.getsockname()
339 self.connection_token = None 348 self.connection_token = None
340 #self.register_introspection_functions() 349 #self.register_introspection_functions()
@@ -343,7 +352,7 @@ class BitBakeXMLRPCServer(SimpleXMLRPCServer):
343 self.interface = interface 352 self.interface = interface
344 353
345 def addcooker(self, cooker): 354 def addcooker(self, cooker):
346 self.cooker = cooker 355 BaseImplServer.addcooker(self, cooker)
347 self.commands.cooker = cooker 356 self.commands.cooker = cooker
348 357
349 def autoregister_all_functions(self, context, prefix): 358 def autoregister_all_functions(self, context, prefix):
@@ -356,10 +365,6 @@ class BitBakeXMLRPCServer(SimpleXMLRPCServer):
356 if name.startswith(prefix): 365 if name.startswith(prefix):
357 self.register_function(method, name[len(prefix):]) 366 self.register_function(method, name[len(prefix):])
358 367
359 def register_idle_function(self, function, data):
360 """Register a function to be called while the server is idle"""
361 assert hasattr(function, '__call__')
362 self._idlefuns[function] = data
363 368
364 def serve_forever(self): 369 def serve_forever(self):
365 # Create and run the event server controller in a separate thread 370 # Create and run the event server controller in a separate thread
@@ -420,16 +425,11 @@ class BitBakeXMLRPCServer(SimpleXMLRPCServer):
420 def set_connection_token(self, token): 425 def set_connection_token(self, token):
421 self.connection_token = token 426 self.connection_token = token
422 427
423class BitbakeServerInfo(): 428class BitBakeXMLRPCServerConnection(BitBakeBaseServerConnection):
424 def __init__(self, host, port): 429 def __init__(self, serverImpl, clientinfo=("localhost", 0)):
425 self.host = host 430 self.connection, self.transport = _create_server(serverImpl.host, serverImpl.port)
426 self.port = port
427
428class BitBakeServerConnection():
429 def __init__(self, serverinfo, clientinfo=("localhost", 0)):
430 self.connection, self.transport = _create_server(serverinfo.host, serverinfo.port)
431 self.clientinfo = clientinfo 431 self.clientinfo = clientinfo
432 self.serverinfo = serverinfo 432 self.serverImpl = serverImpl
433 433
434 def connect(self): 434 def connect(self):
435 token = self.connection.addClient() 435 token = self.connection.addClient()
@@ -457,36 +457,22 @@ class BitBakeServerConnection():
457 except: 457 except:
458 pass 458 pass
459 459
460class BitBakeServer(object): 460class BitBakeServer(BitBakeBaseServer):
461 def initServer(self, interface = ("localhost", 0)): 461 def initServer(self, interface = ("localhost", 0)):
462 self.server = BitBakeXMLRPCServer(interface) 462 self.serverImpl = XMLRPCServer(interface)
463
464 def addcooker(self, cooker):
465 self.cooker = cooker
466 self.server.addcooker(cooker)
467
468 def getServerIdleCB(self):
469 return self.server.register_idle_function
470
471 def saveConnectionDetails(self):
472 self.serverinfo = BitbakeServerInfo(self.server.host, self.server.port)
473 463
474 def detach(self): 464 def detach(self):
475 daemonize.createDaemon(self.server.serve_forever, "bitbake-cookerdaemon.log") 465 daemonize.createDaemon(self.serverImpl.serve_forever, "bitbake-cookerdaemon.log")
476 del self.cooker 466 del self.cooker
477 del self.server
478 467
479 def establishConnection(self): 468 def establishConnection(self):
480 self.connection = BitBakeServerConnection(self.serverinfo) 469 self.connection = BitBakeXMLRPCServerConnection(self.serverImpl)
481 return self.connection.connect() 470 return self.connection.connect()
482 471
483 def set_connection_token(self, token): 472 def set_connection_token(self, token):
484 self.connection.transport.set_connection_token(token) 473 self.connection.transport.set_connection_token(token)
485 474
486 def endSession(self): 475class BitBakeXMLRPCClient(BitBakeBaseServer):
487 self.connection.terminate()
488
489class BitBakeXMLRPCClient(object):
490 476
491 def __init__(self): 477 def __init__(self):
492 pass 478 pass
@@ -510,8 +496,8 @@ class BitBakeXMLRPCClient(object):
510 s.close() 496 s.close()
511 except: 497 except:
512 return None 498 return None
513 self.serverinfo = BitbakeServerInfo(host, port) 499 self.serverImpl = XMLRPCProxyServer(host, port)
514 self.connection = BitBakeServerConnection(self.serverinfo, (ip, 0)) 500 self.connection = BitBakeXMLRPCServerConnection(self.serverImpl, (ip, 0))
515 return self.connection.connect() 501 return self.connection.connect()
516 502
517 def endSession(self): 503 def endSession(self):