diff --git a/client.go b/client.go index 3edda4a8..17cadd21 100644 --- a/client.go +++ b/client.go @@ -34,8 +34,8 @@ func GetEndpoints(ctx context.Context, endpoint string, opts ...Option) ([]*ua.E if err := c.Dial(ctx); err != nil { return nil, err } - defer c.CloseWithContext(ctx) - res, err := c.GetEndpointsWithContext(ctx) + defer c.Close(ctx) + res, err := c.GetEndpoints(ctx) if err != nil { return nil, err } @@ -213,17 +213,16 @@ func (c *Client) Connect(ctx context.Context) error { return err } - s, err := c.CreateSessionWithContext(ctx, c.cfg.session) + s, err := c.CreateSession(ctx, c.cfg.session) if err != nil { - c.CloseWithContext(ctx) + c.Close(ctx) stats.RecordError(err) return err } - if err := c.ActivateSessionWithContext(ctx, s); err != nil { - c.closeSession(ctx, s) // ignore error since we cannot handle it anyway - c.CloseWithContext(ctx) + if err := c.ActivateSession(ctx, s); err != nil { + c.Close(ctx) stats.RecordError(err) return err @@ -241,8 +240,8 @@ func (c *Client) Connect(ctx context.Context) error { // todo(fs): server. For the sake of simplicity we left the option out but // todo(fs): see the discussion in https://github.com/gopcua/opcua/pull/512 // todo(fs): and you should find a commit that implements this option. - if err := c.UpdateNamespacesWithContext(ctx); err != nil { - c.CloseWithContext(ctx) + if err := c.UpdateNamespaces(ctx); err != nil { + c.Close(ctx) stats.RecordError(err) return err @@ -399,7 +398,7 @@ func (c *Client) monitor(ctx context.Context) { } dlog.Printf("trying to restore session") - if err := c.ActivateSessionWithContext(ctx, s); err != nil { + if err := c.ActivateSession(ctx, s); err != nil { dlog.Printf("restore session failed: %v", err) action = recreateSession continue @@ -408,7 +407,7 @@ func (c *Client) monitor(ctx context.Context) { // todo(fs): see comment about guarding this with an option in Connect() dlog.Printf("trying to update namespaces") - if err := c.UpdateNamespacesWithContext(ctx); err != nil { + if err := c.UpdateNamespaces(ctx); err != nil { dlog.Printf("updating namespaces failed: %v", err) action = createSecureChannel continue @@ -424,13 +423,13 @@ func (c *Client) monitor(ctx context.Context) { // create a new session to replace the previous one dlog.Printf("trying to recreate session") - s, err := c.CreateSessionWithContext(ctx, c.cfg.session) + s, err := c.CreateSession(ctx, c.cfg.session) if err != nil { dlog.Printf("recreate session failed: %v", err) action = createSecureChannel continue } - if err := c.ActivateSessionWithContext(ctx, s); err != nil { + if err := c.ActivateSession(ctx, s); err != nil { dlog.Printf("reactivate session failed: %v", err) action = createSecureChannel continue @@ -439,7 +438,7 @@ func (c *Client) monitor(ctx context.Context) { // todo(fs): see comment about guarding this with an option in Connect() dlog.Printf("trying to update namespaces") - if err := c.UpdateNamespacesWithContext(ctx); err != nil { + if err := c.UpdateNamespaces(ctx); err != nil { dlog.Printf("updating namespaces failed: %v", err) action = createSecureChannel continue @@ -590,20 +589,12 @@ func (c *Client) Dial(ctx context.Context) error { } // Close closes the session and the secure channel. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) Close() error { - return c.CloseWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) CloseWithContext(ctx context.Context) error { +func (c *Client) Close(ctx context.Context) error { stats.Client().Add("Close", 1) // try to close the session but ignore any error // so that we close the underlying channel and connection. - c.CloseSessionWithContext(ctx) + c.CloseSession(ctx) c.setState(Closed) if c.mcancel != nil { @@ -720,18 +711,9 @@ func (s *Session) RevisedTimeout() time.Duration { // that the server sent in Create Session Response. The default PolicyID // "Anonymous" wii be set if it's missing in response. // -// # See Part 4, 5.6.2 -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) CreateSession(cfg *uasc.SessionConfig) (*Session, error) { - return c.CreateSessionWithContext(context.Background(), cfg) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) CreateSessionWithContext(ctx context.Context, cfg *uasc.SessionConfig) (*Session, error) { - sc := c.SecureChannel() - if sc == nil { +// See Part 4, 5.6.2 +func (c *Client) CreateSession(ctx context.Context, cfg *uasc.SessionConfig) (*Session, error) { + if c.SecureChannel() == nil { return nil, ua.StatusBadServerNotConnected } @@ -756,14 +738,14 @@ func (c *Client) CreateSessionWithContext(ctx context.Context, cfg *uasc.Session var s *Session // for the CreateSessionRequest the authToken is always nil. - // use sc.SendRequest() to enforce this. - err := sc.SendRequestWithContext(ctx, req, nil, func(v interface{}) error { + // use c.SecureChannel().SendRequest() to enforce this. + err := c.SecureChannel().SendRequest(ctx, req, nil, func(v interface{}) error { var res *ua.CreateSessionResponse if err := safeAssign(v, &res); err != nil { return err } - err := sc.VerifySessionSignature(res.ServerCertificate, nonce, res.ServerSignature.Signature) + err := c.SecureChannel().VerifySessionSignature(res.ServerCertificate, nonce, res.ServerSignature.Signature) if err != nil { log.Printf("error verifying session signature: %s", err) return nil @@ -814,22 +796,13 @@ func anonymousPolicyID(endpoints []*ua.EndpointDescription) string { // the client already has a session it will be closed. To retain the current // session call DetachSession. // -// # See Part 4, 5.6.3 -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) ActivateSession(s *Session) error { - return c.ActivateSessionWithContext(context.Background(), s) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) ActivateSessionWithContext(ctx context.Context, s *Session) error { - sc := c.SecureChannel() - if sc == nil { +// See Part 4, 5.6.3 +func (c *Client) ActivateSession(ctx context.Context, s *Session) error { + if c.SecureChannel() == nil { return ua.StatusBadServerNotConnected } stats.Client().Add("ActivateSession", 1) - sig, sigAlg, err := sc.NewSessionSignature(s.serverCertificate, s.serverNonce) + sig, sigAlg, err := c.SecureChannel().NewSessionSignature(s.serverCertificate, s.serverNonce) if err != nil { log.Printf("error creating session signature: %s", err) return nil @@ -840,7 +813,7 @@ func (c *Client) ActivateSessionWithContext(ctx context.Context, s *Session) err // nothing to do case *ua.UserNameIdentityToken: - pass, passAlg, err := sc.EncryptUserPassword(s.cfg.AuthPolicyURI, s.cfg.AuthPassword, s.serverCertificate, s.serverNonce) + pass, passAlg, err := c.SecureChannel().EncryptUserPassword(s.cfg.AuthPolicyURI, s.cfg.AuthPassword, s.serverCertificate, s.serverNonce) if err != nil { log.Printf("error encrypting user password: %s", err) return err @@ -849,7 +822,7 @@ func (c *Client) ActivateSessionWithContext(ctx context.Context, s *Session) err tok.EncryptionAlgorithm = passAlg case *ua.X509IdentityToken: - tokSig, tokSigAlg, err := sc.NewUserTokenSignature(s.cfg.AuthPolicyURI, s.serverCertificate, s.serverNonce) + tokSig, tokSigAlg, err := c.SecureChannel().NewUserTokenSignature(s.cfg.AuthPolicyURI, s.serverCertificate, s.serverNonce) if err != nil { log.Printf("error creating session signature: %s", err) return err @@ -873,7 +846,7 @@ func (c *Client) ActivateSessionWithContext(ctx context.Context, s *Session) err UserIdentityToken: ua.NewExtensionObject(s.cfg.UserIdentityToken), UserTokenSignature: s.cfg.UserTokenSignature, } - return sc.SendRequestWithContext(ctx, req, s.resp.AuthenticationToken, func(v interface{}) error { + return c.SecureChannel().SendRequest(ctx, req, s.resp.AuthenticationToken, func(v interface{}) error { var res *ua.ActivateSessionResponse if err := safeAssign(v, &res); err != nil { return err @@ -889,7 +862,7 @@ func (c *Client) ActivateSessionWithContext(ctx context.Context, s *Session) err // We decided not to check the error of CloseSession() since we // can't do much about it anyway and it creates a race in the // re-connection logic. - c.CloseSessionWithContext(ctx) + c.CloseSession(ctx) c.setSession(s) return nil @@ -898,16 +871,8 @@ func (c *Client) ActivateSessionWithContext(ctx context.Context, s *Session) err // CloseSession closes the current session. // -// # See Part 4, 5.6.4 -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) CloseSession() error { - return c.CloseSessionWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) CloseSessionWithContext(ctx context.Context) error { +// See Part 4, 5.6.4 +func (c *Client) CloseSession(ctx context.Context) error { stats.Client().Add("CloseSession", 1) if err := c.closeSession(ctx, c.Session()); err != nil { return err @@ -923,7 +888,7 @@ func (c *Client) closeSession(ctx context.Context, s *Session) error { } req := &ua.CloseSessionRequest{DeleteSubscriptions: true} var res *ua.CloseSessionResponse - return c.SendWithContext(ctx, req, func(v interface{}) error { + return c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) } @@ -931,15 +896,7 @@ func (c *Client) closeSession(ctx context.Context, s *Session) error { // DetachSession removes the session from the client without closing it. The // caller is responsible to close or re-activate the session. If the client // does not have an active session the function returns no error. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) DetachSession() (*Session, error) { - return c.DetachSessionWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) DetachSessionWithContext(ctx context.Context) (*Session, error) { +func (c *Client) DetachSession(ctx context.Context) (*Session, error) { stats.Client().Add("DetachSession", 1) s := c.Session() c.setSession(nil) @@ -949,15 +906,7 @@ func (c *Client) DetachSessionWithContext(ctx context.Context) (*Session, error) // Send sends the request via the secure channel and registers a handler for // the response. If the client has an active session it injects the // authentication token. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) Send(req ua.Request, h func(interface{}) error) error { - return c.SendWithContext(context.Background(), req, h) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) SendWithContext(ctx context.Context, req ua.Request, h func(interface{}) error) error { +func (c *Client) Send(ctx context.Context, req ua.Request, h func(interface{}) error) error { stats.Client().Add("Send", 1) err := c.sendWithTimeout(ctx, req, c.cfg.sechan.RequestTimeout, h) @@ -978,7 +927,7 @@ func (c *Client) sendWithTimeout(ctx context.Context, req ua.Request, timeout ti if s := c.Session(); s != nil { authToken = s.resp.AuthenticationToken } - return sc.SendRequestWithTimeoutWithContext(ctx, req, authToken, timeout, h) + return c.SecureChannel().SendRequestWithTimeout(ctx, req, authToken, timeout, h) } // Node returns a node object which accesses its attributes @@ -988,22 +937,14 @@ func (c *Client) Node(id *ua.NodeID) *Node { } // GetEndpoints returns the list of available endpoints of the server. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) GetEndpoints() (*ua.GetEndpointsResponse, error) { - return c.GetEndpointsWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) GetEndpointsWithContext(ctx context.Context) (*ua.GetEndpointsResponse, error) { +func (c *Client) GetEndpoints(ctx context.Context) (*ua.GetEndpointsResponse, error) { stats.Client().Add("GetEndpoints", 1) req := &ua.GetEndpointsRequest{ EndpointURL: c.endpointURL, } var res *ua.GetEndpointsResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err @@ -1033,15 +974,7 @@ func cloneReadRequest(req *ua.ReadRequest) *ua.ReadRequest { // // By default, the function requests the value of the nodes // in the default encoding of the server. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) Read(req *ua.ReadRequest) (*ua.ReadResponse, error) { - return c.ReadWithContext(context.Background(), req) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) ReadWithContext(ctx context.Context, req *ua.ReadRequest) (*ua.ReadResponse, error) { +func (c *Client) Read(ctx context.Context, req *ua.ReadRequest) (*ua.ReadResponse, error) { stats.Client().Add("Read", 1) stats.Client().Add("NodesToRead", int64(len(req.NodesToRead))) @@ -1050,7 +983,7 @@ func (c *Client) ReadWithContext(ctx context.Context, req *ua.ReadRequest) (*ua. req = cloneReadRequest(req) var res *ua.ReadResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { err := safeAssign(v, &res) if err != nil { return err @@ -1076,20 +1009,12 @@ func (c *Client) ReadWithContext(ctx context.Context, req *ua.ReadRequest) (*ua. } // Write executes a synchronous write request. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) Write(req *ua.WriteRequest) (*ua.WriteResponse, error) { - return c.WriteWithContext(context.Background(), req) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) WriteWithContext(ctx context.Context, req *ua.WriteRequest) (*ua.WriteResponse, error) { +func (c *Client) Write(ctx context.Context, req *ua.WriteRequest) (*ua.WriteResponse, error) { stats.Client().Add("Write", 1) stats.Client().Add("NodesToWrite", int64(len(req.NodesToWrite))) var res *ua.WriteResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err @@ -1120,15 +1045,7 @@ func cloneBrowseRequest(req *ua.BrowseRequest) *ua.BrowseRequest { } // Browse executes a synchronous browse request. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) Browse(req *ua.BrowseRequest) (*ua.BrowseResponse, error) { - return c.BrowseWithContext(context.Background(), req) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) BrowseWithContext(ctx context.Context, req *ua.BrowseRequest) (*ua.BrowseResponse, error) { +func (c *Client) Browse(ctx context.Context, req *ua.BrowseRequest) (*ua.BrowseResponse, error) { stats.Client().Add("Browse", 1) stats.Client().Add("NodesToBrowse", int64(len(req.NodesToBrowse))) @@ -1137,29 +1054,21 @@ func (c *Client) BrowseWithContext(ctx context.Context, req *ua.BrowseRequest) ( req = cloneBrowseRequest(req) var res *ua.BrowseResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err } // Call executes a synchronous call request for a single method. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) Call(req *ua.CallMethodRequest) (*ua.CallMethodResult, error) { - return c.CallWithContext(context.Background(), req) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) CallWithContext(ctx context.Context, req *ua.CallMethodRequest) (*ua.CallMethodResult, error) { +func (c *Client) Call(ctx context.Context, req *ua.CallMethodRequest) (*ua.CallMethodResult, error) { stats.Client().Add("Call", 1) creq := &ua.CallRequest{ MethodsToCall: []*ua.CallMethodRequest{req}, } var res *ua.CallResponse - err := c.SendWithContext(ctx, creq, func(v interface{}) error { + err := c.Send(ctx, creq, func(v interface{}) error { return safeAssign(v, &res) }) if err != nil { @@ -1172,19 +1081,11 @@ func (c *Client) CallWithContext(ctx context.Context, req *ua.CallMethodRequest) } // BrowseNext executes a synchronous browse request. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) BrowseNext(req *ua.BrowseNextRequest) (*ua.BrowseNextResponse, error) { - return c.BrowseNextWithContext(context.Background(), req) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) BrowseNextWithContext(ctx context.Context, req *ua.BrowseNextRequest) (*ua.BrowseNextResponse, error) { +func (c *Client) BrowseNext(ctx context.Context, req *ua.BrowseNextRequest) (*ua.BrowseNextResponse, error) { stats.Client().Add("BrowseNext", 1) var res *ua.BrowseNextResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err @@ -1192,21 +1093,13 @@ func (c *Client) BrowseNextWithContext(ctx context.Context, req *ua.BrowseNextRe // RegisterNodes registers node ids for more efficient reads. // -// # Part 4, Section 5.8.5 -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) RegisterNodes(req *ua.RegisterNodesRequest) (*ua.RegisterNodesResponse, error) { - return c.RegisterNodesWithContext(context.Background(), req) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) RegisterNodesWithContext(ctx context.Context, req *ua.RegisterNodesRequest) (*ua.RegisterNodesResponse, error) { +// Part 4, Section 5.8.5 +func (c *Client) RegisterNodes(ctx context.Context, req *ua.RegisterNodesRequest) (*ua.RegisterNodesResponse, error) { stats.Client().Add("RegisterNodes", 1) stats.Client().Add("NodesToRegister", int64(len(req.NodesToRegister))) var res *ua.RegisterNodesResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err @@ -1214,34 +1107,19 @@ func (c *Client) RegisterNodesWithContext(ctx context.Context, req *ua.RegisterN // UnregisterNodes unregisters node ids previously registered with RegisterNodes. // -// # Part 4, Section 5.8.6 -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) UnregisterNodes(req *ua.UnregisterNodesRequest) (*ua.UnregisterNodesResponse, error) { - return c.UnregisterNodesWithContext(context.Background(), req) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) UnregisterNodesWithContext(ctx context.Context, req *ua.UnregisterNodesRequest) (*ua.UnregisterNodesResponse, error) { +// Part 4, Section 5.8.6 +func (c *Client) UnregisterNodes(ctx context.Context, req *ua.UnregisterNodesRequest) (*ua.UnregisterNodesResponse, error) { stats.Client().Add("UnregisterNodes", 1) stats.Client().Add("NodesToUnregister", int64(len(req.NodesToUnregister))) var res *ua.UnregisterNodesResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err } -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) HistoryReadEvent(nodes []*ua.HistoryReadValueID, details *ua.ReadEventDetails) (*ua.HistoryReadResponse, error) { - return c.HistoryReadEventWithContext(context.Background(), nodes, details) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) HistoryReadEventWithContext(ctx context.Context, nodes []*ua.HistoryReadValueID, details *ua.ReadEventDetails) (*ua.HistoryReadResponse, error) { +func (c *Client) HistoryReadEvent(ctx context.Context, nodes []*ua.HistoryReadValueID, details *ua.ReadEventDetails) (*ua.HistoryReadResponse, error) { stats.Client().Add("HistoryReadEvent", 1) stats.Client().Add("HistoryReadValueID", int64(len(nodes))) @@ -1258,20 +1136,13 @@ func (c *Client) HistoryReadEventWithContext(ctx context.Context, nodes []*ua.Hi } var res *ua.HistoryReadResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err } -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) HistoryReadRawModified(nodes []*ua.HistoryReadValueID, details *ua.ReadRawModifiedDetails) (*ua.HistoryReadResponse, error) { - return c.HistoryReadRawModifiedWithContext(context.Background(), nodes, details) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) HistoryReadRawModifiedWithContext(ctx context.Context, nodes []*ua.HistoryReadValueID, details *ua.ReadRawModifiedDetails) (*ua.HistoryReadResponse, error) { +func (c *Client) HistoryReadRawModified(ctx context.Context, nodes []*ua.HistoryReadValueID, details *ua.ReadRawModifiedDetails) (*ua.HistoryReadResponse, error) { stats.Client().Add("HistoryReadRawModified", 1) stats.Client().Add("HistoryReadValueID", int64(len(nodes))) @@ -1288,20 +1159,13 @@ func (c *Client) HistoryReadRawModifiedWithContext(ctx context.Context, nodes [] } var res *ua.HistoryReadResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err } -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) HistoryReadProcessed(nodes []*ua.HistoryReadValueID, details *ua.ReadProcessedDetails) (*ua.HistoryReadResponse, error) { - return c.HistoryReadProcessedWithContext(context.Background(), nodes, details) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) HistoryReadProcessedWithContext(ctx context.Context, nodes []*ua.HistoryReadValueID, details *ua.ReadProcessedDetails) (*ua.HistoryReadResponse, error) { +func (c *Client) HistoryReadProcessed(ctx context.Context, nodes []*ua.HistoryReadValueID, details *ua.ReadProcessedDetails) (*ua.HistoryReadResponse, error) { stats.Client().Add("HistoryReadProcessed", 1) stats.Client().Add("HistoryReadValueID", int64(len(nodes))) @@ -1318,20 +1182,13 @@ func (c *Client) HistoryReadProcessedWithContext(ctx context.Context, nodes []*u } var res *ua.HistoryReadResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err } -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) HistoryReadAtTime(nodes []*ua.HistoryReadValueID, details *ua.ReadAtTimeDetails) (*ua.HistoryReadResponse, error) { - return c.HistoryReadAtTimeWithContext(context.Background(), nodes, details) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) HistoryReadAtTimeWithContext(ctx context.Context, nodes []*ua.HistoryReadValueID, details *ua.ReadAtTimeDetails) (*ua.HistoryReadResponse, error) { +func (c *Client) HistoryReadAtTime(ctx context.Context, nodes []*ua.HistoryReadValueID, details *ua.ReadAtTimeDetails) (*ua.HistoryReadResponse, error) { stats.Client().Add("HistoryReadAtTime", 1) stats.Client().Add("HistoryReadValueID", int64(len(nodes))) @@ -1348,25 +1205,17 @@ func (c *Client) HistoryReadAtTimeWithContext(ctx context.Context, nodes []*ua.H } var res *ua.HistoryReadResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err } // NamespaceArray returns the list of namespaces registered on the server. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) NamespaceArray() ([]string, error) { - return c.NamespaceArrayWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) NamespaceArrayWithContext(ctx context.Context) ([]string, error) { +func (c *Client) NamespaceArray(ctx context.Context) ([]string, error) { stats.Client().Add("NamespaceArray", 1) node := c.Node(ua.NewNumericNodeID(0, id.Server_NamespaceArray)) - v, err := node.ValueWithContext(ctx) + v, err := node.Value(ctx) if err != nil { return nil, err } @@ -1379,17 +1228,9 @@ func (c *Client) NamespaceArrayWithContext(ctx context.Context) ([]string, error } // FindNamespace returns the id of the namespace with the given name. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) FindNamespace(name string) (uint16, error) { - return c.FindNamespaceWithContext(context.Background(), name) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) FindNamespaceWithContext(ctx context.Context, name string) (uint16, error) { +func (c *Client) FindNamespace(ctx context.Context, name string) (uint16, error) { stats.Client().Add("FindNamespace", 1) - nsa, err := c.NamespaceArrayWithContext(ctx) + nsa, err := c.NamespaceArray(ctx) if err != nil { return 0, err } @@ -1402,17 +1243,9 @@ func (c *Client) FindNamespaceWithContext(ctx context.Context, name string) (uin } // UpdateNamespaces updates the list of cached namespaces from the server. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) UpdateNamespaces() error { - return c.UpdateNamespacesWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) UpdateNamespacesWithContext(ctx context.Context) error { +func (c *Client) UpdateNamespaces(ctx context.Context) error { stats.Client().Add("UpdateNamespaces", 1) - ns, err := c.NamespaceArrayWithContext(ctx) + ns, err := c.NamespaceArray(ctx) if err != nil { return err } diff --git a/client_sub.go b/client_sub.go index 63578b46..80b387dc 100644 --- a/client_sub.go +++ b/client_sub.go @@ -17,15 +17,7 @@ import ( // Subscribe creates a Subscription with given parameters. // Parameters that have not been set are set to their default values. // See opcua.DefaultSubscription* constants -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (c *Client) Subscribe(params *SubscriptionParameters, notifyCh chan<- *PublishNotificationData) (*Subscription, error) { - return c.SubscribeWithContext(context.Background(), params, notifyCh) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (c *Client) SubscribeWithContext(ctx context.Context, params *SubscriptionParameters, notifyCh chan<- *PublishNotificationData) (*Subscription, error) { +func (c *Client) Subscribe(ctx context.Context, params *SubscriptionParameters, notifyCh chan<- *PublishNotificationData) (*Subscription, error) { stats.Client().Add("Subscribe", 1) if params == nil { @@ -43,7 +35,7 @@ func (c *Client) SubscribeWithContext(ctx context.Context, params *SubscriptionP } var res *ua.CreateSubscriptionResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) if err != nil { @@ -118,7 +110,7 @@ func (c *Client) transferSubscriptions(ctx context.Context, ids []uint32) (*ua.T } var res *ua.TransferSubscriptionsResponse - err := c.SendWithContext(ctx, req, func(v interface{}) error { + err := c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err @@ -186,7 +178,7 @@ func (c *Client) sendRepublishRequests(ctx context.Context, sub *Subscription, a debug.Printf("RepublishRequest: req=%s", debug.ToJSON(req)) var res *ua.RepublishResponse - err := sc.SendRequestWithContext(ctx, req, s.resp.AuthenticationToken, func(v interface{}) error { + err := c.SecureChannel().SendRequest(ctx, req, c.Session().resp.AuthenticationToken, func(v interface{}) error { return safeAssign(v, &res) }) debug.Printf("RepublishResponse: res=%s err=%v", debug.ToJSON(res), err) diff --git a/client_test.go b/client_test.go index 6a0a1c19..a1b12d82 100644 --- a/client_test.go +++ b/client_test.go @@ -4,14 +4,15 @@ import ( "context" "testing" + "github.com/pascaldekloe/goe/verify" + "github.com/gopcua/opcua/id" "github.com/gopcua/opcua/ua" - "github.com/pascaldekloe/goe/verify" ) func TestClient_Send_DoesNotPanicWhenDisconnected(t *testing.T) { c := NewClient("opc.tcp://example.com:4840") - err := c.SendWithContext(context.Background(), &ua.ReadRequest{}, func(i interface{}) error { + err := c.Send(context.Background(), &ua.ReadRequest{}, func(i interface{}) error { return nil }) verify.Values(t, "", err, ua.StatusBadServerNotConnected) diff --git a/examples/accesslevel/accesslevel.go b/examples/accesslevel/accesslevel.go index fad940ee..39bc2349 100644 --- a/examples/accesslevel/accesslevel.go +++ b/examples/accesslevel/accesslevel.go @@ -29,7 +29,7 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) id, err := ua.ParseNodeID(*nodeID) if err != nil { @@ -37,19 +37,19 @@ func main() { } n := c.Node(id) - accessLevel, err := n.AccessLevelWithContext(ctx) + accessLevel, err := n.AccessLevel(ctx) if err != nil { log.Fatal(err) } log.Print("AccessLevel: ", accessLevel) - userAccessLevel, err := n.UserAccessLevelWithContext(ctx) + userAccessLevel, err := n.UserAccessLevel(ctx) if err != nil { log.Fatal(err) } log.Print("UserAccessLevel: ", userAccessLevel) - v, err := n.ValueWithContext(ctx) + v, err := n.Value(ctx) switch { case err != nil: log.Fatal(err) diff --git a/examples/browse/browse.go b/examples/browse/browse.go index 68678650..2287662c 100644 --- a/examples/browse/browse.go +++ b/examples/browse/browse.go @@ -51,7 +51,7 @@ func browse(ctx context.Context, n *opcua.Node, path string, level int) ([]NodeD return nil, nil } - attrs, err := n.AttributesWithContext(ctx, ua.AttributeIDNodeClass, ua.AttributeIDBrowseName, ua.AttributeIDDescription, ua.AttributeIDAccessLevel, ua.AttributeIDDataType) + attrs, err := n.Attributes(ctx, ua.AttributeIDNodeClass, ua.AttributeIDBrowseName, ua.AttributeIDDescription, ua.AttributeIDAccessLevel, ua.AttributeIDDataType) if err != nil { return nil, err } @@ -138,7 +138,7 @@ func browse(ctx context.Context, n *opcua.Node, path string, level int) ([]NodeD } browseChildren := func(refType uint32) error { - refs, err := n.ReferencedNodesWithContext(ctx, refType, ua.BrowseDirectionForward, ua.NodeClassAll, true) + refs, err := n.ReferencedNodes(ctx, refType, ua.BrowseDirectionForward, ua.NodeClassAll, true) if err != nil { return errors.Errorf("References: %d: %s", refType, err) } @@ -178,7 +178,7 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) id, err := ua.ParseNodeID(*nodeID) if err != nil { diff --git a/examples/crypto/crypto.go b/examples/crypto/crypto.go index b1a32c3a..dc7b6203 100644 --- a/examples/crypto/crypto.go +++ b/examples/crypto/crypto.go @@ -67,10 +67,10 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) // Use our connection (read the server's time) - v, err := c.Node(ua.NewNumericNodeID(0, 2258)).ValueWithContext(ctx) + v, err := c.Node(ua.NewNumericNodeID(0, 2258)).Value(ctx) if err != nil { log.Fatal(err) } @@ -81,7 +81,7 @@ func main() { } // Detach our session and try re-establish it on a different secure channel - s, err := c.DetachSessionWithContext(ctx) + s, err := c.DetachSession(ctx) if err != nil { log.Fatalf("Error detaching session: %s", err) } @@ -90,16 +90,16 @@ func main() { // Create a channel only and do not activate it automatically d.Dial(ctx) - defer d.CloseWithContext(ctx) + defer d.Close(ctx) // Activate the previous session on the new channel - err = d.ActivateSessionWithContext(ctx, s) + err = d.ActivateSession(ctx, s) if err != nil { log.Fatalf("Error reactivating session: %s", err) } // Read the time again to prove our session is still OK - v, err = d.Node(ua.NewNumericNodeID(0, 2258)).ValueWithContext(ctx) + v, err = d.Node(ua.NewNumericNodeID(0, 2258)).Value(ctx) if err != nil { log.Fatal(err) } diff --git a/examples/datetime/datetime.go b/examples/datetime/datetime.go index 59a22f33..ad2ae770 100644 --- a/examples/datetime/datetime.go +++ b/examples/datetime/datetime.go @@ -51,9 +51,9 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) - v, err := c.Node(ua.NewNumericNodeID(0, 2258)).ValueWithContext(ctx) + v, err := c.Node(ua.NewNumericNodeID(0, 2258)).Value(ctx) switch { case err != nil: log.Fatal(err) diff --git a/examples/history-read/history-read.go b/examples/history-read/history-read.go index e514ddc5..d3cc2b53 100644 --- a/examples/history-read/history-read.go +++ b/examples/history-read/history-read.go @@ -28,7 +28,7 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) id, err := ua.ParseNodeID(*nodeID) if err != nil { @@ -54,7 +54,7 @@ func main() { // Reset old nodes nodesToRequest = make([]*ua.HistoryReadValueID, 0) - data, err := c.HistoryReadRawModifiedWithContext(ctx, nodes, &ua.ReadRawModifiedDetails{ + data, err := c.HistoryReadRawModified(ctx, nodes, &ua.ReadRawModifiedDetails{ IsReadModified: false, StartTime: time.Now().UTC().AddDate(0, -1, 0), EndTime: time.Now().UTC().AddDate(0, 1, 0), diff --git a/examples/method/method.go b/examples/method/method.go index 34dc47d0..802dcd7c 100644 --- a/examples/method/method.go +++ b/examples/method/method.go @@ -28,7 +28,7 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) in := int64(12) req := &ua.CallMethodRequest{ @@ -37,7 +37,7 @@ func main() { InputArguments: []*ua.Variant{ua.MustVariant(in)}, } - resp, err := c.CallWithContext(ctx, req) + resp, err := c.Call(ctx, req) if err != nil { log.Fatal(err) } diff --git a/examples/monitor/monitor.go b/examples/monitor/monitor.go index 581d629b..8700cbe7 100644 --- a/examples/monitor/monitor.go +++ b/examples/monitor/monitor.go @@ -68,7 +68,7 @@ func main() { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) m, err := monitor.NewNodeMonitor(c) if err != nil { diff --git a/examples/read/read.go b/examples/read/read.go index c1955567..a921e025 100644 --- a/examples/read/read.go +++ b/examples/read/read.go @@ -32,7 +32,7 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) id, err := ua.ParseNodeID(*nodeID) if err != nil { @@ -49,7 +49,7 @@ func main() { var resp *ua.ReadResponse for { - resp, err = c.ReadWithContext(ctx, req) + resp, err = c.Read(ctx, req) if err == nil { break } diff --git a/examples/regread/regread.go b/examples/regread/regread.go index dd86c401..ca2ca8b8 100644 --- a/examples/regread/regread.go +++ b/examples/regread/regread.go @@ -29,14 +29,14 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) id, err := ua.ParseNodeID(*nodeID) if err != nil { log.Fatalf("invalid node id: %v", err) } - regResp, err := c.RegisterNodesWithContext(ctx, &ua.RegisterNodesRequest{ + regResp, err := c.RegisterNodes(ctx, &ua.RegisterNodesRequest{ NodesToRegister: []*ua.NodeID{id}, }) if err != nil { @@ -51,7 +51,7 @@ func main() { TimestampsToReturn: ua.TimestampsToReturnBoth, } - resp, err := c.ReadWithContext(ctx, req) + resp, err := c.Read(ctx, req) if err != nil { log.Fatalf("Read failed: %s", err) } @@ -60,7 +60,7 @@ func main() { } log.Print(resp.Results[0].Value.Value()) - _, err = c.UnregisterNodesWithContext(ctx, &ua.UnregisterNodesRequest{ + _, err = c.UnregisterNodes(ctx, &ua.UnregisterNodesRequest{ NodesToUnregister: []*ua.NodeID{id}, }) if err != nil { diff --git a/examples/subscribe/subscribe.go b/examples/subscribe/subscribe.go index f3c42689..32134d23 100644 --- a/examples/subscribe/subscribe.go +++ b/examples/subscribe/subscribe.go @@ -64,11 +64,11 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) notifyCh := make(chan *opcua.PublishNotificationData) - sub, err := c.SubscribeWithContext(ctx, &opcua.SubscriptionParameters{ + sub, err := c.Subscribe(ctx, &opcua.SubscriptionParameters{ Interval: *interval, }, notifyCh) if err != nil { @@ -89,7 +89,7 @@ func main() { } else { miCreateRequest = valueRequest(id) } - res, err := sub.Monitor(ua.TimestampsToReturnBoth, miCreateRequest) + res, err := sub.Monitor(ctx, ua.TimestampsToReturnBoth, miCreateRequest) if err != nil || res.Results[0].StatusCode != ua.StatusOK { log.Fatal(err) } diff --git a/examples/translate/translate.go b/examples/translate/translate.go index 91c8cdbe..3f9c6ffe 100644 --- a/examples/translate/translate.go +++ b/examples/translate/translate.go @@ -31,10 +31,10 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) root := c.Node(ua.NewTwoByteNodeID(id.ObjectsFolder)) - nodeID, err := root.TranslateBrowsePathInNamespaceToNodeIDWithContext(ctx, uint16(*ns), *nodePath) + nodeID, err := root.TranslateBrowsePathInNamespaceToNodeID(ctx, uint16(*ns), *nodePath) if err != nil { log.Fatal(err) } diff --git a/examples/trigger/trigger.go b/examples/trigger/trigger.go index 5502272d..e6f685f1 100644 --- a/examples/trigger/trigger.go +++ b/examples/trigger/trigger.go @@ -63,11 +63,11 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) notifyCh := make(chan *opcua.PublishNotificationData) - sub, err := c.Subscribe(&opcua.SubscriptionParameters{ + sub, err := c.Subscribe(ctx, &opcua.SubscriptionParameters{ Interval: *interval, }, notifyCh) if err != nil { @@ -105,13 +105,13 @@ func main() { }, } - subRes, err := sub.Monitor(ua.TimestampsToReturnBoth, miCreateRequests...) + subRes, err := sub.Monitor(ctx, ua.TimestampsToReturnBoth, miCreateRequests...) if err != nil || subRes.Results[0].StatusCode != ua.StatusOK { log.Fatal(err) } triggeringServerID, triggeredServerID := subRes.Results[0].MonitoredItemID, subRes.Results[1].MonitoredItemID - tRes, err := sub.SetTriggering(triggeringServerID, []uint32{triggeredServerID}, nil) + tRes, err := sub.SetTriggering(ctx, triggeringServerID, []uint32{triggeredServerID}, nil) if err != nil { log.Fatal(err) diff --git a/examples/udt/udt.go b/examples/udt/udt.go index a67fc846..b7eebdda 100644 --- a/examples/udt/udt.go +++ b/examples/udt/udt.go @@ -59,9 +59,9 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) - v, err := c.Node(id).ValueWithContext(ctx) + v, err := c.Node(id).Value(ctx) switch { case err != nil: log.Fatal(err) diff --git a/examples/write/write.go b/examples/write/write.go index 92df561f..62f9dd98 100644 --- a/examples/write/write.go +++ b/examples/write/write.go @@ -30,7 +30,7 @@ func main() { if err := c.Connect(ctx); err != nil { log.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) id, err := ua.ParseNodeID(*nodeID) if err != nil { @@ -55,7 +55,7 @@ func main() { }, } - resp, err := c.WriteWithContext(ctx, req) + resp, err := c.Write(ctx, req) if err != nil { log.Fatalf("Write failed: %s", err) } diff --git a/monitor/subscription.go b/monitor/subscription.go index 58698859..22f7ef54 100644 --- a/monitor/subscription.go +++ b/monitor/subscription.go @@ -102,11 +102,11 @@ func newSubscription(ctx context.Context, m *NodeMonitor, params *opcua.Subscrip } var err error - if s.sub, err = m.client.SubscribeWithContext(ctx, params, s.internalNotifyCh); err != nil { + if s.sub, err = m.client.Subscribe(ctx, params, s.internalNotifyCh); err != nil { return nil, err } - if err = s.AddNodesWithContext(ctx, nodes...); err != nil { + if err = s.AddNodes(ctx, nodes...); err != nil { return nil, err } @@ -254,32 +254,16 @@ func (s *Subscription) Dropped() uint64 { } // AddNodes adds nodes defined by their string representation -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) AddNodes(nodes ...string) error { - return s.AddNodesWithContext(context.Background(), nodes...) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) AddNodesWithContext(ctx context.Context, nodes ...string) error { +func (s *Subscription) AddNodes(ctx context.Context, nodes ...string) error { nodeIDs, err := parseNodeSlice(nodes...) if err != nil { return err } - return s.AddNodeIDsWithContext(ctx, nodeIDs...) + return s.AddNodeIDs(ctx, nodeIDs...) } // AddNodeIDs adds nodes -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) AddNodeIDs(nodes ...*ua.NodeID) error { - return s.AddNodeIDsWithContext(context.Background(), nodes...) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) AddNodeIDsWithContext(ctx context.Context, nodes ...*ua.NodeID) error { +func (s *Subscription) AddNodeIDs(ctx context.Context, nodes ...*ua.NodeID) error { requests := make([]Request, len(nodes)) for i, node := range nodes { @@ -288,20 +272,12 @@ func (s *Subscription) AddNodeIDsWithContext(ctx context.Context, nodes ...*ua.N MonitoringMode: ua.MonitoringModeReporting, } } - _, err := s.AddMonitorItemsWithContext(ctx, requests...) + _, err := s.AddMonitorItems(ctx, requests...) return err } // AddMonitorItems adds nodes with monitoring parameters to the subscription -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) AddMonitorItems(nodes ...Request) ([]Item, error) { - return s.AddMonitorItemsWithContext(context.Background(), nodes...) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) AddMonitorItemsWithContext(ctx context.Context, nodes ...Request) ([]Item, error) { +func (s *Subscription) AddMonitorItems(ctx context.Context, nodes ...Request) ([]Item, error) { s.mu.Lock() defer s.mu.Unlock() @@ -328,7 +304,7 @@ func (s *Subscription) AddMonitorItemsWithContext(ctx context.Context, nodes ... } toAdd = append(toAdd, request) } - resp, err := s.sub.MonitorWithContext(ctx, ua.TimestampsToReturnBoth, toAdd...) + resp, err := s.sub.Monitor(ctx, ua.TimestampsToReturnBoth, toAdd...) if err != nil { return nil, err } @@ -358,32 +334,16 @@ func (s *Subscription) AddMonitorItemsWithContext(ctx context.Context, nodes ... } // RemoveNodes removes nodes defined by their string representation -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) RemoveNodes(nodes ...string) error { - return s.RemoveNodesWithContext(context.Background(), nodes...) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) RemoveNodesWithContext(ctx context.Context, nodes ...string) error { +func (s *Subscription) RemoveNodes(ctx context.Context, nodes ...string) error { nodeIDs, err := parseNodeSlice(nodes...) if err != nil { return err } - return s.RemoveNodeIDsWithContext(ctx, nodeIDs...) + return s.RemoveNodeIDs(ctx, nodeIDs...) } // RemoveNodeIDs removes nodes -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) RemoveNodeIDs(nodes ...*ua.NodeID) error { - return s.RemoveNodeIDsWithContext(context.Background(), nodes...) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) RemoveNodeIDsWithContext(ctx context.Context, nodes ...*ua.NodeID) error { +func (s *Subscription) RemoveNodeIDs(ctx context.Context, nodes ...*ua.NodeID) error { if len(nodes) == 0 { return nil } @@ -398,19 +358,11 @@ func (s *Subscription) RemoveNodeIDsWithContext(ctx context.Context, nodes ...*u } } - return s.RemoveMonitorItemsWithContext(ctx, toRemove...) + return s.RemoveMonitorItems(ctx, toRemove...) } // RemoveMonitorItems removes nodes -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) RemoveMonitorItems(items ...Item) error { - return s.RemoveMonitorItemsWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) RemoveMonitorItemsWithContext(ctx context.Context, items ...Item) error { +func (s *Subscription) RemoveMonitorItems(ctx context.Context, items ...Item) error { s.mu.Lock() defer s.mu.Unlock() @@ -429,7 +381,7 @@ func (s *Subscription) RemoveMonitorItemsWithContext(ctx context.Context, items toRemove = append(toRemove, item.id) } - resp, err := s.sub.UnmonitorWithContext(ctx, toRemove...) + resp, err := s.sub.Unmonitor(ctx, toRemove...) if err != nil { return err } @@ -452,16 +404,8 @@ func (s *Subscription) RemoveMonitorItemsWithContext(ctx context.Context, items } // Stats returns statistics for the subscription -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) Stats() (*ua.SubscriptionDiagnosticsDataType, error) { - return s.StatsWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) StatsWithContext(ctx context.Context) (*ua.SubscriptionDiagnosticsDataType, error) { - return s.sub.StatsWithContext(ctx) +func (s *Subscription) Stats(ctx context.Context) (*ua.SubscriptionDiagnosticsDataType, error) { + return s.sub.Stats(ctx) } func parseNodeSlice(nodes ...string) ([]*ua.NodeID, error) { diff --git a/node.go b/node.go index c025e697..9719b036 100644 --- a/node.go +++ b/node.go @@ -27,16 +27,8 @@ func (n *Node) String() string { } // NodeClass returns the node class attribute. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. func (n *Node) NodeClass(ctx context.Context) (ua.NodeClass, error) { - return n.NodeClassWithContext(ctx) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) NodeClassWithContext(ctx context.Context) (ua.NodeClass, error) { - v, err := n.AttributeWithContext(ctx, ua.AttributeIDNodeClass) + v, err := n.Attribute(ctx, ua.AttributeIDNodeClass) if err != nil { return 0, err } @@ -44,16 +36,8 @@ func (n *Node) NodeClassWithContext(ctx context.Context) (ua.NodeClass, error) { } // BrowseName returns the browse name of the node. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) BrowseName() (*ua.QualifiedName, error) { - return n.BrowseNameWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) BrowseNameWithContext(ctx context.Context) (*ua.QualifiedName, error) { - v, err := n.AttributeWithContext(ctx, ua.AttributeIDBrowseName) +func (n *Node) BrowseName(ctx context.Context) (*ua.QualifiedName, error) { + v, err := n.Attribute(ctx, ua.AttributeIDBrowseName) if err != nil { return nil, err } @@ -61,16 +45,8 @@ func (n *Node) BrowseNameWithContext(ctx context.Context) (*ua.QualifiedName, er } // Description returns the description of the node. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) Description() (*ua.LocalizedText, error) { - return n.DescriptionWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) DescriptionWithContext(ctx context.Context) (*ua.LocalizedText, error) { - v, err := n.AttributeWithContext(ctx, ua.AttributeIDDescription) +func (n *Node) Description(ctx context.Context) (*ua.LocalizedText, error) { + v, err := n.Attribute(ctx, ua.AttributeIDDescription) if err != nil { return nil, err } @@ -78,16 +54,8 @@ func (n *Node) DescriptionWithContext(ctx context.Context) (*ua.LocalizedText, e } // DisplayName returns the display name of the node. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) DisplayName() (*ua.LocalizedText, error) { - return n.DisplayNameWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) DisplayNameWithContext(ctx context.Context) (*ua.LocalizedText, error) { - v, err := n.AttributeWithContext(ctx, ua.AttributeIDDisplayName) +func (n *Node) DisplayName(ctx context.Context) (*ua.LocalizedText, error) { + v, err := n.Attribute(ctx, ua.AttributeIDDisplayName) if err != nil { return nil, err } @@ -97,16 +65,8 @@ func (n *Node) DisplayNameWithContext(ctx context.Context) (*ua.LocalizedText, e // AccessLevel returns the access level of the node. // The returned value is a mask where multiple values can be // set, e.g. read and write. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) AccessLevel() (ua.AccessLevelType, error) { - return n.AccessLevelWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) AccessLevelWithContext(ctx context.Context) (ua.AccessLevelType, error) { - v, err := n.AttributeWithContext(ctx, ua.AttributeIDAccessLevel) +func (n *Node) AccessLevel(ctx context.Context) (ua.AccessLevelType, error) { + v, err := n.Attribute(ctx, ua.AttributeIDAccessLevel) if err != nil { return 0, err } @@ -115,16 +75,8 @@ func (n *Node) AccessLevelWithContext(ctx context.Context) (ua.AccessLevelType, // HasAccessLevel returns true if all bits from mask are // set in the access level mask of the node. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) HasAccessLevel(mask ua.AccessLevelType) (bool, error) { - return n.HasAccessLevelWithContext(context.Background(), mask) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) HasAccessLevelWithContext(ctx context.Context, mask ua.AccessLevelType) (bool, error) { - v, err := n.AccessLevelWithContext(ctx) +func (n *Node) HasAccessLevel(ctx context.Context, mask ua.AccessLevelType) (bool, error) { + v, err := n.AccessLevel(ctx) if err != nil { return false, err } @@ -132,16 +84,8 @@ func (n *Node) HasAccessLevelWithContext(ctx context.Context, mask ua.AccessLeve } // UserAccessLevel returns the access level of the node. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) UserAccessLevel() (ua.AccessLevelType, error) { - return n.UserAccessLevelWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) UserAccessLevelWithContext(ctx context.Context) (ua.AccessLevelType, error) { - v, err := n.AttributeWithContext(ctx, ua.AttributeIDUserAccessLevel) +func (n *Node) UserAccessLevel(ctx context.Context) (ua.AccessLevelType, error) { + v, err := n.Attribute(ctx, ua.AttributeIDUserAccessLevel) if err != nil { return 0, err } @@ -150,16 +94,8 @@ func (n *Node) UserAccessLevelWithContext(ctx context.Context) (ua.AccessLevelTy // HasUserAccessLevel returns true if all bits from mask are // set in the user access level mask of the node. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) HasUserAccessLevel(mask ua.AccessLevelType) (bool, error) { - return n.HasUserAccessLevelWithContext(context.Background(), mask) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) HasUserAccessLevelWithContext(ctx context.Context, mask ua.AccessLevelType) (bool, error) { - v, err := n.UserAccessLevelWithContext(ctx) +func (n *Node) HasUserAccessLevel(ctx context.Context, mask ua.AccessLevelType) (bool, error) { + v, err := n.UserAccessLevel(ctx) if err != nil { return false, err } @@ -167,31 +103,15 @@ func (n *Node) HasUserAccessLevelWithContext(ctx context.Context, mask ua.Access } // Value returns the value of the node. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) Value() (*ua.Variant, error) { - return n.ValueWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) ValueWithContext(ctx context.Context) (*ua.Variant, error) { - return n.AttributeWithContext(ctx, ua.AttributeIDValue) +func (n *Node) Value(ctx context.Context) (*ua.Variant, error) { + return n.Attribute(ctx, ua.AttributeIDValue) } // Attribute returns the attribute of the node. with the given id. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) Attribute(attrID ua.AttributeID) (*ua.Variant, error) { - return n.AttributeWithContext(context.Background(), attrID) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) AttributeWithContext(ctx context.Context, attrID ua.AttributeID) (*ua.Variant, error) { +func (n *Node) Attribute(ctx context.Context, attrID ua.AttributeID) (*ua.Variant, error) { rv := &ua.ReadValueID{NodeID: n.ID, AttributeID: attrID} req := &ua.ReadRequest{NodesToRead: []*ua.ReadValueID{rv}} - res, err := n.c.ReadWithContext(ctx, req) + res, err := n.c.Read(ctx, req) if err != nil { return nil, err } @@ -208,21 +128,13 @@ func (n *Node) AttributeWithContext(ctx context.Context, attrID ua.AttributeID) } // Attributes returns the given node attributes. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) Attributes(attrID ...ua.AttributeID) ([]*ua.DataValue, error) { - return n.AttributesWithContext(context.Background(), attrID...) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) AttributesWithContext(ctx context.Context, attrID ...ua.AttributeID) ([]*ua.DataValue, error) { +func (n *Node) Attributes(ctx context.Context, attrID ...ua.AttributeID) ([]*ua.DataValue, error) { req := &ua.ReadRequest{} for _, id := range attrID { rv := &ua.ReadValueID{NodeID: n.ID, AttributeID: id} req.NodesToRead = append(req.NodesToRead, rv) } - res, err := n.c.ReadWithContext(ctx, req) + res, err := n.c.Read(ctx, req) if err != nil { return nil, err } @@ -230,36 +142,20 @@ func (n *Node) AttributesWithContext(ctx context.Context, attrID ...ua.Attribute } // Children returns the child nodes which match the node class mask. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) Children(refs uint32, mask ua.NodeClass) ([]*Node, error) { - return n.ChildrenWithContext(context.Background(), refs, mask) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) ChildrenWithContext(ctx context.Context, refs uint32, mask ua.NodeClass) ([]*Node, error) { +func (n *Node) Children(ctx context.Context, refs uint32, mask ua.NodeClass) ([]*Node, error) { if refs == 0 { refs = id.HierarchicalReferences } - return n.ReferencedNodesWithContext(ctx, refs, ua.BrowseDirectionForward, mask, true) + return n.ReferencedNodes(ctx, refs, ua.BrowseDirectionForward, mask, true) } // ReferencedNodes returns the nodes referenced by this node. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) ReferencedNodes(refs uint32, dir ua.BrowseDirection, mask ua.NodeClass, includeSubtypes bool) ([]*Node, error) { - return n.ReferencedNodesWithContext(context.Background(), refs, dir, mask, includeSubtypes) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) ReferencedNodesWithContext(ctx context.Context, refs uint32, dir ua.BrowseDirection, mask ua.NodeClass, includeSubtypes bool) ([]*Node, error) { +func (n *Node) ReferencedNodes(ctx context.Context, refs uint32, dir ua.BrowseDirection, mask ua.NodeClass, includeSubtypes bool) ([]*Node, error) { if refs == 0 { refs = id.References } var nodes []*Node - res, err := n.ReferencesWithContext(ctx, refs, dir, mask, includeSubtypes) + res, err := n.References(ctx, refs, dir, mask, includeSubtypes) if err != nil { return nil, err } @@ -271,17 +167,9 @@ func (n *Node) ReferencedNodesWithContext(ctx context.Context, refs uint32, dir // References returns all references for the node. // -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -// // todo(fs): this is not complete since it only returns the // todo(fs): top-level reference at this point. -func (n *Node) References(refType uint32, dir ua.BrowseDirection, mask ua.NodeClass, includeSubtypes bool) ([]*ua.ReferenceDescription, error) { - return n.ReferencesWithContext(context.Background(), refType, dir, mask, includeSubtypes) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) ReferencesWithContext(ctx context.Context, refType uint32, dir ua.BrowseDirection, mask ua.NodeClass, includeSubtypes bool) ([]*ua.ReferenceDescription, error) { +func (n *Node) References(ctx context.Context, refType uint32, dir ua.BrowseDirection, mask ua.NodeClass, includeSubtypes bool) ([]*ua.ReferenceDescription, error) { if refType == 0 { refType = id.References } @@ -306,7 +194,7 @@ func (n *Node) ReferencesWithContext(ctx context.Context, refType uint32, dir ua NodesToBrowse: []*ua.BrowseDescription{desc}, } - resp, err := n.c.BrowseWithContext(ctx, req) + resp, err := n.c.Browse(ctx, req) if err != nil { return nil, err } @@ -320,7 +208,7 @@ func (n *Node) browseNext(ctx context.Context, results []*ua.BrowseResult) ([]*u ContinuationPoints: [][]byte{results[0].ContinuationPoint}, ReleaseContinuationPoints: false, } - resp, err := n.c.BrowseNextWithContext(ctx, req) + resp, err := n.c.BrowseNext(ctx, req) if err != nil { return nil, err } @@ -331,15 +219,7 @@ func (n *Node) browseNext(ctx context.Context, results []*ua.BrowseResult) ([]*u } // TranslateBrowsePathsToNodeIDs translates an array of browseName segments to NodeIDs. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) TranslateBrowsePathsToNodeIDs(pathNames []*ua.QualifiedName) (*ua.NodeID, error) { - return n.TranslateBrowsePathsToNodeIDsWithContext(context.Background(), pathNames) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) TranslateBrowsePathsToNodeIDsWithContext(ctx context.Context, pathNames []*ua.QualifiedName) (*ua.NodeID, error) { +func (n *Node) TranslateBrowsePathsToNodeIDs(ctx context.Context, pathNames []*ua.QualifiedName) (*ua.NodeID, error) { req := ua.TranslateBrowsePathsToNodeIDsRequest{ BrowsePaths: []*ua.BrowsePath{ { @@ -361,7 +241,7 @@ func (n *Node) TranslateBrowsePathsToNodeIDsWithContext(ctx context.Context, pat } var nodeID *ua.NodeID - err := n.c.SendWithContext(ctx, &req, func(i interface{}) error { + err := n.c.Send(ctx, &req, func(i interface{}) error { if resp, ok := i.(*ua.TranslateBrowsePathsToNodeIDsResponse); ok { if len(resp.Results) == 0 { return ua.StatusBadUnexpectedError @@ -383,20 +263,12 @@ func (n *Node) TranslateBrowsePathsToNodeIDsWithContext(ctx context.Context, pat } // TranslateBrowsePathInNamespaceToNodeID translates a browseName to a NodeID within the same namespace. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (n *Node) TranslateBrowsePathInNamespaceToNodeID(ns uint16, browsePath string) (*ua.NodeID, error) { - return n.TranslateBrowsePathInNamespaceToNodeIDWithContext(context.Background(), ns, browsePath) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (n *Node) TranslateBrowsePathInNamespaceToNodeIDWithContext(ctx context.Context, ns uint16, browsePath string) (*ua.NodeID, error) { +func (n *Node) TranslateBrowsePathInNamespaceToNodeID(ctx context.Context, ns uint16, browsePath string) (*ua.NodeID, error) { segments := strings.Split(browsePath, ".") var names []*ua.QualifiedName for _, segment := range segments { qn := &ua.QualifiedName{NamespaceIndex: ns, Name: segment} names = append(names, qn) } - return n.TranslateBrowsePathsToNodeIDsWithContext(ctx, names) + return n.TranslateBrowsePathsToNodeIDs(ctx, names) } diff --git a/subscription.go b/subscription.go index 15f9a397..7318f2ba 100644 --- a/subscription.go +++ b/subscription.go @@ -94,7 +94,7 @@ func (s *Subscription) delete(ctx context.Context) error { } var res *ua.DeleteSubscriptionsResponse - err := s.c.SendWithContext(ctx, req, func(v interface{}) error { + err := s.c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) @@ -111,14 +111,7 @@ func (s *Subscription) delete(ctx context.Context) error { } } -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) Monitor(ts ua.TimestampsToReturn, items ...*ua.MonitoredItemCreateRequest) (*ua.CreateMonitoredItemsResponse, error) { - return s.MonitorWithContext(context.Background(), ts, items...) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) MonitorWithContext(ctx context.Context, ts ua.TimestampsToReturn, items ...*ua.MonitoredItemCreateRequest) (*ua.CreateMonitoredItemsResponse, error) { +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))) @@ -130,7 +123,7 @@ func (s *Subscription) MonitorWithContext(ctx context.Context, ts ua.TimestampsT } var res *ua.CreateMonitoredItemsResponse - err := s.c.SendWithContext(ctx, req, func(v interface{}) error { + err := s.c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) @@ -153,14 +146,7 @@ func (s *Subscription) MonitorWithContext(ctx context.Context, ts ua.TimestampsT return res, err } -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) Unmonitor(monitoredItemIDs ...uint32) (*ua.DeleteMonitoredItemsResponse, error) { - return s.UnmonitorWithContext(context.Background(), monitoredItemIDs...) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) UnmonitorWithContext(ctx context.Context, monitoredItemIDs ...uint32) (*ua.DeleteMonitoredItemsResponse, error) { +func (s *Subscription) Unmonitor(ctx context.Context, monitoredItemIDs ...uint32) (*ua.DeleteMonitoredItemsResponse, error) { stats.Subscription().Add("Unmonitor", 1) stats.Subscription().Add("UnmonitoredItems", int64(len(monitoredItemIDs))) @@ -170,7 +156,7 @@ func (s *Subscription) UnmonitorWithContext(ctx context.Context, monitoredItemID } var res *ua.DeleteMonitoredItemsResponse - err := s.c.SendWithContext(ctx, req, func(v interface{}) error { + err := s.c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) if err != nil { @@ -187,14 +173,7 @@ func (s *Subscription) UnmonitorWithContext(ctx context.Context, monitoredItemID return res, nil } -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) ModifyMonitoredItems(ts ua.TimestampsToReturn, items ...*ua.MonitoredItemModifyRequest) (*ua.ModifyMonitoredItemsResponse, error) { - return s.ModifyMonitoredItemsWithContext(context.Background(), ts, items...) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) ModifyMonitoredItemsWithContext(ctx context.Context, ts ua.TimestampsToReturn, items ...*ua.MonitoredItemModifyRequest) (*ua.ModifyMonitoredItemsResponse, error) { +func (s *Subscription) ModifyMonitoredItems(ctx context.Context, ts ua.TimestampsToReturn, items ...*ua.MonitoredItemModifyRequest) (*ua.ModifyMonitoredItemsResponse, error) { stats.Subscription().Add("ModifyMonitoredItems", 1) stats.Subscription().Add("ModifiedMonitoredItems", int64(len(items))) @@ -213,7 +192,7 @@ func (s *Subscription) ModifyMonitoredItemsWithContext(ctx context.Context, ts u ItemsToModify: items, } var res *ua.ModifyMonitoredItemsResponse - err := s.c.SendWithContext(ctx, req, func(v interface{}) error { + err := s.c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) if err != nil { @@ -244,15 +223,7 @@ func (s *Subscription) ModifyMonitoredItemsWithContext(ctx context.Context, ts u // SetTriggering sends a request to the server to add and/or remove triggering links from a triggering item. // To add links from a triggering item to an item to report provide the server assigned ID(s) in the `add` argument. // To remove links from a triggering item to an item to report provide the server assigned ID(s) in the `remove` argument. -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) SetTriggering(triggeringItemID uint32, add, remove []uint32) (*ua.SetTriggeringResponse, error) { - return s.SetTriggeringWithContext(context.Background(), triggeringItemID, add, remove) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) SetTriggeringWithContext(ctx context.Context, triggeringItemID uint32, add, remove []uint32) (*ua.SetTriggeringResponse, error) { +func (s *Subscription) SetTriggering(ctx context.Context, triggeringItemID uint32, add, remove []uint32) (*ua.SetTriggeringResponse, error) { stats.Subscription().Add("SetTriggering", 1) // Part 4, 5.12.5.2 SetTriggering Service Parameters @@ -264,7 +235,7 @@ func (s *Subscription) SetTriggeringWithContext(ctx context.Context, triggeringI } var res *ua.SetTriggeringResponse - err := s.c.SendWithContext(ctx, req, func(v interface{}) error { + err := s.c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) return res, err @@ -290,21 +261,13 @@ func (s *Subscription) notify(ctx context.Context, data *PublishNotificationData } // Stats returns a diagnostic struct with metadata about the current subscription -// -// Note: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *Subscription) Stats() (*ua.SubscriptionDiagnosticsDataType, error) { - return s.StatsWithContext(context.Background()) -} - -// Note: Starting with v0.5 this method is superseded by the non 'WithContext' method. -func (s *Subscription) StatsWithContext(ctx context.Context) (*ua.SubscriptionDiagnosticsDataType, error) { +func (s *Subscription) Stats(ctx context.Context) (*ua.SubscriptionDiagnosticsDataType, error) { // TODO(kung-foo): once browsing feature is merged, attempt to get direct access to the // diagnostics node. for example, Prosys lists them like: // i=2290/ns=1;g=918ee6f4-2d25-4506-980d-e659441c166d // maybe cache the nodeid to speed up future stats queries node := s.c.Node(ua.NewNumericNodeID(0, id.Server_ServerDiagnostics_SubscriptionDiagnosticsArray)) - v, err := node.ValueWithContext(ctx) + v, err := node.Value(ctx) if err != nil { return nil, err } @@ -361,7 +324,7 @@ func (s *Subscription) recreate_NeedsSubMuxLock(ctx context.Context) error { SubscriptionIDs: []uint32{s.SubscriptionID}, } var res *ua.DeleteSubscriptionsResponse - _ = s.c.SendWithContext(ctx, req, func(v interface{}) error { + _ = s.c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) dlog.Print("subscription deleted") @@ -378,7 +341,7 @@ func (s *Subscription) recreate_NeedsSubMuxLock(ctx context.Context) error { Priority: params.Priority, } var res *ua.CreateSubscriptionResponse - err := s.c.SendWithContext(ctx, req, func(v interface{}) error { + err := s.c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) if err != nil { @@ -421,7 +384,7 @@ func (s *Subscription) recreate_NeedsSubMuxLock(ctx context.Context) error { } var res *ua.CreateMonitoredItemsResponse - err := s.c.SendWithContext(ctx, req, func(v interface{}) error { + err := s.c.Send(ctx, req, func(v interface{}) error { return safeAssign(v, &res) }) if err != nil { diff --git a/uasc/secure_channel.go b/uasc/secure_channel.go index f6aa4251..78822642 100644 --- a/uasc/secure_channel.go +++ b/uasc/secure_channel.go @@ -722,27 +722,11 @@ func (s *SecureChannel) Renew(ctx context.Context) error { } // SendRequest sends the service request and calls h with the response. -// Deprecated: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *SecureChannel) SendRequest(req ua.Request, authToken *ua.NodeID, h func(interface{}) error) error { - return s.SendRequestWithContext(context.Background(), req, authToken, h) +func (s *SecureChannel) SendRequest(ctx context.Context, req ua.Request, authToken *ua.NodeID, h func(interface{}) error) error { + return s.SendRequestWithTimeout(ctx, req, authToken, s.cfg.RequestTimeout, h) } -// Note: This method will be replaced by the non "WithContext()" version -// of this method. -func (s *SecureChannel) SendRequestWithContext(ctx context.Context, req ua.Request, authToken *ua.NodeID, h func(interface{}) error) error { - return s.SendRequestWithTimeoutWithContext(ctx, req, authToken, s.cfg.RequestTimeout, h) -} - -// Deprecated: Starting with v0.5 this method will require a context -// and the corresponding XXXWithContext(ctx) method will be removed. -func (s *SecureChannel) SendRequestWithTimeout(req ua.Request, authToken *ua.NodeID, timeout time.Duration, h func(interface{}) error) error { - return s.SendRequestWithTimeoutWithContext(context.Background(), req, authToken, timeout, h) -} - -// Note: This method will be replaced by the non "WithContext()" version -// of this method. -func (s *SecureChannel) SendRequestWithTimeoutWithContext(ctx context.Context, req ua.Request, authToken *ua.NodeID, timeout time.Duration, h func(interface{}) error) error { +func (s *SecureChannel) SendRequestWithTimeout(ctx context.Context, req ua.Request, authToken *ua.NodeID, timeout time.Duration, h func(interface{}) error) error { s.reqLocker.waitIfLock() active, err := s.getActiveChannelInstance() if err != nil { @@ -860,7 +844,7 @@ func (s *SecureChannel) close() error { default: } - err := s.SendRequestWithContext(context.Background(), &ua.CloseSecureChannelRequest{}, nil, nil) + err := s.SendRequest(context.Background(), &ua.CloseSecureChannelRequest{}, nil, nil) if err != nil { return err } diff --git a/uatest/method_test.go b/uatest/method_test.go index f27be8d3..ea0febae 100644 --- a/uatest/method_test.go +++ b/uatest/method_test.go @@ -7,9 +7,10 @@ import ( "context" "testing" + "github.com/pascaldekloe/goe/verify" + "github.com/gopcua/opcua" "github.com/gopcua/opcua/ua" - "github.com/pascaldekloe/goe/verify" ) type Complex struct { @@ -64,11 +65,11 @@ func TestCallMethod(t *testing.T) { if err := c.Connect(ctx); err != nil { t.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) for _, tt := range tests { t.Run(tt.req.ObjectID.String(), func(t *testing.T) { - resp, err := c.CallWithContext(ctx, tt.req) + resp, err := c.Call(ctx, tt.req) if err != nil { t.Fatal(err) } diff --git a/uatest/namespace_test.go b/uatest/namespace_test.go index cb74f813..ca53f9c3 100644 --- a/uatest/namespace_test.go +++ b/uatest/namespace_test.go @@ -22,10 +22,10 @@ func TestNamespace(t *testing.T) { if err := c.Connect(ctx); err != nil { t.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) t.Run("NamespaceArray", func(t *testing.T) { - got, err := c.NamespaceArrayWithContext(ctx) + got, err := c.NamespaceArray(ctx) if err != nil { t.Fatal(err) } @@ -37,7 +37,7 @@ func TestNamespace(t *testing.T) { verify.Values(t, "", got, want) }) t.Run("FindNamespace", func(t *testing.T) { - ns, err := c.FindNamespaceWithContext(ctx, "http://gopcua.com/") + ns, err := c.FindNamespace(ctx, "http://gopcua.com/") if err != nil { t.Fatal(err) } @@ -46,7 +46,7 @@ func TestNamespace(t *testing.T) { } }) t.Run("UpdateNamespaces", func(t *testing.T) { - err := c.UpdateNamespacesWithContext(ctx) + err := c.UpdateNamespaces(ctx) if err != nil { t.Fatal(err) } diff --git a/uatest/read_test.go b/uatest/read_test.go index e14a732d..f425aa16 100644 --- a/uatest/read_test.go +++ b/uatest/read_test.go @@ -37,7 +37,7 @@ func TestRead(t *testing.T) { if err := c.Connect(ctx); err != nil { t.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) for _, tt := range tests { t.Run(tt.id.String(), func(t *testing.T) { @@ -54,7 +54,7 @@ func TestRead(t *testing.T) { func testRead(t *testing.T, ctx context.Context, c *opcua.Client, v interface{}, id *ua.NodeID) { t.Helper() - resp, err := c.ReadWithContext(ctx, &ua.ReadRequest{ + resp, err := c.Read(ctx, &ua.ReadRequest{ NodesToRead: []*ua.ReadValueID{ &ua.ReadValueID{NodeID: id}, }, @@ -74,7 +74,7 @@ func testRead(t *testing.T, ctx context.Context, c *opcua.Client, v interface{}, func testRegisteredRead(t *testing.T, ctx context.Context, c *opcua.Client, v interface{}, id *ua.NodeID) { t.Helper() - resp, err := c.RegisterNodesWithContext(ctx, &ua.RegisterNodesRequest{ + resp, err := c.RegisterNodes(ctx, &ua.RegisterNodesRequest{ NodesToRegister: []*ua.NodeID{id}, }) if err != nil { @@ -87,7 +87,7 @@ func testRegisteredRead(t *testing.T, ctx context.Context, c *opcua.Client, v in testRead(t, ctx, c, v, resp.RegisteredNodeIDs[0]) testRead(t, ctx, c, v, resp.RegisteredNodeIDs[0]) - _, err = c.UnregisterNodesWithContext(ctx, &ua.UnregisterNodesRequest{ + _, err = c.UnregisterNodes(ctx, &ua.UnregisterNodesRequest{ NodesToUnregister: []*ua.NodeID{id}, }) if err != nil { diff --git a/uatest/read_unknow_node_id_test.go b/uatest/read_unknow_node_id_test.go index a9b27b85..a729f98a 100644 --- a/uatest/read_unknow_node_id_test.go +++ b/uatest/read_unknow_node_id_test.go @@ -24,12 +24,12 @@ func TestReadUnknowNodeID(t *testing.T) { if err := c.Connect(ctx); err != nil { t.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) // read node with unknown extension object // This should be OK nodeWithUnknownType := ua.NewStringNodeID(2, "IntValZero") - resp, err := c.Read(&ua.ReadRequest{ + resp, err := c.Read(ctx, &ua.ReadRequest{ NodesToRead: []*ua.ReadValueID{ {NodeID: nodeWithUnknownType}, }, @@ -43,7 +43,7 @@ func TestReadUnknowNodeID(t *testing.T) { } // check that the connection is still usable by reading another node. - _, err = c.ReadWithContext(ctx, &ua.ReadRequest{ + _, err = c.Read(ctx, &ua.ReadRequest{ NodesToRead: []*ua.ReadValueID{ { NodeID: ua.NewNumericNodeID(0, id.Server_ServerStatus_State), diff --git a/uatest/reconnection_test.go b/uatest/reconnection_test.go index f16f5ff7..f6d20508 100644 --- a/uatest/reconnection_test.go +++ b/uatest/reconnection_test.go @@ -31,7 +31,7 @@ func TestAutoReconnection(t *testing.T) { if err := c.Connect(ctx); err != nil { t.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) m, err := monitor.NewNodeMonitor(c) if err != nil { @@ -103,7 +103,7 @@ func TestAutoReconnection(t *testing.T) { downC := make(chan struct{}, 1) dTimeout := time.NewTimer(disconnectTimeout) - go c.CallWithContext(ctx, tt.req) + go c.Call(ctx, tt.req) ctx, cancel := context.WithCancel(context.Background()) go func() { diff --git a/uatest/stats_test.go b/uatest/stats_test.go index cdebbfe5..070a351b 100644 --- a/uatest/stats_test.go +++ b/uatest/stats_test.go @@ -32,8 +32,7 @@ func TestStats(t *testing.T) { if err := c.Connect(ctx); err != nil { t.Fatal(err) } - - c.CloseWithContext(ctx) + c.Close(ctx) want := map[string]*expvar.Int{ "Dial": newExpVarInt(1), diff --git a/uatest/write_test.go b/uatest/write_test.go index a4ffa5f7..b6c0d1cc 100644 --- a/uatest/write_test.go +++ b/uatest/write_test.go @@ -36,7 +36,7 @@ func TestWrite(t *testing.T) { if err := c.Connect(ctx); err != nil { t.Fatal(err) } - defer c.CloseWithContext(ctx) + defer c.Close(ctx) for _, tt := range tests { t.Run(tt.id.String(), func(t *testing.T) { @@ -66,7 +66,7 @@ func TestWrite(t *testing.T) { func testWrite(t *testing.T, ctx context.Context, c *opcua.Client, status ua.StatusCode, req *ua.WriteRequest) { t.Helper() - resp, err := c.WriteWithContext(ctx, req) + resp, err := c.Write(ctx, req) if err != nil { t.Fatalf("Write failed: %s", err) }