ANSI C UA Server SDK  1.6.0.341
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
custom_provider_historyread.c
/*****************************************************************************
* *
* Copyright (c) 2006-2016 Unified Automation GmbH. All rights reserved. *
* *
* Software License Agreement ("SLA") Version 2.5 *
* *
* 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.5, 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.5/ *
* *
* Project: Unified Automation ANSI C based OPC UA Server SDK *
* *
*****************************************************************************/
#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 /* HAVE_DATA_LOGGER */
OPCUA_BEGIN_EXTERN_C
IFMETHODIMP(CustomProvider_HistoryReadRawModifiedAsync)(UaServer_ProviderHistoryReadRawModifiedContext* a_pHistoryReadRawModifiedCtx)
{
OpcUa_Int32 i;
OpcUa_BaseNode *pNode = OpcUa_Null;
UaServer_AddressSpace *pAddressSpace = &(g_pCustomProvider->AddressSpace);
OpcUa_ReturnErrorIfArgumentNull(a_pHistoryReadRawModifiedCtx);
/* we will send exactly one callback */
UaBase_Atomic_Increment(&a_pHistoryReadRawModifiedCtx->nOutstandingCbs);
/* process nodes */
for (i = 0; i < a_pHistoryReadRawModifiedCtx->NoOfNodesToRead; i++)
{
/* check if the node is from our provider's namespace */
if (a_pHistoryReadRawModifiedCtx->pNodesToRead[i].NodeId.NamespaceIndex == g_uCustomProvider_NamespaceIndex)
{
/* get the node pointer from the NodeId */
UaServer_GetNode(pAddressSpace, &a_pHistoryReadRawModifiedCtx->pNodesToRead[i].NodeId, &pNode);
if (pNode)
{
#if UASERVER_SUPPORT_AUTHORIZATION
/* Check if the user has the necessary permission to read the history */
if (!UaServer_UserMgt_IsHistoryReadable(OpcUa_BaseNode_GetINode(pNode), a_pHistoryReadRawModifiedCtx->pSession->UserIdentityData))
{
a_pHistoryReadRawModifiedCtx->pResponse->Results[i].StatusCode = OpcUa_BadNotReadable;
continue;
}
#endif
#if HAVE_DATA_LOGGER && UASERVER_DATALOGGER_SUPPORT_DATA
if (OpcUa_BaseNode_GetId(pNode)->IdentifierType == OpcUa_IdentifierType_Numeric)
{
OpcUa_HistoryReadResult *pHistoryResult = &a_pHistoryReadRawModifiedCtx->pResponse->Results[i];
UserDataCommon *pUserData = (UserDataCommon*)OpcUa_BaseNode_GetUserData(pNode);
if (pUserData && pUserData->Type == UserDataTemperature)
{
TemperatureSensor *pTemperatureSensorData = (TemperatureSensor*)pUserData;
a_pHistoryReadRawModifiedCtx->pResponse->Results[i].StatusCode = UaServer_DataLogger_ReadValues(
g_hDataLogger,
pTemperatureSensorData->hDataLogItemTemperatureValue,
a_pHistoryReadRawModifiedCtx->pHistoryReadRawModifiedDetails,
a_pHistoryReadRawModifiedCtx->TimestampsToReturn,
a_pHistoryReadRawModifiedCtx->ReleaseContinuationPoints,
&a_pHistoryReadRawModifiedCtx->pNodesToRead[i],
pHistoryResult,
a_pHistoryReadRawModifiedCtx->RequestHeader.TimeoutHint);
}
else
{
a_pHistoryReadRawModifiedCtx->pResponse->Results[i].StatusCode = OpcUa_BadNotReadable;
}
}
#endif /* HAVE_DATA_LOGGER && UASERVER_DATALOGGER_SUPPORT_DATA */
}
}
}
/* send callback */
UaServer_HistoryReadRawModifiedComplete(a_pHistoryReadRawModifiedCtx);
return OpcUa_Good;
}
OPCUA_END_EXTERN_C