00001 /*MT* 00002 00003 MediaTomb - http://www.mediatomb.cc/ 00004 00005 session_manager.h - this file is part of MediaTomb. 00006 00007 Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>, 00008 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc> 00009 00010 Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>, 00011 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>, 00012 Leonhard Wimmer <leo@mediatomb.cc> 00013 00014 MediaTomb is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License version 2 00016 as published by the Free Software Foundation. 00017 00018 MediaTomb is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 version 2 along with MediaTomb; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00026 00027 $Id: session_manager.h 2081 2010-03-23 20:18:00Z lww $ 00028 */ 00029 00032 #ifndef __SESSION_MANAGER_H__ 00033 #define __SESSION_MANAGER_H__ 00034 00035 #include "singleton.h" 00036 #include "dictionary.h" 00037 #include "sync.h" 00038 #include "hash.h" 00039 #include "timer.h" 00040 00047 class Session : public Dictionary_r 00048 { 00049 public: 00056 Session(long timeout); 00057 00060 inline struct timespec * getLastAccessTime() { return &last_access; } 00061 00062 inline long getTimeout() { return timeout; } 00063 00065 inline zmm::String getID() { return sessionID; } 00066 00068 inline void setID(zmm::String sessionID) { this->sessionID = sessionID; } 00069 00070 inline bool isLoggedIn() { return loggedIn; } 00071 00072 inline void logIn() { loggedIn = true; } 00073 00074 inline void logOut() { loggedIn = false; } 00075 00076 inline void access() { getTimespecNow(&last_access); } 00077 00081 zmm::String getUIUpdateIDs(); 00082 00083 bool hasUIUpdateIDs(); 00084 00085 void clearUpdateIDs(); 00086 00087 protected: 00090 void containerChangedUI(int objectID); 00091 00092 void containerChangedUI(zmm::Ref<zmm::IntArray> objectIDs); 00093 00096 bool updateAll; 00097 00098 zmm::Ref<DBRHash<int> > uiUpdateIDs; 00099 00101 long timeout; 00102 00104 struct timespec last_access; 00105 00107 zmm::String sessionID; 00108 00109 bool loggedIn; 00110 00111 friend class SessionManager; 00112 }; 00113 00115 class SessionManager : public TimerSubscriberSingleton<SessionManager> 00116 { 00117 protected: 00119 zmm::Ref<zmm::Array<Session> > sessions; 00120 00121 zmm::Ref<Dictionary> accounts; 00122 00123 void checkTimer(); 00124 bool timerAdded; 00125 00126 public: 00128 SessionManager(); 00129 00130 virtual ~SessionManager() { log_debug("SessionManager destroyed\n"); } 00131 00134 zmm::Ref<Session> createSession(long timeout); 00135 00139 zmm::Ref<Session> getSession(zmm::String sessionID, bool doLock = true); 00140 00142 void removeSession(zmm::String sessionID); 00143 00144 zmm::String getUserPassword(zmm::String user); 00145 00150 void containerChangedUI(int objectID); 00151 00152 void containerChangedUI(zmm::Ref<zmm::IntArray> objectIDs); 00153 00154 virtual void timerNotify(zmm::Ref<zmm::Object> parameter); 00155 }; 00156 00157 #endif // __SESSION_MANAGER_H__
1.6.1