From fe363d29627851f87f8a5be99ffef4848e97baa6 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 23 Oct 2022 22:32:30 +0200 Subject: [PATCH] some experimental eventcode --- fsrc-core/src/events.rs | 3 +- fsrc-core/tests/pus_events.rs | 62 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/fsrc-core/src/events.rs b/fsrc-core/src/events.rs index fc9c66f..2934d1f 100644 --- a/fsrc-core/src/events.rs +++ b/fsrc-core/src/events.rs @@ -200,8 +200,7 @@ impl Event { }) } - /// Const version of [new], but panics on invalid input which is invalid group ID - /// values + /// Const version of [new], but panics on invalid group ID input values. pub const fn const_new( severity: Severity, group_id: ::GroupId, diff --git a/fsrc-core/tests/pus_events.rs b/fsrc-core/tests/pus_events.rs index 8b13789..2f554c1 100644 --- a/fsrc-core/tests/pus_events.rs +++ b/fsrc-core/tests/pus_events.rs @@ -1 +1,63 @@ +#![allow(dead_code, unused_imports)] +use fsrc_core::events::{Event, EventProvider, LargestEventRaw, LargestGroupIdRaw, Severity}; +struct GroupIdIntrospection { + name: &'static str, + id: LargestGroupIdRaw, +} + +struct EventIntrospection { + name: &'static str, + group_id: GroupIdIntrospection, + event: &'static Event, + info: &'static str, +} + +//#[event(descr="This is some info event")] +const INFO_EVENT_0: Event = Event::const_new(Severity::INFO, 0, 0); + +// This is ideally auto-generated +const INFO_EVENT_0_INTROSPECTION: EventIntrospection = EventIntrospection { + name: "INFO_EVENT_0", + group_id: GroupIdIntrospection { + id: 0, + name: "Group ID 0 without name", + }, + event: &INFO_EVENT_0, + info: "This is some info event", +}; + +//#[event(descr="This is some low severity event")] +const SOME_LOW_SEV_EVENT: Event = Event::const_new(Severity::LOW, 0, 12); + +const EVENT_LIST: [&'static Event; 2] = [&INFO_EVENT_0, &SOME_LOW_SEV_EVENT]; + +//#[event_group] +const TEST_GROUP_NAME: u16 = 1; +// Auto-generated? +const TEST_GROUP_NAME_NAME: &'static str = "TEST_GROUP_NAME"; + +//#[event(desc="Some medium severity event")] +const MEDIUM_SEV_EVENT_IN_OTHER_GROUP: Event = + Event::const_new(Severity::MEDIUM, TEST_GROUP_NAME, 0); + +// Also auto-generated +const MEDIUM_SEV_EVENT_IN_OTHER_GROUP_INTROSPECTION: EventIntrospection = EventIntrospection { + name: "MEDIUM_SEV_EVENT_IN_OTHER_GROUP", + group_id: GroupIdIntrospection { + name: TEST_GROUP_NAME_NAME, + id: TEST_GROUP_NAME, + }, + event: &MEDIUM_SEV_EVENT_IN_OTHER_GROUP, + info: "Some medium severity event", +}; + +#[test] +fn main() { + let test = stringify!(INFO_EVENT); + println!("{:?}", test); + for event in EVENT_LIST { + println!("{:?}", event); + } + //let test_struct = +}