imag/libimagstorestdhook/src/debug.rs

116 lines
2.7 KiB
Rust
Raw Normal View History

2016-03-24 11:09:45 +00:00
use toml::Value;
use libimagstore::hook::Hook;
use libimagstore::hook::accessor::HookDataAccessor;
use libimagstore::hook::accessor::HookDataAccessorProvider;
use libimagstore::hook::position::HookPosition;
use self::accessor::DebugHookAccessor as DHA;
#[derive(Debug)]
pub struct DebugHook {
position: HookPosition,
accessor: DHA,
}
impl DebugHook {
pub fn new(pos: HookPosition) -> DebugHook {
DebugHook {
position: pos.clone(),
accessor: DHA::new(pos),
}
}
}
impl Hook for DebugHook {
fn name(&self) -> &'static str {
"stdhook_debug"
}
fn set_config(&mut self, c: &Value) {
debug!("Trying to set configuration in debug hook: {:?}", c);
debug!("Ignoring configuration in debug hook, we don't need a config here");
2016-03-24 11:09:45 +00:00
}
}
impl HookDataAccessorProvider for DebugHook {
fn accessor(&self) -> HookDataAccessor {
use libimagstore::hook::position::HookPosition as HP;
use libimagstore::hook::accessor::HookDataAccessor as HDA;
match self.position {
2016-05-26 16:40:58 +00:00
HP::StoreUnload |
HP::PreCreate |
HP::PreRetrieve |
HP::PreDelete |
2016-03-24 11:09:45 +00:00
HP::PostDelete => HDA::StoreIdAccess(&self.accessor),
HP::PostCreate |
HP::PostRetrieve |
HP::PreUpdate |
HP::PostUpdate => HDA::MutableAccess(&self.accessor),
2016-03-24 11:09:45 +00:00
}
}
}
pub mod accessor {
use std::ops::Deref;
use libimagstore::storeid::StoreId;
use libimagstore::store::FileLockEntry;
use libimagstore::hook::result::HookResult;
use libimagstore::hook::accessor::MutableHookDataAccessor;
use libimagstore::hook::accessor::NonMutableHookDataAccessor;
use libimagstore::hook::accessor::StoreIdAccessor;
use libimagstore::hook::position::HookPosition;
#[derive(Debug)]
pub struct DebugHookAccessor {
position: HookPosition,
}
impl DebugHookAccessor {
pub fn new(position: HookPosition) -> DebugHookAccessor {
DebugHookAccessor {
position: position,
}
}
}
impl StoreIdAccessor for DebugHookAccessor {
fn access(&self, id: &StoreId) -> HookResult<()> {
debug!("[DEBUG HOOK]: {:?}", id);
Ok(())
}
}
impl MutableHookDataAccessor for DebugHookAccessor {
fn access_mut(&self, fle: &mut FileLockEntry) -> HookResult<()> {
debug!("[DEBUG HOOK] {:?}", fle.deref().deref());
Ok(())
}
}
impl NonMutableHookDataAccessor for DebugHookAccessor {
fn access(&self, fle: &FileLockEntry) -> HookResult<()> {
debug!("[DEBUG HOOK] {:?}", fle.deref().deref());
Ok(())
}
}
}