summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/Makefile.am4
-rw-r--r--src/Core/Makefile.in8
-rw-r--r--src/Core/RequestHandlers/UserInfoRequestHandler.cpp4
-rw-r--r--src/Core/RequestHandlers/UserListRequestHandler.cpp4
-rw-r--r--src/Core/UserBackend.h39
-rw-r--r--src/Core/UserManager.cpp (renamed from src/Core/UserBackend.cpp)36
-rw-r--r--src/Core/UserManager.h73
7 files changed, 121 insertions, 47 deletions
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index adc4d29..a5e780b 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -2,7 +2,7 @@ SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcore.la
-libcore_la_SOURCES = ConnectionManager.cpp UserBackend.cpp
+libcore_la_SOURCES = ConnectionManager.cpp UserManager.cpp
libcore_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la
-noinst_HEADERS = ConnectionManager.h UserBackend.h
+noinst_HEADERS = ConnectionManager.h UserBackend.h UserManager.h
diff --git a/src/Core/Makefile.in b/src/Core/Makefile.in
index 4e3ef5a..c65470c 100644
--- a/src/Core/Makefile.in
+++ b/src/Core/Makefile.in
@@ -53,7 +53,7 @@ CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libcore_la_DEPENDENCIES = Requests/librequests.la \
RequestHandlers/librequesthandlers.la
-am_libcore_la_OBJECTS = ConnectionManager.lo UserBackend.lo
+am_libcore_la_OBJECTS = ConnectionManager.lo UserManager.lo
libcore_la_OBJECTS = $(am_libcore_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -238,9 +238,9 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcore.la
-libcore_la_SOURCES = ConnectionManager.cpp UserBackend.cpp
+libcore_la_SOURCES = ConnectionManager.cpp UserManager.cpp
libcore_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la
-noinst_HEADERS = ConnectionManager.h UserBackend.h
+noinst_HEADERS = ConnectionManager.h UserBackend.h UserManager.h
all: all-recursive
.SUFFIXES:
@@ -293,7 +293,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConnectionManager.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserBackend.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserManager.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/Core/RequestHandlers/UserInfoRequestHandler.cpp b/src/Core/RequestHandlers/UserInfoRequestHandler.cpp
index d3a8aca..68356f8 100644
--- a/src/Core/RequestHandlers/UserInfoRequestHandler.cpp
+++ b/src/Core/RequestHandlers/UserInfoRequestHandler.cpp
@@ -18,7 +18,7 @@
*/
#include "UserInfoRequestHandler.h"
-#include "../UserBackend.h"
+#include "../UserManager.h"
#include <Common/Exception.h>
#include <Common/Logger.h>
@@ -42,7 +42,7 @@ void UserInfoRequestHandler::handlePacket(const Common::XmlPacket &packet) {
// TODO Require authentication
- if(!UserBackend::getUserInfo(packet["uid"], sigc::mem_fun(this, &UserInfoRequestHandler::userInfoHandler))) {
+ if(!UserManager::get()->getUserInfo(packet["uid"], sigc::mem_fun(this, &UserInfoRequestHandler::userInfoHandler))) {
Common::XmlPacket ret;
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::NOT_IMPLEMENTED);
diff --git a/src/Core/RequestHandlers/UserListRequestHandler.cpp b/src/Core/RequestHandlers/UserListRequestHandler.cpp
index bb67df9..8a61cbd 100644
--- a/src/Core/RequestHandlers/UserListRequestHandler.cpp
+++ b/src/Core/RequestHandlers/UserListRequestHandler.cpp
@@ -18,7 +18,7 @@
*/
#include "UserListRequestHandler.h"
-#include "../UserBackend.h"
+#include "../UserManager.h"
#include <Common/Exception.h>
#include <Common/Logger.h>
@@ -42,7 +42,7 @@ void UserListRequestHandler::handlePacket(const Common::XmlPacket &packet) {
// TODO Require authentication
- if(!UserBackend::getUserList(sigc::mem_fun(this, &UserListRequestHandler::userListHandler))) {
+ if(!UserManager::get()->getUserList(sigc::mem_fun(this, &UserListRequestHandler::userListHandler))) {
Common::XmlPacket ret;
ret.setType("Error");
ret.add("ErrorCode", Common::Exception::NOT_IMPLEMENTED);
diff --git a/src/Core/UserBackend.h b/src/Core/UserBackend.h
index aad9ace..415f6bf 100644
--- a/src/Core/UserBackend.h
+++ b/src/Core/UserBackend.h
@@ -20,12 +20,12 @@
#ifndef MAD_CORE_USERBACKEND_H_
#define MAD_CORE_USERBACKEND_H_
+#include <config.h>
+
#include <Common/UserInfo.h>
#include <map>
-#include <set>
#include <string>
-#include <vector>
#include <sigc++/signal.h>
@@ -33,39 +33,27 @@
namespace Mad {
namespace Core {
-class UserBackend {
- private:
- struct Compare {
- bool operator() (const UserBackend *b1, const UserBackend *b2) {
- if(b1->getPriority() == b2->getPriority())
- return (b1 > b2);
- else
- return (b1->getPriority() > b2->getPriority());
- }
- };
-
- static std::set<UserBackend*, Compare> backends;
+class UserManager;
+class UserBackend {
protected:
- UserBackend() {}
+ friend class UserManager;
- static void registerBackend(UserBackend *backend) {
- backends.insert(backend);
- }
+ UserBackend() {}
- static void unregisterBackend(UserBackend *backend) {
- backends.erase(backend);
+ virtual bool getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback _UNUSED_PARAMETER_) {
+ return false;
}
- virtual bool userList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& >&) {
+ virtual bool getUserInfo(unsigned long uid _UNUSED_PARAMETER_, const sigc::slot<void, const Common::UserInfo&> &callback _UNUSED_PARAMETER_) {
return false;
}
- virtual bool userInfo(unsigned long, const sigc::slot<void, const Common::UserInfo&>&) {
+ virtual bool setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string&, const sigc::slot<void, bool> &callback _UNUSED_PARAMETER_) {
return false;
}
- virtual bool password(unsigned long, const std::string&, const sigc::slot<void, bool>&) {
+ virtual bool addUser(const Common::UserInfo &userInfo _UNUSED_PARAMETER_, const sigc::slot<void, bool> &callback _UNUSED_PARAMETER_) {
return false;
}
@@ -75,11 +63,6 @@ class UserBackend {
public:
virtual ~UserBackend() {}
-
- static bool getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
- static bool getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback);
-
- static bool setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback);
};
}
diff --git a/src/Core/UserBackend.cpp b/src/Core/UserManager.cpp
index de8b943..d560586 100644
--- a/src/Core/UserBackend.cpp
+++ b/src/Core/UserManager.cpp
@@ -1,7 +1,7 @@
/*
- * UserBackend.cpp
+ * UserManager.cpp
*
- * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ * 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 General Public License as published by the
@@ -17,35 +17,53 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "UserManager.h"
#include "UserBackend.h"
namespace Mad {
namespace Core {
-std::set<UserBackend*, UserBackend::Compare> UserBackend::backends;
+UserManager UserManager::userManager;
-bool UserBackend::getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
+bool UserManager::Compare::operator() (const UserBackend *b1, const UserBackend *b2) {
+ if(b1->getPriority() == b2->getPriority())
+ return (b1 > b2);
+ else
+ return (b1->getPriority() > b2->getPriority());
+}
+
+
+bool UserManager::getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
+ for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ if((*backend)->getUserList(callback))
+ return true;
+ }
+
+ return false;
+}
+
+bool UserManager::getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->userList(callback))
+ if((*backend)->getUserInfo(uid, callback))
return true;
}
return false;
}
-bool UserBackend::getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
+bool UserManager::setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->userInfo(uid, callback))
+ if((*backend)->setPassword(uid, password, callback))
return true;
}
return false;
}
-bool UserBackend::setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback) {
+bool UserManager::addUser(const Common::UserInfo &userInfo, const sigc::slot<void, bool> &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
- if((*backend)->password(uid, password, callback))
+ if((*backend)->addUser(userInfo, callback))
return true;
}
diff --git a/src/Core/UserManager.h b/src/Core/UserManager.h
new file mode 100644
index 0000000..a925bbe
--- /dev/null
+++ b/src/Core/UserManager.h
@@ -0,0 +1,73 @@
+/*
+ * UserManager.h
+ *
+ * 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 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CORE_USERMANAGER_H_
+#define MAD_CORE_USERMANAGER_H_
+
+#include <Common/UserInfo.h>
+
+#include <map>
+#include <set>
+
+#include <sigc++/slot.h>
+
+namespace Mad {
+namespace Core {
+
+class UserBackend;
+
+class UserManager {
+ private:
+ struct Compare {
+ bool operator() (const UserBackend *b1, const UserBackend *b2);
+ };
+
+ static UserManager userManager;
+
+ std::set<UserBackend*, Compare> backends;
+
+ UserManager() {}
+
+ public:
+ void registerBackend(UserBackend *backend) {
+ backends.insert(backend);
+ }
+
+ void unregisterBackend(UserBackend *backend) {
+ backends.erase(backend);
+ }
+
+
+ bool getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
+ bool getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback);
+
+ bool setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback);
+
+ bool addUser(const Common::UserInfo &userInfo, const sigc::slot<void, bool> &callback);
+
+
+ static UserManager *get() {
+ return &userManager;
+ }
+};
+
+}
+}
+
+#endif /* MAD_CORE_USERMANAGER_H_ */