You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/06/15 14:54:04 UTC

[plc4x] 01/02: refactor(plc4go): retire Connect on codec

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 5b3633f77dfe1b5af6ec907093434c19bcb62692
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jun 15 16:47:08 2023 +0200

    refactor(plc4go): retire Connect on codec
---
 plc4go/internal/ads/Connection.go       | 2 +-
 plc4go/internal/eip/Connection.go       | 2 +-
 plc4go/internal/knxnetip/Connection.go  | 2 +-
 plc4go/internal/knxnetip/Discoverer.go  | 2 +-
 plc4go/internal/s7/Connection.go        | 2 +-
 plc4go/spi/MessageCodec.go              | 1 +
 plc4go/spi/default/DefaultConnection.go | 1 +
 7 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/plc4go/internal/ads/Connection.go b/plc4go/internal/ads/Connection.go
index f94b71ee41..85af72ce3b 100644
--- a/plc4go/internal/ads/Connection.go
+++ b/plc4go/internal/ads/Connection.go
@@ -119,7 +119,7 @@ func (m *Connection) ConnectWithContext(ctx context.Context) <-chan plc4go.PlcCo
 				ch <- _default.NewDefaultPlcConnectionCloseResult(nil, errors.Errorf("panic-ed %v. Stack: %s", err, debug.Stack()))
 			}
 		}()
-		err := m.messageCodec.Connect()
+		err := m.messageCodec.ConnectWithContext(ctx)
 		if err != nil {
 			ch <- _default.NewDefaultPlcConnectionConnectResult(m, err)
 		}
diff --git a/plc4go/internal/eip/Connection.go b/plc4go/internal/eip/Connection.go
index e88ec1aac1..d6a1c18585 100644
--- a/plc4go/internal/eip/Connection.go
+++ b/plc4go/internal/eip/Connection.go
@@ -129,7 +129,7 @@ func (m *Connection) ConnectWithContext(ctx context.Context) <-chan plc4go.PlcCo
 				ch <- _default.NewDefaultPlcConnectionConnectResult(nil, errors.Errorf("panic-ed %v. Stack: %s", err, debug.Stack()))
 			}
 		}()
-		err := m.messageCodec.Connect()
+		err := m.messageCodec.ConnectWithContext(ctx)
 		if err != nil {
 			ch <- _default.NewDefaultPlcConnectionConnectResult(m, err)
 		}
diff --git a/plc4go/internal/knxnetip/Connection.go b/plc4go/internal/knxnetip/Connection.go
index 494c135778..d71c515a28 100644
--- a/plc4go/internal/knxnetip/Connection.go
+++ b/plc4go/internal/knxnetip/Connection.go
@@ -240,7 +240,7 @@ func (m *Connection) ConnectWithContext(ctx context.Context) <-chan plc4go.PlcCo
 			}
 		}()
 		// Open the UDP Connection
-		err := m.messageCodec.Connect()
+		err := m.messageCodec.ConnectWithContext(ctx)
 		if err != nil {
 			m.doSomethingAndClose(func() { sendResult(nil, errors.Wrap(err, "error opening connection")) })
 			return
diff --git a/plc4go/internal/knxnetip/Discoverer.go b/plc4go/internal/knxnetip/Discoverer.go
index c4fd9310be..392ef3ee73 100644
--- a/plc4go/internal/knxnetip/Discoverer.go
+++ b/plc4go/internal/knxnetip/Discoverer.go
@@ -181,7 +181,7 @@ func (d *Discoverer) createDeviceScanDispatcher(udpTransportInstance *udp.Transp
 		// Create a codec for sending and receiving messages.
 		codec := NewMessageCodec(udpTransportInstance, nil, options.WithCustomLogger(d.log))
 		// Explicitly start the worker
-		if err := codec.Connect(); err != nil {
+		if err := codec.ConnectWithContext(context.TODO()); err != nil {
 			d.log.Error().Err(err).Msg("Error connecting")
 			return
 		}
diff --git a/plc4go/internal/s7/Connection.go b/plc4go/internal/s7/Connection.go
index f77a1ed934..fc23f476c0 100644
--- a/plc4go/internal/s7/Connection.go
+++ b/plc4go/internal/s7/Connection.go
@@ -122,7 +122,7 @@ func (m *Connection) ConnectWithContext(ctx context.Context) <-chan plc4go.PlcCo
 				ch <- _default.NewDefaultPlcConnectionConnectResult(nil, errors.Errorf("panic-ed %v. Stack: %s", err, debug.Stack()))
 			}
 		}()
-		err := m.messageCodec.Connect()
+		err := m.messageCodec.ConnectWithContext(ctx)
 		if err != nil {
 			ch <- _default.NewDefaultPlcConnectionConnectResult(m, err)
 		}
diff --git a/plc4go/spi/MessageCodec.go b/plc4go/spi/MessageCodec.go
index d471ed9c81..94826da578 100644
--- a/plc4go/spi/MessageCodec.go
+++ b/plc4go/spi/MessageCodec.go
@@ -45,6 +45,7 @@ type HandleError func(err error) error
 
 // MessageCodec handles sending and retrieving of messages
 type MessageCodec interface {
+	// Deprecated: use ConnectWithContext
 	// Connect connects this codec
 	Connect() error
 	// ConnectWithContext connects this codec with the supplied context
diff --git a/plc4go/spi/default/DefaultConnection.go b/plc4go/spi/default/DefaultConnection.go
index 370b082acd..27de7506d0 100644
--- a/plc4go/spi/default/DefaultConnection.go
+++ b/plc4go/spi/default/DefaultConnection.go
@@ -233,6 +233,7 @@ func (d *plcConnectionPingResult) GetErr() error {
 ///////////////////////////////////////
 
 func (d *defaultConnection) SetConnected(connected bool) {
+	d.log.Trace().Msgf("set connected %t", connected)
 	d.connected.Store(connected)
 }