components/appid/
assigner_name.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2024.
4
5//! Components for AppID assigners based on names.
6
7use core::mem::MaybeUninit;
8use kernel::component::Component;
9
10#[macro_export]
11macro_rules! appid_assigner_names_component_static {
12    () => {{
13        kernel::static_buf!(
14            capsules_system::process_checker::basic::AppIdAssignerNames<fn(&'static str) -> u32>
15        )
16    };};
17}
18
19pub struct AppIdAssignerNamesComponent {}
20
21impl AppIdAssignerNamesComponent {
22    pub fn new() -> Self {
23        Self {}
24    }
25}
26
27impl Component for AppIdAssignerNamesComponent {
28    type StaticInput = &'static mut MaybeUninit<
29        capsules_system::process_checker::basic::AppIdAssignerNames<
30            'static,
31            fn(&'static str) -> u32,
32        >,
33    >;
34
35    type Output = &'static capsules_system::process_checker::basic::AppIdAssignerNames<
36        'static,
37        fn(&'static str) -> u32,
38    >;
39
40    fn finalize(self, s: Self::StaticInput) -> Self::Output {
41        s.write(
42            capsules_system::process_checker::basic::AppIdAssignerNames::new(
43                &((|s| kernel::utilities::helpers::crc32_posix(s.as_bytes()))
44                    as fn(&'static str) -> u32),
45            ),
46        )
47    }
48}