#include <uaserver_config.h>
#include <opcua_statuscodes.h>
#include <uaserver_historyread.h>
#include <uaserver_basenode.h>
#include <uaserver_utilities.h>
#include <uabase_p_atomic.h>
#include "custom_provider_helper.h"
#if HAVE_DATA_LOGGER
#include <uaserver_datalogger.h>
#endif
OPCUA_BEGIN_EXTERN_C
OpcUa_Void CustomProvider_HistoryReadRawModifiedAsync_DeleteUserData(struct _UaServer_ContinuationPointHistoryInfo* pContinuationPointHistoryInfo)
{
OpcUa_ByteString_Clear(pContinuationPointHistoryInfo->pUserData);
OpcUa_Free(pContinuationPointHistoryInfo->pUserData);
return;
}
{
OpcUa_Int32 i;
OpcUa_BaseNode *pNode = OpcUa_Null;
OpcUa_ReturnErrorIfArgumentNull(a_pHistoryReadRawModifiedCtx);
for (i = 0; i < a_pHistoryReadRawModifiedCtx->NoOfNodesToRead; i++)
{
if (a_pHistoryReadRawModifiedCtx->pNodesToRead[i].NodeId.NamespaceIndex == g_uCustomProvider_NamespaceIndex)
{
UaServer_GetNode(pAddressSpace, &a_pHistoryReadRawModifiedCtx->pNodesToRead[i].NodeId, &pNode);
if (pNode)
{
#if UASERVER_SUPPORT_AUTHORIZATION
{
a_pHistoryReadRawModifiedCtx->pResponse->Results[i].StatusCode = OpcUa_BadNotReadable;
continue;
}
#endif
#if HAVE_DATA_LOGGER && UASERVER_DATALOGGER_SUPPORT_DATA
{
if (pUserData && pUserData->Type == UserDataTemperature)
{
TemperatureSensor *pTemperatureSensorData = (TemperatureSensor*)pUserData;
OpcUa_Int32 noOfHistoryContinuationPoints;
OpcUa_Int32 iCount;
UaServer_ContinuationPointHistoryInfo *pContinuationPointHistoryInfo = OpcUa_Null;
if (a_pHistoryReadRawModifiedCtx->pNodesToRead[i].ContinuationPoint.Data != OpcUa_Null)
{
noOfHistoryContinuationPoints =
UaBase_RingBuffer_Count(&a_pHistoryReadRawModifiedCtx->pSession->HistoryContinuationPoints);
for (iCount = 0; iCount < noOfHistoryContinuationPoints; iCount++)
{
UaServer_ContinuationPointHistoryInfo* pTmpInfo =
UaBase_RingBuffer_Pop(&a_pHistoryReadRawModifiedCtx->pSession->HistoryContinuationPoints);
if (OpcUa_ByteString_Compare(&pTmpInfo->ContinuationPoint, &a_pHistoryReadRawModifiedCtx->pNodesToRead[i].ContinuationPoint) == 0)
{
pContinuationPointHistoryInfo = pTmpInfo;
OpcUa_ByteString_Clear(&a_pHistoryReadRawModifiedCtx->pNodesToRead[i].ContinuationPoint);
OpcUa_ByteString_CopyTo(pContinuationPointHistoryInfo->pUserData, &a_pHistoryReadRawModifiedCtx->pNodesToRead[i].ContinuationPoint);
pHistoryReadRawModifiedDetails = UaServer_GetHistoryReadRawModifiedDetails(&pContinuationPointHistoryInfo->HistoryReadDetails);
TimestampsToReturn = pContinuationPointHistoryInfo->TimestampsToReturn;
break;
}
}
}
if (pContinuationPointHistoryInfo != OpcUa_Null &&
OpcUa_NodeId_Compare(&a_pHistoryReadRawModifiedCtx->pNodesToRead[i].NodeId, &pContinuationPointHistoryInfo->NodeId) != 0)
{
a_pHistoryReadRawModifiedCtx->pResponse->Results[i].StatusCode = OpcUa_BadContinuationPointInvalid;
continue;
}
g_hDataLogger,
pTemperatureSensorData->hDataLogItemTemperatureValue,
pHistoryReadRawModifiedDetails,
TimestampsToReturn,
a_pHistoryReadRawModifiedCtx->ReleaseContinuationPoints,
&a_pHistoryReadRawModifiedCtx->pNodesToRead[i],
pHistoryResult,
a_pHistoryReadRawModifiedCtx->RequestHeader.TimeoutHint);
if (pContinuationPointHistoryInfo == OpcUa_Null)
{
{
{
pHistoryResult->
StatusCode = OpcUa_BadNoContinuationPoints;
}
OpcUa_NodeId_CopyTo(&a_pHistoryReadRawModifiedCtx->pNodesToRead[i].NodeId, &pContinuationPointHistoryInfo->NodeId);
pContinuationPointHistoryInfo->fctDeleteUserData = CustomProvider_HistoryReadRawModifiedAsync_DeleteUserData;
pContinuationPointHistoryInfo->pUserData = OpcUa_Alloc(
sizeof(
OpcUa_ByteString));
OpcUa_ByteString_Initialize(pContinuationPointHistoryInfo->pUserData);
OpcUa_ByteString_CopyTo(&pHistoryResult->
ContinuationPoint, pContinuationPointHistoryInfo->pUserData);
pHistoryReadRawModifiedDetails = OpcUa_Null;
&pContinuationPointHistoryInfo->HistoryReadDetails,
(OpcUa_Void**)&pHistoryReadRawModifiedDetails);
OpcUa_ReadRawModifiedDetails_CopyTo(a_pHistoryReadRawModifiedCtx->pHistoryReadRawModifiedDetails, pHistoryReadRawModifiedDetails);
pContinuationPointHistoryInfo->TimestampsToReturn = a_pHistoryReadRawModifiedCtx->TimestampsToReturn;
if (OpcUa_IsBad(uStatus))
{
pContinuationPointHistoryInfo = OpcUa_Null;
}
else
{
OpcUa_ByteString_CopyTo(&pContinuationPointHistoryInfo->ContinuationPoint, &pHistoryResult->
ContinuationPoint);
a_pHistoryReadRawModifiedCtx->nCreatedContinuationPoints++;
}
}
}
else
{
{
OpcUa_ByteString_Clear(pContinuationPointHistoryInfo->pUserData);
OpcUa_ByteString_CopyTo(&pHistoryResult->
ContinuationPoint, pContinuationPointHistoryInfo->pUserData);
if (OpcUa_IsBad(uStatus))
{
pContinuationPointHistoryInfo = OpcUa_Null;
}
else
{
OpcUa_ByteString_CopyTo(&pContinuationPointHistoryInfo->ContinuationPoint, &pHistoryResult->
ContinuationPoint);
}
}
else
{
pContinuationPointHistoryInfo = OpcUa_Null;
}
}
}
else
{
a_pHistoryReadRawModifiedCtx->pResponse->Results[i].StatusCode = OpcUa_BadNotReadable;
}
}
#endif
}
}
}
return OpcUa_Good;
}
OPCUA_END_EXTERN_C