From 5aed8b4915ff215537c42fddf8d12d8c5bb3ba10 Mon Sep 17 00:00:00 2001 From: Jack Chen Date: Mon, 19 Feb 2024 19:44:44 +0800 Subject: [PATCH] subscription: add ModifySubscription functionality closes #713 Signed-off-by: Jack Chen --- subscription.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/subscription.go b/subscription.go index f08a81f6..07ab3a41 100644 --- a/subscription.go +++ b/subscription.go @@ -111,6 +111,38 @@ func (s *Subscription) delete(ctx context.Context) error { } } +func (s *Subscription) ModifySubscription(ctx context.Context, params SubscriptionParameters) (*ua.ModifySubscriptionResponse, error) { + stats.Subscription().Add("ModifySubscription", 1) + + params.setDefaults() + req := &ua.ModifySubscriptionRequest{ + SubscriptionID: s.SubscriptionID, + RequestedPublishingInterval: float64(params.Interval.Milliseconds()), + RequestedLifetimeCount: params.LifetimeCount, + RequestedMaxKeepAliveCount: params.MaxKeepAliveCount, + MaxNotificationsPerPublish: params.MaxNotificationsPerPublish, + Priority: params.Priority, + } + + var res *ua.ModifySubscriptionResponse + err := s.c.Send(ctx, req, func(v interface{}) error { + return safeAssign(v, &res) + }) + + if err != nil { + return nil, err + } + + // update subscription parameters + s.params = ¶ms + // update revised subscription parameters + s.RevisedPublishingInterval = time.Duration(res.RevisedPublishingInterval) * time.Millisecond + s.RevisedLifetimeCount = res.RevisedLifetimeCount + s.RevisedMaxKeepAliveCount = res.RevisedMaxKeepAliveCount + + return res, nil +} + func (s *Subscription) Monitor(ctx context.Context, ts ua.TimestampsToReturn, items ...*ua.MonitoredItemCreateRequest) (*ua.CreateMonitoredItemsResponse, error) { stats.Subscription().Add("Monitor", 1) stats.Subscription().Add("MonitoredItems", int64(len(items)))