[Orxonox-commit 5880] r10540 - in code/branches/core7/src/libraries/core: . module
landauf at orxonox.net
landauf at orxonox.net
Sun Jun 7 13:11:07 CEST 2015
Author: landauf
Date: 2015-06-07 13:11:07 +0200 (Sun, 07 Jun 2015)
New Revision: 10540
Added:
code/branches/core7/src/libraries/core/module/DynLib.cc
code/branches/core7/src/libraries/core/module/DynLib.h
code/branches/core7/src/libraries/core/module/DynLibManager.cc
code/branches/core7/src/libraries/core/module/DynLibManager.h
Removed:
code/branches/core7/src/libraries/core/DynLib.cc
code/branches/core7/src/libraries/core/DynLib.h
code/branches/core7/src/libraries/core/DynLibManager.cc
code/branches/core7/src/libraries/core/DynLibManager.h
Modified:
code/branches/core7/src/libraries/core/CMakeLists.txt
code/branches/core7/src/libraries/core/Core.cc
code/branches/core7/src/libraries/core/module/CMakeLists.txt
Log:
moved DynLib and DynLibManager into module sub-directory
Modified: code/branches/core7/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/core7/src/libraries/core/CMakeLists.txt 2015-06-07 10:10:24 UTC (rev 10539)
+++ code/branches/core7/src/libraries/core/CMakeLists.txt 2015-06-07 11:11:07 UTC (rev 10540)
@@ -21,8 +21,6 @@
#BUILD_UNIT CoreStableBuildUnit.cc
ClassTreeMask.cc
- DynLib.cc
- DynLibManager.cc
Event.cc
Game.cc
GameConfig.cc
Modified: code/branches/core7/src/libraries/core/Core.cc
===================================================================
--- code/branches/core7/src/libraries/core/Core.cc 2015-06-07 10:10:24 UTC (rev 10539)
+++ code/branches/core7/src/libraries/core/Core.cc 2015-06-07 11:11:07 UTC (rev 10540)
@@ -53,16 +53,15 @@
#include "util/Clock.h"
#include "util/Output.h"
#include "util/Exception.h"
+#include "util/SignalHandler.h"
#include "util/output/LogWriter.h"
#include "util/output/OutputManager.h"
#include "core/singleton/Scope.h"
#include "core/singleton/ScopedSingletonIncludes.h"
-#include "util/SignalHandler.h"
#include "ApplicationPaths.h"
#include "ConfigurablePaths.h"
#include "commandline/CommandLineIncludes.h"
#include "config/ConfigFileManager.h"
-#include "DynLibManager.h"
#include "GameMode.h"
#include "GraphicsManager.h"
#include "GUIManager.h"
@@ -76,6 +75,7 @@
#include "command/TclThreadManager.h"
#include "input/InputManager.h"
#include "object/ObjectList.h"
+#include "module/DynLibManager.h"
#include "module/ModuleInstance.h"
#include "module/StaticInitializationManager.h"
#include "CoreStaticInitializationHandler.h"
Deleted: code/branches/core7/src/libraries/core/DynLib.cc
===================================================================
--- code/branches/core7/src/libraries/core/DynLib.cc 2015-06-07 10:10:24 UTC (rev 10539)
+++ code/branches/core7/src/libraries/core/DynLib.cc 2015-06-07 11:11:07 UTC (rev 10540)
@@ -1,146 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2006 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place - Suite 330, Boston, MA 02111-1307, USA, or go to
-http://www.gnu.org/copyleft/lesser.txt.
-
-You may alternatively use this source under the terms of a specific version of
-the OGRE Unrestricted License provided you have obtained such a license from
-Torus Knot Software Ltd.
------------------------------------------------------------------------------
-*/
-
-// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
-
-#include "DynLib.h"
-
-#include "util/Exception.h"
-
-#ifdef ORXONOX_PLATFORM_WINDOWS
-# define WIN32_LEAN_AND_MEAN
-# ifndef NOMINMAX
-# define NOMINMAX // required to stop windows.h messing up std::min
-# endif
-# include <windows.h>
-#endif
-
-#ifdef ORXONOX_PLATFORM_UNIX
-# include <dlfcn.h>
-#endif
-
-#ifdef ORXONOX_PLATFORM_APPLE
-# include <OSX/macUtils.h> // OGRE include
-#endif
-
-namespace orxonox
-{
- //-----------------------------------------------------------------------
- DynLib::DynLib( const std::string& name )
- {
- mName = name;
- m_hInst = NULL;
- }
-
- //-----------------------------------------------------------------------
- DynLib::~DynLib()
- {
- }
-
- //-----------------------------------------------------------------------
- void DynLib::load()
- {
- // Log library load
- orxout(internal_info) << "load DynLib " << mName << endl;
-
- std::string name = mName;
-#ifdef ORXONOX_PLATFORM_LINUX
- // dlopen() does not add .so to the filename, like windows does for .dll
- if (name.substr(name.length() - 3, 3) != ".so")
- name += ".so";
-#elif defined(ORXONOX_PLATFORM_APPLE)
- // dlopen() does not add .dylib to the filename, like windows does for .dll
- if (name.substr(name.length() - 6, 6) != ".dylib")
- name += ".dylib";
-#elif defined(ORXONOX_PLATFORM_WINDOWS)
- //altered search path doesn't work with paths with forward slashes
- std::replace(name.begin(), name.end(), '/', '\\');
- // Although LoadLibraryEx will add .dll itself when you only specify the library name,
- // if you include a relative path then it does not. So, add it to be sure.
- if (name.substr(name.length() - 4, 4) != ".dll")
- name += ".dll";
-#endif
-
- m_hInst = (DYNLIB_HANDLE)DYNLIB_LOAD( name.c_str() );
-
- if (!m_hInst)
- ThrowException(
- General,
- "Could not load dynamic library " + mName +
- ". System Error: " + dynlibError());
- }
-
- //-----------------------------------------------------------------------
- void DynLib::unload()
- {
- // Log library unload
- orxout(internal_info) << "unload DynLib " << mName << endl;
-
- if (DYNLIB_UNLOAD( m_hInst ))
- {
- ThrowException(
- General,
- "Could not unload dynamic library " + mName +
- ". System Error: " + dynlibError());
- }
-
- }
-
- //-----------------------------------------------------------------------
- void* DynLib::getSymbol( const std::string& strName ) const throw()
- {
- return (void*)DYNLIB_GETSYM( m_hInst, strName.c_str() );
- }
- //-----------------------------------------------------------------------
- std::string DynLib::dynlibError( void )
- {
-#if defined(ORXONOX_PLATFORM_WINDOWS)
- LPVOID lpMsgBuf;
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &lpMsgBuf,
- 0,
- NULL
- );
- std::string ret = (char*)lpMsgBuf;
- // Free the buffer.
- LocalFree( lpMsgBuf );
- return ret;
-#elif defined(ORXONOX_PLATFORM_UNIX)
- return std::string(dlerror());
-#else
- return "";
-#endif
- }
-}
Deleted: code/branches/core7/src/libraries/core/DynLib.h
===================================================================
--- code/branches/core7/src/libraries/core/DynLib.h 2015-06-07 10:10:24 UTC (rev 10539)
+++ code/branches/core7/src/libraries/core/DynLib.h 2015-06-07 11:11:07 UTC (rev 10540)
@@ -1,119 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2006 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place - Suite 330, Boston, MA 02111-1307, USA, or go to
-http://www.gnu.org/copyleft/lesser.txt.
-
-You may alternatively use this source under the terms of a specific version of
-the OGRE Unrestricted License provided you have obtained such a license from
-Torus Knot Software Ltd.
------------------------------------------------------------------------------
-*/
-
-// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
-
-/**
- @file
- @ingroup Management CoreGame
- @brief Declaration of DynLib which represents a dynamically loaded module.
-*/
-
-#ifndef _Core_DynLib_H__
-#define _Core_DynLib_H__
-
-#include "CorePrereqs.h"
-
-#include <string>
-
-#if defined(ORXONOX_PLATFORM_WINDOWS)
-# define DYNLIB_HANDLE hInstance
-# define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
-# define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
-# define DYNLIB_UNLOAD( a ) !FreeLibrary( a )
-
-struct HINSTANCE__;
-typedef struct HINSTANCE__* hInstance;
-
-#elif defined(ORXONOX_PLATFORM_UNIX)
-# define DYNLIB_HANDLE void*
-# define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
-# define DYNLIB_GETSYM( a, b ) dlsym( a, b )
-# define DYNLIB_UNLOAD( a ) dlclose( a )
-#endif
-
-namespace orxonox
-{
- /** %Resource holding data about a dynamic library.
- @remarks
- This class holds the data required to get symbols from
- libraries loaded at run-time (i.e. from DLL's for so's)
- @author
- Adrian Cearnãu (cearny at cearny.ro)
- @since
- 27 January 2002
- */
- class _CoreExport DynLib
- {
- protected:
- std::string mName;
- /// Gets the last loading error
- std::string dynlibError(void);
- public:
- /** Default constructor - used by DynLibManager.
- @warning
- Do not call directly
- */
- DynLib( const std::string& name );
-
- /** Default destructor.
- */
- ~DynLib();
-
- /** Load the library
- */
- void load();
- /** Unload the library
- */
- void unload();
- /// Get the name of the library
- const std::string& getName(void) const { return mName; }
-
- /**
- Returns the address of the given symbol from the loaded library.
- @param
- strName The name of the symbol to search for
- @returns
- If the function succeeds, the returned value is a handle to
- the symbol.
- @par
- If the function fails, the returned value is <b>NULL</b>.
-
- */
- void* getSymbol( const std::string& strName ) const throw();
-
- protected:
-
- /// Handle to the loaded library.
- DYNLIB_HANDLE m_hInst;
- };
-
-}
-
-#endif /* _Core_DynLib_H__ */
Deleted: code/branches/core7/src/libraries/core/DynLibManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/DynLibManager.cc 2015-06-07 10:10:24 UTC (rev 10539)
+++ code/branches/core7/src/libraries/core/DynLibManager.cc 2015-06-07 11:11:07 UTC (rev 10540)
@@ -1,86 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2006 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place - Suite 330, Boston, MA 02111-1307, USA, or go to
-http://www.gnu.org/copyleft/lesser.txt.
-
-You may alternatively use this source under the terms of a specific version of
-the OGRE Unrestricted License provided you have obtained such a license from
-Torus Knot Software Ltd.
------------------------------------------------------------------------------
-*/
-
-// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
-
-#include "DynLibManager.h"
-
-#include "DynLib.h"
-
-namespace orxonox
-{
- //-----------------------------------------------------------------------
- //! Static pointer to the singleton
- DynLibManager* DynLibManager::singletonPtr_s = 0;
-
- //-----------------------------------------------------------------------
- DynLibManager::DynLibManager()
- {
- }
- //-----------------------------------------------------------------------
- DynLib* DynLibManager::load( const std::string& filename)
- {
- DynLibList::iterator i = mLibList.find(filename);
- if (i != mLibList.end())
- {
- return i->second;
- }
- else
- {
- DynLib* pLib = new DynLib(filename);
- pLib->load();
- mLibList[filename] = pLib;
- return pLib;
- }
- }
- //-----------------------------------------------------------------------
- void DynLibManager::unload(DynLib* lib)
- {
- DynLibList::iterator i = mLibList.find(lib->getName());
- if (i != mLibList.end())
- {
- mLibList.erase(i);
- }
- lib->unload();
- delete lib;
- }
- //-----------------------------------------------------------------------
- DynLibManager::~DynLibManager()
- {
- // Unload & delete resources in turn
- for (DynLibList::iterator it = mLibList.begin(); it != mLibList.end(); ++it)
- {
- it->second->unload();
- delete it->second;
- }
-
- // Empty the list
- mLibList.clear();
- }
-}
Deleted: code/branches/core7/src/libraries/core/DynLibManager.h
===================================================================
--- code/branches/core7/src/libraries/core/DynLibManager.h 2015-06-07 10:10:24 UTC (rev 10539)
+++ code/branches/core7/src/libraries/core/DynLibManager.h 2015-06-07 11:11:07 UTC (rev 10540)
@@ -1,104 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2006 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place - Suite 330, Boston, MA 02111-1307, USA, or go to
-http://www.gnu.org/copyleft/lesser.txt.
-
-You may alternatively use this source under the terms of a specific version of
-the OGRE Unrestricted License provided you have obtained such a license from
-Torus Knot Software Ltd.
------------------------------------------------------------------------------
-*/
-
-// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
-
-/**
- @file
- @ingroup Management CoreGame
- @brief Declaration of DynLibManager, used to load modules at runtime.
-*/
-
-#ifndef _Core_DynLibManager_H__
-#define _Core_DynLibManager_H__
-
-#include "CorePrereqs.h"
-
-#include <map>
-#include <string>
-#include "util/Singleton.h"
-
-namespace orxonox
-{
- /** Manager for Dynamic-loading Libraries.
- @remarks
- This manager keeps a track of all the open dynamic-loading
- libraries, opens them and returns references to already-open
- libraries.
- */
- class _CoreExport DynLibManager: public Singleton<DynLibManager>
- {
- friend class Singleton<DynLibManager>;
-
- protected:
- typedef std::map<std::string, DynLib*> DynLibList;
- DynLibList mLibList;
-
- public:
- /**
- @brief
- Default constructor.
- @note
- Should never be called as the singleton is automatically
- created during the creation of the Root object.
- @see
- Root::Root
- */
- DynLibManager();
-
- /**
- @brief
- Default destructor.
- @see
- Root::~Root
- */
- virtual ~DynLibManager();
-
- /**
- @brief
- Loads the passed library.
- @param filename
- The name of the library. The extension can be omitted
- */
- DynLib* load(const std::string& filename);
-
- /**
- @brief
- Unloads the passed library.
- @param lib
- A pointer to the library object
- */
- void unload(DynLib* lib);
-
- private:
- static DynLibManager* singletonPtr_s;
- };
-}
-
-#endif /* _Core_DynLibManager_H__ */
Modified: code/branches/core7/src/libraries/core/module/CMakeLists.txt
===================================================================
--- code/branches/core7/src/libraries/core/module/CMakeLists.txt 2015-06-07 10:10:24 UTC (rev 10539)
+++ code/branches/core7/src/libraries/core/module/CMakeLists.txt 2015-06-07 11:11:07 UTC (rev 10540)
@@ -1,4 +1,6 @@
ADD_SOURCE_FILES(CORE_SRC_FILES
+ DynLib.cc
+ DynLibManager.cc
ModuleInstance.cc
StaticallyInitializedInstance.cc
StaticInitializationHandlerIncludes.cc
Copied: code/branches/core7/src/libraries/core/module/DynLib.cc (from rev 10534, code/branches/core7/src/libraries/core/DynLib.cc)
===================================================================
--- code/branches/core7/src/libraries/core/module/DynLib.cc (rev 0)
+++ code/branches/core7/src/libraries/core/module/DynLib.cc 2015-06-07 11:11:07 UTC (rev 10540)
@@ -0,0 +1,146 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
+
+#include "DynLib.h"
+
+#include "util/Exception.h"
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+# define WIN32_LEAN_AND_MEAN
+# ifndef NOMINMAX
+# define NOMINMAX // required to stop windows.h messing up std::min
+# endif
+# include <windows.h>
+#endif
+
+#ifdef ORXONOX_PLATFORM_UNIX
+# include <dlfcn.h>
+#endif
+
+#ifdef ORXONOX_PLATFORM_APPLE
+# include <OSX/macUtils.h> // OGRE include
+#endif
+
+namespace orxonox
+{
+ //-----------------------------------------------------------------------
+ DynLib::DynLib( const std::string& name )
+ {
+ mName = name;
+ m_hInst = NULL;
+ }
+
+ //-----------------------------------------------------------------------
+ DynLib::~DynLib()
+ {
+ }
+
+ //-----------------------------------------------------------------------
+ void DynLib::load()
+ {
+ // Log library load
+ orxout(internal_info) << "load DynLib " << mName << endl;
+
+ std::string name = mName;
+#ifdef ORXONOX_PLATFORM_LINUX
+ // dlopen() does not add .so to the filename, like windows does for .dll
+ if (name.substr(name.length() - 3, 3) != ".so")
+ name += ".so";
+#elif defined(ORXONOX_PLATFORM_APPLE)
+ // dlopen() does not add .dylib to the filename, like windows does for .dll
+ if (name.substr(name.length() - 6, 6) != ".dylib")
+ name += ".dylib";
+#elif defined(ORXONOX_PLATFORM_WINDOWS)
+ //altered search path doesn't work with paths with forward slashes
+ std::replace(name.begin(), name.end(), '/', '\\');
+ // Although LoadLibraryEx will add .dll itself when you only specify the library name,
+ // if you include a relative path then it does not. So, add it to be sure.
+ if (name.substr(name.length() - 4, 4) != ".dll")
+ name += ".dll";
+#endif
+
+ m_hInst = (DYNLIB_HANDLE)DYNLIB_LOAD( name.c_str() );
+
+ if (!m_hInst)
+ ThrowException(
+ General,
+ "Could not load dynamic library " + mName +
+ ". System Error: " + dynlibError());
+ }
+
+ //-----------------------------------------------------------------------
+ void DynLib::unload()
+ {
+ // Log library unload
+ orxout(internal_info) << "unload DynLib " << mName << endl;
+
+ if (DYNLIB_UNLOAD( m_hInst ))
+ {
+ ThrowException(
+ General,
+ "Could not unload dynamic library " + mName +
+ ". System Error: " + dynlibError());
+ }
+
+ }
+
+ //-----------------------------------------------------------------------
+ void* DynLib::getSymbol( const std::string& strName ) const throw()
+ {
+ return (void*)DYNLIB_GETSYM( m_hInst, strName.c_str() );
+ }
+ //-----------------------------------------------------------------------
+ std::string DynLib::dynlibError( void )
+ {
+#if defined(ORXONOX_PLATFORM_WINDOWS)
+ LPVOID lpMsgBuf;
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0,
+ NULL
+ );
+ std::string ret = (char*)lpMsgBuf;
+ // Free the buffer.
+ LocalFree( lpMsgBuf );
+ return ret;
+#elif defined(ORXONOX_PLATFORM_UNIX)
+ return std::string(dlerror());
+#else
+ return "";
+#endif
+ }
+}
Copied: code/branches/core7/src/libraries/core/module/DynLib.h (from rev 10534, code/branches/core7/src/libraries/core/DynLib.h)
===================================================================
--- code/branches/core7/src/libraries/core/module/DynLib.h (rev 0)
+++ code/branches/core7/src/libraries/core/module/DynLib.h 2015-06-07 11:11:07 UTC (rev 10540)
@@ -0,0 +1,119 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
+
+/**
+ @file
+ @ingroup Management CoreGame
+ @brief Declaration of DynLib which represents a dynamically loaded module.
+*/
+
+#ifndef _Core_DynLib_H__
+#define _Core_DynLib_H__
+
+#include "CorePrereqs.h"
+
+#include <string>
+
+#if defined(ORXONOX_PLATFORM_WINDOWS)
+# define DYNLIB_HANDLE hInstance
+# define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
+# define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
+# define DYNLIB_UNLOAD( a ) !FreeLibrary( a )
+
+struct HINSTANCE__;
+typedef struct HINSTANCE__* hInstance;
+
+#elif defined(ORXONOX_PLATFORM_UNIX)
+# define DYNLIB_HANDLE void*
+# define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
+# define DYNLIB_GETSYM( a, b ) dlsym( a, b )
+# define DYNLIB_UNLOAD( a ) dlclose( a )
+#endif
+
+namespace orxonox
+{
+ /** %Resource holding data about a dynamic library.
+ @remarks
+ This class holds the data required to get symbols from
+ libraries loaded at run-time (i.e. from DLL's for so's)
+ @author
+ Adrian Cearnãu (cearny at cearny.ro)
+ @since
+ 27 January 2002
+ */
+ class _CoreExport DynLib
+ {
+ protected:
+ std::string mName;
+ /// Gets the last loading error
+ std::string dynlibError(void);
+ public:
+ /** Default constructor - used by DynLibManager.
+ @warning
+ Do not call directly
+ */
+ DynLib( const std::string& name );
+
+ /** Default destructor.
+ */
+ ~DynLib();
+
+ /** Load the library
+ */
+ void load();
+ /** Unload the library
+ */
+ void unload();
+ /// Get the name of the library
+ const std::string& getName(void) const { return mName; }
+
+ /**
+ Returns the address of the given symbol from the loaded library.
+ @param
+ strName The name of the symbol to search for
+ @returns
+ If the function succeeds, the returned value is a handle to
+ the symbol.
+ @par
+ If the function fails, the returned value is <b>NULL</b>.
+
+ */
+ void* getSymbol( const std::string& strName ) const throw();
+
+ protected:
+
+ /// Handle to the loaded library.
+ DYNLIB_HANDLE m_hInst;
+ };
+
+}
+
+#endif /* _Core_DynLib_H__ */
Copied: code/branches/core7/src/libraries/core/module/DynLibManager.cc (from rev 10534, code/branches/core7/src/libraries/core/DynLibManager.cc)
===================================================================
--- code/branches/core7/src/libraries/core/module/DynLibManager.cc (rev 0)
+++ code/branches/core7/src/libraries/core/module/DynLibManager.cc 2015-06-07 11:11:07 UTC (rev 10540)
@@ -0,0 +1,86 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
+
+#include "DynLibManager.h"
+
+#include "DynLib.h"
+
+namespace orxonox
+{
+ //-----------------------------------------------------------------------
+ //! Static pointer to the singleton
+ DynLibManager* DynLibManager::singletonPtr_s = 0;
+
+ //-----------------------------------------------------------------------
+ DynLibManager::DynLibManager()
+ {
+ }
+ //-----------------------------------------------------------------------
+ DynLib* DynLibManager::load( const std::string& filename)
+ {
+ DynLibList::iterator i = mLibList.find(filename);
+ if (i != mLibList.end())
+ {
+ return i->second;
+ }
+ else
+ {
+ DynLib* pLib = new DynLib(filename);
+ pLib->load();
+ mLibList[filename] = pLib;
+ return pLib;
+ }
+ }
+ //-----------------------------------------------------------------------
+ void DynLibManager::unload(DynLib* lib)
+ {
+ DynLibList::iterator i = mLibList.find(lib->getName());
+ if (i != mLibList.end())
+ {
+ mLibList.erase(i);
+ }
+ lib->unload();
+ delete lib;
+ }
+ //-----------------------------------------------------------------------
+ DynLibManager::~DynLibManager()
+ {
+ // Unload & delete resources in turn
+ for (DynLibList::iterator it = mLibList.begin(); it != mLibList.end(); ++it)
+ {
+ it->second->unload();
+ delete it->second;
+ }
+
+ // Empty the list
+ mLibList.clear();
+ }
+}
Copied: code/branches/core7/src/libraries/core/module/DynLibManager.h (from rev 10534, code/branches/core7/src/libraries/core/DynLibManager.h)
===================================================================
--- code/branches/core7/src/libraries/core/module/DynLibManager.h (rev 0)
+++ code/branches/core7/src/libraries/core/module/DynLibManager.h 2015-06-07 11:11:07 UTC (rev 10540)
@@ -0,0 +1,104 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
+
+/**
+ @file
+ @ingroup Management CoreGame
+ @brief Declaration of DynLibManager, used to load modules at runtime.
+*/
+
+#ifndef _Core_DynLibManager_H__
+#define _Core_DynLibManager_H__
+
+#include "CorePrereqs.h"
+
+#include <map>
+#include <string>
+#include "util/Singleton.h"
+
+namespace orxonox
+{
+ /** Manager for Dynamic-loading Libraries.
+ @remarks
+ This manager keeps a track of all the open dynamic-loading
+ libraries, opens them and returns references to already-open
+ libraries.
+ */
+ class _CoreExport DynLibManager: public Singleton<DynLibManager>
+ {
+ friend class Singleton<DynLibManager>;
+
+ protected:
+ typedef std::map<std::string, DynLib*> DynLibList;
+ DynLibList mLibList;
+
+ public:
+ /**
+ @brief
+ Default constructor.
+ @note
+ Should never be called as the singleton is automatically
+ created during the creation of the Root object.
+ @see
+ Root::Root
+ */
+ DynLibManager();
+
+ /**
+ @brief
+ Default destructor.
+ @see
+ Root::~Root
+ */
+ virtual ~DynLibManager();
+
+ /**
+ @brief
+ Loads the passed library.
+ @param filename
+ The name of the library. The extension can be omitted
+ */
+ DynLib* load(const std::string& filename);
+
+ /**
+ @brief
+ Unloads the passed library.
+ @param lib
+ A pointer to the library object
+ */
+ void unload(DynLib* lib);
+
+ private:
+ static DynLibManager* singletonPtr_s;
+ };
+}
+
+#endif /* _Core_DynLibManager_H__ */
More information about the Orxonox-commit
mailing list