szaszm commented on code in PR #2056:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2056#discussion_r2481187120
##########
core-framework/include/utils/minifi-c-utils.h:
##########
@@ -14,19 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#pragma once
-#include "Extension.h"
+#include "minifi-c/minifi-c.h"
+#include <string_view>
+#include <optional>
+#include <functional>
+#include "minifi-cpp/utils/gsl.h"
-namespace org::apache::nifi::minifi::core::extension {
+namespace org::apache::nifi::minifi::utils {
-class ExtensionManager {
- public:
- static ExtensionManager& get();
+inline MinifiStringView toStringView(std::string_view str) {
+ return MinifiStringView{.data = str.data(), .length =
gsl::narrow<size_t>(str.length())};
Review Comment:
I don't think narrowing is happening here with the length, the gsl::narrow
is unnecessary.
##########
minifi-api/include/minifi-c/minifi-c.h:
##########
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+
+#ifndef MINIFI_API_INCLUDE_MINIFI_C_MINIFI_C_H_
+#define MINIFI_API_INCLUDE_MINIFI_C_MINIFI_C_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef struct MinifiConfig MinifiConfig;
+typedef struct MinifiExtension MinifiExtension;
+
+typedef struct MinifiStringView {
+ const char* data;
+ size_t length;
+} MinifiStringView;
+
+typedef struct MinifiExtensionCreateInfo {
+ MinifiStringView name;
+ MinifiStringView version;
+ void(*deinit)(void* user_data);
+ void* user_data;
+} MinifiExtensionCreateInfo;
+
+MinifiExtension* MinifiCreateExtension(const MinifiExtensionCreateInfo*);
Review Comment:
Why don't we just return the MinifiExtensionCreateInfo directly and skip the
cast to MinifiExtension*? The struct could be an out param to the extension
init function in typical C style.
##########
minifi-api/include/minifi-c/minifi-c.h:
##########
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+
+#ifndef MINIFI_API_INCLUDE_MINIFI_C_MINIFI_C_H_
+#define MINIFI_API_INCLUDE_MINIFI_C_MINIFI_C_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef struct MinifiConfig MinifiConfig;
+typedef struct MinifiExtension MinifiExtension;
+
+typedef struct MinifiStringView {
+ const char* data;
+ size_t length;
+} MinifiStringView;
+
+typedef struct MinifiExtensionCreateInfo {
+ MinifiStringView name;
+ MinifiStringView version;
+ void(*deinit)(void* user_data);
+ void* user_data;
+} MinifiExtensionCreateInfo;
+
+MinifiExtension* MinifiCreateExtension(const MinifiExtensionCreateInfo*);
+void MinifiConfigureGet(MinifiConfig*, MinifiStringView, void(*cb)(void*
user_data, MinifiStringView value), void* user_data);
Review Comment:
I think it would be simpler to return a `const char*` that points to memory
owned by the supplied `MinifiConfig*`/`Configure` object.
Is the second parameter a config key? I think it would be nice to add a name
and maybe some docs to make it clear how this works to all readers.
##########
minifi-api/include/minifi-c/minifi-c.h:
##########
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+
+#ifndef MINIFI_API_INCLUDE_MINIFI_C_MINIFI_C_H_
+#define MINIFI_API_INCLUDE_MINIFI_C_MINIFI_C_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef struct MinifiConfig MinifiConfig;
+typedef struct MinifiExtension MinifiExtension;
+
+typedef struct MinifiStringView {
+ const char* data;
+ size_t length;
+} MinifiStringView;
+
+typedef struct MinifiExtensionCreateInfo {
+ MinifiStringView name;
+ MinifiStringView version;
Review Comment:
I would've used standard null-terminated C strings just for simplicity, but
either is fine, I just wanna spark some discussion about it.
--
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]