[mapguide-commits] r4278 - in trunk/MgDev: Common/MapGuideCommon/System Server/src/Common/Manager

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Oct 2 12:50:35 EDT 2009


Author: brucedechant
Date: 2009-10-02 12:50:33 -0400 (Fri, 02 Oct 2009)
New Revision: 4278

Modified:
   trunk/MgDev/Common/MapGuideCommon/System/UserInformation.cpp
   trunk/MgDev/Common/MapGuideCommon/System/UserInformation.h
   trunk/MgDev/Server/src/Common/Manager/Connection.cpp
   trunk/MgDev/Server/src/Common/Manager/Connection.h
Log:
Fix for trac ticket 1110 - Stability improvements
http://trac.osgeo.org/mapguide/ticket/1110

Notes:
- Added copy constructor and assignment operator to MgUserInformation class
- Added copy constructor and assignment operator to MgConnection class
- Make a copy of the MgUserInformation to be owned by the TLS
- Make a copy of the MgConnection to be owned by the TLS


Modified: trunk/MgDev/Common/MapGuideCommon/System/UserInformation.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/System/UserInformation.cpp	2009-10-02 16:28:31 UTC (rev 4277)
+++ trunk/MgDev/Common/MapGuideCommon/System/UserInformation.cpp	2009-10-02 16:50:33 UTC (rev 4278)
@@ -75,6 +75,14 @@
     m_apiVersion = MG_API_VERSION(1,0,0);
 }
 
+//////////////////////////////////////////////////////////////
+/// <summary>
+/// Copy constructor.
+/// </summary>
+MgUserInformation::MgUserInformation(const MgUserInformation& userInfo) 
+{
+    *this = userInfo;
+}
 
 ///////////////////////////////
 ///<summary>
@@ -87,6 +95,27 @@
 {
 }
 
+//////////////////////////////////////////////////////////////
+/// <summary>
+/// Assignment operator.
+/// </summary>
+MgUserInformation& MgUserInformation::operator=(const MgUserInformation& userInfo) 
+{
+    if (&userInfo != this)
+    {
+        m_username = userInfo.m_username;
+        m_password = userInfo.m_password;
+        m_sessionId = userInfo.m_sessionId;
+        m_locale = userInfo.m_locale;
+        m_type = userInfo.m_type;
+        m_clientAgent = userInfo.m_clientAgent;
+        m_clientIp = userInfo.m_clientIp;
+        m_apiVersion = userInfo.m_apiVersion;
+    }
+
+    return *this;
+}
+
 ///////////////////////////////
 ///<summary>
 ///Initializes userInformation with a Mg user name and password.  The
@@ -155,14 +184,14 @@
 {
     MgUtil::CheckXss(sessionId);
 
-    int sepChar = (int)sessionId.find(L"_");
+    size_t sepChar = sessionId.find(L"_");
 
-    if (sepChar > 0 && sepChar < (int)sessionId.length())
+    if (sepChar > 0 && sepChar < sessionId.length())
     {
         // the locale can be either in the form "en" or "en-US"
         STRING subStr = sessionId.substr(sepChar+1);
-        int dashChar = (int)subStr.find(L"-");
-        int secondSepChar = (int)subStr.find(L"_");
+        size_t dashChar = subStr.find(L"-");
+        size_t secondSepChar = subStr.find(L"_");
         if (ExtendedLocaleDashLocation == dashChar && ExtendedLocaleSecondSepLocation == secondSepChar)
         {
             SetLocale(sessionId.substr(sepChar+1, MG_EXTENDED_LOCALE_LENGTH));
@@ -201,7 +230,7 @@
 
     if (MG_EXTENDED_LOCALE_LENGTH == locale.length())
     {
-        int dashChar = (int)locale.find(L"-");
+        size_t dashChar = locale.find(L"-");
         if (ExtendedLocaleDashLocation != dashChar)
         {
             throw new MgLengthException(L"MgUserInformation.SetLocale",
@@ -339,6 +368,10 @@
             {
                 g_threadLocalUserInformation = 0;
             }
+            else
+            {
+                ACE_OS::thr_setspecific(g_threadLocalUserInformation, NULL);
+            }
         }
     }
 
@@ -347,17 +380,19 @@
         MgUserInformation* oldInfo = NULL;
         ACE_OS::thr_getspecific(g_threadLocalUserInformation, (void**) &oldInfo);
 
-        if (ACE_OS::thr_setspecific(g_threadLocalUserInformation, userInformation) >= 0)
+        // Allocate a new MgUserInformation
+        MgUserInformation* tempUserInformation = NULL;
+        if(userInformation != NULL)
         {
-            if (NULL != userInformation)
-            {
-                SAFE_ADDREF(userInformation);
-            }
+            tempUserInformation = new MgUserInformation(*userInformation);
         }
 
+        ACE_OS::thr_setspecific(g_threadLocalUserInformation, tempUserInformation);
+
+        // Clean up old one if applicable
         if (NULL != oldInfo)
         {
-            SAFE_RELEASE(oldInfo);
+            delete oldInfo;
         }
     }
 }

Modified: trunk/MgDev/Common/MapGuideCommon/System/UserInformation.h
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/System/UserInformation.h	2009-10-02 16:28:31 UTC (rev 4277)
+++ trunk/MgDev/Common/MapGuideCommon/System/UserInformation.h	2009-10-02 16:50:33 UTC (rev 4278)
@@ -397,6 +397,18 @@
     ///
     virtual void Deserialize(MgStream* stream);
 
+    //////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Copy constructor.
+    ///
+    MgUserInformation(const MgUserInformation& userInfo);
+
+    //////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Assignment operator.
+    ///
+    MgUserInformation& operator=(const MgUserInformation& userInfo);
+
 protected:
 
     /////////////////////////////////////////////////////////////////

Modified: trunk/MgDev/Server/src/Common/Manager/Connection.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/Connection.cpp	2009-10-02 16:28:31 UTC (rev 4277)
+++ trunk/MgDev/Server/src/Common/Manager/Connection.cpp	2009-10-02 16:50:33 UTC (rev 4278)
@@ -37,6 +37,15 @@
     Start();
 }
 
+//////////////////////////////////////////////////////////////
+/// <summary>
+/// Copy constructor.
+/// </summary>
+MgConnection::MgConnection(const MgConnection& connection)
+{
+    *this = connection;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Destructor
@@ -47,6 +56,30 @@
     End();
 }
 
+//////////////////////////////////////////////////////////////
+/// <summary>
+/// Assignment operator.
+/// </summary>
+MgConnection& MgConnection::operator=(const MgConnection& connection)
+{
+    if (&connection != this)
+    {
+        m_busy = connection.m_busy;
+        m_clientAgent = connection.m_clientAgent;
+        m_clientIp = connection.m_clientIp;
+        m_userName = connection.m_userName;
+        m_sessionId = connection.m_sessionId;
+        m_startTime = connection.m_startTime;
+        m_lastUsageTime = connection.m_lastUsageTime;
+        m_nReceivedOperations = connection.m_nReceivedOperations;
+        m_nProcessedOperations = connection.m_nProcessedOperations;
+        m_currOperationStatus = connection.m_currOperationStatus;
+        m_currOperationTime = connection.m_currOperationTime;
+    }
+
+    return *this;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 ///<summary>
 ///Sets the connection information for the current thread.  This
@@ -64,12 +97,30 @@
             {
                 g_threadLocalConnection = 0;
             }
+            else
+            {
+                ACE_OS::thr_setspecific(g_threadLocalConnection, NULL);
+            }
         }
     }
 
     if (0 != g_threadLocalConnection)
     {
-        ACE_OS::thr_setspecific(g_threadLocalConnection, connection);
+        MgConnection* oldInfo = NULL;
+        ACE_OS::thr_getspecific(g_threadLocalConnection, (void**) &oldInfo);
+
+        MgConnection* tempConnection = NULL;
+        if(connection != NULL)
+        {
+            tempConnection = new MgConnection(*connection);
+        }
+
+        ACE_OS::thr_setspecific(g_threadLocalConnection, tempConnection);
+
+        if (NULL != oldInfo)
+        {
+            delete oldInfo;
+        }
     }
 }
 

Modified: trunk/MgDev/Server/src/Common/Manager/Connection.h
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/Connection.h	2009-10-02 16:28:31 UTC (rev 4277)
+++ trunk/MgDev/Server/src/Common/Manager/Connection.h	2009-10-02 16:50:33 UTC (rev 4278)
@@ -51,6 +51,18 @@
     MgConnection();
     ~MgConnection();
 
+    //////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Copy constructor.
+    ///
+    MgConnection(const MgConnection& connection);
+
+    //////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Assignment operator.
+    ///
+    MgConnection& operator=(const MgConnection& connection);
+
 /// Methods
 
 public:



More information about the mapguide-commits mailing list