lordgamez commented on code in PR #2268: URL: https://github.com/apache/nifi-minifi-cpp/pull/2268#discussion_r4121330321
########## extensions/opc/include/OPCCommon.h: ########## @@ -19,9 +19,12 @@ #pragma once #include <array> +#include <chrono> +#include <deque> #include <string> #include <functional> #include <map> +#include <mutex> Review Comment: Updated in https://github.com/apache/nifi-minifi-cpp/pull/2268/commits/330b6b7882de20576d2e38e71dc3267090e93aca ########## extensions/opc/src/FetchOPCEvents.cpp: ########## @@ -0,0 +1,225 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "FetchOPCEvents.h" + +#include <chrono> +#include <memory> +#include <string> +#include <vector> + +#include "OPCCommon.h" +#include "core/ProcessSession.h" +#include "core/Resource.h" +#include "minifi-cpp/core/ProcessContext.h" +#include "utils/Enum.h" +#include "utils/ProcessorConfigUtils.h" +#include "utils/StringUtils.h" + +namespace org::apache::nifi::minifi::processors { + +namespace { +// How long one iteration of the event thread waits for notifications to arrive from the server. +constexpr UA_UInt32 NOTIFICATION_WAIT_TIME_MS = 200; +} // namespace + +void FetchOPCEvents::initialize() { + setSupportedProperties(Properties); + setSupportedRelationships(Relationships); +} + +void FetchOPCEvents::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory& factory) { + logger_->log_trace("FetchOPCEvents::onSchedule"); + BaseOPCProcessor::onSchedule(context, factory); + + node_id_ = utils::parseProperty(context, NodeID); + id_type_ = utils::parseEnumProperty<opc::OPCNodeIDType>(context, NodeIDType); + namespace_idx_ = gsl::narrow<UA_UInt16>(utils::parseU64Property(context, NameSpaceIndex)); + parseNode(context); + + const auto record_set_writer_name = utils::parseProperty(context, RecordSetWriter); + auto controller_service = context.getControllerService(record_set_writer_name, getUUID()); + if (!record_set_writer_name.empty() && !controller_service) { + throw Exception(PROCESS_SCHEDULE_EXCEPTION, fmt::format("Controller service '{}' not found", record_set_writer_name)); + } + record_set_writer_ = std::dynamic_pointer_cast<core::RecordSetWriter>(controller_service); + if (!record_set_writer_) { + throw Exception(PROCESS_SCHEDULE_EXCEPTION, fmt::format("Failed to obtain RecordSetWriter controller service '{}'", record_set_writer_name)); + } + + const auto max_queue_size = utils::parseOptionalU64Property(context, MaxQueueSize); + max_event_queue_size_ = max_queue_size && *max_queue_size > 0 + ? std::optional<size_t>(gsl::narrow<size_t>(*max_queue_size)) + : std::nullopt; + + const auto minimum_severity = utils::parseOptionalU64Property(context, MinimumSeverity); + event_filter_.minimum_severity = minimum_severity && *minimum_severity > 0 ? minimum_severity : std::nullopt; + + event_filter_.event_type_node_id = utils::parseProperty(context, EventTypeNodeId); + event_filter_.filter_expression = context.getProperty(EventFilterExpression).value_or(""); + + event_filter_.select_fields = utils::string::splitAndTrimRemovingEmpty(utils::parseProperty(context, SelectFields), ","); + if (event_filter_.select_fields.empty() && event_filter_.filter_expression.empty()) { + throw Exception(PROCESS_SCHEDULE_EXCEPTION, + fmt::format("At least one field must be set in '{}', otherwise the events would carry no data", SelectFields.name)); + } + + const auto batch_size = utils::parseOptionalU64Property(context, BatchSize); + batch_size_ = batch_size && *batch_size > 0 ? batch_size : std::nullopt; + + connection_ = opc::Client::createClient(logger_, application_uri_, cert_buffer_, key_buffer_, trust_buffers_, max_event_queue_size_); + if (!connection_) { + throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Failed to create the OPC UA client"); + } + + gsl_Expects(!event_thread_); + event_thread_ = std::make_unique<utils::StoppableThread>([this]() { runEventLoop(); }); Review Comment: Updated in https://github.com/apache/nifi-minifi-cpp/pull/2268/commits/330b6b7882de20576d2e38e71dc3267090e93aca -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
