#include <uaserver_config.h>
#include <pthread.h>
#include <errno.h>
#include <opcua_statuscodes.h>
#include <opcua_attributes.h>
#include <uabase_p_atomic.h>
#include <uaserver_basenode.h>
#include <uaserver_utilities.h>
#include <uaserver_write.h>
#include "uaprovider_oversampling_helper.h"
#include "uaprovider_oversampling_identifiers_1.h"
OpcUa_List g_WriteJobs;
pthread_t g_WriteThread;
pthread_attr_t g_WriteAttr;
pthread_mutex_t g_WriteMutex;
pthread_cond_t g_WriteCondition;
OPCUA_BEGIN_EXTERN_C
void* UaProvider_OverSampling_WriteThread(void *arg)
{
OpcUa_ReferenceParameter(arg);
while (1)
{
int i;
OpcUa_BaseNode *pNode;
pthread_mutex_lock(&g_WriteMutex);
while (!pWriteCtx && g_bShutdown == OpcUa_False)
{
pthread_cond_wait(&g_WriteCondition, &g_WriteMutex);
}
pthread_mutex_unlock(&g_WriteMutex);
if (g_bShutdown)
{
while (pWriteCtx)
{
}
break;
}
for (i = 0; i < pReq->NoOfNodesToWrite; i++)
{
pNodeId = &pNodeToWrite->
NodeId;
if (pNodeId->
NamespaceIndex != g_UaProviderOverSampling_uNamespaceIndex1)
continue;
if (pNode)
{
if (pNodeToWrite->
AttributeId == OpcUa_Attributes_Value)
{
#if UASERVER_SUPPORT_AUTHORIZATION
if ((pNodeToWrite->
AttributeId == OpcUa_Attributes_Value
|| (pNodeToWrite->
AttributeId != OpcUa_Attributes_Value
{
pRes->
Results[i] = OpcUa_BadNotWritable;
continue;
}
#endif
switch (pNodeToWrite->
NodeId.Identifier.Numeric)
{
case OverSampling_Objects_S1KHz_Voltage:
case OverSampling_Objects_S1KHz_Current:
{
if (OpcUa_String_IsNull(&pNodeToWrite->
IndexRange))
{
switch (pNodeToWrite->
NodeId.Identifier.Numeric)
{
case OverSampling_Objects_S1KHz_Voltage:
break;
case OverSampling_Objects_S1KHz_Current:
break;
default:
break;
}
}
else
{
pRes->
Results[i] = OpcUa_BadIndexRangeInvalid;
}
}
else
{
pRes->
Results[i] = OpcUa_BadTypeMismatch;
}
break;
default:
break;
}
}
else
{
}
}
else
{
pRes->
Results[i] = OpcUa_BadNodeIdUnknown;
}
}
}
return 0;
}
{
pthread_mutex_lock(&g_WriteMutex);
OpcUa_List_AddElementToEnd(&g_WriteJobs, a_pWriteCtx);
pthread_cond_signal(&g_WriteCondition);
pthread_mutex_unlock(&g_WriteMutex);
return OpcUa_Good;
}
OPCUA_END_EXTERN_C