ChimeraTK-ControlSystemAdapter-OPCUAAdapter  04.00.01
ua_mapped_class.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ChimeraTKs ControlSystem-OPC-UA-Adapter.
3  *
4  * ChimeraTKs ControlSystem-OPC-UA-Adapter is free software: you can
5  * redistribute it and/or modify it under the terms of the Lesser GNU
6  * General Public License as published by the Free Software Foundation,
7  * either version 3 of the License, or (at your option) any later version.
8  *
9  * ChimeraTKs ControlSystem-OPC-UA-Adapter is distributed in the hope
10  * that it will be useful, but WITHOUT ANY WARRANTY; without even the
11  * implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the Lesser GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Foobar. If not, see https://www.gnu.org/licenses/lgpl.html
16  *
17  * Copyright (c) 2016 Chris Iatrou <Chris_Paul.Iatrou@tu-dresden.de>
18  * Copyright (c) 2016 Julian Rahm <Julian.Rahm@tu-dresden.de>
19  * Copyright (c) 2021-2023 Andreas Ebner <Andreas.Ebner@iosb.fraunhofer.de>
20  */
21 
22 #include "ua_mapped_class.h"
23 
24 #include <iostream>
25 
26 using namespace std;
27 
28 namespace ChimeraTK {
29  ua_mapped_class::ua_mapped_class() {
30  this->baseNodeId = UA_NODEID_NUMERIC(0, 0);
31  this->mappedServer = nullptr;
32 
33  ua_mapSelfToNamespace();
34  }
35 
36  ua_mapped_class::ua_mapped_class(UA_Server* server, UA_NodeId baseNodeId) {
37  UA_NodeId_copy(&baseNodeId, &this->baseNodeId);
38  this->mappedServer = server;
39 
40  ua_mapSelfToNamespace();
41  }
42 
43  ua_mapped_class::~ua_mapped_class() {
44  this->ua_unmapSelfFromNamespace();
45  this->mappedServer = nullptr;
46  UA_NodeId_clear(&this->baseNodeId);
47  }
48 
49  UA_StatusCode ua_mapped_class::ua_mapSelfToNamespace() {
50  UA_StatusCode retval = UA_STATUSCODE_GOOD;
51  UA_NodeId nullId = UA_NODEID_NULL;
52  if(UA_NodeId_equal(&this->baseNodeId, &nullId)) {
53  return -1;
54  }
55  if(this->mappedServer == nullptr) {
56  return -2;
57  }
58 
59  return retval;
60  }
61 
62  UA_StatusCode ua_mapped_class::ua_unmapSelfFromNamespace() {
63  while(!this->ownedNodes.empty()) {
64  UA_NodeId_pair* p = *(this->ownedNodes.begin());
65  // Node is deleted by UA_Server_delete
66  UA_NodeId_clear(&p->sourceNodeId);
67  UA_NodeId_clear(&p->targetNodeId);
68  this->ownedNodes.remove(p);
69  delete p;
70  }
71  return UA_STATUSCODE_GOOD;
72  }
73 } // namespace ChimeraTK
ChimeraTK::UA_NodeId_pair_t::sourceNodeId
UA_NodeId sourceNodeId
Definition: ua_map_types.h:39
ua_mapped_class.h
ChimeraTK::UA_NodeId_pair_t::targetNodeId
UA_NodeId targetNodeId
Definition: ua_map_types.h:40
ChimeraTK
Definition: csa_additionalvariable.h:28
ChimeraTK::UA_NodeId_pair_t
This struct contains a NodeId generated from the open62541-stack and the NodeId of the model side.
Definition: ua_map_types.h:38