Skip to content

Commit

Permalink
feat(plc4go/simulated): new subscriber stub
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Apr 11, 2023
1 parent 2776597 commit 63c1641
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plc4go/internal/simulated/Connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions plc4go/internal/simulated/Reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 59 additions & 0 deletions plc4go/internal/simulated/Subscriber.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 3 additions & 4 deletions plc4go/internal/simulated/Writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63c1641

Please sign in to comment.