From 63c1641c9d27d197771ea9d1d97b47a1f23595eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20R=C3=BChl?= Date: Thu, 6 Apr 2023 14:09:39 +0200 Subject: [PATCH] feat(plc4go/simulated): new subscriber stub --- plc4go/internal/simulated/Connection.go | 2 +- plc4go/internal/simulated/Reader.go | 7 ++- plc4go/internal/simulated/Subscriber.go | 59 +++++++++++++++++++++++++ plc4go/internal/simulated/Writer.go | 7 ++- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 plc4go/internal/simulated/Subscriber.go diff --git a/plc4go/internal/simulated/Connection.go b/plc4go/internal/simulated/Connection.go index 2f364f33264..e6ef48d4921 100644 --- a/plc4go/internal/simulated/Connection.go +++ b/plc4go/internal/simulated/Connection.go @@ -237,7 +237,7 @@ func (c *Connection) WriteRequestBuilder() model.PlcWriteRequestBuilder { } func (c *Connection) SubscriptionRequestBuilder() model.PlcSubscriptionRequestBuilder { - panic("not implemented") + return internalModel.NewDefaultPlcSubscriptionRequestBuilder(c.tagHandler, c.valueHandler, NewSubscriber(c.device, c.options, c.tracer)) } func (c *Connection) UnsubscriptionRequestBuilder() model.PlcUnsubscriptionRequestBuilder { diff --git a/plc4go/internal/simulated/Reader.go b/plc4go/internal/simulated/Reader.go index bff6e12b801..dabbf34a14c 100644 --- a/plc4go/internal/simulated/Reader.go +++ b/plc4go/internal/simulated/Reader.go @@ -36,16 +36,15 @@ type Reader struct { tracer *spi.Tracer } -func NewReader(device *Device, options map[string][]string, tracer *spi.Tracer) Reader { - return Reader{ +func NewReader(device *Device, options map[string][]string, tracer *spi.Tracer) *Reader { + return &Reader{ device: device, options: options, tracer: tracer, } } -func (r Reader) Read(ctx context.Context, readRequest model.PlcReadRequest) <-chan model.PlcReadRequestResult { - // TODO: handle ctx +func (r *Reader) Read(_ context.Context, readRequest model.PlcReadRequest) <-chan model.PlcReadRequestResult { ch := make(chan model.PlcReadRequestResult) go func() { var txId string diff --git a/plc4go/internal/simulated/Subscriber.go b/plc4go/internal/simulated/Subscriber.go new file mode 100644 index 00000000000..4f23a30b697 --- /dev/null +++ b/plc4go/internal/simulated/Subscriber.go @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package simulated + +import ( + "context" + apiModel "github.com/apache/plc4x/plc4go/pkg/api/model" + "github.com/apache/plc4x/plc4go/spi" +) + +type Subscriber struct { + device *Device + options map[string][]string + tracer *spi.Tracer +} + +func NewSubscriber(device *Device, options map[string][]string, tracer *spi.Tracer) *Subscriber { + return &Subscriber{ + device: device, + options: options, + tracer: tracer, + } +} + +func (r Subscriber) Subscribe(_ context.Context, subscriptionRequest apiModel.PlcSubscriptionRequest) <-chan apiModel.PlcSubscriptionRequestResult { + // TODO: implement me + return make(chan apiModel.PlcSubscriptionRequestResult) +} + +func (r Subscriber) Unsubscribe(_ context.Context, unsubscriptionRequest apiModel.PlcUnsubscriptionRequest) <-chan apiModel.PlcUnsubscriptionRequestResult { + // TODO: implement me + return make(chan apiModel.PlcUnsubscriptionRequestResult) +} + +func (r Subscriber) Register(consumer apiModel.PlcSubscriptionEventConsumer, handles []apiModel.PlcSubscriptionHandle) apiModel.PlcConsumerRegistration { + // TODO: implement me + return nil +} + +func (r Subscriber) Unregister(registration apiModel.PlcConsumerRegistration) { + // TODO: implement me +} diff --git a/plc4go/internal/simulated/Writer.go b/plc4go/internal/simulated/Writer.go index fd620565acd..83b8f5428a0 100644 --- a/plc4go/internal/simulated/Writer.go +++ b/plc4go/internal/simulated/Writer.go @@ -35,16 +35,15 @@ type Writer struct { tracer *spi.Tracer } -func NewWriter(device *Device, options map[string][]string, tracer *spi.Tracer) Writer { - return Writer{ +func NewWriter(device *Device, options map[string][]string, tracer *spi.Tracer) *Writer { + return &Writer{ device: device, options: options, tracer: tracer, } } -func (w Writer) Write(ctx context.Context, writeRequest model.PlcWriteRequest) <-chan model.PlcWriteRequestResult { - // TODO: handle context +func (w *Writer) Write(_ context.Context, writeRequest model.PlcWriteRequest) <-chan model.PlcWriteRequestResult { ch := make(chan model.PlcWriteRequestResult) go func() { var txId string