Skip to content

Commit

Permalink
fix(plc4j/spi) Make sure OPC UA discover event is fired prior connect…
Browse files Browse the repository at this point in the history
…ed event.

Signed-off-by: Łukasz Dywicki <[email protected]>
  • Loading branch information
splatch committed Nov 20, 2023
1 parent 998e977 commit 1ff9e25
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,19 @@ protected org.apache.plc4x.java.api.value.PlcValueHandler getValueHandler() {
return new PlcValueHandler();
}

protected boolean fireDiscoverEvent() {
return true;
}

protected boolean awaitDisconnectComplete() {
return true;
}

protected boolean awaitDiscoverComplete() {
return true;
}


@Override
protected ProtocolStackConfigurer<OpcuaAPU> getStackConfigurer() {
return SingleProtocolStackConfigurer.builder(OpcuaAPU.class, OpcuaAPU::staticParse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ private void onDisconnectCloseSecureChannel(ConversationContext<OpcuaAPU> contex
public void onDiscover(ConversationContext<OpcuaAPU> context) {
if (!driverContext.getEncrypted()) {
LOGGER.debug("not encrypted, ignoring onDiscover");
context.fireDiscovered(configuration);
return;
}
// Only the TCP transport supports login.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public ChannelHandler getChannelHandler(CompletableFuture<Void> sessionSetupComp
return new ChannelInitializer<>() {
@Override
protected void initChannel(Channel channel) {
// Build the protocol stack for communicating with the s7 protocol.
// Build the protocol stack for communicating with desired protocol.
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast(new ChannelInboundHandlerAdapter() {
@Override
Expand All @@ -239,7 +239,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
super.userEventTriggered(ctx, evt);
} else if (evt instanceof DiscoveredEvent) {
sessionDiscoverCompleteFuture.complete(((DiscoveredEvent) evt).getConfiguration());
} else if (evt instanceof ConnectEvent) {
} else if (evt instanceof ConnectEvent || evt instanceof DiscoverEvent) {
// Fix for https://github.com/apache/plc4x/issues/801
if (!sessionSetupCompleteFuture.isCompletedExceptionally()) {
if (awaitSessionSetupComplete) {
Expand All @@ -248,7 +248,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
configuration,
pipeline,
getAuthentication(),
channelFactory.isPassive()
channelFactory.isPassive(),
listeners
)
);
}
Expand Down

0 comments on commit 1ff9e25

Please sign in to comment.