summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-05-21 00:42:57 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-05-21 00:42:57 +0200
commit9c076d2649ff8c6997c2dec1e1ef4f7359d404ec (patch)
tree2e73f262998fe27326459c69605554b150eb6c82 /src/modules
parent325ee09f8fa61185efd6ec8b64b6432686170ac8 (diff)
downloadmad-9c076d2649ff8c6997c2dec1e1ef4f7359d404ec.tar
mad-9c076d2649ff8c6997c2dec1e1ef4f7359d404ec.zip
UserBackend-Interface ueberarbeitet
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.cpp46
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.h8
2 files changed, 26 insertions, 28 deletions
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp
index ebea4dc..a8751ee 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.cpp
+++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp
@@ -34,7 +34,7 @@
namespace Mad {
namespace Modules {
-UserBackendMysql *UserBackendMysql::backend;
+boost::shared_ptr<UserBackendMysql> UserBackendMysql::backend;
bool UserBackendMysql::handleConfigEntry(const Common::ConfigEntry &entry, bool handled) {
if(handled)
@@ -132,16 +132,18 @@ void UserBackendMysql::configFinished() {
}
-bool UserBackendMysql::getUserList(const boost::function1<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
+boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > UserBackendMysql::getUserList() {
+ Net::ThreadManager::get()->detach();
+
mysql_ping(mysql);
mysql_real_query(mysql, queryListUsers.c_str(), queryListUsers.length());
MYSQL_RES *result = mysql_use_result(mysql);
if(mysql_num_fields(result) < 4)
- return true; // TODO Error
+ return boost::shared_ptr<std::map<unsigned long, Common::UserInfo> >(); // TODO Error
- std::map<unsigned long, Common::UserInfo> users;
+ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > users(new std::map<unsigned long, Common::UserInfo>());
while(MYSQL_ROW row = mysql_fetch_row(result)) {
Common::UserInfo user(strtoul(row[0], 0, 10), row[2]);
@@ -149,15 +151,15 @@ bool UserBackendMysql::getUserList(const boost::function1<void, const std::map<u
user.setGid(strtoul(row[1], 0, 10));
user.setFullName(row[3]);
- users.insert(std::make_pair(user.getUid(), user));
+ users->insert(std::make_pair(user.getUid(), user));
}
- Net::ThreadManager::get()->pushWork(boost::bind(callback, users));
-
- return true;
+ return users;
}
-bool UserBackendMysql::getUserInfo(unsigned long uid, const boost::function1<void, const Common::UserInfo&> &callback) {
+boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long uid) {
+ Net::ThreadManager::get()->detach();
+
mysql_ping(mysql);
std::string query = queryUserById;
@@ -173,25 +175,22 @@ bool UserBackendMysql::getUserInfo(unsigned long uid, const boost::function1<voi
MYSQL_RES *result = mysql_use_result(mysql);
if(mysql_num_fields(result) < 4)
- return true; // TODO Error
+ return boost::shared_ptr<Common::UserInfo>(); // TODO Error
MYSQL_ROW row = mysql_fetch_row(result);
if(row) {
- Common::UserInfo user(strtoul(row[0], 0, 10), row[2]);
+ boost::shared_ptr<Common::UserInfo> user(new Common::UserInfo(strtoul(row[0], 0, 10), row[2]));
- user.setGid(strtoul(row[1], 0, 10));
- user.setFullName(row[3]);
-
- Net::ThreadManager::get()->pushWork(boost::bind(callback, user));
+ user->setGid(strtoul(row[1], 0, 10));
+ user->setFullName(row[3]);
while((row = mysql_fetch_row(result)) != 0) {}
- }
- else {
- Net::ThreadManager::get()->pushWork(boost::bind(callback, Common::UserInfo()));
+
+ return user;
}
- return true;
+ return boost::shared_ptr<Common::UserInfo>();
}
@@ -199,19 +198,18 @@ void UserBackendMysql::registerBackend() {
if(backend)
return;
- backend = new UserBackendMysql();
- Common::ConfigManager::get()->registerConfigurable(backend);
+ backend.reset(new UserBackendMysql());
+ Common::ConfigManager::get()->registerConfigurable(backend.get());
}
void UserBackendMysql::unregisterBackend() {
if(!backend)
return;
- Common::ConfigManager::get()->unregisterConfigurable(backend);
+ Common::ConfigManager::get()->unregisterConfigurable(backend.get());
Server::UserManager::get()->unregisterBackend(backend);
- delete backend;
- backend = 0;
+ backend.reset();
}
}
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h
index 2e4f1ff..de28069 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.h
+++ b/src/modules/UserBackendMysql/UserBackendMysql.h
@@ -30,9 +30,9 @@
namespace Mad {
namespace Modules {
-class UserBackendMysql : private Server::UserBackend, private Common::Configurable {
+class UserBackendMysql : public Server::UserBackend, private Common::Configurable {
private:
- static UserBackendMysql *backend;
+ static boost::shared_ptr<UserBackendMysql> backend;
std::string host, username, passwd, db, unixSocket;
uint16_t port;
@@ -50,8 +50,8 @@ class UserBackendMysql : private Server::UserBackend, private Common::Configurab
virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool);
virtual void configFinished();
- virtual bool getUserList(const boost::function1<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
- virtual bool getUserInfo(unsigned long uid, const boost::function1<void, const Common::UserInfo&> &callback);
+ virtual boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList();
+ virtual boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid);
public:
virtual ~UserBackendMysql() {