-
Notifications
You must be signed in to change notification settings - Fork 100
MINIFICPP-2715 - Use symbols to check api compatibility #2105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3e75dcf
34ac5ad
a0ddf31
b3fb655
c0fcc0c
8e1f526
7681fd5
678a0da
a081824
17b9305
4ed46e1
912479b
029dbe2
fa51693
a8c619e
bfe4f5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,39 @@ | |
| To enable all extensions for your platform, you may use -DENABLE_ALL=TRUE OR select the option to "Enable all Extensions" in the bootstrap script. [ReadMe](https://github.com/apache/nifi-minifi-cpp/#bootstrapping) | ||
|
|
||
| # Extension internals | ||
| Extensions are dynamic libraries loaded at runtime by the agent. An extension makes its | ||
| capabilities (classes) available to the system through registrars. Registration must happen in source files, not headers. | ||
| Extensions are dynamic libraries loaded at runtime by the agent. | ||
|
|
||
| ## C extensions | ||
| You can build a shared library depending on the C capabilities of the agent as given in the `minifi-c.h` file. | ||
| For the shared library to be considered a valid extension, it has to have a global symbol with the name `MinifiCApiVersion` | ||
| with its value as a null terminated string (`const char*`) of the macro `MINIFI_API_VERSION` from `minifi-c.h`. | ||
|
|
||
| Moreover the actual resource registration (processors/controller services) has to happen during the `MinifiInitExtension` call. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this enforced?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these kinds of questions are better addressed in PR #2150 as there have been some changes touching this part as well |
||
| One possible example of this is: | ||
|
|
||
| ```C++ | ||
| extern "C" const char* const MinifiApiVersion = MINIFI_API_VERSION; | ||
|
|
||
| extern "C" void MinifiInitExtension(MinifiExtension* extension, MinifiConfig* /*config*/) { | ||
| minifi::api::core::useProcessorClassDescription<minifi::extensions::llamacpp::processors::RunLlamaCppInference>([&] (const MinifiProcessorClassDefinition& description) { | ||
| MinifiExtensionCreateInfo ext_create_info{ | ||
| .name = minifi::api::utils::toStringView(MAKESTRING(EXTENSION_NAME)), | ||
| .version = minifi::api::utils::toStringView(MAKESTRING(EXTENSION_VERSION)), | ||
| .deinit = nullptr, | ||
| .user_data = nullptr, | ||
| .processors_count = 1, | ||
| .processors_ptr = &description, | ||
| }; | ||
| MinifiCreateExtension(extension, &ext_create_info); | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| ## C++ extensions | ||
| You can utilize the C++ api, linking to `minifi-api` and possibly using the helpers in `extension-framework`. | ||
| No compatibilities are guaranteed beyond what extensions are built together with the agent at the same time. | ||
|
|
||
| An extension makes its capabilities (classes) available to the system through registrars. Registration must happen in source files, not headers. | ||
|
|
||
| ```C++ | ||
| // register user-facing classes as | ||
|
|
@@ -33,10 +64,10 @@ REGISTER_RESOURCE(RESTSender, DescriptionOnly); | |
| ``` | ||
|
|
||
| Some extensions (e.g. `OpenCVExtension`) require initialization before use. | ||
| You need to define an `InitExtension` function of type `MinifiExtension*(MinifiConfig*)` to be called. | ||
| You need to define an `MinifiInitCppExtension` function of type `MinifiExtension*(MinifiConfig*)` to be called. | ||
|
|
||
| ```C++ | ||
| extern "C" MinifiExtension* InitExtension(MinifiConfig* /*config*/) { | ||
| extern "C" void MinifiInitCppExtension(MinifiExtension* extension, MinifiConfig* /*config*/) { | ||
| const auto success = org::apache::nifi::minifi::utils::Environment::setEnvironmentVariable("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp", false /*overwrite*/); | ||
| if (!success) { | ||
| return nullptr; | ||
|
|
@@ -49,7 +80,7 @@ extern "C" MinifiExtension* InitExtension(MinifiConfig* /*config*/) { | |
| .processors_count = 0, | ||
| .processors_ptr = nullptr | ||
| }; | ||
| return MinifiCreateExtension(minifi::utils::toStringView(MINIFI_API_VERSION), &ext_create_info); | ||
| minifi::utils::MinifiCreateCppExtension(extension, &ext_create_info); | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** | ||
| * | ||
| * 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 "utils/ExtensionInitUtils.h" | ||
| #include "minifi-cpp/agent/agent_version.h" | ||
| #include "core/Resource.h" | ||
|
|
||
| namespace minifi = org::apache::nifi::minifi; | ||
|
|
||
| extern "C" void MinifiInitCppExtension(MinifiExtension* extension, MinifiConfig* /*config*/) { | ||
| MinifiExtensionCreateInfo ext_create_info{ | ||
| .name = minifi::utils::toStringView(MAKESTRING(MODULE_NAME)), | ||
| .version = minifi::utils::toStringView(minifi::AgentBuild::VERSION), | ||
| .deinit = nullptr, | ||
| .user_data = nullptr, | ||
| .processors_count = 0, | ||
| .processors_ptr = nullptr | ||
| }; | ||
| minifi::utils::MinifiCreateCppExtension(extension, &ext_create_info); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * 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 <string> | ||
| #include <cinttypes> | ||
|
|
||
| namespace org::apache::nifi::minifi::core::extension { | ||
|
|
||
| uint32_t getAgentApiVersion(); | ||
| uint32_t getMinSupportedApiVersion(); | ||
| void test_setAgentApiVersion(uint32_t api_version); | ||
| void test_setMinSupportedApiVersion(uint32_t min_api_version); | ||
|
|
||
| } // namespace org::apache::nifi::minifi::core::extension |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states the symbol should be named
MinifiCApiVersion, but the actual code in Extension.cpp line 70 looks forMinifiApiVersion(without the "C"). The documentation should be corrected to match the implementation.