X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fserver.cpp;h=879770c5e341f169e656f41d30d2a15ee199b43d;hb=5ebff88302017e024f6c8cc0d1b8d518d6c2070a;hp=718a0a2905f62d32fc03ef89d16a07f9509ad460;hpb=9dfae1c9b270ee369c6362903a9205b30751b95f;p=xonotic%2Fnetradiant.git diff --git a/radiant/server.cpp b/radiant/server.cpp index 718a0a29..879770c5 100644 --- a/radiant/server.cpp +++ b/radiant/server.cpp @@ -31,71 +31,61 @@ #include "modulesystem.h" -class RadiantModuleServer : public ModuleServer { - typedef std::pair ModuleType; - typedef std::pair ModuleKey; - typedef std::map Modules_; - Modules_ m_modules; - bool m_error; +class RadiantModuleServer : public ModuleServer +{ +typedef std::pair ModuleType; +typedef std::pair ModuleKey; +typedef std::map Modules_; +Modules_ m_modules; +bool m_error; public: - RadiantModuleServer() : m_error(false) - { - } - - void setError(bool error) - { - m_error = error; - } - - bool getError() const - { - return m_error; - } - - TextOutputStream &getOutputStream() - { - return globalOutputStream(); - } - - TextOutputStream &getErrorStream() - { - return globalErrorStream(); - } - - DebugMessageHandler &getDebugMessageHandler() - { - return globalDebugMessageHandler(); - } - - void registerModule(const char *type, int version, const char *name, Module &module) - { - if (!m_modules.insert(Modules_::value_type(ModuleKey(ModuleType(type, version), name), &module)).second) { - globalErrorStream() << "module already registered: type=" << makeQuoted(type) << " name=" - << makeQuoted(name) << "\n"; - } else { - globalOutputStream() << "Module Registered: type=" << makeQuoted(type) << " version=" << makeQuoted(version) - << " name=" << makeQuoted(name) << "\n"; - } - } - - Module *findModule(const char *type, int version, const char *name) const - { - Modules_::const_iterator i = m_modules.find(ModuleKey(ModuleType(type, version), name)); - if (i != m_modules.end()) { - return (*i).second; - } - return 0; - } - - void foreachModule(const char *type, int version, const Visitor &visitor) - { - for (Modules_::const_iterator i = m_modules.begin(); i != m_modules.end(); ++i) { - if (string_equal((*i).first.first.first.c_str(), type)) { - visitor.visit((*i).first.second.c_str(), *(*i).second); - } - } - } +RadiantModuleServer() : m_error( false ){ +} + +void setError( bool error ){ + m_error = error; +} +bool getError() const { + return m_error; +} + +TextOutputStream& getOutputStream(){ + return globalOutputStream(); +} +TextOutputStream& getErrorStream(){ + return globalErrorStream(); +} +DebugMessageHandler& getDebugMessageHandler(){ + return globalDebugMessageHandler(); +} + +void registerModule( const char* type, int version, const char* name, Module& module ){ + if ( !m_modules.insert( Modules_::value_type( ModuleKey( ModuleType( type, version ), name ), &module ) ).second ) { + globalErrorStream() << "module already registered: type=" << makeQuoted( type ) << " name=" << makeQuoted( name ) << "\n"; + } + else + { + globalOutputStream() << "Module Registered: type=" << makeQuoted( type ) << " version=" << makeQuoted( version ) << " name=" << makeQuoted( name ) << "\n"; + } +} + +Module* findModule( const char* type, int version, const char* name ) const { + Modules_::const_iterator i = m_modules.find( ModuleKey( ModuleType( type, version ), name ) ); + if ( i != m_modules.end() ) { + return ( *i ).second; + } + return 0; +} + +void foreachModule( const char* type, int version, const Visitor& visitor ){ + for ( Modules_::const_iterator i = m_modules.begin(); i != m_modules.end(); ++i ) + { + if ( string_equal( ( *i ).first.first.first.c_str(), type ) ) { + visitor.visit( ( *i ).first.second.c_str(), *( *i ).second ); + } + } +} }; @@ -105,18 +95,18 @@ public: const int FORMAT_BUFSIZE = 2048; const char* FormatGetLastError(){ - static char buf[FORMAT_BUFSIZE]; - FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language - buf, - FORMAT_BUFSIZE, - NULL - ); - return buf; + static char buf[FORMAT_BUFSIZE]; + FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language + buf, + FORMAT_BUFSIZE, + NULL + ); + return buf; } class DynamicLibrary @@ -126,27 +116,27 @@ public: typedef int ( __stdcall * FunctionPointer )(); DynamicLibrary( const char* filename ){ - m_library = LoadLibrary( filename ); - if ( m_library == 0 ) { - globalErrorStream() << "LoadLibrary failed: '" << filename << "'\n"; - globalErrorStream() << "GetLastError: " << FormatGetLastError(); - } + m_library = LoadLibrary( filename ); + if ( m_library == 0 ) { + globalErrorStream() << "LoadLibrary failed: '" << filename << "'\n"; + globalErrorStream() << "GetLastError: " << FormatGetLastError(); + } } ~DynamicLibrary(){ - if ( !failed() ) { - FreeLibrary( m_library ); - } + if ( !failed() ) { + FreeLibrary( m_library ); + } } bool failed(){ - return m_library == 0; + return m_library == 0; } FunctionPointer findSymbol( const char* symbol ){ - FunctionPointer address = (FunctionPointer) GetProcAddress( m_library, symbol ); - if ( address == 0 ) { - globalErrorStream() << "GetProcAddress failed: '" << symbol << "'\n"; - globalErrorStream() << "GetLastError: " << FormatGetLastError(); - } - return address; + FunctionPointer address = (FunctionPointer) GetProcAddress( m_library, symbol ); + if ( address == 0 ) { + globalErrorStream() << "GetProcAddress failed: '" << symbol << "'\n"; + globalErrorStream() << "GetLastError: " << FormatGetLastError(); + } + return address; } }; @@ -154,129 +144,116 @@ FunctionPointer findSymbol( const char* symbol ){ #include +#if GDEF_OS_MACOS +#ifndef RTLD_DEEPBIND +#define RTLD_DEEPBIND 0 +#endif // RTLD_DEEPBIND +#endif // GDEF_OS_MACOS + class DynamicLibrary { - void *m_library; + void *m_library; public: - typedef int ( *FunctionPointer )(); - - DynamicLibrary(const char *filename) - { - m_library = dlopen(filename, RTLD_NOW); - } - - ~DynamicLibrary() - { - if (!failed()) { - dlclose(m_library); - } - } - - bool failed() - { - return m_library == 0; - } - - FunctionPointer findSymbol(const char *symbol) - { - FunctionPointer p = (FunctionPointer) dlsym(m_library, symbol); - if (p == 0) { - const char *error = reinterpret_cast( dlerror()); - if (error != 0) { - globalErrorStream() << error; - } - } - return p; - } +typedef int ( *FunctionPointer )(); + +DynamicLibrary( const char* filename ){ + m_library = dlopen( filename, RTLD_NOW ); +} +~DynamicLibrary(){ + if ( !failed() ) { + dlclose( m_library ); + } +} +bool failed(){ + return m_library == 0; +} +FunctionPointer findSymbol( const char* symbol ){ + FunctionPointer p = (FunctionPointer)dlsym( m_library, symbol ); + if ( p == 0 ) { + const char* error = reinterpret_cast( dlerror() ); + if ( error != 0 ) { + globalErrorStream() << error; + } + } + return p; +} }; -#else +#else // !GDEF_OS_POSIX #error "unsupported platform" -#endif +#endif // !GDEF_OS_POSIX -class DynamicLibraryModule { - typedef void ( RADIANT_DLLIMPORT *RegisterModulesFunc )(ModuleServer &server); - - DynamicLibrary m_library; - RegisterModulesFunc m_registerModule; +class DynamicLibraryModule +{ +typedef void ( RADIANT_DLLIMPORT * RegisterModulesFunc )( ModuleServer& server ); +DynamicLibrary m_library; +RegisterModulesFunc m_registerModule; public: - DynamicLibraryModule(const char *filename) - : m_library(filename), m_registerModule(0) - { - if (!m_library.failed()) { - m_registerModule = reinterpret_cast( m_library.findSymbol("Radiant_RegisterModules")); +DynamicLibraryModule( const char* filename ) + : m_library( filename ), m_registerModule( 0 ){ + if ( !m_library.failed() ) { + m_registerModule = reinterpret_cast( m_library.findSymbol( "Radiant_RegisterModules" ) ); #if 0 - if ( !m_registerModule ) { - m_registerModule = reinterpret_cast( m_library.findSymbol( "Radiant_RegisterModules@4" ) ); - } + if ( !m_registerModule ) { + m_registerModule = reinterpret_cast( m_library.findSymbol( "Radiant_RegisterModules@4" ) ); + } #endif - } - } - - bool failed() - { - return m_registerModule == 0; - } - - void registerModules(ModuleServer &server) - { - m_registerModule(server); - } + } +} +bool failed(){ + return m_registerModule == 0; +} +void registerModules( ModuleServer& server ){ + m_registerModule( server ); +} }; -class Libraries { - typedef std::vector libraries_t; - libraries_t m_libraries; +class Libraries +{ +typedef std::vector libraries_t; +libraries_t m_libraries; public: - ~Libraries() - { - release(); - } - - void registerLibrary(const char *filename, ModuleServer &server) - { - DynamicLibraryModule *library = new DynamicLibraryModule(filename); - - if (library->failed()) { - delete library; - } else { - m_libraries.push_back(library); - library->registerModules(server); - } - } - - void release() - { - for (libraries_t::iterator i = m_libraries.begin(); i != m_libraries.end(); ++i) { - delete *i; - } - } - - void clear() - { - m_libraries.clear(); - } +~Libraries(){ + release(); +} +void registerLibrary( const char* filename, ModuleServer& server ){ + DynamicLibraryModule* library = new DynamicLibraryModule( filename ); + + if ( library->failed() ) { + delete library; + } + else + { + m_libraries.push_back( library ); + library->registerModules( server ); + } +} +void release(){ + for ( libraries_t::iterator i = m_libraries.begin(); i != m_libraries.end(); ++i ) + { + delete *i; + } +} +void clear(){ + m_libraries.clear(); +} }; Libraries g_libraries; RadiantModuleServer g_server; -ModuleServer &GlobalModuleServer_get() -{ - return g_server; +ModuleServer& GlobalModuleServer_get(){ + return g_server; } -void GlobalModuleServer_loadModule(const char *filename) -{ - g_libraries.registerLibrary(filename, g_server); +void GlobalModuleServer_loadModule( const char* filename ){ + g_libraries.registerLibrary( filename, g_server ); } -void GlobalModuleServer_Initialise() -{ +void GlobalModuleServer_Initialise(){ } -void GlobalModuleServer_Shutdown() -{ +void GlobalModuleServer_Shutdown(){ }