def __init__(self, ciiUrl): """\ **Initialisation takes the following parameters:** :param ciiUrl: (:class:`str`) The WebSocket URL of the CSS-CII Server (e.g. "ws://127.0.0.1/myservice/cii") """ super(CIIClient,self).__init__() self.log = logging.getLogger("dvbcss.protocol.client.cii.CIIClient") self._conn = CIIClientConnection(ciiUrl) self._conn.onCII = self._onCII self._conn.onConnected = self._onConnectionOpen self._conn.onDisconnected = self._onConnectionClose self._conn.onProtocolError = self._onProtocolError self.connected = False #: True if currently connected to the server, otherwise False. self.cii = CII() #: (:class:`~dvbcss.protocol.cii.CII`) CII object representing the CII state at the server self.latestCII = None #: (:class:`~dvbcss.protocol.cii.CII` or :class:`None`) The most recent CII message received from the server or None if nothing has yet been received. self._callBackFuncNames = {} for name in CII.allProperties(): funcname = "on" + name[0].upper() + name[1:] + "Change" self._callBackFuncNames[name] = funcname
def __init__(self, ciiUrl): """\ **Initialisation takes the following parameters:** :param ciiUrl: (:class:`str`) The WebSocket URL of the CSS-CII Server (e.g. "ws://127.0.0.1/myservice/cii") """ super(CIIClient, self).__init__() self.log = logging.getLogger("dvbcss.protocol.client.cii.CIIClient") self._conn = CIIClientConnection(ciiUrl) self._conn.onCII = self._onCII self._conn.onConnected = self._onConnectionOpen self._conn.onDisconnected = self._onConnectionClose self._conn.onProtocolError = self._onProtocolError self.connected = False #: True if currently connected to the server, otherwise False. self.cii = CII( ) #: (:class:`~dvbcss.protocol.cii.CII`) CII object representing the CII state at the server self.latestCII = None #: (:class:`~dvbcss.protocol.cii.CII` or :class:`None`) The most recent CII message received from the server or None if nothing has yet been received. self._callBackFuncNames = {} for name in CII.allProperties(): funcname = "on" + name[0].upper() + name[1:] + "Change" self._callBackFuncNames[name] = funcname
if callback is not None: newValue=getattr(diff, name) callback(newValue) # fire general catch-all callback self.onChange(changes) else: self.log.debug("No properties have changed") def getStatusSummary(self): if self.latestCII is None: return "Nothing received from TV yet." return str(self.cii) # programmatically create the onXXXChange methods for every property in a CII message for propertyName in CII.allProperties(): def f(self, newValue): pass f.__doc__="Called when the "+propertyName+" property of the CII message has been changed by a state update from the CII Server.\n\n" + \ "|stub-method|\n\n" + \ ":param newValue: The new value for this property." setattr(CIIClient, "on"+propertyName[0].upper() + propertyName[1:]+"Change", f) __all__ = [ "CIIClientConnection", "CIIClient", ]
if args.quiet: logging.disable(logging.CRITICAL) else: logging.basicConfig(level=args.loglevel[0]) cii = CIIClient(ciiUrl) # logger for outputting messages ciiClientLogger = logging.getLogger("CIIClient") # attach callbacks to generate notifications cii.onConnected = makeCallback("connected") cii.onDisconnected = makeCallback("disconnected") cii.onError = makeCallback("error") for name in CII.allProperties(): funcname = "on" + name[0].upper() + name[1:] + "Change" callback = makePropertyChangeCallback(name) setattr(cii, funcname, callback) # specific handler for when a CII 'change' notification callback fires def onChange(changes): ciiClientLogger.info("CII is now: " + str(cii.cii)) cii.onChange = onChange # connect and goto sleep. All callback activity happens in the websocket's own thread cii.connect() while True: time.sleep(1)
logging.disable(logging.CRITICAL) else: logging.basicConfig(level=args.loglevel[0]) cii = CIIClient(ciiUrl) # logger for outputting messages ciiClientLogger = logging.getLogger("CIIClient") # attach callbacks to generate notifications cii.onConnected = makeCallback("connected") cii.onDisconnected = makeCallback("disconnected") cii.onError = makeCallback("error"); for name in CII.allProperties(): funcname="on" + name[0].upper() + name[1:] + "Change" callback = makePropertyChangeCallback(name) setattr(cii, funcname, callback) # specific handler for when a CII 'change' notification callback fires def onChange(changes): ciiClientLogger.info("CII is now: "+str(cii.cii)) cii.onChange = onChange # connect and goto sleep. All callback activity happens in the websocket's own thread cii.connect() while True: time.sleep(1)
newValue = getattr(diff, name) callback(newValue) # fire general catch-all callback self.onChange(changes) else: self.log.debug("No properties have changed") def getStatusSummary(self): if self.latestCII is None: return "Nothing received from TV yet." return str(self.cii) # programmatically create the onXXXChange methods for every property in a CII message for propertyName in CII.allProperties(): def f(self, newValue): pass f.__doc__="Called when the "+propertyName+" property of the CII message has been changed by a state update from the CII Server.\n\n" + \ "|stub-method|\n\n" + \ ":param newValue: The new value for this property." setattr(CIIClient, "on" + propertyName[0].upper() + propertyName[1:] + "Change", f) __all__ = [ "CIIClientConnection", "CIIClient", ]