[mapguide-commits] r9702 - in sandbox/jng/library_init: Common/Foundation Common/Foundation/System Web/src/DotNetUnmanagedApi/Foundation

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Aug 4 06:19:27 PDT 2020


Author: jng
Date: 2020-08-04 06:19:26 -0700 (Tue, 04 Aug 2020)
New Revision: 9702

Added:
   sandbox/jng/library_init/Common/Foundation/System/LibraryInit.cpp
   sandbox/jng/library_init/Common/Foundation/System/LibraryInit.h
   sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/InitializeLibrary.i
Modified:
   sandbox/jng/library_init/Common/Foundation/Foundation.h
   sandbox/jng/library_init/Common/Foundation/Foundation.vcxproj
   sandbox/jng/library_init/Common/Foundation/Foundation.vcxproj.filters
   sandbox/jng/library_init/Common/Foundation/FoundationBuild.cpp
   sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/FoundationApi.vcxproj
   sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/FoundationApiGen.xml
Log:
Add MgInitializeLibrary and MgUninitializeLibrary to Foundation and exposed to .net API. This API is reserved for .net applications that only use the Foundation/Geometry/PlatformBase subset of the MapGuide API where there is currently no means to init ACE and/or an appropriate localized string bundle for exception messages.

Modified: sandbox/jng/library_init/Common/Foundation/Foundation.h
===================================================================
--- sandbox/jng/library_init/Common/Foundation/Foundation.h	2020-08-04 13:16:56 UTC (rev 9701)
+++ sandbox/jng/library_init/Common/Foundation/Foundation.h	2020-08-04 13:19:26 UTC (rev 9702)
@@ -137,6 +137,7 @@
 #include "System/Configuration.h"
 #include "System/Resources.h"
 #endif
+#include "System/LibraryInit.h"
 
 // Base exception classes and defines
 #include "Exception/ExceptionDefs.h"
@@ -193,7 +194,6 @@
 #include "Exception/XmlException.h"
 #include "Exception/XmlParserException.h"
 
-
 #ifndef SWIG_PUBLIC_API
 #include "System/ByteSourceFileImpl.h"
 #include "System/ByteSourceMemoryImpl.h"

Modified: sandbox/jng/library_init/Common/Foundation/Foundation.vcxproj
===================================================================
--- sandbox/jng/library_init/Common/Foundation/Foundation.vcxproj	2020-08-04 13:16:56 UTC (rev 9701)
+++ sandbox/jng/library_init/Common/Foundation/Foundation.vcxproj	2020-08-04 13:19:26 UTC (rev 9702)
@@ -694,6 +694,12 @@
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
     </ClCompile>
+    <ClCompile Include="System\LibraryInit.cpp">
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+    </ClCompile>
     <ClCompile Include="System\MemoryStreamHelper.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -884,6 +890,7 @@
     <ClInclude Include="System\FoundationClassId.h" />
     <ClInclude Include="System\FoundationConfigProperties.h" />
     <ClInclude Include="System\GuardDisposable.h" />
+    <ClInclude Include="System\LibraryInit.h" />
     <ClInclude Include="System\LinuxMemoryStatus.h" />
     <ClInclude Include="System\MemoryStreamHelper.h" />
     <ClInclude Include="System\NamedSerializable.h" />

Modified: sandbox/jng/library_init/Common/Foundation/Foundation.vcxproj.filters
===================================================================
--- sandbox/jng/library_init/Common/Foundation/Foundation.vcxproj.filters	2020-08-04 13:16:56 UTC (rev 9701)
+++ sandbox/jng/library_init/Common/Foundation/Foundation.vcxproj.filters	2020-08-04 13:19:26 UTC (rev 9702)
@@ -304,6 +304,9 @@
       <Filter>System</Filter>
     </ClCompile>
     <ClCompile Include="FoundationBuild.cpp" />
+    <ClCompile Include="System\LibraryInit.cpp">
+      <Filter>System</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Exception\ApplicationException.h">
@@ -650,8 +653,11 @@
     </ClInclude>
     <ClInclude Include="Foundation.h" />
     <ClInclude Include="FoundationDefs.h" />
+    <ClInclude Include="System\LibraryInit.h">
+      <Filter>System</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="Foundation.rc" />
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file

Modified: sandbox/jng/library_init/Common/Foundation/FoundationBuild.cpp
===================================================================
--- sandbox/jng/library_init/Common/Foundation/FoundationBuild.cpp	2020-08-04 13:16:56 UTC (rev 9701)
+++ sandbox/jng/library_init/Common/Foundation/FoundationBuild.cpp	2020-08-04 13:19:26 UTC (rev 9702)
@@ -104,6 +104,7 @@
 #include "System/FileUtil.cpp"
 #include "System/FoundationConfigProperties.cpp"
 #include "System/GuardDisposable.cpp"
+#include "System/LibraryInit.cpp"
 #include "System/MemoryStreamHelper.cpp"
 #include "System/NamedSerializable.cpp"
 #include "System/Object.cpp"

Added: sandbox/jng/library_init/Common/Foundation/System/LibraryInit.cpp
===================================================================
--- sandbox/jng/library_init/Common/Foundation/System/LibraryInit.cpp	                        (rev 0)
+++ sandbox/jng/library_init/Common/Foundation/System/LibraryInit.cpp	2020-08-04 13:19:26 UTC (rev 9702)
@@ -0,0 +1,76 @@
+//
+//  Copyright (C) 2004-2020 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#include "Foundation.h"
+#include "LibraryInit.h"
+
+// Initialize only once per process
+static bool m_bInitialized = false;
+
+void MgInitializeLibraryInternal(CREFSTRING stringResourcesPath, CREFSTRING locale)
+{
+    MG_TRY()
+
+    if (m_bInitialized)
+        return;
+
+    // Initialize ACE, this should enable sockets as well
+    ACE::init();
+
+    // Initialize resource path as well
+    MgResources* resources = MgResources::GetInstance();
+    resources->Initialize(stringResourcesPath);
+    resources->LoadResources(locale);
+
+    m_bInitialized = true;
+
+    MG_CATCH_AND_THROW(L"MgInitializeLibraryInternal")
+}
+
+void MgInitializeLibrary(CREFSTRING stringResourcesPath, CREFSTRING locale)
+{
+    MG_TRY()
+
+    ACE_MT(ACE_GUARD_ACTION(ACE_Recursive_Thread_Mutex, ace_mon, *ACE_Static_Object_Lock::instance(), MgInitializeLibraryInternal(stringResourcesPath, locale); , ;));
+
+    MG_CATCH_AND_THROW(L"MgInitializeLibrary")
+}
+
+void MgUninitializeLibrary()
+{
+    // ACE::fini removes the thread mutex so we cannot use it to protect this call.
+    MG_TRY()
+
+    MgUninitializeLibraryInternal();
+
+    MG_CATCH_AND_THROW(L"MgUninitializeLibrary")
+}
+
+void MgUninitializeLibraryInternal()
+{
+    MG_TRY()
+
+    if (!m_bInitialized)
+        return;
+
+    // Uninitialize ACE
+    ACE::fini();
+
+    m_bInitialized = false;
+
+    MG_CATCH_AND_THROW(L"MgUninitializeLibraryInternal")
+}

Added: sandbox/jng/library_init/Common/Foundation/System/LibraryInit.h
===================================================================
--- sandbox/jng/library_init/Common/Foundation/System/LibraryInit.h	                        (rev 0)
+++ sandbox/jng/library_init/Common/Foundation/System/LibraryInit.h	2020-08-04 13:19:26 UTC (rev 9702)
@@ -0,0 +1,56 @@
+//
+//  Copyright (C) 2004-2020 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+#ifndef MGLIBRARYINIT_H_
+#define MGLIBRARYINIT_H_
+
+#include "FoundationDefs.h"
+
+#if defined(_WIN32) || defined(__CYGWIN32__)
+#  define DllExport   __declspec( dllexport )
+#  define SWIGSTDCALL __stdcall
+#else
+#  define DllExport
+#  define SWIGSTDCALL
+#endif
+
+void MgInitializeLibraryInternal(CREFSTRING stringResourcesPath, CREFSTRING locale);
+
+///////////////////////////////////////////////////////////////////////////
+/// \brief
+///
+/// Initializes this library for use in contexts outside of MapGuide web
+/// applications
+///
+/// \param stringResourcesPath
+/// Path to the localized mapguide string bundle
+///
+/// \param locale
+/// The locale of the given string bundle
+///
+DllExport void MgInitializeLibrary(CREFSTRING stringResourcesPath, CREFSTRING locale);
+
+///////////////////////////////////////////////////////////////////////////
+/// \brief
+///
+/// Tears down this library. Only call this if you called MgInitializeLibrary
+/// to initialize
+///
+DllExport void MgUninitializeLibrary();
+
+void MgUninitializeLibraryInternal();
+
+#endif 
\ No newline at end of file

Modified: sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/FoundationApi.vcxproj
===================================================================
--- sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/FoundationApi.vcxproj	2020-08-04 13:16:56 UTC (rev 9701)
+++ sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/FoundationApi.vcxproj	2020-08-04 13:19:26 UTC (rev 9702)
@@ -247,6 +247,7 @@
     <None Include="FoundationApiGen.xml" />
     <None Include="FoundationConstants.xml" />
     <None Include="..\getclassid.code" />
+    <None Include="InitializeLibrary.i" />
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="FoundationApi.rc" />

Modified: sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/FoundationApiGen.xml
===================================================================
--- sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/FoundationApiGen.xml	2020-08-04 13:16:56 UTC (rev 9701)
+++ sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/FoundationApiGen.xml	2020-08-04 13:19:26 UTC (rev 9702)
@@ -51,6 +51,7 @@
 <SwigInline>
   %include "FoundationApi_Doc.i" //doc fragments
   %include "language.i"   //typemaps specific for each language
+  %include "InitializeLibrary.i"
   %include "../../../../Common/Foundation/System/FoundationClassId.h"
 
 #if defined(PHPSWIG)
@@ -96,6 +97,8 @@
 
     <!-- The MgDisposableCollection depends on the MgCollection above and so must come after it -->
     <Header path="../../../../Common/Foundation/System/DisposableCollection.h" />
+    
+    <Header path="../../../../Common/Foundation/System/LibraryInit.h" />
 
     <Header path="../../../../Common/Foundation/Data/BatchPropertyCollection.h" />
     <Header path="../../../../Common/Foundation/Data/ByteReader.h" />

Added: sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/InitializeLibrary.i
===================================================================
--- sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/InitializeLibrary.i	                        (rev 0)
+++ sandbox/jng/library_init/Web/src/DotNetUnmanagedApi/Foundation/InitializeLibrary.i	2020-08-04 13:19:26 UTC (rev 9702)
@@ -0,0 +1,22 @@
+//
+//  Copyright (C) 2004-2020 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+///////////////////////////////////////////////////////////
+// Global functions
+//
+void MgInitializeLibrary(STRINGPARAM stringResourcesPath, STRINGPARAM locale);
+void MgUninitializeLibrary();
\ No newline at end of file



More information about the mapguide-commits mailing list