ua_services_view.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "ua_services.h"
  2. #include "ua_statuscodes.h"
  3. #include "ua_server_internal.h"
  4. #include "ua_namespace_0.h"
  5. #include "ua_util.h"
  6. #include "ua_namespace_manager.h"
  7. void Service_Browse(UA_Server *server, UA_Session *session,
  8. const UA_BrowseRequest *request, UA_BrowseResponse *response) {
  9. UA_Int32 *numberOfFoundIndices;
  10. UA_UInt16 *associatedIndices;
  11. UA_UInt32 differentNamespaceIndexCount = 0;
  12. UA_assert(server != UA_NULL && session != UA_NULL && request != UA_NULL && response != UA_NULL);
  13. if(request->nodesToBrowseSize <= 0) {
  14. response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
  15. return;
  16. }
  17. if(UA_Array_new((void **)&(response->results), request->nodesToBrowseSize, &UA_TYPES[UA_BROWSERESULT])
  18. != UA_STATUSCODE_GOOD) {
  19. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  20. return;
  21. }
  22. response->resultsSize = request->nodesToBrowseSize;
  23. if(UA_Array_new((void **)&numberOfFoundIndices,request->nodesToBrowseSize,&UA_TYPES[UA_UINT32]) != UA_STATUSCODE_GOOD){
  24. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  25. return ;
  26. }
  27. if(UA_Array_new((void **)&associatedIndices,request->nodesToBrowseSize,&UA_TYPES[UA_UINT16]) != UA_STATUSCODE_GOOD){
  28. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  29. return ;
  30. }
  31. BUILD_INDEX_ARRAYS(request->nodesToBrowseSize,request->nodesToBrowse,nodeId,differentNamespaceIndexCount,associatedIndices,numberOfFoundIndices);
  32. UA_UInt32 *browseDescriptionIndices;
  33. if(UA_Array_new((void **)&browseDescriptionIndices,request->nodesToBrowseSize,&UA_TYPES[UA_UINT32]) != UA_STATUSCODE_GOOD){
  34. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  35. return ;
  36. }
  37. for(UA_UInt32 i = 0; i < differentNamespaceIndexCount; i++){
  38. UA_Namespace *tmpNamespace;
  39. UA_NamespaceManager_getNamespace(server->namespaceManager,associatedIndices[i],&tmpNamespace);
  40. if(tmpNamespace != UA_NULL){
  41. //build up index array for each read operation onto a different namespace
  42. UA_UInt32 n = 0;
  43. for(UA_Int32 j = 0; j < request->nodesToBrowseSize; j++){
  44. if(request->nodesToBrowse[j].nodeId.namespaceIndex == associatedIndices[i]){
  45. browseDescriptionIndices[n] = j;
  46. n++;
  47. }
  48. }
  49. //call read for every namespace
  50. tmpNamespace->nodeStore->browseNodes(&request->requestHeader,
  51. request->nodesToBrowse,
  52. browseDescriptionIndices,
  53. numberOfFoundIndices[i],
  54. request->requestedMaxReferencesPerNode,
  55. response->results,
  56. response->diagnosticInfos);
  57. }
  58. }
  59. UA_free(browseDescriptionIndices);
  60. UA_free(numberOfFoundIndices);
  61. UA_free(associatedIndices);
  62. }
  63. void Service_TranslateBrowsePathsToNodeIds(UA_Server *server, UA_Session *session,
  64. const UA_TranslateBrowsePathsToNodeIdsRequest *request,
  65. UA_TranslateBrowsePathsToNodeIdsResponse *response) {
  66. UA_assert(server != UA_NULL && session != UA_NULL && request != UA_NULL && response != UA_NULL);
  67. if(request->browsePathsSize <= 0) {
  68. response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
  69. return;
  70. }
  71. // Allocate space for a correct answer
  72. response->resultsSize = request->browsePathsSize;
  73. // _init of the elements is done in Array_new
  74. if(UA_Array_new((void **)&response->results, request->browsePathsSize, &UA_TYPES[UA_BROWSEPATHRESULT])
  75. != UA_STATUSCODE_GOOD) {
  76. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  77. return;
  78. }
  79. for(UA_Int32 i = 0;i < request->browsePathsSize;i++)
  80. response->results[i].statusCode = UA_STATUSCODE_BADNOMATCH; //FIXME: implement
  81. }