From 71dc41a9b7b0e939314a886383daa6fb2e297a55 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 25 Apr 2009 16:27:03 +0200 Subject: SystemBackend und UserBackend in Backend und Manager aufgeteilt --- src/Core/Makefile.am | 4 +- src/Core/Makefile.in | 8 +-- .../RequestHandlers/UserInfoRequestHandler.cpp | 4 +- .../RequestHandlers/UserListRequestHandler.cpp | 4 +- src/Core/UserBackend.cpp | 56 ---------------- src/Core/UserBackend.h | 39 ++++-------- src/Core/UserManager.cpp | 74 ++++++++++++++++++++++ src/Core/UserManager.h | 73 +++++++++++++++++++++ 8 files changed, 168 insertions(+), 94 deletions(-) delete mode 100644 src/Core/UserBackend.cpp create mode 100644 src/Core/UserManager.cpp create mode 100644 src/Core/UserManager.h (limited to 'src/Core') 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 #include @@ -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 #include @@ -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.cpp b/src/Core/UserBackend.cpp deleted file mode 100644 index de8b943..0000000 --- a/src/Core/UserBackend.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * UserBackend.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#include "UserBackend.h" - -namespace Mad { -namespace Core { - -std::set UserBackend::backends; - - -bool UserBackend::getUserList(const sigc::slot& > &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->userList(callback)) - return true; - } - - return false; -} - -bool UserBackend::getUserInfo(unsigned long uid, const sigc::slot &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->userInfo(uid, callback)) - return true; - } - - return false; -} - -bool UserBackend::setPassword(unsigned long uid, const std::string &password, const sigc::slot &callback) { - for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { - if((*backend)->password(uid, password, callback)) - return true; - } - - return false; -} - -} -} 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 + #include #include -#include #include -#include #include @@ -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 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& > &callback _UNUSED_PARAMETER_) { + return false; } - virtual bool userList(const sigc::slot& >&) { + virtual bool getUserInfo(unsigned long uid _UNUSED_PARAMETER_, const sigc::slot &callback _UNUSED_PARAMETER_) { return false; } - virtual bool userInfo(unsigned long, const sigc::slot&) { + virtual bool setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string&, const sigc::slot &callback _UNUSED_PARAMETER_) { return false; } - virtual bool password(unsigned long, const std::string&, const sigc::slot&) { + virtual bool addUser(const Common::UserInfo &userInfo _UNUSED_PARAMETER_, const sigc::slot &callback _UNUSED_PARAMETER_) { return false; } @@ -75,11 +63,6 @@ class UserBackend { public: virtual ~UserBackend() {} - - static bool getUserList(const sigc::slot& > &callback); - static bool getUserInfo(unsigned long uid, const sigc::slot &callback); - - static bool setPassword(unsigned long uid, const std::string &password, const sigc::slot &callback); }; } diff --git a/src/Core/UserManager.cpp b/src/Core/UserManager.cpp new file mode 100644 index 0000000..d560586 --- /dev/null +++ b/src/Core/UserManager.cpp @@ -0,0 +1,74 @@ +/* + * UserManager.cpp + * + * Copyright (C) 2009 Matthias Schiffer + * + * 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 . + */ + +#include "UserManager.h" +#include "UserBackend.h" + +namespace Mad { +namespace Core { + +UserManager UserManager::userManager; + + +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& > &callback) { + for(std::set::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 &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->getUserInfo(uid, callback)) + return true; + } + + return false; +} + +bool UserManager::setPassword(unsigned long uid, const std::string &password, const sigc::slot &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->setPassword(uid, password, callback)) + return true; + } + + return false; +} + +bool UserManager::addUser(const Common::UserInfo &userInfo, const sigc::slot &callback) { + for(std::set::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + if((*backend)->addUser(userInfo, callback)) + return true; + } + + return false; +} + +} +} 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 + * + * 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 . + */ + +#ifndef MAD_CORE_USERMANAGER_H_ +#define MAD_CORE_USERMANAGER_H_ + +#include + +#include +#include + +#include + +namespace Mad { +namespace Core { + +class UserBackend; + +class UserManager { + private: + struct Compare { + bool operator() (const UserBackend *b1, const UserBackend *b2); + }; + + static UserManager userManager; + + std::set backends; + + UserManager() {} + + public: + void registerBackend(UserBackend *backend) { + backends.insert(backend); + } + + void unregisterBackend(UserBackend *backend) { + backends.erase(backend); + } + + + bool getUserList(const sigc::slot& > &callback); + bool getUserInfo(unsigned long uid, const sigc::slot &callback); + + bool setPassword(unsigned long uid, const std::string &password, const sigc::slot &callback); + + bool addUser(const Common::UserInfo &userInfo, const sigc::slot &callback); + + + static UserManager *get() { + return &userManager; + } +}; + +} +} + +#endif /* MAD_CORE_USERMANAGER_H_ */ -- cgit v1.2.3