High Performance OPC UA Server SDK  1.2.0.193
custom_provider.c
/*****************************************************************************
* *
* Copyright (c) 2006-2016 Unified Automation GmbH. All rights reserved. *
* *
* Software License Agreement ("SLA") Version 2.6 *
* *
* 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.6, 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.6/ *
* *
*****************************************************************************/
#include <memory/memory.h>
#include <uaserver/addressspace/addressspace.h>
#include <uaserver/valuestore/valuestore.h>
#include <uaserver/provider/provider.h>
#include <trace/trace.h>
#include "custom_provider_store.h"
#include "custom_provider_nodes.h"
#include "custom_provider.h"
#include "custom_provider_method.h"
#include "custom_provider_event.h"
uint16_t g_custom_provider_nsidx;
static struct ua_variant g_memorystore_values[10];
struct ua_memorystore g_memorystore;
uint8_t g_custom_store_idx = 0;
/* cleanup resources allocated by the custom provider */
static void custom_provider_cleanup(struct uaprovider *ctx)
{
UA_UNUSED(ctx);
ua_memorystore_clear(&g_memorystore);
ua_valuestore_unregister_store(g_custom_store_idx);
custom_provider_event_clear();
return;
}
int custom_provider_init(struct uaprovider *ctx)
{
struct ua_valuestore_interface store_if;
struct ua_addressspace_config config;
int ret;
ua_memset(&config, 0, sizeof(config));
config.nsidx = UA_NSIDX_INVALID; /* assign auto index */
config.max_variables = 20;
config.max_methods = 1;
config.max_objects = 2;
config.max_references = 30;
config.max_strings = 20;
/* register new namespace */
"http://www.unifiedautomation.com/CustomServer/",
&config,
if (ret < 0) return ret;
g_custom_provider_nsidx = (uint16_t) ret;
/* register namespace index */
ret = uaprovider_register_nsindex(ctx, g_custom_provider_nsidx);
if (ret != 0) return ret;
/* initialize memorystore context */
ret = ua_memorystore_init(&g_memorystore, 0, g_memorystore_values, countof(g_memorystore_values));
if (ret != 0) return ret;
/* register custom store */
store_if.get_fct = custom_store_get_value;
store_if.attach_fct = custom_store_attach_value;
ret = ua_valuestore_register_store(&store_if, &g_custom_store_idx);
if (ret != 0) return ret;
/* create nodes in the namespace */
ret = custom_provider_create_nodes();
if (ret != 0) return ret;
#ifdef ENABLE_SERVICE_CALL
ret = custom_provider_method_init();
if (ret != 0) return ret;
#endif
ret = custom_provider_event_init();
if (ret != 0) return ret;
#ifdef ENABLE_SERVICE_CALL
ctx->call = custom_provider_method_call;
#endif
/* register cleanup function */
ctx->cleanup = custom_provider_cleanup;
return ret;
}