summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-09-11 02:15:13 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-09-11 02:15:13 +0200
commit36a3a590ffa4133f7f2d980a57d48ef95c680b71 (patch)
tree47a5f37f571db0918fe3f48bb14c819d01e13777
parentf540560feb093143569f8a85eb5280d9c7504a0e (diff)
downloadmad-36a3a590ffa4133f7f2d980a57d48ef95c680b71.tar
mad-36a3a590ffa4133f7f2d980a57d48ef95c680b71.zip
Extended StorageManager
-rw-r--r--src/Common/StorageBackend.h4
-rw-r--r--src/Common/StorageManager.cpp16
-rw-r--r--src/Common/StorageManager.h3
-rw-r--r--src/Common/XmlData.h19
-rw-r--r--src/modules/StorageBackendFile/StorageBackendFile.cpp39
-rw-r--r--src/modules/StorageBackendFile/StorageBackendFile.h3
6 files changed, 84 insertions, 0 deletions
diff --git a/src/Common/StorageBackend.h b/src/Common/StorageBackend.h
index 027109e..1d53570 100644
--- a/src/Common/StorageBackend.h
+++ b/src/Common/StorageBackend.h
@@ -24,6 +24,7 @@
#include <Core/Exception.h>
#include <boost/shared_ptr.hpp>
+#include <set>
namespace Mad {
namespace Common {
@@ -34,6 +35,9 @@ class StorageBackend {
protected:
friend class StorageManager;
+ virtual std::set<std::string> listTypes() throw (Core::Exception) = 0;
+ virtual std::set<std::string> list(const std::string &type) throw (Core::Exception) = 0;
+
virtual void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception) = 0;
virtual boost::shared_ptr<XmlData> load(const std::string &type, const std::string &name) throw (Core::Exception) = 0;
diff --git a/src/Common/StorageManager.cpp b/src/Common/StorageManager.cpp
index a1610fe..ac83476 100644
--- a/src/Common/StorageManager.cpp
+++ b/src/Common/StorageManager.cpp
@@ -36,6 +36,22 @@ void StorageManager::unsetBackend(boost::shared_ptr<StorageBackend> oldBackend)
backend.reset();
}
+std::set<std::string> StorageManager::listTypes() throw (Core::Exception) {
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+ if(!backend)
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+
+ return backend->listTypes();
+}
+
+std::set<std::string> StorageManager::list(const std::string &type) throw (Core::Exception) {
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+ if(!backend)
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+
+ return backend->list(type);
+}
+
void StorageManager::store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception) {
boost::shared_lock<boost::shared_mutex> lock(mutex);
if(!backend)
diff --git a/src/Common/StorageManager.h b/src/Common/StorageManager.h
index c81c707..98533fb 100644
--- a/src/Common/StorageManager.h
+++ b/src/Common/StorageManager.h
@@ -51,6 +51,9 @@ class MAD_COMMON_EXPORT StorageManager {
void setBackend(boost::shared_ptr<StorageBackend> newBackend);
void unsetBackend(boost::shared_ptr<StorageBackend> oldBackend);
+ std::set<std::string> listTypes() throw (Core::Exception);
+ std::set<std::string> list(const std::string &type) throw (Core::Exception);
+
void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception);
boost::shared_ptr<XmlData> load(const std::string &type, const std::string &name) throw (Core::Exception);
};
diff --git a/src/Common/XmlData.h b/src/Common/XmlData.h
index 51e5327..b7e8ec1 100644
--- a/src/Common/XmlData.h
+++ b/src/Common/XmlData.h
@@ -26,6 +26,7 @@
#include <Core/Exception.h>
#include <map>
+#include <set>
#include <string>
#include <sstream>
#include <vector>
@@ -283,6 +284,24 @@ class MAD_COMMON_EXPORT XmlData {
return;
}
+
+ std::set<std::string> getChildren() const {
+ std::set<std::string> childNames;
+
+ for(std::map<std::string, Element*>::const_iterator it = elements.begin(); it != elements.end(); ++it)
+ childNames.insert(it->first);
+
+ return childNames;
+ }
+
+ std::set<std::string> getLists() const {
+ std::set<std::string> listNames;
+
+ for(std::map<std::string, List*>::const_iterator it = lists.begin(); it != lists.end(); ++it)
+ listNames.insert(it->first);
+
+ return listNames;
+ }
};
class MAD_COMMON_EXPORT List : private boost::noncopyable {
diff --git a/src/modules/StorageBackendFile/StorageBackendFile.cpp b/src/modules/StorageBackendFile/StorageBackendFile.cpp
index 7f4b6b5..54d74ad 100644
--- a/src/modules/StorageBackendFile/StorageBackendFile.cpp
+++ b/src/modules/StorageBackendFile/StorageBackendFile.cpp
@@ -71,6 +71,45 @@ boost::filesystem::path StorageBackendFile::getFileName(const std::string &type,
return path;
}
+std::set<std::string> StorageBackendFile::listTypes() throw (Core::Exception) {
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+
+ if(!configured)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ std::set<std::string> ret;
+
+ for(boost::filesystem::directory_iterator it(storageRoot); it != boost::filesystem::directory_iterator(); ++it) {
+ boost::filesystem::path path = *it;
+
+ if(boost::filesystem::is_directory(path))
+ ret.insert(path.filename());
+ }
+
+ return ret;
+}
+
+std::set<std::string> StorageBackendFile::list(const std::string &type) throw (Core::Exception) {
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+
+ if(!configured)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ std::set<std::string> ret;
+
+ boost::filesystem::path path(storageRoot);
+ path /= type;
+
+ for(boost::filesystem::directory_iterator it(path); it != boost::filesystem::directory_iterator(); ++it) {
+ boost::filesystem::path filePath = *it;
+
+ if(boost::filesystem::is_regular_file(filePath) && filePath.extension() == ".xml")
+ ret.insert(filePath.replace_extension().filename());
+ }
+
+ return ret;
+}
+
void StorageBackendFile::store(const std::string &type, const std::string &name, const Common::XmlData *data) throw (Core::Exception) {
boost::lock_guard<boost::shared_mutex> lock(mutex);
diff --git a/src/modules/StorageBackendFile/StorageBackendFile.h b/src/modules/StorageBackendFile/StorageBackendFile.h
index 7246b2e..45f4f98 100644
--- a/src/modules/StorageBackendFile/StorageBackendFile.h
+++ b/src/modules/StorageBackendFile/StorageBackendFile.h
@@ -48,6 +48,9 @@ class StorageBackendFile : public Common::StorageBackend, private Core::Configur
virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled);
virtual void configFinished();
+ virtual std::set<std::string> listTypes() throw (Core::Exception);
+ virtual std::set<std::string> list(const std::string &type) 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<Common::XmlData> load(const std::string &type, const std::string &name) throw (Core::Exception);