MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / onTrigger

Method onTrigger

extensions/opc/src/fetchopc.cpp:136–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134 }
135
136 void FetchOPCProcessor::onTrigger(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session){
137 logger_->log_trace("FetchOPCProcessor::onTrigger");
138
139 std::unique_lock<std::mutex> lock(onTriggerMutex_, std::try_to_lock);
140 if(!lock.owns_lock()){
141 logger_->log_warn("processor was triggered before previous listing finished, configuration should be revised!");
142 return;
143 }
144
145 if (!reconnect()) {
146 yield();
147 return;
148 }
149
150 nodesFound_ = 0;
151 variablesFound_ = 0;
152
153 std::function<opc::nodeFoundCallBackFunc> f = std::bind(&FetchOPCProcessor::nodeFoundCallBack, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, context, session);
154 if(idType_ != opc::OPCNodeIDType::Path) {
155 UA_NodeId myID;
156 myID.namespaceIndex = nameSpaceIdx_;
157 if(idType_ == opc::OPCNodeIDType::Int) {
158 myID.identifierType = UA_NODEIDTYPE_NUMERIC;
159 myID.identifier.numeric = std::stoi(nodeID_);
160 } else if (idType_ == opc::OPCNodeIDType::String) {
161 myID.identifierType = UA_NODEIDTYPE_STRING;
162 myID.identifier.string = UA_STRING_ALLOC(nodeID_.c_str());
163 }
164 connection_->traverse(myID, f, "", maxDepth_);
165 } else {
166 if(translatedNodeIDs_.empty()) {
167 auto sc = connection_->translateBrowsePathsToNodeIdsRequest(nodeID_, translatedNodeIDs_, logger_);
168 if(sc != UA_STATUSCODE_GOOD) {
169 logger_->log_error("Failed to translate %s to node id, no flow files will be generated (%s)", nodeID_.c_str(), UA_StatusCode_name(sc));
170 yield();
171 return;
172 }
173 }
174 for(auto& nodeID: translatedNodeIDs_) {
175 connection_->traverse(nodeID, f, nodeID_, maxDepth_);
176 }
177 }
178 if(nodesFound_ == 0) {
179 logger_->log_warn("Connected to OPC server, but no variable nodes were found. Configuration might be incorrect! Yielding...");
180 yield();
181 } else if (variablesFound_ == 0) {
182 logger_->log_warn("Found no variables when traversing the specified node. No flowfiles are generated. Yielding...");
183 yield();
184 }
185
186 }
187
188 bool FetchOPCProcessor::nodeFoundCallBack(opc::Client& client, const UA_ReferenceDescription *ref, const std::string& path,
189 const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session) {

Callers

nothing calls this directly

Calls 7

log_traceMethod · 0.80
log_warnMethod · 0.80
c_strMethod · 0.80
traverseMethod · 0.80
log_errorMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected