Revision: 40820
          http://brlcad.svn.sourceforge.net/brlcad/?rev=40820&view=rev
Author:   davidloman
Date:     2010-09-29 14:14:12 +0000 (Wed, 29 Sep 2010)

Log Message:
-----------
The Session mapping was getting pretty stupid.  Save some headaches by using a 
simple list and iterating over it to find what i need.  If this ends up being a 
perf hit, then changes can be made then (aka when its a problem).  Implemented 
3 getters, get by: Account*, QUuid, and Portal*

Modified Paths:
--------------
    rt^3/trunk/src/GS/SessionManager.cxx
    rt^3/trunk/src/GS/SessionManager.h

Modified: rt^3/trunk/src/GS/SessionManager.cxx
===================================================================
--- rt^3/trunk/src/GS/SessionManager.cxx        2010-09-29 14:00:33 UTC (rev 
40819)
+++ rt^3/trunk/src/GS/SessionManager.cxx        2010-09-29 14:14:12 UTC (rev 
40820)
@@ -35,8 +35,6 @@
 
 SessionManager::SessionManager()
 {
-    this->sessionIdMap = new QMap<QUuid, Session*> ();
-    this->accountIdMap = new QMap<quint32, Session*> ();
     this->log = Logger::getInstance();
 }
 
@@ -59,9 +57,7 @@
        Session* s = NULL;
 
        //check to see if its already cached.
-       this->mapsLock.lock();
-    s = this->accountIdMap->value(a->getID());
-    this->mapsLock.unlock();
+    s = this->getSession(a);
 
     if (s != 0) {
        s->stampLastAccess();
@@ -71,14 +67,47 @@
 
                //cache
                this->mapsLock.lock();
-               this->sessionIdMap->insert(s->getSessionID(),s);
-               this->accountIdMap->insert(s->getAccount()->getID(),s);
+               this->sessionList.append(s);
                this->mapsLock.unlock();
 
     }
     return s;
 }
 
+Session*
+SessionManager::getSession(Account* a) {
+       QMutexLocker locker(&this->mapsLock);
+       for (int i = 0; i < this->sessionList.size(); ++i) {
+               Session* s = this->sessionList[i];
+               if (s->getAccount() == a)
+                       return s;
+       }
+       return NULL;
+}
+
+//TODO need to verify the QUuid == QUuid works.
+Session*
+SessionManager::getSession(QUuid sessID) {
+       QMutexLocker locker(&this->mapsLock);
+       for (int i = 0; i < this->sessionList.size(); ++i) {
+               Session* s = this->sessionList[i];
+               if (s->getSessionID() == sessID)
+                       return s;
+       }
+       return NULL;
+}
+
+Session*
+SessionManager::getSession(Portal* p) {
+       QMutexLocker locker(&this->mapsLock);
+       for (int i = 0; i < this->sessionList.size(); ++i) {
+               Session* s = this->sessionList[i];
+               if (s->getAccount()->getPortal() == p)
+                       return s;
+       }
+       return NULL;
+}
+
 bool
 SessionManager::handleNetMsg(NetMsg* msg)
 {

Modified: rt^3/trunk/src/GS/SessionManager.h
===================================================================
--- rt^3/trunk/src/GS/SessionManager.h  2010-09-29 14:00:33 UTC (rev 40819)
+++ rt^3/trunk/src/GS/SessionManager.h  2010-09-29 14:14:12 UTC (rev 40820)
@@ -42,6 +42,10 @@
     virtual ~SessionManager();
     bool handleNetMsg(NetMsg* msg);
 
+    Session* getSession(Account* a);
+    Session* getSession(QUuid sessID);
+    Session* getSession(Portal* p);
+
 private:
     static SessionManager* pInstance;
     SessionManager();
@@ -49,8 +53,7 @@
     Logger* log;
 
     QMutex mapsLock;
-    QMap<QUuid, Session*>* sessionIdMap;
-    QMap<quint32, Session*>* accountIdMap;
+    QList<Session*> sessionList;
 
     Session* newSession(Account* a);
     void handleNewSessionReqMsg(NewSessionReqMsg* msg);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to