summaryrefslogtreecommitdiffstats
path: root/src/Common/UserManager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/UserManager.h')
-rw-r--r--src/Common/UserManager.h51
1 files changed, 39 insertions, 12 deletions
diff --git a/src/Common/UserManager.h b/src/Common/UserManager.h
index d2529e7..5cf14db 100644
--- a/src/Common/UserManager.h
+++ b/src/Common/UserManager.h
@@ -35,38 +35,65 @@ namespace Mad {
namespace Common {
class Application;
-class UserBackend;
+class UserConfigBackend;
+class UserDBBackend;
class UserCache;
class UserManager : private boost::noncopyable {
private:
friend class Application;
- struct Compare {
- bool operator() (boost::shared_ptr<UserBackend> b1, boost::shared_ptr<UserBackend> b2);
- };
-
- typedef std::map<boost::shared_ptr<UserBackend>, boost::shared_ptr<UserBackend>, Compare> BackendMap;
+ typedef std::map<boost::shared_ptr<UserDBBackend>, std::pair<boost::shared_ptr<UserDBBackend>, std::string> > BackendMap;
Application *application;
- BackendMap backends;
+ std::set<boost::shared_ptr<UserConfigBackend> > configBackends;
+
+ BackendMap dbBackends;
+ std::map<std::string, boost::shared_ptr<UserDBBackend> > dbBackendNames;
+
+ boost::shared_ptr<UserDBBackend> dbBackend;
boost::shared_mutex mutex;
UserManager(Application *application0) : application(application0) {}
public:
- void registerBackend(boost::shared_ptr<UserBackend> backend) {
+ void registerBackend(boost::shared_ptr<UserDBBackend> backend);
+ void registerBackendCached(boost::shared_ptr<UserDBBackend> backend);
+
+ void unregisterBackend(boost::shared_ptr<UserDBBackend> backend) {
boost::lock_guard<boost::shared_mutex> lock(mutex);
- backends.insert(std::make_pair(backend, backend));
+
+ BackendMap::iterator it = dbBackends.find(backend);
+ if(it == dbBackends.end())
+ return;
+
+ boost::shared_ptr<UserDBBackend> oldBackend = it->second.first;
+
+ std::map<std::string, boost::shared_ptr<UserDBBackend> >::iterator it2 = dbBackendNames.find(it->second.second);
+ if(it2->second == backend)
+ dbBackendNames.erase(it2);
+
+ dbBackends.erase(it);
+
+ if(dbBackend == oldBackend) {
+ if(dbBackends.empty())
+ dbBackend.reset();
+ else
+ dbBackend = dbBackends.begin()->second.first;
+ }
}
- void registerBackendCached(boost::shared_ptr<UserBackend> backend);
- void unregisterBackend(boost::shared_ptr<UserBackend> backend) {
+ void registerBackend(boost::shared_ptr<UserConfigBackend> backend) {
+ boost::lock_guard<boost::shared_mutex> lock(mutex);
+ configBackends.insert(backend);
+ }
+
+ void unregisterBackend(boost::shared_ptr<UserConfigBackend> backend) {
boost::lock_guard<boost::shared_mutex> lock(mutex);
- backends.erase(backend);
+ configBackends.erase(backend);
}
boost::shared_ptr<const std::map<unsigned long, UserInfo> > getUserList(boost::posix_time::ptime *timestamp = 0) throw(Core::Exception);