Copilot commented on code in PR #2054:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2054#discussion_r2473393789
##########
Extensions.md:
##########
@@ -33,20 +33,22 @@ REGISTER_RESOURCE(RESTSender, DescriptionOnly);
```
Some extensions (e.g. `OpenCVExtension`) require initialization before use.
-You need to create `init` and `deinit` functions and register them using
`REGISTER_EXTENSION`.
+You need to define an `InitExtension` function to be called.
```C++
-static bool init(const std::shared_ptr<org::apache::nifi::minifi::Configure>&
/*config*/) {
- return
org::apache::nifi::minifi::utils::Environment::setEnvironmentVariable("OPENCV_FFMPEG_CAPTURE_OPTIONS",
"rtsp_transport;udp", false /*overwrite*/);
+extern "C"
std::optional<org::apache::nifi:minifi::core::extension::ExtensionInfo>
InitExtension(const std::shared_ptr<org::apache::nifi::minifi::Configure>&
/*config*/) {
+
org::apache::nifi::minifi::utils::Environment::setEnvironmentVariable("OPENCV_FFMPEG_CAPTURE_OPTIONS",
"rtsp_transport;udp", false /*overwrite*/);
+ return org::apache::nifi:minifi::core::extension::ExtensionInfo{
Review Comment:
Corrected namespace separator from single colon to double colon:
'nifi:minifi' should be 'nifi::minifi'.
##########
Extensions.md:
##########
@@ -33,20 +33,22 @@ REGISTER_RESOURCE(RESTSender, DescriptionOnly);
```
Some extensions (e.g. `OpenCVExtension`) require initialization before use.
-You need to create `init` and `deinit` functions and register them using
`REGISTER_EXTENSION`.
+You need to define an `InitExtension` function to be called.
```C++
-static bool init(const std::shared_ptr<org::apache::nifi::minifi::Configure>&
/*config*/) {
- return
org::apache::nifi::minifi::utils::Environment::setEnvironmentVariable("OPENCV_FFMPEG_CAPTURE_OPTIONS",
"rtsp_transport;udp", false /*overwrite*/);
+extern "C"
std::optional<org::apache::nifi:minifi::core::extension::ExtensionInfo>
InitExtension(const std::shared_ptr<org::apache::nifi::minifi::Configure>&
/*config*/) {
Review Comment:
Corrected namespace separator from single colon to double colon:
'nifi:minifi' should be 'nifi::minifi'.
##########
extensions/sftp/SFTPLoader.cpp:
##########
@@ -16,23 +16,33 @@
* limitations under the License.
*/
-#include "core/extension/Extension.h"
+#include "minifi-cpp/core/extension/ExtensionInfo.h"
+#include "minifi-cpp/agent/agent_version.h"
+#include "minifi-cpp/properties/Configure.h"
#include "client/SFTPClient.h"
-static bool init(const std::shared_ptr<org::apache::nifi::minifi::Configure>&
/*config*/) {
- if (libssh2_init(0) != 0) {
- return false;
- }
- if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) {
- libssh2_exit();
- return false;
- }
- return true;
-}
+namespace minifi = org::apache::nifi::minifi;
static void deinit() {
curl_global_cleanup();
libssh2_exit();
}
-REGISTER_EXTENSION("SFTPExtension", init, deinit);
+extern "C" std::optional<minifi::core::extension::ExtensionInfo>
InitExtension(const std::shared_ptr<minifi::Configure>& config) {
+ if (libssh2_init(0) != 0) {
+ return std::nullopt;
+ }
+ if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) {
+ libssh2_exit();
+ return std::nullopt;
+ }
+ return minifi::core::extension::ExtensionInfo{
+ .name = "SFTPExtension",
+ .version = minifi::AgentBuild::VERSION,
+ .deinit = [] (void* /*ctx*/) {
+ curl_global_cleanup();
+ libssh2_exit();
+ },
Review Comment:
The deinitialization logic is duplicated. The `deinit()` function at line
26-29 performs the same cleanup but is never called. Consider removing the
standalone `deinit()` function to eliminate code duplication.
--
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]