ANSI C Based OPC UA Client/Server SDK  1.9.0.430
custom_provider_browse.c
/*****************************************************************************
* *
* Copyright (c) 2006-2019 Unified Automation GmbH. All rights reserved. *
* *
* Software License Agreement ("SLA") Version 2.7 *
* *
* 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.7, 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.7/ *
* *
* Project: Unified Automation ANSI C based OPC UA Server SDK *
* *
*****************************************************************************/
#include <uaserver_config.h>
#include <opcua_statuscodes.h>
#include <uabase_p_atomic.h>
#include <uaserver_browse.h>
#include <uaserver_translate.h>
#include <uaserver_basenode.h>
#include <uaserver_utilities.h>
#include "custom_provider_helper.h"
OPCUA_BEGIN_EXTERN_C
IFMETHODIMP(CustomProvider_BrowseAsync)(UaServer_ProviderBrowseContext *a_pBrowseCtx)
{
OpcUa_Int32 i;
OpcUa_BaseNode *pNode;
OpcUa_NodeId *pNodeId = OpcUa_Null;
UaServer_AddressSpace *pAddressSpace = &(g_pCustomProvider->AddressSpace);
OpcUa_InitializeStatus(OpcUa_Module_Server, "CustomProvider_BrowseAsync");
OpcUa_ReturnErrorIfArgumentNull(a_pBrowseCtx);
pReq = a_pBrowseCtx->pRequest;
pRes = a_pBrowseCtx->pResponse;
/* We will send exactly one callback */
UaBase_Atomic_Increment(&a_pBrowseCtx->nOutstandingCbs);
/* Iterate over nodes and check if the provider is responsible for processing them */
for (i = 0; i < pReq->NoOfNodesToBrowse; i++)
{
if (pReq->NodesToBrowse[i].NodeId.NamespaceIndex == g_uCustomProvider_NamespaceIndex)
{
pNodeId = &(pReq->NodesToBrowse[i].NodeId);
UaServer_GetNode(pAddressSpace, pNodeId, &pNode);
if (pNode != OpcUa_Null)
{
/* Use the SDK's helper function to process the request */
UaServer_BrowseInternal(pNode, a_pBrowseCtx, i);
}
else
{
pRes->Results[i].StatusCode = OpcUa_BadNodeIdUnknown;
}
}
}
/* Send callback */
UaServer_BrowseComplete(a_pBrowseCtx);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
IFMETHODIMP(CustomProvider_TranslateAsync)(UaServer_ProviderTranslateContext *a_pTranslateCtx)
{
OpcUa_UInt32 iNoOfStartingNodes, i;
OpcUa_NodeId *pStartingNode = OpcUa_Null;
UaServer_AddressSpace *pNodeAddressSpace = OpcUa_Null;
UaBase_Atomic_Increment(&a_pTranslateCtx->nOutstandingCbs);
iNoOfStartingNodes = UaBase_Vector_GetSize(&a_pTranslateCtx->StartingNodes);
for (i = 0; i < iNoOfStartingNodes; i++)
{
pStartingNode = UaBase_Vector_Get(&a_pTranslateCtx->StartingNodes, i);
UaServer_AddressSpace_Get(pStartingNode->NamespaceIndex, &pNodeAddressSpace);
if (pNodeAddressSpace == &g_pCustomProvider->AddressSpace)
{
UaServer_TranslateInternal(a_pTranslateCtx, i);
}
}
/* send callback */
UaServer_TranslateComplete(a_pTranslateCtx);
return OpcUa_Good;
}
OPCUA_END_EXTERN_C