00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "CEGUIBase.h"
00027 #include "CEGUIString.h"
00028 #include "CEGUIExceptions.h"
00029 #include "CEGUIFactoryModule.h"
00030
00031 #if defined(__WIN32__) || defined(_WIN32)
00032 # if defined(_MSC_VER)
00033 # pragma warning(disable : 4552) // warning: operator has no effect; expected operator with side-effect
00034 # endif
00035 # define WIN32_LEAN_AND_MEAN
00036 # include <windows.h>
00037 #endif
00038
00039 #if defined(__APPLE_CC__)
00040 # include "macPlugins.h"
00041 #endif
00042
00043 #if defined(__linux__)
00044 # include "dlfcn.h"
00045 #endif
00046
00047
00048 namespace CEGUI
00049 {
00050
00051
00052
00053 const char FactoryModule::RegisterFactoryFunctionName[] = "registerFactory";
00054 const char FactoryModule::RegisterAllFunctionName[] = "registerAllFactories";
00055
00056
00057
00058
00059
00060
00061 FactoryModule::FactoryModule(const String& filename) :
00062 d_moduleName(filename)
00063 {
00064 #if defined(__linux__)
00065
00066 if (d_moduleName.substr(d_moduleName.length() - 3, 3) != (utf8*)".so")
00067 {
00068 d_moduleName += (utf8*)".so";
00069 }
00070
00071
00072 if (d_moduleName.substr(0, 3) != (utf8*)"lib")
00073 {
00074 d_moduleName.insert(0, (utf8*)"lib");
00075 }
00076 #endif
00077
00079 #if defined(__WIN32__) || defined(_WIN32)
00080 # if defined (_DEBUG) && defined (CEGUI_LOAD_MODULE_APPEND_SUFFIX_FOR_DEBUG)
00081
00082 if (d_moduleName.substr(d_moduleName.length() - 4, 4) != (utf8*)".dll")
00083 {
00084 d_moduleName += (utf8*)CEGUI_LOAD_MODULE_DEBUG_SUFFIX;
00085 }
00086 # endif
00087 #endif
00088
00089 d_handle = DYNLIB_LOAD(d_moduleName.c_str());
00090
00091
00092 if (d_handle == NULL)
00093 {
00094 throw GenericException((utf8*)"FactoryModule::FactoryModule - Failed to load module '" + d_moduleName + "'.");
00095 }
00096
00097
00098 d_regFunc = (FactoryRegisterFunction)DYNLIB_GETSYM(d_handle, RegisterFactoryFunctionName);
00099 d_regAllFunc = (RegisterAllFunction)DYNLIB_GETSYM(d_handle, RegisterAllFunctionName);
00100 }
00101
00102
00103
00104
00105
00106 FactoryModule::~FactoryModule(void)
00107 {
00108 DYNLIB_UNLOAD(d_handle);
00109 }
00110
00111
00112
00113
00114
00115 void FactoryModule::registerFactory(const String& type) const
00116 {
00117
00118 if (!d_regFunc)
00119 {
00120 throw InvalidRequestException("FactoryModule::registerFactory - Required function export 'void registerFactory(const String& type)' was not found in module '" + d_moduleName + "'.");
00121 }
00122
00123 d_regFunc(type);
00124 }
00125
00126 uint FactoryModule::registerAllFactories() const
00127 {
00128
00129 if (!d_regAllFunc)
00130 {
00131 throw InvalidRequestException("FactoryModule::registerAllFactories - Required function export 'uint registerAllFactories(void)' was not found in module '" + d_moduleName + "'.");
00132 }
00133
00134 return d_regAllFunc();
00135 }
00136
00137 }