def _send_notification(self, resource, sub):
        self.logger.debug("sending notification for resource: %s", resource)

        def get_subscription_reference(to, path):
            if to.startswith('//'):
                return self._abs_cse_id + '/' + path
            elif to.startswith('/'):
                return self._rel_cse_id + '/' + path
            else:
                return path

        for uri in sub.notificationURI:
            self.api.handle_onem2m_request(
                OneM2MRequest(
                    op=OneM2MOperation.notify,
                    to=uri,
                    pc=Notification(
                        notificationEvent=NotificationEventC(
                            representation=resource),
                        subscriptionReference=get_subscription_reference(
                            uri, sub.path),
                        # TODO(rst): check if this is the sub creator or the creator of the notification
                        # TODO          in this case the CSE
                        creator=sub.creator),
                ))
Beispiel #2
0
    def _handle_subscription_deleted(self, subscription, req):
        # only when subscription is deleted directly
        if not req.cascading:
            try:
                del self.subscriptions_info[subscription.resourceID]
            except KeyError:
                pass

        # 7.5.1.2.4 Notification for Subscription Deletion
        # Originator:
        # When the <subscription> resource is deleted and subscriberURI of the
        # <subscription> resource is configured, the Originator shall send a
        # Notify request primitive with subscriptionDeletion element of the
        # notification data object set as TRUE and subscriptionReference element
        # set as the URI of the <subscription> resource to the entity indicated
        # in subscriberURI.

        su = subscription.subscriberURI
        if not su:
            return

        try:
            self.api.handle_onem2m_request(OneM2MRequest(
                OneM2MOperation.notify,
                su,
                pc=Notification(
                    subscriptionDeletion=True,
                    subscriptionReference=self._get_subscription_reference(su, subscription.path),
                    # TODO(rst): check if this is the sub creator or the creator of the notification
                    # TODO          in this case the CSE
                    creator=subscription.creator,
                ),
            ))
        except CSENotFound:
            self.logger.debug("subscription target %s already deleted or not existing." % su)
        def send_verification(notify_uri):
            notification = Notification(
                verificationRequest=True,
                creator=self.request.originator
            )

            send_notify_request = OneM2MRequest(OneM2MOperation.notify,
                                                notify_uri, None,
                                                MetaInformation(None),
                                                notification)
            return self.api.send_onem2m_request(send_notify_request)
Beispiel #4
0
    def _send_notification(self, resource, sub):
        self.logger.debug("sending notification for resource: %s", resource)

        for uri in sub.notificationURI:
            self.api.handle_onem2m_request(OneM2MRequest(
                op=OneM2MOperation.notify,
                to=uri,
                pc=Notification(
                    notificationEvent=NotificationEventC(
                        representation=resource
                    ),
                    subscriptionReference=self._get_subscription_reference(uri, sub.path),
                    # TODO(rst): check if this is the sub creator or the creator of the notification
                    # TODO          in this case the CSE
                    creator=sub.creator
                ),
            ))
    def _send_notification(self, resource, sub, req):
        self.logger.debug("sending notification for resource: %s", resource)

        notification = Notification(
            notificationEvent=NotificationEventC(
                representation=resource
            ),
            subscriptionReference=sub.path,
            creator=sub.creator

        )

        for uri in sub.notificationURI:
            send_notification_request = OneM2MRequest(OneM2MOperation.notify,
                                                      uri, req.originator,
                                                      pc=notification)
            self.api.send_onem2m_request(send_notification_request)