Skip to content

Commit

Permalink
Fix browse definition
Browse files Browse the repository at this point in the history
  • Loading branch information
kanapuli committed Oct 23, 2024
1 parent 2860cc8 commit d7f84da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions opcua_plugin/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func sanitize(s string) string {
//
// **Returns:**
// - `void`: Errors are sent through `errChan`, and discovered nodes are sent through `nodeChan`.
func browse(ctx context.Context, n *opcua.Node, path string, level int, logger *service.Logger, parentNodeId string, nodeChan chan NodeDef, errChan chan error, pathIDMapChan chan map[string]string, wg *sync.WaitGroup, client *opcua.Client) {
func browse(ctx context.Context, n *opcua.Node, path string, level int, logger *service.Logger, parentNodeId string, nodeChan chan NodeDef, errChan chan error, pathIDMapChan chan map[string]string, wg *sync.WaitGroup) {
defer wg.Done()

logger.Debugf("node:%s path:%q level:%d parentNodeId:%s\n", n, path, level, parentNodeId)
Expand Down Expand Up @@ -241,7 +241,7 @@ func browse(ctx context.Context, n *opcua.Node, path string, level int, logger *
logger.Debugf("found %d child refs\n", len(refs))
for _, rn := range refs {
wg.Add(1)
go browse(ctx, rn, def.Path, level+1, logger, def.NodeID.String(), nodeChan, errChan, pathIDMapChan, wg, client)
go browse(ctx, rn, def.Path, level+1, logger, def.NodeID.String(), nodeChan, errChan, pathIDMapChan, wg)
}
return nil
}
Expand Down Expand Up @@ -431,7 +431,7 @@ func (g *OPCUAInput) discoverNodes(ctx context.Context) ([]NodeDef, map[string]s

// Start a goroutine for browsing
wg.Add(1)
go browse(ctx, g.Client.Node(nodeID), "", 0, g.Log, nodeID.String(), nodeChan, errChan, pathIDMapChan, &wg, g.Client)
go browse(ctx, g.Client.Node(nodeID), "", 0, g.Log, nodeID.String(), nodeChan, errChan, pathIDMapChan, &wg)
}

// close nodeChan, nodeIDMapChan and errChan once all browsing is done
Expand Down Expand Up @@ -503,7 +503,7 @@ func (g *OPCUAInput) BrowseAndSubscribeIfNeeded(ctx context.Context) error {
var wgHeartbeat sync.WaitGroup

wgHeartbeat.Add(1)
go browse(ctx, g.Client.Node(heartbeatNodeID), "", 1, g.Log, heartbeatNodeID.String(), nodeHeartbeatChan, errChanHeartbeat, pathIDMapChan, &wgHeartbeat, g.Client)
go browse(ctx, g.Client.Node(heartbeatNodeID), "", 1, g.Log, heartbeatNodeID.String(), nodeHeartbeatChan, errChanHeartbeat, pathIDMapChan, &wgHeartbeat)

wgHeartbeat.Wait()
close(nodeHeartbeatChan)
Expand Down
6 changes: 3 additions & 3 deletions opcua_plugin/server_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func (g *OPCUAInput) GetOPCUAServerInformation(ctx context.Context) (ServerInfo,
var wg sync.WaitGroup

wg.Add(3)
go browse(ctx, g.Client.Node(manufacturerNameNodeID), "", 0, g.Log, manufacturerNameNodeID.String(), nodeChan, errChan, pathIDMapChan, &wg, g.Client)
go browse(ctx, g.Client.Node(productNameNodeID), "", 0, g.Log, productNameNodeID.String(), nodeChan, errChan, pathIDMapChan, &wg, g.Client)
go browse(ctx, g.Client.Node(softwareVersionNodeID), "", 0, g.Log, softwareVersionNodeID.String(), nodeChan, errChan, pathIDMapChan, &wg, g.Client)
go browse(ctx, g.Client.Node(manufacturerNameNodeID), "", 0, g.Log, manufacturerNameNodeID.String(), nodeChan, errChan, pathIDMapChan, &wg)
go browse(ctx, g.Client.Node(productNameNodeID), "", 0, g.Log, productNameNodeID.String(), nodeChan, errChan, pathIDMapChan, &wg)
go browse(ctx, g.Client.Node(softwareVersionNodeID), "", 0, g.Log, softwareVersionNodeID.String(), nodeChan, errChan, pathIDMapChan, &wg)
wg.Wait()

close(nodeChan)
Expand Down

0 comments on commit d7f84da

Please sign in to comment.