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 2022/09/01 16:00:07 UTC
[plc4x] branch develop updated: fix(plc4go): fixed PlcSubscriptionHandle registering the wrong handle
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
The following commit(s) were added to refs/heads/develop by this push:
new e6a7255b0 fix(plc4go): fixed PlcSubscriptionHandle registering the wrong handle
e6a7255b0 is described below
commit e6a7255b0a97c685e8271e74744797e5441b55d5
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Sep 1 17:59:59 2022 +0200
fix(plc4go): fixed PlcSubscriptionHandle registering the wrong handle
---
plc4go/internal/cbus/SubscriptionHandle.go | 13 +++++++------
plc4go/internal/knxnetip/SubscriptionHandle.go | 4 +++-
plc4go/spi/model/DefaultPlcSubscriptionHandle.go | 19 ++++++++++++++++---
3 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/plc4go/internal/cbus/SubscriptionHandle.go b/plc4go/internal/cbus/SubscriptionHandle.go
index 93d8b0ed1..c575378b2 100644
--- a/plc4go/internal/cbus/SubscriptionHandle.go
+++ b/plc4go/internal/cbus/SubscriptionHandle.go
@@ -33,11 +33,12 @@ type SubscriptionHandle struct {
}
func NewSubscriptionHandle(subscriber *Subscriber, fieldName string, field any, fieldType spiModel.SubscriptionType, interval time.Duration) *SubscriptionHandle {
- return &SubscriptionHandle{
- DefaultPlcSubscriptionHandle: spiModel.NewDefaultPlcSubscriptionHandle(subscriber),
- fieldName: fieldName,
- field: field,
- fieldType: fieldType,
- interval: interval,
+ s := &SubscriptionHandle{
+ fieldName: fieldName,
+ field: field,
+ fieldType: fieldType,
+ interval: interval,
}
+ s.DefaultPlcSubscriptionHandle = spiModel.NewDefaultPlcSubscriptionHandleWithHandleToRegister(subscriber, s)
+ return s
}
diff --git a/plc4go/internal/knxnetip/SubscriptionHandle.go b/plc4go/internal/knxnetip/SubscriptionHandle.go
index 838be9c86..889c6fd20 100644
--- a/plc4go/internal/knxnetip/SubscriptionHandle.go
+++ b/plc4go/internal/knxnetip/SubscriptionHandle.go
@@ -33,11 +33,13 @@ type SubscriptionHandle struct {
}
func NewSubscriptionHandle(subscriber *Subscriber, fieldName string, field Field, fieldType spiModel.SubscriptionType, interval time.Duration) *SubscriptionHandle {
- return &SubscriptionHandle{
+ s := &SubscriptionHandle{
DefaultPlcSubscriptionHandle: spiModel.NewDefaultPlcSubscriptionHandle(subscriber),
fieldName: fieldName,
field: field,
fieldType: fieldType,
interval: interval,
}
+ s.DefaultPlcSubscriptionHandle = spiModel.NewDefaultPlcSubscriptionHandleWithHandleToRegister(subscriber, s)
+ return s
}
diff --git a/plc4go/spi/model/DefaultPlcSubscriptionHandle.go b/plc4go/spi/model/DefaultPlcSubscriptionHandle.go
index 9b966f987..ab6b22924 100644
--- a/plc4go/spi/model/DefaultPlcSubscriptionHandle.go
+++ b/plc4go/spi/model/DefaultPlcSubscriptionHandle.go
@@ -25,15 +25,28 @@ import (
)
type DefaultPlcSubscriptionHandle struct {
- plcSubscriber spi.PlcSubscriber
+ handleToRegister model.PlcSubscriptionHandle
+ plcSubscriber spi.PlcSubscriber
}
+// NewDefaultPlcSubscriptionHandle can be used when the DefaultPlcSubscriptionHandle is sufficient
func NewDefaultPlcSubscriptionHandle(plcSubscriber spi.PlcSubscriber) *DefaultPlcSubscriptionHandle {
- return &DefaultPlcSubscriptionHandle{
+ handle := &DefaultPlcSubscriptionHandle{
plcSubscriber: plcSubscriber,
}
+ handle.handleToRegister = handle
+ return handle
+}
+
+// NewDefaultPlcSubscriptionHandleWithHandleToRegister should be used when an extension of DefaultPlcSubscriptionHandle is used
+func NewDefaultPlcSubscriptionHandleWithHandleToRegister(plcSubscriber spi.PlcSubscriber, handleToRegister model.PlcSubscriptionHandle) *DefaultPlcSubscriptionHandle {
+ return &DefaultPlcSubscriptionHandle{
+ handleToRegister: handleToRegister,
+ plcSubscriber: plcSubscriber,
+ }
}
+// Register registers at the spi.PlcSubscriber
func (d *DefaultPlcSubscriptionHandle) Register(consumer model.PlcSubscriptionEventConsumer) model.PlcConsumerRegistration {
- return d.plcSubscriber.Register(consumer, []model.PlcSubscriptionHandle{d})
+ return d.plcSubscriber.Register(consumer, []model.PlcSubscriptionHandle{d.handleToRegister})
}