#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"
volatile OpcUa_Boolean g_bShutdown = OpcUa_False;
OpcUa_UInt16 g_UaProviderOverSampling_uNamespaceIndex1 = OpcUa_UInt16_Max;
#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
#if UASERVER_SERVICES_HISTORYREAD
#endif
#if UASERVER_SERVICES_CALL
#endif
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;
}
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)(
{
OpcUa_StatusCode uStatus = OpcUa_Good;
printf("Initialize OverSampling Provider ...\n");
#ifdef _WIN32
signals_init();
#endif
g_pOverSamplingProvider = a_pProvider;
g_pOverSamplingProviderInterface = a_pProviderInterface;
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;
&g_UaProviderOverSampling_uNamespaceIndex1,
"http://www.unifiedautomation.com/OverSampling",
UAPROVIDER_OVERSAMPLING_HASHTABLESIZE);
OpcUa_ReturnErrorIfBad(uStatus);
uStatus = UaProvider_OverSampling_CreateAddressSpace();
OpcUa_ReturnErrorIfBad(uStatus);
uStatus = UaProvider_OverSampling_Subscription_Initialize();
OpcUa_ReturnErrorIfBad(uStatus);
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(
{
return UaProvider_OverSampling_Initialize(pProvider, pProviderInterface);
}
#endif