@Override
public CompletableFuture<PlcUnsubscriptionResponse> unsubscribe(PlcUnsubscriptionRequest plcUnsubscriptionRequest) {
InternalPlcUnsubscriptionRequest internalPlcUnsubscriptionRequest = checkInternal(plcUnsubscriptionRequest, InternalPlcUnsubscriptionRequest.class);
for (InternalPlcSubscriptionHandle internalPlcSubscriptionHandle : internalPlcUnsubscriptionRequest.getInternalPlcSubscriptionHandles()) {
if (internalPlcSubscriptionHandle instanceof AdsSubscriptionHandle) {
AdsSubscriptionHandle adsSubscriptionHandle = (AdsSubscriptionHandle) internalPlcSubscriptionHandle;
AdsDeleteDeviceNotificationRequest adsDeleteDeviceNotificationRequest =
AdsDeleteDeviceNotificationRequest.of(
targetAmsNetId,
targetAmsPort,
sourceAmsNetId,
sourceAmsPort,
Invoke.NONE,
adsSubscriptionHandle.getNotificationHandle()
);
CompletableFuture<InternalPlcProprietaryResponse<AdsDeleteDeviceNotificationResponse>> deleteDeviceFuture =
new CompletableFuture<>();
channel.writeAndFlush(new PlcRequestContainer<>(new DefaultPlcProprietaryRequest<>(adsDeleteDeviceNotificationRequest), deleteDeviceFuture));
InternalPlcProprietaryResponse<AdsDeleteDeviceNotificationResponse> deleteDeviceResponse =
getFromFuture(deleteDeviceFuture, DEL_DEVICE_TIMEOUT);
AdsDeleteDeviceNotificationResponse response = deleteDeviceResponse.getResponse();
if (response.getResult().toAdsReturnCode() != AdsReturnCode.ADS_CODE_0) {
throw new PlcRuntimeException("Non error code received " + response.getResult());
}
}
}
CompletableFuture<PlcUnsubscriptionResponse> future = new CompletableFuture<>();
future.complete(new DefaultPlcUnsubscriptionResponse(internalPlcUnsubscriptionRequest));
return future;
}