Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/health_monitoring_lib/cpp/include/score/hm/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RustDroppable
/// Marks object as no longer managed by C++ side, releasing handle to be passed to Rust side for dropping
std::optional<FFIHandle> drop_by_rust()
{
return static_cast<T*>(this)->__drop_by_rust_impl();
return static_cast<T*>(this)->_drop_by_rust_impl();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DeadlineMonitorBuilder final : public internal::RustDroppable<DeadlineMoni
DeadlineMonitorBuilder add_deadline(const DeadlineTag& deadline_tag, const TimeRange& range) &&;

protected:
std::optional<internal::FFIHandle> __drop_by_rust_impl()
std::optional<internal::FFIHandle> _drop_by_rust_impl()
{
return monitor_builder_handler_.drop_by_rust();
}
Expand Down
16 changes: 8 additions & 8 deletions src/health_monitoring_lib/rust/deadline/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl DeadlineMonitorCpp {
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn deadline_monitor_builder_create(deadline_monitor_builder_handle_out: *mut FFIHandle) -> FFICode {
if deadline_monitor_builder_handle_out.is_null() {
return FFICode::NullParameter;
Expand All @@ -54,7 +54,7 @@ pub extern "C" fn deadline_monitor_builder_create(deadline_monitor_builder_handl
FFICode::Success
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn deadline_monitor_builder_destroy(deadline_monitor_builder_handle: FFIHandle) -> FFICode {
if deadline_monitor_builder_handle.is_null() {
return FFICode::NullParameter;
Expand All @@ -70,7 +70,7 @@ pub extern "C" fn deadline_monitor_builder_destroy(deadline_monitor_builder_hand
FFICode::Success
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn deadline_monitor_builder_add_deadline(
deadline_monitor_builder_handle: FFIHandle,
deadline_tag: *const DeadlineTag,
Expand Down Expand Up @@ -108,7 +108,7 @@ pub extern "C" fn deadline_monitor_builder_add_deadline(
FFICode::Success
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn deadline_monitor_get_deadline(
deadline_monitor_handle: FFIHandle,
deadline_tag: *const DeadlineTag,
Expand Down Expand Up @@ -141,7 +141,7 @@ pub extern "C" fn deadline_monitor_get_deadline(
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn deadline_monitor_destroy(deadline_monitor_handle: FFIHandle) -> FFICode {
if deadline_monitor_handle.is_null() {
return FFICode::NullParameter;
Expand All @@ -157,7 +157,7 @@ pub extern "C" fn deadline_monitor_destroy(deadline_monitor_handle: FFIHandle) -
FFICode::Success
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn deadline_start(deadline_handle: FFIHandle) -> FFICode {
if deadline_handle.is_null() {
return FFICode::NullParameter;
Expand All @@ -176,7 +176,7 @@ pub extern "C" fn deadline_start(deadline_handle: FFIHandle) -> FFICode {
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn deadline_stop(deadline_handle: FFIHandle) -> FFICode {
if deadline_handle.is_null() {
return FFICode::NullParameter;
Expand All @@ -193,7 +193,7 @@ pub extern "C" fn deadline_stop(deadline_handle: FFIHandle) -> FFICode {
FFICode::Success
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn deadline_destroy(deadline_handle: FFIHandle) -> FFICode {
if deadline_handle.is_null() {
return FFICode::NullParameter;
Expand Down
14 changes: 7 additions & 7 deletions src/health_monitoring_lib/rust/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<T: DerefMut> DerefMut for FFIBorrowed<T> {
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn health_monitor_builder_create(health_monitor_builder_handle_out: *mut FFIHandle) -> FFICode {
if health_monitor_builder_handle_out.is_null() {
return FFICode::NullParameter;
Expand All @@ -87,7 +87,7 @@ pub extern "C" fn health_monitor_builder_create(health_monitor_builder_handle_ou
FFICode::Success
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn health_monitor_builder_destroy(health_monitor_builder_handle: FFIHandle) -> FFICode {
if health_monitor_builder_handle.is_null() {
return FFICode::NullParameter;
Expand All @@ -104,7 +104,7 @@ pub extern "C" fn health_monitor_builder_destroy(health_monitor_builder_handle:
FFICode::Success
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn health_monitor_builder_build(
health_monitor_builder_handle: FFIHandle,
supervisor_cycle_ms: u32,
Expand Down Expand Up @@ -137,7 +137,7 @@ pub extern "C" fn health_monitor_builder_build(
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn health_monitor_builder_add_deadline_monitor(
health_monitor_builder_handle: FFIHandle,
monitor_tag: *const MonitorTag,
Expand Down Expand Up @@ -171,7 +171,7 @@ pub extern "C" fn health_monitor_builder_add_deadline_monitor(
FFICode::Success
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn health_monitor_get_deadline_monitor(
health_monitor_handle: FFIHandle,
monitor_tag: *const MonitorTag,
Expand Down Expand Up @@ -202,7 +202,7 @@ pub extern "C" fn health_monitor_get_deadline_monitor(
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn health_monitor_start(health_monitor_handle: FFIHandle) -> FFICode {
if health_monitor_handle.is_null() {
return FFICode::NullParameter;
Expand All @@ -221,7 +221,7 @@ pub extern "C" fn health_monitor_start(health_monitor_handle: FFIHandle) -> FFIC
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn health_monitor_destroy(health_monitor_handle: FFIHandle) -> FFICode {
if health_monitor_handle.is_null() {
return FFICode::NullParameter;
Expand Down
42 changes: 42 additions & 0 deletions src/health_monitoring_lib/rust/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ struct Tag {
length: usize,
}

impl Tag {
const fn new(value: &str) -> Self {
Self {
data: value.as_ptr(),
length: value.len(),
}
}
}

unsafe impl Send for Tag {}
unsafe impl Sync for Tag {}

Expand Down Expand Up @@ -86,6 +95,12 @@ impl From<&str> for Tag {
#[repr(C)]
pub struct MonitorTag(Tag);

impl MonitorTag {
pub const fn new(value: &str) -> Self {
MonitorTag(Tag::new(value))
}
}

impl fmt::Debug for MonitorTag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// SAFETY: the underlying data was created from a valid `&str`.
Expand Down Expand Up @@ -121,6 +136,12 @@ impl From<&str> for MonitorTag {
#[repr(C)]
pub struct DeadlineTag(Tag);

impl DeadlineTag {
pub const fn new(value: &str) -> Self {
DeadlineTag(Tag::new(value))
}
}

impl fmt::Debug for DeadlineTag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// SAFETY: the underlying data was created from a valid `&str`.
Expand Down Expand Up @@ -230,6 +251,13 @@ mod tests {
assert_eq!(tag_as_str, expected);
}

#[test]
fn tag_new() {
const EXAMPLE_STR: &str = "EXAMPLE";
const TAG: Tag = Tag::new(EXAMPLE_STR);
compare_tag(TAG, EXAMPLE_STR);
}

#[test]
fn tag_debug() {
let example_str = "EXAMPLE";
Expand Down Expand Up @@ -312,6 +340,13 @@ mod tests {
compare_tag(tag, example_str);
}

#[test]
fn monitor_tag_new() {
const EXAMPLE_STR: &str = "EXAMPLE";
const TAG: MonitorTag = MonitorTag::new(EXAMPLE_STR);
compare_tag(TAG.0, EXAMPLE_STR);
}

#[test]
fn monitor_tag_debug() {
let example_str = "EXAMPLE";
Expand Down Expand Up @@ -342,6 +377,13 @@ mod tests {
compare_tag(tag.0, example_str);
}

#[test]
fn deadline_tag_new() {
const EXAMPLE_STR: &str = "EXAMPLE";
const TAG: DeadlineTag = DeadlineTag::new(EXAMPLE_STR);
compare_tag(TAG.0, EXAMPLE_STR);
}

#[test]
fn deadline_tag_debug() {
let example_str = "EXAMPLE";
Expand Down
Loading