1
0
Fork 0
forked from wry/wry
wry/src/ifs/jay_log_file.rs
2024-02-06 12:05:03 +01:00

61 lines
1.3 KiB
Rust

use {
crate::{
client::{Client, ClientError},
leaks::Tracker,
object::Object,
utils::buffd::{MsgParser, MsgParserError},
wire::{jay_log_file::*, JayLogFileId},
},
bstr::BStr,
std::rc::Rc,
thiserror::Error,
};
pub struct JayLogFile {
pub id: JayLogFileId,
pub client: Rc<Client>,
pub tracker: Tracker<Self>,
}
impl JayLogFile {
pub fn new(id: JayLogFileId, client: &Rc<Client>) -> Self {
Self {
id,
client: client.clone(),
tracker: Default::default(),
}
}
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), JayLogFileError> {
let _req: Destroy = self.client.parse(self, parser)?;
self.client.remove_obj(self)?;
Ok(())
}
pub fn send_path(&self, path: &BStr) {
self.client.event(Path {
self_id: self.id,
path,
});
}
}
object_base! {
self = JayLogFile;
DESTROY => destroy,
}
impl Object for JayLogFile {}
simple_add_obj!(JayLogFile);
#[derive(Debug, Error)]
pub enum JayLogFileError {
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(JayLogFileError, ClientError);
efrom!(JayLogFileError, MsgParserError);