# vim: ts=4 et sts=4 sw=4 autoindent import Pyro.core from sndcs.TerminalFactory import TerminalFactory from sndcs_common.SndcsExceptions import * from MiddleKit.Run.ObjectStore import UnknownObjectError from sndcs_common.Logger import logger log = logger.getLogger("sndcsd") class TerminalProxyFactory(Pyro.core.ObjBase): """ The most common usage is to use one of the __init__ functions to make TerminalProxy represent a single terminal and then use the rest of the functions to manipulate the terminal. """ ### __init__ functions ### ### From TerminalFactory ### def setTerminalByTerminalName(self, terminal_name): """ Explicit __init__ function to set the terminal.""" terminal = TerminalFactory().getTerminalByTerminalName(terminal_name) if not terminal: raise SndcsTerminalError("No terminal with terminalName = '%s'" % (terminal_name)) proxy = TerminalProxy() proxy.terminal = terminal[0] self.getDaemon().connect(proxy) log.debug("Returning terminal proxy object %s.", proxy) return proxy.getProxy() def setTerminalBySerialNum(self, serialNum): """ Explicit __init__ function to set the terminal.""" terminal = TerminalFactory().getTerminalBySerialNum(serialNum) if not terminal: raise SndcsEmployeeError("No terminal with serialNum = '%s'" % (serialNum)) proxy = TerminalProxy() proxy.terminal = terminal self.getDaemon().connect(proxy) log.debug("Returning terminal proxy object %s.", proxy) return proxy.getProxy() class TerminalProxy(Pyro.core.ObjBase): def getTerminalDepartments(self): result = self.terminal.department() departments = [] for x in result: departments.extend([x.code()]) # Returns a list of department numbers to compare to. return departments ### Getters and Setters ### def getTerminalName(self): return self.terminal.terminalName() ### Cleanup ### def disconnect(self): daemon = self.getDaemon() log.debug("Disconnecting terminal proxy object %s.", self) daemon.disconnect(self)