Go to the documentation of this file.00001
00002
00003 #ifndef _PLUGIN_H_
00004 #define _PLUGIN_H_
00005
00006 #include <EngineConfig.h>
00007 #include <core/Types.h>
00008 #include <engine/Object.h>
00009
00010 #include <string>
00011
00012 #if ENGINE_PLATFORM == PLATFORM_WIN32
00013 # define DYNLIB_HANDLE hInstance
00014 # define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
00015 # define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
00016 # define DYNLIB_UNLOAD( a ) !FreeLibrary( a )
00017
00018 struct HINSTANCE__;
00019 typedef struct HINSTANCE__* hInstance;
00020
00021 #elif ENGINE_PLATFORM == PLATFORM_LINUX
00022 # define DYNLIB_HANDLE void*
00023 # define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
00024 # define DYNLIB_GETSYM( a, b ) dlsym( a, b )
00025 # define DYNLIB_UNLOAD( a ) dlclose( a )
00026
00027 #elif ENGINE_PLATFORM == PLATFORM_APPLE
00028 # define DYNLIB_HANDLE CFBundleRef
00029 # define DYNLIB_LOAD( a ) mac_loadExeBundle( a )
00030 # define DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b )
00031 # define DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a )
00032 #endif
00033
00034 namespace engine
00035 {
00036
00037 typedef void (*DLL_LOAD_PLUGIN)();
00038 typedef void (*DLL_UNLOAD_PLUGIN)();
00039
00044 class ENGINE_PUBLIC_EXPORT Plugin: public Object
00045 {
00046 public:
00049 Plugin(std::string& name, std::string& filename);
00050
00052 ~Plugin();
00053
00055 const std::string& getFilename() const;
00056
00058 bool load();
00060 void unload();
00062 bool reload();
00063
00069 void* getSymbol(const std::string& strName) const throw();
00070
00071 protected:
00072
00073 std::string mFileName;
00075 std::string dynlibError();
00076
00077 bool mLoaded;
00078
00079
00080 DYNLIB_HANDLE m_hInst;
00081 };
00082
00083 }
00084
00085 #endif