Beispiel #1
0
 def _onCII(self, newCII):
     self.latestCII = newCII
     self.onCiiReceived(newCII)
     
     # take a diff since we cannot assume the received message is a diff
     diff=CII.diff(self.cii, newCII)
     changes=diff.definedProperties()
     
     if len(changes) > 0:      
         self.log.debug("Changed properties: "+ " ".join(changes))
         self.cii.update(diff)
         
         # now we examine changes and fire change specific callbacks as well as a general callback 
         for name in changes:
             if name in changes:
                 funcname = self._callBackFuncNames[name]
                 callback = getattr(self, 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")
Beispiel #2
0
    def _onCII(self, newCII):
        self.latestCII = newCII
        self.onCiiReceived(newCII)

        # take a diff since we cannot assume the received message is a diff
        diff = CII.diff(self.cii, newCII)
        changes = diff.definedProperties()

        if len(changes) > 0:
            self.log.debug("Changed properties: " + " ".join(changes))
            self.cii.update(diff)

            # now we examine changes and fire change specific callbacks as well as a general callback
            for name in changes:
                if name in changes:
                    funcname = self._callBackFuncNames[name]
                    callback = getattr(self, 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")
Beispiel #3
0
    def updateClients(self, sendOnlyDiff=True, sendIfEmpty=False):
        """\
        Send update of current CII state from the :data:`CIIServer.cii` object to all connected clients.
        
        :param sendOnlyDiff: (bool, default=True) Send only the properties in the CII state that have changed since last time a message was sent. Set to False to send the entire message.
        :param sendIfEmpty: (bool, default=False) Set to True to force that a CII message be sent, even if it will be empty (e.g. no change since last time)
        
        By default this method will only send a CII message to clients informing them of the differencesin state since last time a message was sent to them.
        If no properties have changed at all, then no message will be sent.
        
        The two optional arguments allow you to change this behaviour. For example, to force the messages sent to include all properties, even if they have not changed:
        
        .. code-block:: python
        
            myCiiServer.updateClients(sendOnlyDiff=False)
            
        To additionally force it to send even if the CII state held at this server has no values for any of the properties:

        .. code-block:: python
        
            myCiiServer.updateClients(sendOnlyDiff=False, sendIfEmpty=True)
            
        """
        connections = self.getConnections()
        for webSock in connections:
            self.log.debug("Sending CII to connection " + webSock.id())
            connectionData = connections[webSock]
            prevCII = connectionData["prevCII"]

            # perform rewrite substitutions, if any
            cii = self._customiseCii(webSock)

            # work out whether we are sending the full CII or a diff
            if sendOnlyDiff:
                diff = CII.diff(prevCII, cii)
                toSend = diff
                # enforce requirement that contentId must be accompanied by contentIdStatus
                if diff.contentId != OMIT:
                    toSend.contentIdStatus = cii.contentIdStatus
            else:
                toSend = cii

            # only send if forced to, or if the mesage to send is not empty (all OMITs)
            if sendIfEmpty or toSend.definedProperties():
                webSock.send(toSend.pack())

            connectionData["prevCII"] = cii.copy()
Beispiel #4
0
    def updateClients(self, sendOnlyDiff=True,sendIfEmpty=False):
        """\
        Send update of current CII state from the :data:`CIIServer.cii` object to all connected clients.
        
        :param sendOnlyDiff: (bool, default=True) Send only the properties in the CII state that have changed since last time a message was sent. Set to False to send the entire message.
        :param sendIfEmpty: (bool, default=False) Set to True to force that a CII message be sent, even if it will be empty (e.g. no change since last time)
        
        By default this method will only send a CII message to clients informing them of the differencesin state since last time a message was sent to them.
        If no properties have changed at all, then no message will be sent.
        
        The two optional arguments allow you to change this behaviour. For example, to force the messages sent to include all properties, even if they have not changed:
        
        .. code-block:: python
        
            myCiiServer.updateClients(sendOnlyDiff=False)
            
        To additionally force it to send even if the CII state held at this server has no values for any of the properties:

        .. code-block:: python
        
            myCiiServer.updateClients(sendOnlyDiff=False, sendIfEmpty=True)
            
        """
        connections = self.getConnections()
        for webSock in connections:
            self.log.debug("Sending CII to connection "+webSock.id())
            connectionData = connections[webSock]
            prevCII = connectionData["prevCII"]
            
            # work out whether we are sending the full CII or a diff
            if sendOnlyDiff:
                diff = CII.diff(prevCII, self.cii)
                toSend = diff
                # enforce requirement that contentId must be accompanied by contentIdStatus
                if diff.contentId != OMIT:
                    toSend.contentIdStatus = self.cii.contentIdStatus
            else:
                toSend = self.cii
            
            # only send if forced to, or if the mesage to send is not empty (all OMITs)
            if sendIfEmpty or toSend.definedProperties():
                webSock.send(toSend.pack())
                
            connectionData["prevCII"] = self.cii.copy()