Search in sources :

Example 1 with WriteRequest

use of org.eclipse.milo.opcua.stack.core.types.structured.WriteRequest in project milo by eclipse.

the class DefaultAttributeServiceSet method onWrite.

@Override
public void onWrite(ServiceRequest service) {
    WriteRequest request = (WriteRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<WriteValue> nodesToWrite = l(request.getNodesToWrite());
    if (nodesToWrite.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (nodesToWrite.size() > server.getConfig().getLimits().getMaxNodesPerWrite().intValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    DiagnosticsContext<WriteValue> diagnosticsContext = new DiagnosticsContext<>();
    WriteContext context = new WriteContext(server, session, new DiagnosticsContext<>());
    server.getAddressSpaceManager().write(context, nodesToWrite);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToWrite);
        WriteResponse response = new WriteResponse(header, values.toArray(new StatusCode[0]), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) WriteRequest(org.eclipse.milo.opcua.stack.core.types.structured.WriteRequest) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) WriteResponse(org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) WriteContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.WriteContext) WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) Session(org.eclipse.milo.opcua.sdk.server.Session)

Aggregations

DiagnosticsContext (org.eclipse.milo.opcua.sdk.server.DiagnosticsContext)1 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)1 Session (org.eclipse.milo.opcua.sdk.server.Session)1 WriteContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.WriteContext)1 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1 WriteRequest (org.eclipse.milo.opcua.stack.core.types.structured.WriteRequest)1 WriteResponse (org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse)1 WriteValue (org.eclipse.milo.opcua.stack.core.types.structured.WriteValue)1