Skip to content

Commit

Permalink
subscription: add ModifySubscription functionality
Browse files Browse the repository at this point in the history
closes #713

Signed-off-by: Jack Chen <[email protected]>
  • Loading branch information
jackchenjc committed May 9, 2024
1 parent 504cad3 commit 6d09349
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Here is the current set of supported services. For low-level access use the clie
| | SetMonitoringMode | | |
| | SetTriggering | | |
| Subscription Service Set | CreateSubscription | Yes | |
| | ModifySubscription | | |
| | ModifySubscription | Yes | |
| | SetPublishingMode | | |
| | Publish | Yes | |
| | Republish | | |
Expand Down
45 changes: 45 additions & 0 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,51 @@ 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
}

// recreate a new subscription with new parameters
s.itemsMu.Lock()
sub := &Subscription{
SubscriptionID: s.SubscriptionID,
RevisedPublishingInterval: time.Duration(res.RevisedPublishingInterval) * time.Millisecond,
RevisedLifetimeCount: res.RevisedLifetimeCount,
RevisedMaxKeepAliveCount: res.RevisedMaxKeepAliveCount,
Notifs: s.Notifs,
items: s.items,
params: &params,
nextSeq: s.nextSeq,
c: s.c,
}
s.itemsMu.Unlock()

err = sub.recreate_NeedsSubMuxLock(ctx)
if err != nil {
return nil, err
}

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)))
Expand Down

0 comments on commit 6d09349

Please sign in to comment.