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/08/30 08:37:23 UTC
[plc4x] branch develop updated: feat(plc4go/cbus): handle context in browse field
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 a58916131 feat(plc4go/cbus): handle context in browse field
a58916131 is described below
commit a58916131b43234e287da9ecab20f353970663ad
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Aug 30 10:37:10 2022 +0200
feat(plc4go/cbus): handle context in browse field
---
plc4go/internal/cbus/Browser.go | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/plc4go/internal/cbus/Browser.go b/plc4go/internal/cbus/Browser.go
index 782897aea..a52b96163 100644
--- a/plc4go/internal/cbus/Browser.go
+++ b/plc4go/internal/cbus/Browser.go
@@ -49,7 +49,6 @@ func NewBrowser(connection *Connection, messageCodec spi.MessageCodec) *Browser
}
func (m Browser) BrowseField(ctx context.Context, browseRequest apiModel.PlcBrowseRequest, interceptor func(result apiModel.PlcBrowseEvent) bool, fieldName string, field apiModel.PlcField) (apiModel.PlcResponseCode, []apiModel.PlcBrowseFoundField) {
- // TODO: handle ctx
var queryResults []apiModel.PlcBrowseFoundField
switch field := field.(type) {
case *unitInfoField:
@@ -79,6 +78,10 @@ func (m Browser) BrowseField(ctx context.Context, browseRequest apiModel.PlcBrow
}
unitLoop:
for _, unit := range units {
+ if err := ctx.Err(); err != nil {
+ log.Info().Err(err).Msgf("Aborting scan at unit %s", unit)
+ return apiModel.PlcResponseCode_INVALID_ADDRESS, nil
+ }
unitAddress := unit.GetAddress()
if !allUnits && allAttributes {
log.Info().Msgf("Querying all attributes of unit %d", unitAddress)
@@ -89,6 +92,10 @@ func (m Browser) BrowseField(ctx context.Context, browseRequest apiModel.PlcBrow
}
event.Msgf("Query unit %d", unitAddress)
for _, attribute := range attributes {
+ if err := ctx.Err(); err != nil {
+ log.Info().Err(err).Msgf("Aborting scan at unit %s", unit)
+ return apiModel.PlcResponseCode_INVALID_ADDRESS, nil
+ }
if !allUnits && !allAttributes {
log.Info().Msgf("Querying attribute %s of unit %d", attribute, unitAddress)
} else {
@@ -132,7 +139,7 @@ func (m Browser) BrowseField(ctx context.Context, browseRequest apiModel.PlcBrow
}
}
default:
- return apiModel.PlcResponseCode_INTERNAL_ERROR, nil
+ return apiModel.PlcResponseCode_INVALID_ADDRESS, nil
}
return apiModel.PlcResponseCode_OK, queryResults
}