Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2009, 10:22:55 PM (15 years ago)
Author:
landauf
Message:

Added a dynamic library loader (more or less a copy of Ogre::DynLibManager but with some adjustments for Orxonox). This allows us to load plugins at runtime. Plugin-libraries must be declared with the "PLUGIN" switch in ORXONOX_ADD_LIBRARY in CMake.

Location:
code/branches/libraries/src
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/libraries/src/SpecialConfig.h.in

    r5625 r5626  
    8787    const char ORXONOX_LOG_DEV_PATH[]         = "@CMAKE_LOG_OUTPUT_DIRECTORY@/"    BOOST_PP_STRINGIZE(CMAKE_BUILD_TYPE);
    8888#else
     89    const char ORXONOX_PLUGIN_DEV_PATH[]      = "@CMAKE_PLUGIN_OUTPUT_DIRECTORY@";
    8990    const char ORXONOX_CONFIG_DEV_PATH[]      = "@CMAKE_CONFIG_OUTPUT_DIRECTORY@";
    9091    const char ORXONOX_LOG_DEV_PATH[]         = "@CMAKE_LOG_OUTPUT_DIRECTORY@";
  • code/branches/libraries/src/core/CMakeLists.txt

    r3370 r5626  
    2323  ConfigValueContainer.cc
    2424  Core.cc
     25  DynLib.cc
     26  DynLibManager.cc
    2527  Event.cc
    2628  Game.cc
  • code/branches/libraries/src/core/Core.cc

    r5625 r5626  
    4040#include <cstdlib>
    4141#include <cstdio>
     42#include <boost/version.hpp>
    4243#include <boost/filesystem.hpp>
    4344#include <OgreRenderWindow.h>
     
    6869#include "ConfigValueIncludes.h"
    6970#include "CoreIncludes.h"
     71#include "DynLibManager.h"
    7072#include "Factory.h"
    7173#include "GameMode.h"
     
    8082#include "input/InputManager.h"
    8183
     84// Boost 1.36 has some issues with deprecated functions that have been omitted
     85#if (BOOST_VERSION == 103600)
     86#  define BOOST_LEAF_FUNCTION filename
     87#else
     88#  define BOOST_LEAF_FUNCTION leaf
     89#endif
     90
    8291namespace orxonox
    8392{
     
    260269        this->setFixedPaths();
    261270
    262         // TODO: Load plugins
     271        // Create a new dynamic library manager
     272        this->dynLibManager_.reset(new DynLibManager());
     273
     274        // Load plugins
     275        try
     276        {
     277            // We search for helper files with the following extension
     278            std::string pluginextension = ".plugin";
     279            size_t pluginextensionlength = pluginextension.size();
     280
     281            // Search in the directory of our executable
     282            boost::filesystem::path searchpath = this->getRootPath() / ORXONOX_PLUGIN_INSTALL_PATH;
     283
     284            boost::filesystem::directory_iterator file(searchpath);
     285            boost::filesystem::directory_iterator end;
     286
     287            // Iterate through all files
     288            while (file != end)
     289            {
     290                std::string filename = file->BOOST_LEAF_FUNCTION();
     291
     292                // Check if the file ends with the exension in question
     293                if (filename.size() > pluginextensionlength)
     294                {
     295                    if (filename.substr(filename.size() - pluginextensionlength) == pluginextension)
     296                    {
     297                        // We've found a helper file - now load the library with the same name
     298                        std::string library = filename.substr(0, filename.size() - pluginextensionlength);
     299                        boost::filesystem::path librarypath = searchpath / library;
     300
     301                        this->dynLibManager_->load(librarypath.string());
     302                    }
     303                }
     304
     305                ++file;
     306            }
     307        }
     308        catch (const std::exception& e)
     309        {
     310            COUT(1) << "An error occurred while loading plugins: " << e.what() << std::endl;
     311        }
     312        catch (...)
     313        {
     314            COUT(1) << "An error occurred while loading plugins." << std::endl;
     315        }
    263316
    264317        // Parse command line arguments AFTER the plugins have been loaded (static code!)
  • code/branches/libraries/src/core/Core.h

    r5625 r5626  
    119119
    120120            // Mind the order for the destruction!
     121            scoped_ptr<DynLibManager>     dynLibManager_;
    121122            scoped_ptr<SignalHandler>     signalHandler_;
    122123            SimpleScopeGuard              identifierDestroyer_;
  • code/branches/libraries/src/core/CorePrereqs.h

    r3370 r5626  
    112112    class ConsoleCommand;
    113113    class Core;
     114    class DynLib;
     115    class DynLibManager;
    114116    struct Event;
    115117    class EventContainer;
Note: See TracChangeset for help on using the changeset viewer.