summaryrefslogtreecommitdiffstats
path: root/libimagstorestdhook
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-03-24 12:09:45 +0100
committerMatthias Beyer <mail@beyermatthias.de>2016-03-26 18:20:12 +0100
commit7f1a671e4da102c9b6a28945f60deb389b1ba10f (patch)
tree7bc512336c9421d093d89f594d70cd89faa4047b /libimagstorestdhook
parent6e74145739d167ac381616f00c2b06b1ff3c9849 (diff)
Add debug hook
Diffstat (limited to 'libimagstorestdhook')
-rw-r--r--libimagstorestdhook/src/debug.rs113
-rw-r--r--libimagstorestdhook/src/lib.rs2
2 files changed, 115 insertions, 0 deletions
diff --git a/libimagstorestdhook/src/debug.rs b/libimagstorestdhook/src/debug.rs
new file mode 100644
index 00000000..2a68529e
--- /dev/null
+++ b/libimagstorestdhook/src/debug.rs
@@ -0,0 +1,113 @@
+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, _: &Value) {
+ () // We are not configurable here.
+ }
+
+}
+
+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 {
+ HP::PreCreate => HDA::StoreIdAccess(&self.accessor),
+ HP::PostCreate => HDA::MutableAccess(&self.accessor),
+ HP::PreRetrieve => HDA::StoreIdAccess(&self.accessor),
+ HP::PostRetrieve => HDA::MutableAccess(&self.accessor),
+ HP::PreUpdate => HDA::MutableAccess(&self.accessor),
+ HP::PostUpdate => HDA::MutableAccess(&self.accessor),
+ HP::PreDelete => HDA::StoreIdAccess(&self.accessor),
+ HP::PostDelete => HDA::StoreIdAccess(&self.accessor),
+ }
+ }
+
+}
+
+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(())
+ }
+
+ }
+
+}
+
diff --git a/libimagstorestdhook/src/lib.rs b/libimagstorestdhook/src/lib.rs
index 880c1231..e9394024 100644
--- a/libimagstorestdhook/src/lib.rs
+++ b/libimagstorestdhook/src/lib.rs
@@ -3,3 +3,5 @@ extern crate toml;
extern crate libimagstore;
+pub mod debug;
+