fgerlits commented on code in PR #1987: URL: https://github.com/apache/nifi-minifi-cpp/pull/1987#discussion_r2534446258
########## core-framework/c-api-framework/src/core/ProcessorImpl.cpp: ########## @@ -0,0 +1,83 @@ +/** + * 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 "api/core/ProcessorImpl.h" + +#include <ctime> +#include <cctype> + +#include <memory> +#include <set> +#include <string> +#include <vector> + +#include "fmt/format.h" + +using namespace std::literals::chrono_literals; + +namespace org::apache::nifi::minifi::api::core { + +ProcessorImpl::ProcessorImpl(minifi::core::ProcessorMetadata metadata) + : metadata_(std::move(metadata)), + trigger_when_empty_(false), + logger_(metadata_.logger) { + logger_->log_debug("Processor {} created with uuid {}", getName(), getUUIDStr()); +} + +ProcessorImpl::~ProcessorImpl() { + logger_->log_debug("Destroying processor {} with uuid {}", getName(), getUUIDStr()); +} + +bool ProcessorImpl::isWorkAvailable() { + return false; +} + +void ProcessorImpl::restore(const std::shared_ptr<FlowFile>& /*file*/) { + gsl_Assert("Not implemented"); Review Comment: this should be ```suggestion gsl_Assert(false && "Not implemented"); ``` (also in `minifi::core::ProcessorImpl::restore`) ########## core-framework/c-api-framework/include/api/utils/minifi-c-utils.h: ########## Review Comment: Do we need both `minifi-c-utils.h` files? If we need both, can you rename one of them, please? ########## core-framework/c-api-framework/src/core/logging/Logger.cpp: ########## @@ -0,0 +1,69 @@ +/** +* 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 "api/core/logging/Logger.h" + +namespace org::apache::nifi::minifi::api::core::logging { + +namespace { + +MinifiLogLevel toCLogLevel(minifi::core::logging::LOG_LEVEL lvl) { + switch (lvl) { + case minifi::core::logging::trace: return MINIFI_LOG_LEVEL_TRACE; + case minifi::core::logging::debug: return MINIFI_LOG_LEVEL_DEBUG; + case minifi::core::logging::info: return MINIFI_LOG_LEVEL_INFO; + case minifi::core::logging::warn: return MINIFI_LOG_LEVEL_WARNING; + case minifi::core::logging::err: return MINIFI_LOG_LEVEL_ERROR; + case minifi::core::logging::critical: return MINIFI_LOG_LEVEL_CRITICAL; + case minifi::core::logging::off: return MINIFI_LOG_LEVEL_OFF; + } + gsl_FailFast(); +} + +minifi::core::logging::LOG_LEVEL toLogLevel(MinifiLogLevel level) { + switch (level) { + case MINIFI_LOG_LEVEL_TRACE: return minifi::core::logging::trace; + case MINIFI_LOG_LEVEL_DEBUG: return minifi::core::logging::debug; + case MINIFI_LOG_LEVEL_INFO: return minifi::core::logging::info; + case MINIFI_LOG_LEVEL_WARNING: return minifi::core::logging::warn; + case MINIFI_LOG_LEVEL_ERROR: return minifi::core::logging::err; + case MINIFI_LOG_LEVEL_CRITICAL: return minifi::core::logging::critical; + case MINIFI_LOG_LEVEL_OFF: return minifi::core::logging::off; + } + gsl_FailFast(); +} + +} // namespace + +void Logger::set_max_log_size(int size) { + MinifiLoggerSetMaxLogSize(impl_, size); +} + +void Logger::log_string(minifi::core::logging::LOG_LEVEL level, std::string str) { + MinifiLoggerLogString(impl_, toCLogLevel(level), MinifiStringView{.data = str.data(), .length = gsl::narrow_cast<uint32_t>(str.length())}); Review Comment: `narrow_cast` can be removed ########## core-framework/c-api-framework/include/api/utils/minifi-c-utils.h: ########## @@ -0,0 +1,95 @@ +/** +* 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. + */ +#pragma once + +#include "minifi-c.h" +#include <string_view> +#include "minifi-cpp/core/Annotation.h" +#include "minifi-cpp/utils/gsl.h" +#include "core/ClassName.h" +#include "utils/StringUtils.h" +#include "minifi-cpp/core/PropertyDefinition.h" + +namespace org::apache::nifi::minifi::api::utils { + +inline MinifiStringView toStringView(std::string_view str) { + return MinifiStringView{.data = str.data(), .length = str.length()}; +} + +template<typename T> +std::string classNameWithDots() { + std::string class_name{minifi::core::className<T>()}; + return minifi::utils::string::replaceAll(class_name, "::", "."); +} + +MinifiStandardPropertyValidator toStandardPropertyValidator(const minifi::core::PropertyValidator* validator); + +inline MinifiInputRequirement toInputRequirement(minifi::core::annotation::Input req) { + switch (req) { + case minifi::core::annotation::Input::INPUT_REQUIRED: return MINIFI_INPUT_REQUIRED; + case minifi::core::annotation::Input::INPUT_ALLOWED: return MINIFI_INPUT_ALLOWED; + case minifi::core::annotation::Input::INPUT_FORBIDDEN: return MINIFI_INPUT_FORBIDDEN; + } + gsl_FailFast(); +} + +inline std::vector<MinifiProperty> toProperties(std::span<const minifi::core::PropertyReference> props, std::vector<std::vector<MinifiStringView>>& cache) { + std::vector<MinifiProperty> properties; + for (auto& prop : props) { + std::vector<MinifiStringView> sv_cache; + const size_t allowed_values_begin = sv_cache.size(); + for (auto& allowed_value : prop.allowed_values) { + sv_cache.emplace_back(toStringView(allowed_value)); + } + const std::optional<size_t> allowed_types_begin = [&] () -> std::optional<size_t> { + if (prop.allowed_types.empty()) { + return std::nullopt; + } + gsl_Expects(prop.allowed_types.size() == 1); + sv_cache.emplace_back(toStringView(prop.allowed_types[0])); + return sv_cache.size() - 1; + }(); + const std::optional<size_t> default_value_begin = [&] () -> std::optional<size_t> { + if (!prop.default_value) { + return std::nullopt; + } + sv_cache.emplace_back(toStringView(*prop.default_value)); + return sv_cache.size() - 1; + }(); + properties.push_back(MinifiProperty{ + .name = toStringView(prop.name), + .display_name = toStringView(prop.display_name), + .description = toStringView(prop.description), + .is_required = prop.is_required, + .is_sensitive = prop.is_sensitive, + + .default_value = default_value_begin ? sv_cache.data() + default_value_begin.value() : nullptr, + .allowed_values_count = gsl::narrow<uint32_t>(prop.allowed_values.size()), Review Comment: both sides are `size_t`, so the `narrow()` can be removed -- 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]
