39 adapter = std::make_shared<ua_uaadapter>(std::move(configFile));
40 UA_LOG_INFO(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
"Start the mapping of %s", configFile.c_str());
41 UA_LOG_INFO(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
"Create the adapter");
44 vector<string> mappedPvSources = adapter->getAllMappedPvSourceNames();
45 if(mappedPvSources.size() > 0) {
47 for(
const auto& f : mappedPvSources) {
48 ss <<
"\n\t\t - " << f;
50 UA_LOG_INFO(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
"List of mapped process variables: %s", ss.str().c_str());
53 vector<ProcessVariable::SharedPtr> allProcessVariables = this->csManager->getAllProcessVariables();
56 bool skip_var =
false;
57 for(
const ProcessVariable::SharedPtr& oneProcessVariable : allProcessVariables) {
58 std::type_info
const& valueType = oneProcessVariable->getValueType();
59 if(valueType ==
typeid(Void)) {
61 UA_LOG_DEBUG(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
"Skip Variable: Variable: %s has a void type",
62 oneProcessVariable->getName().c_str());
65 for(
auto e : this->adapter->exclude) {
66 string suffix_1 =
"/*", suffix_2 =
"*";
67 if(e.rfind(suffix_1) == e.size() - suffix_1.size()) {
68 if(oneProcessVariable->getName().rfind(e.substr(0, e.size() - 1)) == 0) {
70 for(
const auto& ele : mappedPvSources) {
71 if(ele == oneProcessVariable->getName().substr(1, oneProcessVariable->getName().size() - 1)) {
72 UA_LOG_WARNING(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
73 "Skip exclude node - Used in pv-mapping (directory match) PV: %s",
74 oneProcessVariable->getName().c_str());
80 for(
auto folder : this->adapter->folder_with_history) {
81 if(oneProcessVariable->getName().substr(0, folder.size()) == folder) {
82 UA_LOG_WARNING(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
83 "Skip exclude node - Used in folder history setting: %s", oneProcessVariable->getName().c_str());
90 UA_LOG_INFO(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
"Directory var exclude (/*) from mapping %s",
91 oneProcessVariable->getName().c_str());
96 else if(e.rfind(suffix_2) == e.size() - suffix_2.size()) {
97 if(oneProcessVariable->getName().rfind(e.substr(0, e.size() - 1), 0) == 0) {
99 for(
const auto& ele : mappedPvSources) {
100 if(ele == oneProcessVariable->getName().substr(1, oneProcessVariable->getName().size() - 1)) {
101 UA_LOG_WARNING(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
102 "Skip exclude node - Used in pv-mapping (greedy match) PV: %s",
103 oneProcessVariable->getName().c_str());
108 for(
auto folder : this->adapter->folder_with_history) {
109 if(oneProcessVariable->getName().substr(1, folder.size() - 1) == folder) {
110 UA_LOG_WARNING(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
111 "Skip exclude node - Used in folder history setting: %s", oneProcessVariable->getName().c_str());
117 UA_LOG_INFO(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
"Greedy var exclude (*) from mapping %s",
118 oneProcessVariable->getName().c_str());
123 else if(oneProcessVariable->getName() == e) {
125 if(std::find(mappedPvSources.begin(), mappedPvSources.end(), e.substr(1, e.size() - 1)) !=
126 mappedPvSources.end()) {
127 UA_LOG_WARNING(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
128 "Skip exclude node - Used in pv-mapping (direct match) PV: %s", oneProcessVariable->getName().c_str());
131 UA_LOG_INFO(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
"Direct exclude var (direct match) from mapping %s",
132 oneProcessVariable->getName().c_str());
135 for(
auto folder : this->adapter->folder_with_history) {
136 if(oneProcessVariable->getName().substr(1, folder.size() - 1) == folder) {
137 UA_LOG_WARNING(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
138 "Skip exclude node - Used in folder history setting: %s", oneProcessVariable->getName().c_str());
146 adapter->implicitVarMapping(oneProcessVariable->getName(), this->csManager);
150 this->unusedVariables.insert(oneProcessVariable->getName());
155 adapter->applyMapping(this->csManager);
156 vector<string> allNotMappedVariables = adapter->getAllNotMappableVariablesNames();
157 if(!allNotMappedVariables.empty()) {
158 std::stringstream ss;
159 for(
const string& var : allNotMappedVariables) {
160 ss <<
"\t" << var << endl;
162 UA_LOG_WARNING(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
163 "The following VariableNodes cant be mapped, because they are not member in PV-Manager: \n%s",
173 return this->csManager;
181 if(!this->adapter_thread.joinable()) {
186 vector<ProcessVariable::SharedPtr> allProcessVariables = csManager->getAllProcessVariables();
187 for(
const ProcessVariable::SharedPtr& oneProcessVariable : allProcessVariables) {
188 std::type_info
const& valueType = oneProcessVariable->getValueType();
189 if(valueType ==
typeid(Void)) {
191 if(!oneProcessVariable->isWriteable()) {
192 data->
pvs.insert(data->
pvs.end(), oneProcessVariable->getName());
193 UA_LOG_INFO(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
"Adding variable %s to void thread.",
194 oneProcessVariable->getName().c_str());
197 UA_LOG_WARNING(this->
getLogger(), UA_LOGCATEGORY_USERLAND,
198 "Ignoring Void input %s. Void inputs are not yet supported.", oneProcessVariable->getName().c_str());
202 if(!data->
pvs.empty()) {
203 auto conf = adapter->get_server_config();
209 this->observer_thread.detach();
217 if(this->adapter_thread.joinable()) {
218 adapter->running =
false;
219 this->adapter_thread.join();
221 if(this->observer_thread.joinable()) {
222 this->observer_thread.join();
227 return this->adapter_thread.joinable();
230 return unusedVariables;
234 return adapter->server_config->logging;