diff options
Diffstat (limited to 'src/Common/UserManager.h')
-rw-r--r-- | src/Common/UserManager.h | 77 |
1 files changed, 72 insertions, 5 deletions
diff --git a/src/Common/UserManager.h b/src/Common/UserManager.h index 215fde8..c9b0712 100644 --- a/src/Common/UserManager.h +++ b/src/Common/UserManager.h @@ -28,8 +28,8 @@ #include <map> #include <set> -#include <boost/smart_ptr.hpp> -#include <boost/noncopyable.hpp> +#include <boost/thread/locks.hpp> +#include <boost/thread/shared_mutex.hpp> namespace Mad { namespace Common { @@ -47,15 +47,82 @@ class UserManager : boost::noncopyable { std::set<boost::shared_ptr<UserBackend>, Compare> backends; - UserManager() {} + boost::shared_mutex backendMutex; + boost::shared_mutex mutex; + + bool caching; + + boost::shared_ptr<const std::map<unsigned long, UserInfo> > users; + boost::shared_ptr<const std::map<std::string, unsigned long> > userNames; + boost::shared_ptr<Core::Exception> userException; + + boost::shared_ptr<const std::map<unsigned long, GroupInfo> > groups; + boost::shared_ptr<const std::map<std::string, unsigned long> > groupNames; + boost::shared_ptr<Core::Exception> groupException; + + boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > userGroups; + boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > groupUsers; + boost::shared_ptr<Core::Exception> userGroupException; + + UserManager() : caching(false) {} public: void registerBackend(boost::shared_ptr<UserBackend> backend) { - backends.insert(backend); + { + boost::lock_guard<boost::shared_mutex> lock(backendMutex); + backends.insert(backend); + } + + update(); } void unregisterBackend(boost::shared_ptr<UserBackend> backend) { - backends.erase(backend); + { + boost::lock_guard<boost::shared_mutex> lock(backendMutex); + backends.erase(backend); + } + + update(); + } + + bool isCaching() { + boost::shared_lock<boost::shared_mutex> lock(mutex); + return caching; + } + + void setCaching(bool cache) { + { + boost::lock_guard<boost::shared_mutex> lock(mutex); + caching = cache; + } + + update(); + } + + void update(bool refresh = false) { + { + boost::lock_guard<boost::shared_mutex> lock(mutex); + + if(!caching) + return; + + users.reset(); + userNames.reset(); + userException.reset(); + + groups.reset(); + groupNames.reset(); + groupException.reset(); + + userGroups.reset(); + groupUsers.reset(); + userGroupException.reset(); + } + + if(refresh) { + getUserList(); + getGroupList(); + } } boost::shared_ptr<const std::map<unsigned long, UserInfo> > getUserList() throw(Core::Exception); |