UA ANSI C Server Professional  1.4.2.297
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
oversampling_provider.c
/******************************************************************************
**
** **************************** auto-generated ****************************
** This code was generated by a tool: UaModeler
** Runtime Version: 1.2.0, using ANSI C SDK 1.4.0 provider template (version 1)
**
** Changes to this file may cause incorrect behavior and will be lost if
** the code is regenerated.
** **************************** auto-generated ****************************
** Copyright (c) 2006-2014 Unified Automation GmbH All rights reserved.
** Web: http://www.unifiedautomation.com
**
** Software License Agreement ("SLA") Version 2.3
**
** 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.3, 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.
**
** Project: OPC Ansi C OverSamplingProvider for namespace http://www.unifiedautomation.com/OverSampling
**
** Description: OPC Unified Architecture Software Development Kit.
**
** The complete license agreement can be found here:
** http://unifiedautomation/License/SLA/2.3/
**
** Created: 15.07.2014
**
******************************************************************************/
#include "uaprovider_oversampling.h"
#include <opcua_proxystub.h>
#include <opcua_errorhandling.h>
#include <opcua_identifiers.h>
#include <opcua_string.h>
#include <opcua_pki.h>
#include <opcua_trace.h>
#include <signal.h>
#include <uaserver_p_utilities.h>
#include "uaprovider_oversampling_helper.h"
#include "uaprovider_oversampling_nodes_1.h"
/* Global Provider data */
UaServer_Provider* g_pOverSamplingProvider;
UaServer_pProviderInterface* g_pOverSamplingProviderInterface;
volatile OpcUa_Boolean g_bShutdown = OpcUa_False;
/* These are the basenodes managed by the server. */
OpcUa_UInt16 g_UaProviderOverSampling_uNamespaceIndex1 = OpcUa_UInt16_Max;
/* The number of nodes managed by the server. */
#if HAVE_ENCODING_BINARY
#define UAPROVIDER_OVERSAMPLING_NUMBEROFNODES1 3
#define UAPROVIDER_OVERSAMPLING_NUMBEROFREFERENCES1 6
#else
#define UAPROVIDER_OVERSAMPLING_NUMBEROFNODES1 3
#define UAPROVIDER_OVERSAMPLING_NUMBEROFREFERENCES1 6
#endif
#define UAPROVIDER_OVERSAMPLING_NUMBEROFMETHODS1 0
#define UAPROVIDER_OVERSAMPLING_HASHTABLESIZE 1009
IFMETHODIMP(UaProvider_OverSampling_ReadAsync)(UaServer_ProviderReadContext* a_pReadCtx);
IFMETHODIMP(UaProvider_OverSampling_WriteAsync)(UaServer_ProviderWriteContext* a_pWriteCtx);
#if UASERVER_SERVICES_HISTORYREAD
IFMETHODIMP(UaProvider_OverSampling_HistoryReadRawModifiedAsync)(UaServer_ProviderHistoryReadRawModifiedContext* a_pReadCtx);
#endif
IFMETHODIMP(UaProvider_OverSampling_BrowseAsync)(UaServer_ProviderBrowseContext* a_pBrowseCtx);
IFMETHODIMP(UaProvider_OverSampling_TranslateAsync)(UaServer_ProviderTranslateContext* a_pTranslateCtx);
IFMETHODIMP(UaProvider_OverSampling_RegisterNodesAsync)(UaServer_ProviderRegisterNodesContext* a_pRegisterNodesCtx);
IFMETHODIMP(UaProvider_OverSampling_UnregisterNodesAsync)(UaServer_ProviderUnregisterNodesContext* a_pUnregisterNodesCtx);
#if UASERVER_SERVICES_CALL
IFMETHODIMP(UaProvider_OverSampling_CallAsync)(UaServer_ProviderCallContext* a_pCallContext);
#endif
IFMETHODIMP(UaProvider_OverSampling_AddItem)(UaServer_MonitoredItem* a_pItem);
IFMETHODIMP(UaProvider_OverSampling_RemoveItem)(UaServer_MonitoredItem* a_pItem);
IFMETHODIMP(UaProvider_OverSampling_Subscribe)(UaServer_ProviderSubscribeContext *a_pCtx);
OpcUa_StatusCode UaProvider_OverSampling_Subscription_Initialize();
OpcUa_StatusCode UaProvider_OverSampling_Subscription_Cleanup();
IFMETHODIMP(UaProvider_OverSampling_Cleanup)()
{
printf("Cleanup OverSampling Provider ...\n");
UaProvider_OverSampling_Subscription_Cleanup();
pthread_mutex_lock(&g_ReadMutex);
pthread_mutex_lock(&g_WriteMutex);
g_bShutdown = OpcUa_True;
pthread_cond_signal(&g_ReadCondition);
pthread_cond_signal(&g_WriteCondition);
pthread_mutex_unlock(&g_WriteMutex);
pthread_mutex_unlock(&g_ReadMutex);
pthread_join(g_WriteThread, OpcUa_Null);
pthread_mutex_destroy(&g_WriteMutex);
pthread_cond_destroy(&g_WriteCondition);
pthread_join(g_ReadThread, OpcUa_Null);
pthread_mutex_destroy(&g_ReadMutex);
pthread_cond_destroy(&g_ReadCondition);
#ifdef _WIN32
signals_cleanup();
#endif
printf("Cleanup OverSampling Provider DONE!\n");
return OpcUa_Good;
}
/*============================================================================
* Internal Helper For Creating The AddressSpace In The Server
*===========================================================================*/
static OpcUa_StatusCode UaProvider_OverSampling_CreateAddressSpace()
{
OpcUa_InitializeStatus(OpcUa_Module_Server, "UaProvider_OverSampling_CreateAddressSpace");
uStatus = UaProvider_OverSampling_CreateAddressSpace1();
OpcUa_GotoErrorIfBad(uStatus);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
IFMETHODIMP(UaProvider_OverSampling_Initialize)(
UaServer_Provider* a_pProvider,
UaServer_pProviderInterface* a_pProviderInterface)
{
OpcUa_StatusCode uStatus = OpcUa_Good;
printf("Initialize OverSampling Provider ...\n");
#ifdef _WIN32
signals_init();
#endif
/* store values */
g_pOverSamplingProvider = a_pProvider;
g_pOverSamplingProviderInterface = a_pProviderInterface;
OpcUa_MemSet(g_pOverSamplingProviderInterface, 0, sizeof(UaServer_pProviderInterface));
/* Register Handlers */
a_pProviderInterface->Cleanup = UaProvider_OverSampling_Cleanup;
a_pProviderInterface->ReadAsync = UaProvider_OverSampling_ReadAsync;
a_pProviderInterface->WriteAsync = UaProvider_OverSampling_WriteAsync;
#if UASERVER_SERVICES_HISTORYREAD
a_pProviderInterface->HistoryReadRawModifiedAsync = UaProvider_OverSampling_HistoryReadRawModifiedAsync;
#endif
a_pProviderInterface->BrowseAsync = UaProvider_OverSampling_BrowseAsync;
a_pProviderInterface->TranslateAsync = UaProvider_OverSampling_TranslateAsync;
a_pProviderInterface->RegisterNodesAsync = UaProvider_OverSampling_RegisterNodesAsync;
a_pProviderInterface->UnregisterNodesAsync = UaProvider_OverSampling_UnregisterNodesAsync;
#if UASERVER_SERVICES_CALL
a_pProviderInterface->CallAsync = UaProvider_OverSampling_CallAsync;
#endif
a_pProviderInterface->AddItem = UaProvider_OverSampling_AddItem;
a_pProviderInterface->RemoveItem = UaProvider_OverSampling_RemoveItem;
a_pProviderInterface->Subscribe = UaProvider_OverSampling_Subscribe;
uStatus = UaServer_RegisterAddressSpace((OpcUa_Handle *)a_pProvider,
&g_UaProviderOverSampling_uNamespaceIndex1,
"http://www.unifiedautomation.com/OverSampling",
UAPROVIDER_OVERSAMPLING_HASHTABLESIZE);
OpcUa_ReturnErrorIfBad(uStatus);
/* Create Server Managed AddressSpace */
uStatus = UaProvider_OverSampling_CreateAddressSpace();
OpcUa_ReturnErrorIfBad(uStatus);
/* initialize subscriptions */
uStatus = UaProvider_OverSampling_Subscription_Initialize();
OpcUa_ReturnErrorIfBad(uStatus);
/* create write and read threads */
pthread_attr_init(&g_WriteAttr);
pthread_attr_init(&g_ReadAttr);
pthread_attr_setstacksize(&g_WriteAttr, 1024*1024);
pthread_attr_setstacksize(&g_ReadAttr, 1024*1024);
pthread_mutex_init(&g_WriteMutex, 0);
pthread_cond_init(&g_WriteCondition, 0);
pthread_create(&g_WriteThread, &g_WriteAttr, UaProvider_OverSampling_WriteThread, OpcUa_Null);
pthread_mutex_init(&g_ReadMutex, 0);
pthread_cond_init(&g_ReadCondition, 0);
pthread_create(&g_ReadThread, &g_ReadAttr, UaProvider_OverSampling_ReadThread, OpcUa_Null);
printf("OverSampling Provider initialized!\n");
printf(" %d Nodes created\n", a_pProvider->AddressSpace.uNumNodes);
printf(" NS%d:\n", g_UaProviderOverSampling_uNamespaceIndex1);
printf(" %d static nodes created\n", UAPROVIDER_OVERSAMPLING_NUMBEROFNODES1);
printf(" %d static references created\n", UAPROVIDER_OVERSAMPLING_NUMBEROFREFERENCES1);
printf(" %d static methods created\n", UAPROVIDER_OVERSAMPLING_NUMBEROFMETHODS1);
return uStatus;
}
#if BUILD_SHARED_LIBS
OVERSAMPLINGPROVIDER_API(OpcUa_StatusCode) InitializeProvider(
UaServer_Provider* pProvider,
UaServer_pProviderInterface* pProviderInterface)
{
return UaProvider_OverSampling_Initialize(pProvider, pProviderInterface);
}
#endif