summaryrefslogtreecommitdiffstats
path: root/src/Common/StorageManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/StorageManager.cpp')
-rw-r--r--src/Common/StorageManager.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/Common/StorageManager.cpp b/src/Common/StorageManager.cpp
new file mode 100644
index 0000000..a1610fe
--- /dev/null
+++ b/src/Common/StorageManager.cpp
@@ -0,0 +1,56 @@
+/*
+ * StorageManager.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "StorageManager.h"
+#include "StorageBackend.h"
+
+#include <boost/thread/locks.hpp>
+
+namespace Mad {
+namespace Common {
+
+void StorageManager::setBackend(boost::shared_ptr<StorageBackend> newBackend) {
+ boost::lock_guard<boost::shared_mutex> lock(mutex);
+ backend = newBackend;
+}
+
+void StorageManager::unsetBackend(boost::shared_ptr<StorageBackend> oldBackend) {
+ boost::lock_guard<boost::shared_mutex> lock(mutex);
+ if(backend == oldBackend)
+ backend.reset();
+}
+
+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)
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+
+ backend->store(type, name, data);
+}
+
+boost::shared_ptr<XmlData> StorageManager::load(const std::string &type, const std::string &name) throw (Core::Exception) {
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+ if(!backend)
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+
+ return backend->load(type, name);
+}
+
+}
+}