示例#1
0
    def new_subscriber(self, subscriber):
        notify = []
        for vdict in self._variables.values():
            notify += [v for v in vdict.values() if v.send_events == True]

        self.info("new_subscriber", subscriber, notify)
        if len(notify) <= 0:
            return

        root = ET.Element('e:propertyset')
        root.attrib['xmlns:e']='urn:schemas-upnp-org:event-1-0'
        evented_variables = 0
        for n in notify:
            e = ET.SubElement( root, 'e:property')
            if n.name == 'LastChange':
                if subscriber['seq'] == 0:
                    text = self.build_last_change_event(n.instance, force=True)
                else:
                    text = self.build_last_change_event(n.instance)
                if text is not None:
                    ET.SubElement( e, n.name).text = text
                    evented_variables += 1
            else:
                ET.SubElement( e, n.name).text = str(n.value)
                evented_variables += 1

        if evented_variables > 0:
            xml = ET.tostring( root, encoding='utf-8')
            d,p = event.send_notification(subscriber, xml)
            self._pending_notifications[d] = p
            d.addBoth(self.rm_notification,d)
        self._subscribers[subscriber['sid']] = subscriber
示例#2
0
 def process_value(result):
     variable.update(result)
     if default == True:
         variable.default_value = variable.value
     if(variable.send_events == True and
         variable.moderated == False and
         len(self._subscribers) > 0):
         xml = self.build_single_notification(instance, variable_name, variable.value)
         for s in self._subscribers.values():
             d,p = event.send_notification(s, xml)
             self._pending_notifications[d] = p
             d.addBoth(self.rm_notification,d)
示例#3
0
    def propagate_notification(self, notify):
        #print "propagate_notification", notify
        if len(self._subscribers) <= 0:
            return
        if len(notify) <= 0:
            return

        root = ET.Element('e:propertyset')
        root.attrib['xmlns:e']='urn:schemas-upnp-org:event-1-0'

        if isinstance( notify, variable.StateVariable):
            notify = [notify,]

        evented_variables = 0
        for n in notify:
            e = ET.SubElement( root, 'e:property')
            if n.name == 'LastChange':
                text = self.build_last_change_event(instance=n.instance)
                if text is not None:
                    ET.SubElement( e, n.name).text = text
                    evented_variables += 1
            else:
                s = ET.SubElement( e, n.name).text = str(n.value)
                evented_variables += 1
                if n.dependant_variable != None:
                    dependants = n.dependant_variable.get_allowed_values()
                    if dependants != None and len(dependants) > 0:
                        s.attrib['channel']=dependants[0]

        if evented_variables == 0:
            return
        xml = ET.tostring( root, encoding='utf-8')
        #print "propagate_notification", xml
        for s in self._subscribers.values():
            d,p = event.send_notification(s,xml)
            self._pending_notifications[d] = p
            d.addBoth(self.rm_notification,d)