ua_services_view.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "ua_services.h"
  2. #include "ua_statuscodes.h"
  3. #include "nodestore/ua_nodestoreExample.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_[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_[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_[UA_UINT16]) != UA_STATUSCODE_GOOD){
  28. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  29. return ;
  30. }
  31. // find out count of different namespace indices
  32. for(UA_Int32 i = 0; i<request->nodesToBrowseSize; i++){
  33. for(UA_UInt32 j = 0; j <= differentNamespaceIndexCount; j++){
  34. if(associatedIndices[j] == request->nodesToBrowse[i].nodeId.namespaceIndex){
  35. if(j==0){
  36. differentNamespaceIndexCount++;
  37. }
  38. numberOfFoundIndices[j]++;
  39. break;
  40. }
  41. else if(j == (differentNamespaceIndexCount - 1)){
  42. associatedIndices[j] = request->nodesToBrowse[i].nodeId.namespaceIndex;
  43. associatedIndices[j] = 1;
  44. differentNamespaceIndexCount++;
  45. }
  46. }
  47. }
  48. UA_UInt32 *browseDescriptionIndices;
  49. if(UA_Array_new((void **)&browseDescriptionIndices,request->nodesToBrowseSize,&UA_[UA_UINT32]) != UA_STATUSCODE_GOOD){
  50. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  51. return ;
  52. }
  53. for(UA_UInt32 i = 0; i < differentNamespaceIndexCount; i++){
  54. UA_Namespace *tmpNamespace;
  55. UA_NamespaceManager_getNamespace(server->namespaceManager,associatedIndices[i],&tmpNamespace);
  56. if(tmpNamespace != UA_NULL){
  57. //build up index array for each read operation onto a different namespace
  58. UA_UInt32 n = 0;
  59. for(UA_Int32 j = 0; j < request->nodesToBrowseSize; j++){
  60. if(request->nodesToBrowse[j].nodeId.namespaceIndex == associatedIndices[i]){
  61. browseDescriptionIndices[n] = j;
  62. }
  63. }
  64. //call read for every namespace
  65. tmpNamespace->nodeStore->browseNodes(
  66. request->nodesToBrowse,
  67. browseDescriptionIndices,
  68. numberOfFoundIndices[i],
  69. request->requestedMaxReferencesPerNode,
  70. response->results,
  71. response->diagnosticInfos);
  72. }
  73. }
  74. UA_free(browseDescriptionIndices);
  75. UA_free(numberOfFoundIndices);
  76. UA_free(associatedIndices);
  77. }
  78. void Service_TranslateBrowsePathsToNodeIds(UA_Server *server, UA_Session *session,
  79. const UA_TranslateBrowsePathsToNodeIdsRequest *request,
  80. UA_TranslateBrowsePathsToNodeIdsResponse *response) {
  81. UA_assert(server != UA_NULL && session != UA_NULL && request != UA_NULL && response != UA_NULL);
  82. if(request->browsePathsSize <= 0) {
  83. response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
  84. return;
  85. }
  86. // Allocate space for a correct answer
  87. response->resultsSize = request->browsePathsSize;
  88. // _init of the elements is done in Array_new
  89. if(UA_Array_new((void **)&response->results, request->browsePathsSize, &UA_[UA_BROWSEPATHRESULT])
  90. != UA_STATUSCODE_GOOD) {
  91. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  92. return;
  93. }
  94. for(UA_Int32 i = 0;i < request->browsePathsSize;i++)
  95. response->results[i].statusCode = UA_STATUSCODE_BADNOMATCH; //FIXME: implement
  96. }