Skip to content

Commit e218b43

Browse files
committed
hmon: C++ interface logic monitor post-review fix
Post-review fixes do C++ interface of logic monitor.
1 parent fe4dbfa commit e218b43

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/health_monitoring_lib/cpp/include/score/hm/tag.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,27 @@ template <typename T>
2525
class Tag
2626
{
2727
public:
28-
/// Create an empty tag.
29-
Tag() : data_{nullptr}, length_{0} {}
30-
3128
/// Create a new tag from a C-style string.
3229
template <size_t N>
3330
explicit Tag(const char (&tag)[N]) : data_(tag), length_(N - 1)
3431
{
3532
}
3633

37-
bool operator==(const T& other)
34+
bool operator==(const T& other) const noexcept
3835
{
3936
std::string_view this_sv{data_, length_};
4037
std::string_view other_sv{other.data_, other.length_};
4138
return this_sv.compare(other_sv) == 0;
4239
}
4340

44-
bool operator!=(const T& other)
41+
bool operator!=(const T& other) const noexcept
4542
{
4643
return !(*this == other);
4744
}
4845

4946
private:
5047
/// SAFETY: This has to be FFI compatible with the Rust side representation.
51-
const char* const data_;
48+
const char* data_;
5249
size_t length_;
5350
};
5451

src/health_monitoring_lib/cpp/logic_monitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ score::cpp::expected<StateTag, Error> LogicMonitor::state()
8181
auto monitor_handle{monitor_handle_.as_rust_handle()};
8282
SCORE_LANGUAGE_FUTURECPP_PRECONDITION(monitor_handle.has_value());
8383

84-
StateTag state_tag;
84+
StateTag state_tag{""};
8585
auto result{logic_monitor_state(monitor_handle.value(), &state_tag)};
8686
if (result != kSuccess)
8787
{

src/health_monitoring_lib/rust/logic/ffi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ pub extern "C" fn logic_monitor_builder_add_state(
7777
// `allowed_states` must contain a valid continuous array.
7878
// Number of elements must match `num_allowed_states`.
7979
// Null is allowed when `num_allowed_states` equals 0.
80-
let allowed_states: Vec<StateTag> = if num_allowed_states > 0 {
81-
unsafe { core::slice::from_raw_parts(allowed_states, num_allowed_states).to_vec() }
80+
let allowed_states = if num_allowed_states > 0 {
81+
unsafe { core::slice::from_raw_parts(allowed_states, num_allowed_states) }
8282
} else {
83-
Vec::new()
83+
&[]
8484
};
8585

8686
// SAFETY:
@@ -90,7 +90,7 @@ pub extern "C" fn logic_monitor_builder_add_state(
9090
let mut logic_monitor_builder =
9191
FFIBorrowed::new(unsafe { Box::from_raw(logic_monitor_builder_handle as *mut LogicMonitorBuilder) });
9292

93-
logic_monitor_builder.add_state_internal(state, &allowed_states);
93+
logic_monitor_builder.add_state_internal(state, allowed_states);
9494

9595
FFICode::Success
9696
}

0 commit comments

Comments
 (0)