open62541 / open62541

Open source implementation of OPC UA (OPC Unified Architecture) aka IEC 62541 licensed under Mozilla Public License v2.0
http://open62541.org
Mozilla Public License 2.0
2.59k stars 1.24k forks source link

Provide output argument meta-data to allow generic callback for methods #4801

Open jonasgreen88 opened 2 years ago

jonasgreen88 commented 2 years ago

Description

Imagine a use case where all methods share a generic method callback. This callback may translate OPC UA method calls to some equivalent feature of a sub-system in the application. We have such a use case and we need to know the OPC UA data type of the output arguments to set the correct data type in the output argument variants (in our case the sub-system's data types maps 1:N to OPC UA types).

We can solve this with the current open62541 implementation and find the OutputArguments node of the Method node by duplicating the implementation of getArgumentsVariableNode() in ua_services_method.c. https://github.com/open62541/open62541/blob/223d3d5d55e6bbc771f9e0d6bfe2af0facc6f395/src/server/ua_services_method.c#L22

But to avoid copying internal code to a callback implementation we would like to see the method callback provide this information. Our proposal is to update the method callback definition by adding a new argument UA_Argument *outputArgs which should provide the value of the OutputArguments node.

typedef UA_StatusCode
(*UA_MethodCallback)(UA_Server *server, const UA_NodeId *sessionId,
                     void *sessionContext, const UA_NodeId *methodId,
                     void *methodContext, const UA_NodeId *objectId,
                     void *objectContext, size_t inputSize,
                     const UA_Variant *input, size_t outputSize,
                     UA_Variant *output, UA_Argument *outputArgs);

We can provide a PR once we agreed to a solution.

Background Information / Reproduction Steps

N/A

Checklist

Please provide the following information:

mlgiraud commented 2 years ago

I'm not sure if understood your problem correctly, but the input and output argument types are already encoded in the variants that are supplied during the callback.