falco_plugin/plugin/listen/
mod.rs1pub mod routine;
2#[doc(hidden)]
3pub mod wrappers;
4
5use crate::base::Plugin;
6use crate::listen::ThreadPool;
7use crate::plugin::error::last_error::LastError;
8use crate::plugin::listen::wrappers::CaptureListenPluginExported;
9use crate::plugin::tables::vtable::writer::LazyTableWriter;
10use crate::tables::LazyTableReader;
11use falco_plugin_api::ss_plugin_capture_listen_input;
12
13pub trait CaptureListenPlugin: Plugin + CaptureListenPluginExported {
15 fn capture_open(&mut self, listen_input: &CaptureListenInput) -> Result<(), anyhow::Error>;
19
20 fn capture_close(&mut self, listen_input: &CaptureListenInput) -> Result<(), anyhow::Error>;
24}
25
26#[derive(Debug)]
32pub struct CaptureListenInput<'t> {
33 pub thread_pool: ThreadPool,
35 pub reader: LazyTableReader<'t>,
37 pub writer: LazyTableWriter<'t>,
39}
40
41impl CaptureListenInput<'_> {
42 pub(in crate::plugin::listen) unsafe fn try_from(
43 value: *const ss_plugin_capture_listen_input,
44 last_error: LastError,
45 ) -> Result<Self, anyhow::Error> {
46 let input = unsafe {
47 value
48 .as_ref()
49 .ok_or_else(|| anyhow::anyhow!("Got null event parse input"))?
50 };
51
52 let thread_pool = ThreadPool::try_from(input.owner, input.routine, last_error.clone())?;
53
54 let reader = unsafe {
55 input
56 .table_reader_ext
57 .as_ref()
58 .ok_or_else(|| anyhow::anyhow!("Got null reader vtable"))?
59 };
60 let writer = unsafe {
61 input
62 .table_writer_ext
63 .as_ref()
64 .ok_or_else(|| anyhow::anyhow!("Got null writer vtable"))?
65 };
66
67 let reader = LazyTableReader::new(reader, last_error.clone());
68 let writer = LazyTableWriter::try_from(writer, last_error)?;
69
70 Ok(Self {
71 thread_pool,
72 reader,
73 writer,
74 })
75 }
76}