示例#1
0
    def __init__(self,
                 isession,
                 etype=None,
                 emitting_node=ua.ObjectIds.Server):
        if not etype:
            etype = event_objects.BaseEvent()

        self.logger = logging.getLogger(__name__)
        self.isession = isession
        self.event = None
        node = None

        if isinstance(etype, event_objects.BaseEvent):
            self.event = etype
        elif isinstance(etype, Node):
            node = etype
        elif isinstance(etype, ua.NodeId):
            node = Node(self.isession, etype)
        else:
            node = Node(self.isession, ua.NodeId(etype))

        if node:
            self.event = events.get_event_obj_from_type_node(node)

        if isinstance(emitting_node, Node):
            pass
        elif isinstance(emitting_node, ua.NodeId):
            emitting_node = Node(isession, emitting_node)
        else:
            emitting_node = Node(isession, ua.NodeId(emitting_node))

        self.event.emitting_node = emitting_node.nodeid

        if not self.event.SourceNode:
            self.event.SourceNode = emitting_node.nodeid
            self.event.SourceName = emitting_node.get_browse_name().Name

        emitting_node.set_event_notifier([ua.EventNotifier.SubscribeToEvents])
        refs = []
        ref = ua.AddReferencesItem()
        ref.IsForward = True
        ref.ReferenceTypeId = ua.NodeId(ua.ObjectIds.GeneratesEvent)
        ref.SourceNodeId = emitting_node.nodeid
        ref.TargetNodeClass = ua.NodeClass.ObjectType
        ref.TargetNodeId = self.event.EventType
        refs.append(ref)
        results = self.isession.add_references(refs)
        # result.StatusCode.check()

        self.emitting_node = emitting_node
示例#2
0
    def __init__(self, isession, etype=None, source=ua.ObjectIds.Server):
        if not etype:
            etype = event_objects.BaseEvent()

        self.logger = logging.getLogger(__name__)
        self.isession = isession
        self.event = None
        node = None

        if isinstance(etype, event_objects.BaseEvent):
            self.event = etype
        elif isinstance(etype, Node):
            node = etype
        elif isinstance(etype, ua.NodeId):
            node = Node(self.isession, etype)
        else:
            node = Node(self.isession, ua.NodeId(etype))

        if node:
            self.event = events.get_event_obj_from_type_node(node)

        if isinstance(source, Node):
            pass
        elif isinstance(source, ua.NodeId):
            source = Node(isession, source)
        else:
            source = Node(isession, ua.NodeId(source))

        if self.event.SourceNode:
            if source.nodeid != self.event.SourceNode:
                self.logger.warning(
                    "Source NodeId: '%s' and event SourceNode: '%s' are not the same. Using '%s' as SourceNode",
                    str(source.nodeid), str(self.event.SourceNode),
                    str(self.event.SourceNode))
                source = Node(self.isession, self.event.SourceNode)

        self.event.SourceNode = source.nodeid
        self.event.SourceName = source.get_browse_name().Name

        source.set_event_notifier(
            [ua.EventNotifier.SubscribeToEvents, ua.EventNotifier.HistoryRead])
        refs = []
        ref = ua.AddReferencesItem()
        ref.IsForward = True
        ref.ReferenceTypeId = ua.NodeId(ua.ObjectIds.GeneratesEvent)
        ref.SourceNodeId = source.nodeid
        ref.TargetNodeClass = ua.NodeClass.ObjectType
        ref.TargetNodeId = self.event.EventType
        refs.append(ref)
        results = self.isession.add_references(refs)