PUS Event Manager #19

Merged
muellerr merged 41 commits from pus-event-manager into main 2022-11-19 12:26:17 +01:00
2 changed files with 41 additions and 44 deletions
Showing only changes of commit 18a3be8439 - Show all commits

View File

@ -22,6 +22,7 @@ pub enum Severity {
pub trait HasSeverity { pub trait HasSeverity {
const SEVERITY: Severity; const SEVERITY: Severity;
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct SeverityInfo {} pub struct SeverityInfo {}
impl HasSeverity for SeverityInfo { impl HasSeverity for SeverityInfo {
@ -229,10 +230,10 @@ macro_rules! const_from_fn {
($from_fn_name: ident, $TypedIdent: ident, $SevIdent: ident) => { ($from_fn_name: ident, $TypedIdent: ident, $SevIdent: ident) => {
pub const fn $from_fn_name(event: $TypedIdent<$SevIdent>) -> Self { pub const fn $from_fn_name(event: $TypedIdent<$SevIdent>) -> Self {
Self { Self {
base: event.event.base base: event.event.base,
} }
} }
} };
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
@ -255,6 +256,17 @@ impl<SEVERITY: HasSeverity> From<EventU32TypedSev<SEVERITY>> for EventU32 {
impl_event_provider!(EventU32, EventU32TypedSev, u32, u16, u16); impl_event_provider!(EventU32, EventU32TypedSev, u32, u16, u16);
impl EventU32 { impl EventU32 {
/// Generate an event. The raw representation of an event has 32 bits.
/// If the passed group ID is invalid (too large), None wil be returned
///
/// # Parameter
///
/// * `severity`: Each event has a [severity][Severity]. The raw value of the severity will
/// be stored inside the uppermost 2 bits of the raw event ID
/// * `group_id`: Related events can be grouped using a group ID. The group ID will occupy the
/// next 14 bits after the severity. Therefore, the size is limited by dec 16383 hex 0x3FFF.
/// * `unique_id`: Each event has a unique 16 bit ID occupying the last 16 bits of the
/// raw event ID
pub fn new( pub fn new(
severity: Severity, severity: Severity,
group_id: <Self as GenericEvent>::GroupId, group_id: <Self as GenericEvent>::GroupId,
@ -297,17 +309,8 @@ impl EventU32 {
} }
impl<SEVERITY: HasSeverity> EventU32TypedSev<SEVERITY> { impl<SEVERITY: HasSeverity> EventU32TypedSev<SEVERITY> {
/// Generate an event. The raw representation of an event has 32 bits. /// This is similar to [EventU32::new] but the severity is a type generic, which allows to
/// If the passed group ID is invalid (too large), None wil be returned /// have distinct types for events with different severities
///
/// # Parameter
///
/// * `severity`: Each event has a [severity][Severity]. The raw value of the severity will
/// be stored inside the uppermost 2 bits of the raw event ID
/// * `group_id`: Related events can be grouped using a group ID. The group ID will occupy the
/// next 14 bits after the severity. Therefore, the size is limited by dec 16383 hex 0x3FFF.
/// * `unique_id`: Each event has a unique 16 bit ID occupying the last 16 bits of the
/// raw event ID
pub fn new( pub fn new(
group_id: <Self as GenericEvent>::GroupId, group_id: <Self as GenericEvent>::GroupId,
unique_id: <Self as GenericEvent>::UniqueId, unique_id: <Self as GenericEvent>::UniqueId,
@ -418,6 +421,7 @@ impl EventU16 {
}) })
} }
/// Const version of [new], but panics on invalid group ID input values.
pub const fn const_new( pub const fn const_new(
severity: Severity, severity: Severity,
group_id: <Self as GenericEvent>::GroupId, group_id: <Self as GenericEvent>::GroupId,
@ -440,18 +444,10 @@ impl EventU16 {
const_from_fn!(const_from_medium, EventU16TypedSev, SeverityMedium); const_from_fn!(const_from_medium, EventU16TypedSev, SeverityMedium);
const_from_fn!(const_from_high, EventU16TypedSev, SeverityHigh); const_from_fn!(const_from_high, EventU16TypedSev, SeverityHigh);
} }
impl<SEVERITY: HasSeverity> EventU16TypedSev<SEVERITY> { impl<SEVERITY: HasSeverity> EventU16TypedSev<SEVERITY> {
/// Generate a small event. The raw representation of a small event has 16 bits. /// This is similar to [EventU16::new] but the severity is a type generic, which allows to
/// If the passed group ID is invalid (too large), [None] wil be returned /// have distinct types for events with different severities
///
/// # Parameter
///
/// * `severity`: Each event has a [severity][Severity]. The raw value of the severity will
/// be stored inside the uppermost 2 bits of the raw event ID
/// * `group_id`: Related events can be grouped using a group ID. The group ID will occupy the
/// next 6 bits after the severity. Therefore, the size is limited by dec 63 hex 0x3F.
/// * `unique_id`: Each event has a unique 8 bit ID occupying the last 8 bits of the
/// raw event ID
pub fn new( pub fn new(
group_id: <Self as GenericEvent>::GroupId, group_id: <Self as GenericEvent>::GroupId,
unique_id: <Self as GenericEvent>::UniqueId, unique_id: <Self as GenericEvent>::UniqueId,
@ -463,6 +459,7 @@ impl<SEVERITY: HasSeverity> EventU16TypedSev<SEVERITY> {
}) })
} }
/// Const version of [new], but panics on invalid group ID input values.
pub const fn const_new( pub const fn const_new(
group_id: <Self as GenericEvent>::GroupId, group_id: <Self as GenericEvent>::GroupId,
unique_id: <Self as GenericEvent>::UniqueId, unique_id: <Self as GenericEvent>::UniqueId,

View File

@ -1,7 +1,10 @@
#![allow(dead_code, unused_imports)] #![allow(dead_code, unused_imports)]
use fsrc_core::events::{
EventU32, EventU32TypedSev, GenericEvent, HasSeverity, LargestEventRaw, LargestGroupIdRaw,
Severity, SeverityInfo, SeverityLow, SeverityMedium,
};
use std::convert::AsRef; use std::convert::AsRef;
use fsrc_core::events::{EventU32, EventU32TypedSev, GenericEvent, HasSeverity, LargestEventRaw, LargestGroupIdRaw, Severity, SeverityInfo, SeverityLow, SeverityMedium};
#[derive(Debug)] #[derive(Debug)]
struct GroupIdIntrospection { struct GroupIdIntrospection {
@ -45,36 +48,33 @@ const TEST_GROUP_NAME_NAME: &str = "TEST_GROUP_NAME";
//#[event(desc="Some medium severity event")] //#[event(desc="Some medium severity event")]
const MEDIUM_SEV_EVENT_IN_OTHER_GROUP: EventU32TypedSev<SeverityMedium> = const MEDIUM_SEV_EVENT_IN_OTHER_GROUP: EventU32TypedSev<SeverityMedium> =
EventU32TypedSev::const_new(TEST_GROUP_NAME, 0); EventU32TypedSev::const_new(TEST_GROUP_NAME, 0);
const MEDIUM_SEV_EVENT_IN_OTHER_GROUP_REDUCED: EventU32 = EventU32::const_from_medium(MEDIUM_SEV_EVENT_IN_OTHER_GROUP); const MEDIUM_SEV_EVENT_IN_OTHER_GROUP_REDUCED: EventU32 =
EventU32::const_from_medium(MEDIUM_SEV_EVENT_IN_OTHER_GROUP);
// Also auto-generated // Also auto-generated
const MEDIUM_SEV_EVENT_IN_OTHER_GROUP_INTROSPECTION: EventIntrospection = const MEDIUM_SEV_EVENT_IN_OTHER_GROUP_INTROSPECTION: EventIntrospection = EventIntrospection {
EventIntrospection { name: "MEDIUM_SEV_EVENT_IN_OTHER_GROUP",
name: "MEDIUM_SEV_EVENT_IN_OTHER_GROUP", group_id: GroupIdIntrospection {
group_id: GroupIdIntrospection { name: TEST_GROUP_NAME_NAME,
name: TEST_GROUP_NAME_NAME, id: TEST_GROUP_NAME,
id: TEST_GROUP_NAME, },
}, event: &MEDIUM_SEV_EVENT_IN_OTHER_GROUP_REDUCED,
event: &MEDIUM_SEV_EVENT_IN_OTHER_GROUP_REDUCED, info: "Some medium severity event",
info: "Some medium severity event", };
};
const CONST_SLICE: &'static [u8] = &[0, 1, 2, 3]; const CONST_SLICE: &'static [u8] = &[0, 1, 2, 3];
const INTROSPECTION_FOR_TEST_GROUP_0: [&EventIntrospection; 2] = [ const INTROSPECTION_FOR_TEST_GROUP_0: [&EventIntrospection; 2] =
&INFO_EVENT_0_INTROSPECTION, [&INFO_EVENT_0_INTROSPECTION, &INFO_EVENT_0_INTROSPECTION];
&INFO_EVENT_0_INTROSPECTION
];
//const INTROSPECTION_FOR_TABLE: &'static [&EventIntrospection] = &INTROSPECTION_FOR_TEST_GROUP_0; //const INTROSPECTION_FOR_TABLE: &'static [&EventIntrospection] = &INTROSPECTION_FOR_TEST_GROUP_0;
const INTROSPECTION_FOR_TEST_GROUP_NAME: [&EventIntrospection; 1] = [ const INTROSPECTION_FOR_TEST_GROUP_NAME: [&EventIntrospection; 1] =
&MEDIUM_SEV_EVENT_IN_OTHER_GROUP_INTROSPECTION [&MEDIUM_SEV_EVENT_IN_OTHER_GROUP_INTROSPECTION];
];
//const BLAH: &'static [&EventIntrospection] = &INTROSPECTION_FOR_TEST_GROUP_NAME; //const BLAH: &'static [&EventIntrospection] = &INTROSPECTION_FOR_TEST_GROUP_NAME;
const ALL_EVENTS: [&[&EventIntrospection]; 2] = [ const ALL_EVENTS: [&[&EventIntrospection]; 2] = [
&INTROSPECTION_FOR_TEST_GROUP_0, &INTROSPECTION_FOR_TEST_GROUP_0,
&INTROSPECTION_FOR_TEST_GROUP_NAME &INTROSPECTION_FOR_TEST_GROUP_NAME,
]; ];
#[test] #[test]