Skip to content

Commit 419588e

Browse files
authored
Merge pull request #108 from qorix-group/arkjedrz_global-fixes
hmon: global fixes to HMON
2 parents dbc6a81 + 6c3ed43 commit 419588e

5 files changed

Lines changed: 59 additions & 17 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class RustDroppable
4444
/// Marks object as no longer managed by C++ side, releasing handle to be passed to Rust side for dropping
4545
std::optional<FFIHandle> drop_by_rust()
4646
{
47-
return static_cast<T*>(this)->__drop_by_rust_impl();
47+
return static_cast<T*>(this)->_drop_by_rust_impl();
4848
}
4949
};
5050

src/health_monitoring_lib/cpp/include/score/hm/deadline/deadline_monitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class DeadlineMonitorBuilder final : public internal::RustDroppable<DeadlineMoni
5151
DeadlineMonitorBuilder add_deadline(const DeadlineTag& deadline_tag, const TimeRange& range) &&;
5252

5353
protected:
54-
std::optional<internal::FFIHandle> __drop_by_rust_impl()
54+
std::optional<internal::FFIHandle> _drop_by_rust_impl()
5555
{
5656
return monitor_builder_handler_.drop_by_rust();
5757
}

src/health_monitoring_lib/rust/deadline/ffi.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl DeadlineMonitorCpp {
4040
}
4141
}
4242

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

57-
#[no_mangle]
57+
#[unsafe(no_mangle)]
5858
pub extern "C" fn deadline_monitor_builder_destroy(deadline_monitor_builder_handle: FFIHandle) -> FFICode {
5959
if deadline_monitor_builder_handle.is_null() {
6060
return FFICode::NullParameter;
@@ -70,7 +70,7 @@ pub extern "C" fn deadline_monitor_builder_destroy(deadline_monitor_builder_hand
7070
FFICode::Success
7171
}
7272

73-
#[no_mangle]
73+
#[unsafe(no_mangle)]
7474
pub extern "C" fn deadline_monitor_builder_add_deadline(
7575
deadline_monitor_builder_handle: FFIHandle,
7676
deadline_tag: *const DeadlineTag,
@@ -108,7 +108,7 @@ pub extern "C" fn deadline_monitor_builder_add_deadline(
108108
FFICode::Success
109109
}
110110

111-
#[no_mangle]
111+
#[unsafe(no_mangle)]
112112
pub extern "C" fn deadline_monitor_get_deadline(
113113
deadline_monitor_handle: FFIHandle,
114114
deadline_tag: *const DeadlineTag,
@@ -141,7 +141,7 @@ pub extern "C" fn deadline_monitor_get_deadline(
141141
}
142142
}
143143

144-
#[no_mangle]
144+
#[unsafe(no_mangle)]
145145
pub extern "C" fn deadline_monitor_destroy(deadline_monitor_handle: FFIHandle) -> FFICode {
146146
if deadline_monitor_handle.is_null() {
147147
return FFICode::NullParameter;
@@ -157,7 +157,7 @@ pub extern "C" fn deadline_monitor_destroy(deadline_monitor_handle: FFIHandle) -
157157
FFICode::Success
158158
}
159159

160-
#[no_mangle]
160+
#[unsafe(no_mangle)]
161161
pub extern "C" fn deadline_start(deadline_handle: FFIHandle) -> FFICode {
162162
if deadline_handle.is_null() {
163163
return FFICode::NullParameter;
@@ -176,7 +176,7 @@ pub extern "C" fn deadline_start(deadline_handle: FFIHandle) -> FFICode {
176176
}
177177
}
178178

179-
#[no_mangle]
179+
#[unsafe(no_mangle)]
180180
pub extern "C" fn deadline_stop(deadline_handle: FFIHandle) -> FFICode {
181181
if deadline_handle.is_null() {
182182
return FFICode::NullParameter;
@@ -193,7 +193,7 @@ pub extern "C" fn deadline_stop(deadline_handle: FFIHandle) -> FFICode {
193193
FFICode::Success
194194
}
195195

196-
#[no_mangle]
196+
#[unsafe(no_mangle)]
197197
pub extern "C" fn deadline_destroy(deadline_handle: FFIHandle) -> FFICode {
198198
if deadline_handle.is_null() {
199199
return FFICode::NullParameter;

src/health_monitoring_lib/rust/ffi.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<T: DerefMut> DerefMut for FFIBorrowed<T> {
7373
}
7474
}
7575

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

90-
#[no_mangle]
90+
#[unsafe(no_mangle)]
9191
pub extern "C" fn health_monitor_builder_destroy(health_monitor_builder_handle: FFIHandle) -> FFICode {
9292
if health_monitor_builder_handle.is_null() {
9393
return FFICode::NullParameter;
@@ -104,7 +104,7 @@ pub extern "C" fn health_monitor_builder_destroy(health_monitor_builder_handle:
104104
FFICode::Success
105105
}
106106

107-
#[no_mangle]
107+
#[unsafe(no_mangle)]
108108
pub extern "C" fn health_monitor_builder_build(
109109
health_monitor_builder_handle: FFIHandle,
110110
supervisor_cycle_ms: u32,
@@ -137,7 +137,7 @@ pub extern "C" fn health_monitor_builder_build(
137137
}
138138
}
139139

140-
#[no_mangle]
140+
#[unsafe(no_mangle)]
141141
pub extern "C" fn health_monitor_builder_add_deadline_monitor(
142142
health_monitor_builder_handle: FFIHandle,
143143
monitor_tag: *const MonitorTag,
@@ -171,7 +171,7 @@ pub extern "C" fn health_monitor_builder_add_deadline_monitor(
171171
FFICode::Success
172172
}
173173

174-
#[no_mangle]
174+
#[unsafe(no_mangle)]
175175
pub extern "C" fn health_monitor_get_deadline_monitor(
176176
health_monitor_handle: FFIHandle,
177177
monitor_tag: *const MonitorTag,
@@ -202,7 +202,7 @@ pub extern "C" fn health_monitor_get_deadline_monitor(
202202
}
203203
}
204204

205-
#[no_mangle]
205+
#[unsafe(no_mangle)]
206206
pub extern "C" fn health_monitor_start(health_monitor_handle: FFIHandle) -> FFICode {
207207
if health_monitor_handle.is_null() {
208208
return FFICode::NullParameter;
@@ -221,7 +221,7 @@ pub extern "C" fn health_monitor_start(health_monitor_handle: FFIHandle) -> FFIC
221221
}
222222
}
223223

224-
#[no_mangle]
224+
#[unsafe(no_mangle)]
225225
pub extern "C" fn health_monitor_destroy(health_monitor_handle: FFIHandle) -> FFICode {
226226
if health_monitor_handle.is_null() {
227227
return FFICode::NullParameter;

src/health_monitoring_lib/rust/tag.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ struct Tag {
2323
length: usize,
2424
}
2525

26+
impl Tag {
27+
const fn new(value: &str) -> Self {
28+
Self {
29+
data: value.as_ptr(),
30+
length: value.len(),
31+
}
32+
}
33+
}
34+
2635
unsafe impl Send for Tag {}
2736
unsafe impl Sync for Tag {}
2837

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

98+
impl MonitorTag {
99+
pub const fn new(value: &str) -> Self {
100+
MonitorTag(Tag::new(value))
101+
}
102+
}
103+
89104
impl fmt::Debug for MonitorTag {
90105
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91106
// SAFETY: the underlying data was created from a valid `&str`.
@@ -121,6 +136,12 @@ impl From<&str> for MonitorTag {
121136
#[repr(C)]
122137
pub struct DeadlineTag(Tag);
123138

139+
impl DeadlineTag {
140+
pub const fn new(value: &str) -> Self {
141+
DeadlineTag(Tag::new(value))
142+
}
143+
}
144+
124145
impl fmt::Debug for DeadlineTag {
125146
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
126147
// SAFETY: the underlying data was created from a valid `&str`.
@@ -230,6 +251,13 @@ mod tests {
230251
assert_eq!(tag_as_str, expected);
231252
}
232253

254+
#[test]
255+
fn tag_new() {
256+
const EXAMPLE_STR: &str = "EXAMPLE";
257+
const TAG: Tag = Tag::new(EXAMPLE_STR);
258+
compare_tag(TAG, EXAMPLE_STR);
259+
}
260+
233261
#[test]
234262
fn tag_debug() {
235263
let example_str = "EXAMPLE";
@@ -312,6 +340,13 @@ mod tests {
312340
compare_tag(tag, example_str);
313341
}
314342

343+
#[test]
344+
fn monitor_tag_new() {
345+
const EXAMPLE_STR: &str = "EXAMPLE";
346+
const TAG: MonitorTag = MonitorTag::new(EXAMPLE_STR);
347+
compare_tag(TAG.0, EXAMPLE_STR);
348+
}
349+
315350
#[test]
316351
fn monitor_tag_debug() {
317352
let example_str = "EXAMPLE";
@@ -342,6 +377,13 @@ mod tests {
342377
compare_tag(tag.0, example_str);
343378
}
344379

380+
#[test]
381+
fn deadline_tag_new() {
382+
const EXAMPLE_STR: &str = "EXAMPLE";
383+
const TAG: DeadlineTag = DeadlineTag::new(EXAMPLE_STR);
384+
compare_tag(TAG.0, EXAMPLE_STR);
385+
}
386+
345387
#[test]
346388
fn deadline_tag_debug() {
347389
let example_str = "EXAMPLE";

0 commit comments

Comments
 (0)