-
Notifications
You must be signed in to change notification settings - Fork 100
MINIFICPP-2708 Controller Service C API #2096
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
576b345
MINIFICPP-2708 Controller Service C API
martinzink 11c5382
review changes
martinzink 09e550c
API changes from MINIFICPP-2764
martinzink ef22795
CControllerService rule of 5
martinzink d194181
notifyStop -> disable on C API
martinzink 4da5679
expand comment about logger being non nullable
martinzink f290332
CControllerServiceFactory formatting
martinzink bbc9d10
MinifiProcessContextGetControllerService fix
martinzink b31c946
fix build
martinzink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /** | ||
| * 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 <vector> | ||
|
|
||
| #include "minifi-c/minifi-c.h" | ||
| #include "minifi-cpp/Exception.h" | ||
| #include "minifi-cpp/core/ControllerServiceMetadata.h" | ||
| #include "minifi-cpp/core/Property.h" | ||
| #include "minifi-cpp/core/controller/ControllerServiceApi.h" | ||
|
|
||
| namespace org::apache::nifi::minifi::utils { | ||
| class CControllerService; | ||
|
|
||
|
|
||
| struct CControllerServiceClassDescription { | ||
| std::string full_name; | ||
| std::vector<core::Property> class_properties; | ||
| MinifiControllerServiceCallbacks callbacks; | ||
| }; | ||
|
|
||
| class CControllerService final : public core::controller::ControllerServiceApi, public core::controller::ControllerServiceHandle { | ||
| public: | ||
| CControllerService(CControllerServiceClassDescription class_description, core::ControllerServiceMetadata metadata) | ||
| : class_description_(std::move(class_description)), | ||
| metadata_(std::move(metadata)) { | ||
| MinifiControllerServiceMetadata c_metadata; | ||
| auto uuid_str = metadata_.uuid.to_string(); | ||
| c_metadata.uuid = MinifiStringView{.data = uuid_str.data(), .length = uuid_str.length()}; | ||
| c_metadata.name = MinifiStringView{.data = metadata_.name.data(), .length = metadata_.name.length()}; | ||
| c_metadata.logger = reinterpret_cast<MinifiLogger*>(&metadata_.logger); | ||
| impl_ = class_description_.callbacks.create(c_metadata); | ||
| } | ||
| CControllerService(CControllerServiceClassDescription class_description, core::ControllerServiceMetadata metadata, gsl::owner<void*> impl) | ||
| : class_description_(std::move(class_description)), | ||
| impl_(impl), | ||
| metadata_(std::move(metadata)) {} | ||
| CControllerService(const CControllerService&) = delete; | ||
| CControllerService& operator=(const CControllerService&) = delete; | ||
| CControllerService(CControllerService&&) = delete; | ||
| CControllerService& operator=(CControllerService&&) = delete; | ||
| ~CControllerService() override { | ||
| class_description_.callbacks.destroy(impl_); | ||
| } | ||
|
|
||
| [[nodiscard]] bool supportsDynamicProperties() const override { | ||
| return false; | ||
| } | ||
|
|
||
| void initialize(core::controller::ControllerServiceDescriptor& descriptor) override { | ||
| descriptor.setSupportedProperties(std::span(class_description_.class_properties)); | ||
| } | ||
|
|
||
| void onEnable(core::controller::ControllerServiceContext& controller_service_context, | ||
| const std::shared_ptr<Configure>&, | ||
| const std::vector<std::shared_ptr<core::controller::ControllerServiceHandle>>&) override { | ||
| const auto enable_status = class_description_.callbacks.enable(impl_, reinterpret_cast<MinifiControllerServiceContext*>(&controller_service_context)); | ||
| if (enable_status != MINIFI_STATUS_SUCCESS) { | ||
| throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Could not enable controller service"); | ||
| } | ||
| } | ||
|
|
||
| void notifyStop() override { | ||
| class_description_.callbacks.disable(impl_); | ||
| } | ||
|
|
||
| ControllerServiceHandle* getControllerServiceHandle() override { | ||
| return this; | ||
| } | ||
|
|
||
| [[nodiscard]] std::string getName() const { | ||
| return metadata_.name; | ||
| } | ||
|
|
||
| [[nodiscard]] Identifier getUUID() const { | ||
| return metadata_.uuid; | ||
| } | ||
|
|
||
| [[nodiscard]] void* getImpl() const { | ||
| return this->impl_; | ||
| } | ||
|
|
||
| [[nodiscard]] const CControllerServiceClassDescription& getClassDescription() const { | ||
| return class_description_; | ||
| } | ||
|
|
||
| private: | ||
| CControllerServiceClassDescription class_description_; | ||
| gsl::owner<void*> impl_; | ||
| minifi::core::ControllerServiceMetadata metadata_; | ||
| }; | ||
|
|
||
| void useCControllerServiceClassDescription(const MinifiControllerServiceClassDefinition& class_description, | ||
| const BundleIdentifier& bundle_id, | ||
| const std::function<void(ClassDescription, CControllerServiceClassDescription)>& fn); | ||
|
|
||
| } // namespace org::apache::nifi::minifi::utils | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.