Skip to content

Commit

Permalink
feat(plc4go): added DiscoverWithContext to driver manager
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 15, 2022
1 parent 576951d commit 5ff39f7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion plc4go/pkg/api/driverManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package plc4go

import (
"context"
"github.com/apache/plc4x/plc4go/pkg/api/model"
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/transports"
Expand All @@ -42,6 +43,8 @@ type PlcDriverManager interface {

// Discover Execute all available discovery methods on all available drivers using all transports
Discover(callback func(event model.PlcDiscoveryEvent), discoveryOptions ...WithDiscoveryOption) error
// DiscoverWithContext Execute all available discovery methods on all available drivers using all transports
DiscoverWithContext(ctx context.Context, callback func(event model.PlcDiscoveryEvent), discoveryOptions ...WithDiscoveryOption) error
}

func NewPlcDriverManager() PlcDriverManager {
Expand Down Expand Up @@ -283,6 +286,10 @@ func (m *plcDriverManger) GetConnection(connectionString string) <-chan PlcConne
}

func (m *plcDriverManger) Discover(callback func(event model.PlcDiscoveryEvent), discoveryOptions ...WithDiscoveryOption) error {
return m.DiscoverWithContext(context.TODO(), callback, discoveryOptions...)
}

func (m *plcDriverManger) DiscoverWithContext(ctx context.Context, callback func(event model.PlcDiscoveryEvent), discoveryOptions ...WithDiscoveryOption) error {
// Check if we've got at least one option to restrict to certain protocols only.
// If there is at least one, we only check that protocol, if there are none, all
// available protocols are checked.
Expand All @@ -302,7 +309,7 @@ func (m *plcDriverManger) Discover(callback func(event model.PlcDiscoveryEvent),
// Execute discovery on all selected drivers
for _, driver := range discoveryDrivers {
if driver.SupportsDiscovery() {
err := driver.Discover(callback, internalOptions...)
err := driver.DiscoverWithContext(ctx, callback, internalOptions...)
if err != nil {
return errors.Wrapf(err, "Error running Discover on driver %s", driver.GetProtocolName())
}
Expand Down

0 comments on commit 5ff39f7

Please sign in to comment.