High Performance OPC UA Server SDK  1.7.1.383
custom_provider_method.c
/*****************************************************************************
* *
* Copyright (c) 2006-2023 Unified Automation GmbH. All rights reserved. *
* *
* Software License Agreement ("SLA") Version 2.8 *
* *
* Unless explicitly acquired and licensed from Licensor under another *
* license, the contents of this file are subject to the Software License *
* Agreement ("SLA") Version 2.8, or subsequent versions as allowed by the *
* SLA, and You may not copy or use this file in either source code or *
* executable form, except in compliance with the terms and conditions of *
* the SLA. *
* *
* All software distributed under the SLA is provided strictly on an "AS *
* IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, *
* AND LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT *
* LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR *
* PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the SLA for specific *
* language governing rights and limitations under the SLA. *
* *
* The complete license agreement can be found here: *
* http://unifiedautomation.com/License/SLA/2.8/ *
* *
*****************************************************************************/
#include <uaserver/addressspace/method.h>
#include <uaserver/provider/provider.h>
#include <uabase/basetypes.h>
#include <memory/memory.h>
#include "custom_provider.h"
#include "custom_provider_identifiers.h"
#include "custom_provider_method.h"
#ifdef ENABLE_SERVICE_CALL
#include <uaprovider/server/uaprovider_server.h>
#include <uabase/service/callrequest.h>
#include <uabase/service/callresponse.h>
#include <uaserver/method/call_utility.h>
#include <uaserver/method/call_table.h>
static ua_statuscode custom_provider_method_multiply(
/* in */ struct uaprovider_call_ctx *ctx,
/* in */ const struct ua_nodeid *method_id,
/* in */ const struct ua_nodeid *object_id,
/* in */ float a,
/* in */ float b,
/* out */ float *product)
{
UA_UNUSED(ctx);
UA_UNUSED(method_id);
UA_UNUSED(object_id);
*product = a * b;
return 0;
}
/* description of the input arguments */
static const struct uaserver_call_utility_arg g_multiply_in_args[] = {
{&g_uaprovider_server_nsidx, 0, UA_VT_FLOAT, UASERVER_CALL_UTILITY_FLAG_NONE},
{&g_uaprovider_server_nsidx, 0, UA_VT_FLOAT, UASERVER_CALL_UTILITY_FLAG_NONE},
};
/* description of the output arguments */
static const struct uaserver_call_utility_arg g_multiply_out_args[] = {
{&g_uaprovider_server_nsidx, 0, UA_VT_FLOAT, UASERVER_CALL_UTILITY_FLAG_NONE},
};
static ua_statuscode custom_provider_call_multiply(
struct uaprovider_call_ctx *ctx,
const struct ua_callmethodrequest *req,
struct ua_callmethodresult *res)
{
float out_product = 0;
/* check argument types */
status_code = uaserver_call_utility_check_arguments(g_multiply_in_args, countof(g_multiply_in_args), req, res);
if (status_code != 0) return status_code;
/* call the actual method implementation */
status_code = custom_provider_method_multiply( //-V1048
ctx,
&req->method_id,
&req->object_id,
req->input_arguments[0].value.f,
req->input_arguments[1].value.f,
&out_product
);
if (!ua_statuscode_is_good(status_code)) {
goto error;
}
/* attach the output arguments to the response */
res,
g_multiply_out_args,
countof(g_multiply_out_args),
&out_product
);
if (status_code != 0) {
goto error;
}
/* success */
return 0;
error:
return status_code;
}
int custom_provider_method_init(void)
{
ua_node_t method_node, object_node;
/* find the object node */
object_node = ua_node_find_numeric(g_custom_provider_nsidx, DEMO_OBJECT_ID);
if (object_node == UA_NODE_INVALID) return UA_EBADNOTFOUND;
/* find the method node */
method_node = ua_node_find_numeric(g_custom_provider_nsidx, MULTIPLY_METHOD_ID);
if (method_node == UA_NODE_INVALID) return UA_EBADNOTFOUND;
return uaserver_call_table_register(object_node, method_node, custom_provider_call_multiply);
}
#endif /* ENABLE_SERVICE_CALL */