-
Notifications
You must be signed in to change notification settings - Fork 15
hmon: add C++ interface to heartbeat monitor #72
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
Merged
arkjedrz
merged 1 commit into
eclipse-score:main
from
qorix-group:arkjedrz_heartbeat-monitor-cpp
Mar 6, 2026
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #include "score/hm/heartbeat/heartbeat_monitor.h" | ||
|
|
||
| namespace { | ||
| extern "C" { | ||
| using namespace score::hm; | ||
| using namespace score::hm::internal; | ||
| using namespace score::hm::heartbeat; | ||
|
|
||
| FFICode heartbeat_monitor_builder_create(uint32_t range_min_ms, uint32_t range_max_ms, FFIHandle* heartbeat_monitor_builder_handle_out); | ||
| FFICode heartbeat_monitor_builder_destroy(FFIHandle heartbeat_monitor_builder_handle); | ||
| FFICode heartbeat_monitor_destroy(FFIHandle heartbeat_monitor_builder_handle); | ||
| FFICode heartbeat_monitor_heartbeat(FFIHandle heartbeat_monitor_builder_handle); | ||
| } | ||
|
|
||
| FFIHandle heartbeat_monitor_builder_create_wrapper(uint32_t range_min_ms, uint32_t range_max_ms) | ||
| { | ||
| FFIHandle handle{nullptr}; | ||
| auto result{heartbeat_monitor_builder_create(range_min_ms, range_max_ms, &handle)}; | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT(result == kSuccess); | ||
| return handle; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| namespace score::hm::heartbeat | ||
| { | ||
| HeartbeatMonitorBuilder::HeartbeatMonitorBuilder(const TimeRange& range) | ||
| : monitor_builder_handle_{heartbeat_monitor_builder_create_wrapper(range.min_ms(), range.max_ms()), | ||
| &heartbeat_monitor_builder_destroy} | ||
| { | ||
| } | ||
|
|
||
| HeartbeatMonitor::HeartbeatMonitor(FFIHandle monitor_handle) | ||
| : monitor_handle_{monitor_handle, &heartbeat_monitor_destroy} | ||
| { | ||
| } | ||
|
|
||
| void HeartbeatMonitor::heartbeat() | ||
| { | ||
| auto monitor_handle{monitor_handle_.as_rust_handle()}; | ||
| SCORE_LANGUAGE_FUTURECPP_PRECONDITION(monitor_handle.has_value()); | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT(heartbeat_monitor_heartbeat(monitor_handle.value()) == kSuccess); | ||
| } | ||
|
|
||
| } // namespace score::hm::heartbeat | ||
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
84 changes: 84 additions & 0 deletions
84
src/health_monitoring_lib/cpp/include/score/hm/heartbeat/heartbeat_monitor.h
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,84 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #ifndef SCORE_HM_HEARTBEAT_HEARTBEAT_MONITOR_H | ||
| #define SCORE_HM_HEARTBEAT_HEARTBEAT_MONITOR_H | ||
|
|
||
| #include <score/expected.hpp> | ||
| #include <score/hm/common.h> | ||
|
|
||
| namespace score::hm | ||
| { | ||
| // Forward declaration | ||
| class HealthMonitor; | ||
| class HealthMonitorBuilder; | ||
| } // namespace score::hm | ||
|
|
||
| namespace score::hm::heartbeat | ||
| { | ||
| // Forward declaration | ||
| class HeartbeatMonitor; | ||
|
|
||
| /// Builder for `HeartbeatMonitor`. | ||
| class HeartbeatMonitorBuilder final : public internal::RustDroppable<HeartbeatMonitorBuilder> | ||
| { | ||
| public: | ||
| /// Create a new `HeartbeatMonitorBuilder`. | ||
| /// | ||
| /// - `range` - time range between heartbeats. | ||
| HeartbeatMonitorBuilder(const TimeRange& range); | ||
|
|
||
| HeartbeatMonitorBuilder(const HeartbeatMonitorBuilder&) = delete; | ||
| HeartbeatMonitorBuilder& operator=(const HeartbeatMonitorBuilder&) = delete; | ||
|
|
||
| HeartbeatMonitorBuilder(HeartbeatMonitorBuilder&&) = default; | ||
| HeartbeatMonitorBuilder& operator=(HeartbeatMonitorBuilder&&) = delete; | ||
|
|
||
| protected: | ||
| std::optional<internal::FFIHandle> _drop_by_rust_impl() | ||
| { | ||
| return monitor_builder_handle_.drop_by_rust(); | ||
| } | ||
|
|
||
| private: | ||
| internal::DroppableFFIHandle monitor_builder_handle_; | ||
|
|
||
| // Allow to hide drop_by_rust implementation | ||
| friend class internal::RustDroppable<HeartbeatMonitorBuilder>; | ||
|
|
||
| // Allow HealthMonitorBuilder to access drop_by_rust implementation | ||
| friend class ::score::hm::HealthMonitorBuilder; | ||
| }; | ||
|
|
||
| class HeartbeatMonitor final | ||
| { | ||
| public: | ||
| // Delete copy, allow move | ||
| HeartbeatMonitor(const HeartbeatMonitor&) = delete; | ||
| HeartbeatMonitor& operator=(const HeartbeatMonitor&) = delete; | ||
|
|
||
| HeartbeatMonitor(HeartbeatMonitor&& other) noexcept = default; | ||
| HeartbeatMonitor& operator=(HeartbeatMonitor&& other) noexcept = default; | ||
|
|
||
| void heartbeat(); | ||
|
|
||
| private: | ||
| explicit HeartbeatMonitor(internal::FFIHandle monitor_handle); | ||
|
|
||
| // Only `HealthMonitor` is allowed to create `HeartbeatMonitor` instances. | ||
| friend class score::hm::HealthMonitor; | ||
| internal::DroppableFFIHandle monitor_handle_; | ||
| }; | ||
|
|
||
| } // namespace score::hm::heartbeat | ||
|
|
||
| #endif // SCORE_HM_HEARTBEAT_HEARTBEAT_MONITOR_H |
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.
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.