adamdebreceni commented on code in PR #1987:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1987#discussion_r2526252168


##########
libminifi/src/minifi-c.cpp:
##########
@@ -0,0 +1,502 @@
+/**
+* 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 "minifi-c/minifi-c.h"
+
+#include <memory>
+#include <vector>
+
+#include "agent/agent_docs.h"
+#include "core/ProcessorMetrics.h"
+#include "minifi-cpp/core/Annotation.h"
+#include "minifi-cpp/core/ClassLoader.h"
+#include "minifi-cpp/core/ProcessContext.h"
+#include "minifi-cpp/core/ProcessSession.h"
+#include "minifi-cpp/core/ProcessorApi.h"
+#include "minifi-cpp/core/ProcessorDescriptor.h"
+#include "minifi-cpp/core/ProcessorFactory.h"
+#include "minifi-cpp/core/ProcessorMetadata.h"
+#include "minifi-cpp/core/PropertyValidator.h"
+#include "minifi-cpp/core/logging/Logger.h"
+#include "minifi-cpp/core/state/PublishedMetricProvider.h"
+#include "minifi-cpp/Exception.h"
+#include "minifi-cpp/core/extension/ExtensionManager.h"
+#include "utils/PropertyErrors.h"
+#include "minifi-cpp/agent/build_description.h"
+#include "utils/CProcessor.h"
+
+namespace minifi = org::apache::nifi::minifi;
+
+namespace {
+
+std::string toString(MinifiStringView sv) {
+  return {sv.data, sv.length};
+}
+
+std::string_view toStringView(MinifiStringView sv) {
+  return {sv.data, sv.length};
+}
+
+minifi::core::annotation::Input toInputRequirement(MinifiInputRequirement req) 
{
+  switch (req) {
+    case MINIFI_INPUT_REQUIRED: return 
minifi::core::annotation::Input::INPUT_REQUIRED;
+    case MINIFI_INPUT_ALLOWED: return 
minifi::core::annotation::Input::INPUT_ALLOWED;
+    case MINIFI_INPUT_FORBIDDEN: return 
minifi::core::annotation::Input::INPUT_FORBIDDEN;
+  }
+  gsl_FailFast();
+}
+
+minifi::core::logging::LOG_LEVEL toLogLevel(MinifiLogLevel lvl) {
+  switch (lvl) {
+    case MINIFI_TRACE: return minifi::core::logging::trace;
+    case MINIFI_DEBUG: return minifi::core::logging::debug;
+    case MINIFI_INFO: return minifi::core::logging::info;
+    case MINIFI_WARNING: return minifi::core::logging::warn;
+    case MINIFI_ERROR: return minifi::core::logging::err;
+    case MINIFI_CRITICAL: return minifi::core::logging::critical;
+    case MINIFI_OFF: return minifi::core::logging::off;
+  }
+  gsl_FailFast();
+}
+
+minifi::core::Property createProperty(const MinifiProperty* 
property_description) {
+  gsl_Expects(property_description);
+  std::vector<std::string_view> allowed_values;
+  allowed_values.reserve(property_description->allowed_values_count);
+  for (size_t i = 0; i < property_description->allowed_values_count; ++i) {
+    
allowed_values.push_back(toStringView(property_description->allowed_values_ptr[i]));
+  }
+  std::vector<std::string_view> allowed_types;
+  allowed_types.reserve(property_description->types_count);
+  for (size_t i = 0; i < property_description->types_count; ++i) {
+    allowed_types.push_back(toStringView(property_description->types_ptr[i]));
+  }
+  std::vector<std::string_view> dependent_properties;
+  
dependent_properties.reserve(property_description->dependent_properties_count);
+  for (size_t i = 0; i < property_description->dependent_properties_count; 
++i) {
+    
dependent_properties.push_back(toStringView(property_description->dependent_properties_ptr[i]));
+  }
+  std::vector<std::pair<std::string_view, std::string_view>> 
exclusive_of_properties;
+  
exclusive_of_properties.reserve(property_description->exclusive_of_properties_count);
+  for (size_t i = 0; i < property_description->exclusive_of_properties_count; 
++i) {
+    
exclusive_of_properties.push_back({toStringView(property_description->exclusive_of_property_names_ptr[i]),
 toStringView(property_description->exclusive_of_property_values_ptr[i])});
+  }
+  std::optional<std::string_view> default_value;
+  if (property_description->default_value) {
+    default_value = toStringView(*property_description->default_value);
+  }
+  return minifi::core::Property{minifi::core::PropertyReference{
+    toStringView(property_description->name),
+    toStringView(property_description->display_name),
+    toStringView(property_description->description),
+    static_cast<bool>(property_description->is_required),
+    static_cast<bool>(property_description->is_sensitive),
+    std::span(allowed_values),
+    std::span(allowed_types),
+    std::span(dependent_properties),
+    std::span(exclusive_of_properties),
+    default_value,
+    gsl::make_not_null(reinterpret_cast<const 
minifi::core::PropertyValidator*>(property_description->validator)),
+    static_cast<bool>(property_description->supports_expression_language)
+  }};
+}
+
+class CProcessorFactory : public minifi::core::ProcessorFactory {
+ public:
+  CProcessorFactory(std::string group_name, std::string class_name, 
minifi::utils::CProcessorClassDescription class_description)
+    : group_name_(std::move(group_name)),
+      class_name_(std::move(class_name)),
+      class_description_(std::move(class_description)) {}
+  std::unique_ptr<minifi::core::ProcessorApi> 
create(minifi::core::ProcessorMetadata metadata) override {
+    return std::make_unique<minifi::utils::CProcessor>(class_description_, 
metadata);
+  }
+
+  [[nodiscard]] std::string getGroupName() const override {
+    return group_name_;
+  }
+
+  [[nodiscard]] std::string getClassName() const override {
+    return class_name_;
+  }
+
+  CProcessorFactory() = delete;
+  CProcessorFactory(const CProcessorFactory&) = delete;
+  CProcessorFactory& operator=(const CProcessorFactory&) = delete;
+  CProcessorFactory(CProcessorFactory&&) = delete;
+  CProcessorFactory& operator=(CProcessorFactory&&) = delete;
+  ~CProcessorFactory() override = default;
+
+ private:
+  std::string group_name_;
+  std::string class_name_;
+  minifi::utils::CProcessorClassDescription class_description_;
+};
+
+class CExtension : public minifi::core::extension::Extension {
+ public:
+  CExtension(std::string name, MinifiBool(*initializer)(void*, 
MinifiConfigure), void* user_data): name_(std::move(name)), 
initializer_(initializer), user_data_(user_data) {}
+  bool initialize(const minifi::core::extension::ExtensionConfig& config) 
override {
+    gsl_Assert(initializer_);
+    return static_cast<bool>(initializer_(user_data_, 
reinterpret_cast<MinifiConfigure>(config.get())));
+  }
+
+  [[nodiscard]] const std::string& getName() const override {
+    return name_;
+  }
+
+ private:
+  std::string name_;
+  MinifiBool(*initializer_)(void*, MinifiConfigure);

Review Comment:
   since the extension loading revamp, there aren't really such function 
pointers anymore



-- 
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]

Reply via email to