1use std::thread::JoinHandle;
2
3use crossbeam_channel::{SendError, Sender};
4
5use crate::components::{
6 command::{SiemCommandCall, SiemCommandHeader},
7 common::SiemMessage,
8 SiemComponent,
9};
10pub mod parsers;
11
12pub fn do_before_stoping_component<F>(
15 component: &Box<dyn SiemComponent>,
16 action: F,
17) -> JoinHandle<Result<(), SendError<SiemMessage>>>
18where
19 F: FnOnce() + Send + 'static,
20{
21 let sender: Sender<SiemMessage> = component.local_channel();
22 let comp_name = component.name().to_string();
23 std::thread::spawn(move || {
24 action();
25 sender.send(SiemMessage::Command(
26 SiemCommandHeader {
27 comp_id: 0,
28 comm_id: 0,
29 user: String::from("kernel"),
30 },
31 SiemCommandCall::STOP_COMPONENT(comp_name),
32 ))
33 })
34}