From 7f4f260d732c849c1e88fcb91023faab5316d9c6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 13 Sep 2009 19:04:14 +0200 Subject: StorageManager can delete stored data now --- src/Common/StorageBackend.h | 6 ++++++ src/Common/StorageManager.cpp | 16 ++++++++++++++++ src/Common/StorageManager.h | 4 ++++ .../StorageBackendFile/StorageBackendFile.cpp | 22 ++++++++++++++++++++++ .../StorageBackendFile/StorageBackendFile.h | 4 ++++ 5 files changed, 52 insertions(+) diff --git a/src/Common/StorageBackend.h b/src/Common/StorageBackend.h index 1d53570..abec185 100644 --- a/src/Common/StorageBackend.h +++ b/src/Common/StorageBackend.h @@ -38,9 +38,15 @@ class StorageBackend { virtual std::set listTypes() throw (Core::Exception) = 0; virtual std::set list(const std::string &type) throw (Core::Exception) = 0; + virtual bool exists(const std::string &type, const std::string &name) throw (Core::Exception) { + return (list(type).count(name) > 0); + } + virtual void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception) = 0; virtual boost::shared_ptr load(const std::string &type, const std::string &name) throw (Core::Exception) = 0; + virtual void remove(const std::string &type, const std::string &name) throw (Core::Exception) = 0; + public: virtual ~StorageBackend() {} }; diff --git a/src/Common/StorageManager.cpp b/src/Common/StorageManager.cpp index ac83476..3b14554 100644 --- a/src/Common/StorageManager.cpp +++ b/src/Common/StorageManager.cpp @@ -52,6 +52,14 @@ std::set StorageManager::list(const std::string &type) throw (Core: return backend->list(type); } +bool StorageManager::exists(const std::string &type, const std::string &name) throw (Core::Exception) { + boost::shared_lock lock(mutex); + if(!backend) + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); + + return backend->exists(type, name); +} + void StorageManager::store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception) { boost::shared_lock lock(mutex); if(!backend) @@ -68,5 +76,13 @@ boost::shared_ptr StorageManager::load(const std::string &type, const s return backend->load(type, name); } +void StorageManager::remove(const std::string &type, const std::string &name) throw (Core::Exception) { + boost::shared_lock lock(mutex); + if(!backend) + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); + + backend->remove(type, name); +} + } } diff --git a/src/Common/StorageManager.h b/src/Common/StorageManager.h index 98533fb..594c294 100644 --- a/src/Common/StorageManager.h +++ b/src/Common/StorageManager.h @@ -54,8 +54,12 @@ class MAD_COMMON_EXPORT StorageManager { std::set listTypes() throw (Core::Exception); std::set list(const std::string &type) throw (Core::Exception); + bool exists(const std::string &type, const std::string &name) throw (Core::Exception); + void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception); boost::shared_ptr load(const std::string &type, const std::string &name) throw (Core::Exception); + + void remove(const std::string &type, const std::string &name) throw (Core::Exception); }; } diff --git a/src/modules/StorageBackendFile/StorageBackendFile.cpp b/src/modules/StorageBackendFile/StorageBackendFile.cpp index 7c952bd..c8bc4f7 100644 --- a/src/modules/StorageBackendFile/StorageBackendFile.cpp +++ b/src/modules/StorageBackendFile/StorageBackendFile.cpp @@ -116,6 +116,18 @@ std::set StorageBackendFile::list(const std::string &type) throw (C return ret; } + +bool StorageBackendFile::exists(const std::string &type, const std::string &name) throw (Core::Exception) { + boost::shared_lock lock(mutex); + + if(!configured) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + boost::filesystem::path path = getFileName(type, name); + + return boost::filesystem::is_regular_file(path); +} + void StorageBackendFile::store(const std::string &type, const std::string &name, const Common::XmlData *data) throw (Core::Exception) { boost::lock_guard lock(mutex); @@ -138,6 +150,16 @@ boost::shared_ptr StorageBackendFile::load(const std::string &t return boost::shared_ptr(new Common::XmlData(path.file_string())); } +void StorageBackendFile::remove(const std::string &type, const std::string &name) throw (Core::Exception) { + boost::lock_guard lock(mutex); + + if(!configured) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + boost::filesystem::path path = getFileName(type, name); + boost::filesystem::remove(path); +} + } } } diff --git a/src/modules/StorageBackendFile/StorageBackendFile.h b/src/modules/StorageBackendFile/StorageBackendFile.h index 45f4f98..5cce4fc 100644 --- a/src/modules/StorageBackendFile/StorageBackendFile.h +++ b/src/modules/StorageBackendFile/StorageBackendFile.h @@ -51,9 +51,13 @@ class StorageBackendFile : public Common::StorageBackend, private Core::Configur virtual std::set listTypes() throw (Core::Exception); virtual std::set list(const std::string &type) throw (Core::Exception); + virtual bool exists(const std::string &type, const std::string &name) throw (Core::Exception); + virtual void store(const std::string &type, const std::string &name, const Common::XmlData *data) throw (Core::Exception); virtual boost::shared_ptr load(const std::string &type, const std::string &name) throw (Core::Exception); + virtual void remove(const std::string &type, const std::string &name) throw (Core::Exception); + public: StorageBackendFile(Common::Application *application0) : application(application0), configured(false) { application->getConfigManager()->registerConfigurable(this); -- cgit v1.2.3