Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # BitBake Base Server Code |
| 3 | # |
| 4 | # Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer |
| 5 | # Copyright (C) 2006 - 2008 Richard Purdie |
| 6 | # Copyright (C) 2013 Alexandru Damian |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License version 2 as |
| 10 | # published by the Free Software Foundation. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License along |
| 18 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | |
| 21 | """ Base code for Bitbake server process |
| 22 | |
| 23 | Have a common base for that all Bitbake server classes ensures a consistent |
| 24 | approach to the interface, and minimize risks associated with code duplication. |
| 25 | |
| 26 | """ |
| 27 | |
| 28 | """ BaseImplServer() the base class for all XXServer() implementations. |
| 29 | |
| 30 | These classes contain the actual code that runs the server side, i.e. |
| 31 | listens for the commands and executes them. Although these implementations |
| 32 | contain all the data of the original bitbake command, i.e the cooker instance, |
| 33 | they may well run on a different process or even machine. |
| 34 | |
| 35 | """ |
| 36 | |
| 37 | class BaseImplServer(): |
| 38 | def __init__(self): |
| 39 | self._idlefuns = {} |
| 40 | |
| 41 | def addcooker(self, cooker): |
| 42 | self.cooker = cooker |
| 43 | |
| 44 | def register_idle_function(self, function, data): |
| 45 | """Register a function to be called while the server is idle""" |
| 46 | assert hasattr(function, '__call__') |
| 47 | self._idlefuns[function] = data |
| 48 | |
| 49 | |
| 50 | |
| 51 | """ BitBakeBaseServerConnection class is the common ancestor to all |
| 52 | BitBakeServerConnection classes. |
| 53 | |
| 54 | These classes control the remote server. The only command currently |
| 55 | implemented is the terminate() command. |
| 56 | |
| 57 | """ |
| 58 | |
| 59 | class BitBakeBaseServerConnection(): |
| 60 | def __init__(self, serverImpl): |
| 61 | pass |
| 62 | |
| 63 | def terminate(self): |
| 64 | pass |
| 65 | |
| 66 | |
| 67 | """ BitBakeBaseServer class is the common ancestor to all Bitbake servers |
| 68 | |
| 69 | Derive this class in order to implement a BitBakeServer which is the |
| 70 | controlling stub for the actual server implementation |
| 71 | |
| 72 | """ |
| 73 | class BitBakeBaseServer(object): |
| 74 | def initServer(self): |
| 75 | self.serverImpl = None # we ensure a runtime crash if not overloaded |
| 76 | self.connection = None |
| 77 | return |
| 78 | |
| 79 | def addcooker(self, cooker): |
| 80 | self.cooker = cooker |
| 81 | self.serverImpl.addcooker(cooker) |
| 82 | |
| 83 | def getServerIdleCB(self): |
| 84 | return self.serverImpl.register_idle_function |
| 85 | |
| 86 | def saveConnectionDetails(self): |
| 87 | return |
| 88 | |
| 89 | def detach(self): |
| 90 | return |
| 91 | |
| 92 | def establishConnection(self, featureset): |
| 93 | raise "Must redefine the %s.establishConnection()" % self.__class__.__name__ |
| 94 | |
| 95 | def endSession(self): |
| 96 | self.connection.terminate() |