diff --git a/interfaces/interfaces.cpp b/interfaces/interfaces.cpp index fe25c8f6..b126ed2c 100644 --- a/interfaces/interfaces.cpp +++ b/interfaces/interfaces.cpp @@ -386,3 +386,44 @@ void ReconnectInterface(CreateInterfaceFn factory, const char *pInterfaceName) ReconnectInterface(factory, iface.m_pInterfaceName, (void **)iface.m_ppGlobal); } } + +// ------------------------------------------------------------------------------------ // +// InterfaceReg. +// ------------------------------------------------------------------------------------ // +InterfaceReg *s_pInterfaceRegs = NULL; + +InterfaceReg::InterfaceReg(InstantiateInterfaceFn fn, const char *pName) : + m_pName(pName) +{ + m_CreateFn = fn; + m_pNext = s_pInterfaceRegs; + s_pInterfaceRegs = this; +} + +// ------------------------------------------------------------------------------------ // +// CreateInterface. +// This is the primary exported function by a dll, referenced by name via dynamic binding +// that exposes an opqaue function pointer to the interface. +// ------------------------------------------------------------------------------------ // +void* CreateInterface(const char *pName, int *pReturnCode) +{ + InterfaceReg *pCur; + + for (pCur = s_pInterfaceRegs; pCur; pCur = pCur->m_pNext) + { + if (strcmp(pCur->m_pName, pName) == 0) + { + if (pReturnCode) + { + *pReturnCode = IFACE_OK; + } + return pCur->m_CreateFn(); + } + } + + if (pReturnCode) + { + *pReturnCode = IFACE_FAILED; + } + return NULL; +} diff --git a/lib/public/tier0.lib b/lib/public/tier0.lib index c10640c3..22e9e0c9 100644 Binary files a/lib/public/tier0.lib and b/lib/public/tier0.lib differ diff --git a/lib/public/vstdlib.lib b/lib/public/vstdlib.lib index d3e758eb..85b0d94d 100644 Binary files a/lib/public/vstdlib.lib and b/lib/public/vstdlib.lib differ diff --git a/lib/public/win64/tier0.lib b/lib/public/win64/tier0.lib index 67f1247b..db3dd96c 100644 Binary files a/lib/public/win64/tier0.lib and b/lib/public/win64/tier0.lib differ diff --git a/lib/public/win64/vstdlib.lib b/lib/public/win64/vstdlib.lib index 7622253c..83bfceb6 100644 Binary files a/lib/public/win64/vstdlib.lib and b/lib/public/win64/vstdlib.lib differ diff --git a/public/appframework/IAppSystem.h b/public/appframework/IAppSystem.h index e9e3e1f1..cf7ed5a2 100644 --- a/public/appframework/IAppSystem.h +++ b/public/appframework/IAppSystem.h @@ -13,7 +13,6 @@ #pragma once #endif -#include "tier1/interface.h" #include "interfaces/interfaces.h" diff --git a/public/filesystem.h b/public/filesystem.h index 6b0ce3ec..20bf2746 100644 --- a/public/filesystem.h +++ b/public/filesystem.h @@ -17,7 +17,7 @@ #include "tier0/threadtools.h" #include "tier0/memalloc.h" #include "tier0/tslist.h" -#include "tier1/interface.h" +#include "tier0/interface.h" #include "tier1/utlsymbol.h" #include "tier1/utlstring.h" //#include "tier1/functors.h" @@ -537,8 +537,8 @@ public: //-------------------------------------------------------- // load/unload modules - virtual CSysModule *LoadModule( const char *pFileName, const char *pPathID = 0, bool bValidatedDllOnly = true ) = 0; - virtual void UnloadModule( CSysModule *pModule ) = 0; + virtual HMODULE *LoadModule( const char *pFileName, const char *pPathID = 0, bool bValidatedDllOnly = true ) = 0; + virtual void UnloadModule( HMODULE *pModule ) = 0; //-------------------------------------------------------- // File searching operations diff --git a/public/interfaces/interfaces.h b/public/interfaces/interfaces.h index e8bddfa8..aec6ba06 100644 --- a/public/interfaces/interfaces.h +++ b/public/interfaces/interfaces.h @@ -12,12 +12,107 @@ #pragma once #endif +#include "tier0/interface.h" + +// All interfaces derive from this. +class IBaseInterface +{ +public: + virtual ~IBaseInterface() {} +}; + +typedef void* (*InstantiateInterfaceFn)(); + +// Used internally to register classes. +class InterfaceReg +{ +public: + InterfaceReg(InstantiateInterfaceFn fn, const char *pName); + +public: + InstantiateInterfaceFn m_CreateFn; + const char *m_pName; + + InterfaceReg *m_pNext; // For the global list. +}; + +// Use this to expose an interface that can have multiple instances. +// e.g.: +// EXPOSE_INTERFACE( CInterfaceImp, IInterface, "MyInterface001" ) +// This will expose a class called CInterfaceImp that implements IInterface (a pure class) +// clients can receive a pointer to this class by calling CreateInterface( "MyInterface001" ) +// +// In practice, the shared header file defines the interface (IInterface) and version name ("MyInterface001") +// so that each component can use these names/vtables to communicate +// +// A single class can support multiple interfaces through multiple inheritance +// +// Use this if you want to write the factory function. +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \ + static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); +#else +#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \ + namespace _SUBSYSTEM \ + { \ + static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); \ + } +#endif + +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_INTERFACE(className, interfaceName, versionName) \ + static void* __Create##className##_interface() {return static_cast( new className );} \ + static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); +#else +#define EXPOSE_INTERFACE(className, interfaceName, versionName) \ + namespace _SUBSYSTEM \ + { \ + static void* __Create##className##_interface() {return static_cast( new className );} \ + static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); \ + } +#endif + +// Use this to expose a singleton interface with a global variable you've created. +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \ + static void* __Create##className##interfaceName##_interface() {return static_cast( &globalVarName );} \ + static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); +#else +#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \ + namespace _SUBSYSTEM \ + { \ + static void* __Create##className##interfaceName##_interface() {return static_cast( &globalVarName );} \ + static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); \ + } +#endif + +// Use this to expose a singleton interface. This creates the global variable for you automatically. +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \ + static className __g_##className##_singleton; \ + EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton) +#else +#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \ + namespace _SUBSYSTEM \ + { \ + static className __g_##className##_singleton; \ + } \ + EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton) +#endif + +// interface return status +enum +{ + IFACE_OK = 0, + IFACE_FAILED +}; //----------------------------------------------------------------------------- -// Interface creation function +// This function is automatically exported and allows you to access any interfaces exposed with the above macros. +// if pReturnCode is set, it will return one of the following values (IFACE_OK, IFACE_FAILED) +// extend this for other error conditions/code //----------------------------------------------------------------------------- -typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode); - +DLL_EXPORT void* CreateInterface(const char *pName, int *pReturnCode); //----------------------------------------------------------------------------- // Macros to declare interfaces appropriate for various tiers diff --git a/public/tier0/dbg.h b/public/tier0/dbg.h index 72699fcf..2e2f68f8 100644 --- a/public/tier0/dbg.h +++ b/public/tier0/dbg.h @@ -14,6 +14,7 @@ #include "tier0/platform.h" #include "tier0/basetypes.h" +#include #include "dbgflag.h" #include "logging.h" #include @@ -231,20 +232,10 @@ PLATFORM_INTERFACE bool SetupWin32ConsoleIO(); // Legacy Logging System ////////////////////////////////////////////////////////////////////////// -// Channels which map the legacy logging system to the new system. +// Channels which map the legacy logging system to the new system. Only LOG_GENERAL exists as shared in Source 2 // Channel for all default Msg/Warning/Error commands. -DECLARE_LOGGING_CHANNEL( LOG_GENERAL ); -// Channel for all asserts. -DECLARE_LOGGING_CHANNEL( LOG_ASSERT ); -// Channel for all ConMsg and ConColorMsg commands. -DECLARE_LOGGING_CHANNEL( LOG_CONSOLE ); -// Channel for all DevMsg and DevWarning commands with level < 2. -DECLARE_LOGGING_CHANNEL( LOG_DEVELOPER ); -// Channel for ConDMsg commands. -DECLARE_LOGGING_CHANNEL( LOG_DEVELOPER_CONSOLE ); -// Channel for all DevMsg and DevWarning commands with level >= 2. -DECLARE_LOGGING_CHANNEL( LOG_DEVELOPER_VERBOSE ); +PLATFORM_INTERFACE LoggingChannelID_t LOG_GENERAL; // Legacy logging functions @@ -252,21 +243,15 @@ PLATFORM_INTERFACE void Msg( const tchar* pMsg, ... ); PLATFORM_INTERFACE void Warning( const tchar *pMsg, ... ) FMTFUNCTION( 1, 2 ); PLATFORM_INTERFACE void Warning_SpewCallStack( int iMaxCallStackLength, const tchar *pMsg, ... ) FMTFUNCTION( 2, 3 ); -// This is gone in Source2. Provide helper to roughyl mimic Source1 behavior -void Error( const tchar *pMsg, ... ) FMTFUNCTION( 1, 2 ); -inline void Error( const tchar *pMsg, ... ) +// This is gone in Source2. Provide helper to roughly mimic Source1 behavior +inline void Error( const tchar* pMsg, ... ) FMTFUNCTION( 1, 2 ) { - char szBuf[256]; - va_list arg_ptr; - - va_start(arg_ptr, pMsg); - vsnprintf(szBuf, sizeof(szBuf)-1, pMsg, arg_ptr); - va_end(arg_ptr); - - szBuf[sizeof(szBuf)-1] = 0; - - Msg("%s", szBuf); - Plat_ExitProcess(1); + static char szBuffer[MAX_LOGGING_MESSAGE_LENGTH]; + va_list params; + va_start(params, pMsg); + V_vsnprintf(szBuffer, sizeof(szBuffer), pMsg, params); + va_end(params); + LoggingSystem_LogDirect(LOG_GENERAL, LS_ERROR, szBuffer); } // @TODO: these callstack spew functions are currently disabled in the new logging system. Need to add support for these if desired. diff --git a/public/tier0/interface.h b/public/tier0/interface.h new file mode 100644 index 00000000..18cc8e9e --- /dev/null +++ b/public/tier0/interface.h @@ -0,0 +1,48 @@ +//========= Copyright ? 1996-2005, Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#pragma once + +#include "platform.h" + +#if defined( _WIN32 ) && !defined( _X360 ) +#define WIN32_LEAN_AND_MEAN +#include "windows.h" +#endif + +#if !defined COMPILER_MSVC && !defined HMODULE +#define HMODULE void * +#endif + +//----------------------------------------------------------------------------- +// Interface creation function +//----------------------------------------------------------------------------- +typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode); + +//----------------------------------------------------------------------------- +// Load & Unload should be called in exactly one place for each module +// The factory for that module should be passed on to dependent components for +// proper versioning. +//----------------------------------------------------------------------------- +PLATFORM_INTERFACE HMODULE Plat_LoadModule( const char *pModuleName ); +PLATFORM_INTERFACE void Plat_UnloadModule( HMODULE module ); + +// Determines if current process is running with any debug modules +PLATFORM_INTERFACE bool Plat_RunningWithDebugModules(); + +PLATFORM_INTERFACE HMODULE Plat_FindModuleByAddress( void *pAddress ); +PLATFORM_INTERFACE CreateInterfaceFn Plat_GetModuleInterfaceFactory( HMODULE module, int *pReturnCode = NULL ); + +// This is a helper function to load a module, get its factory, and get a specific interface. +// You are expected to free all of these things. +// Returns false and cleans up if any of the steps fail. +PLATFORM_INTERFACE bool Plat_LoadInterface( + const char *pModuleName, + const char *pInterfaceVersionName, + HMODULE *pOutModule, + void **pOutInterface ); \ No newline at end of file diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 785c0e96..dd303ef5 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -11,6 +11,8 @@ #ifdef COMPILER_MSVC #pragma once +#define WIN32_LEAN_AND_MEAN +#include #endif #if defined( _X360 ) @@ -1642,16 +1644,6 @@ FORCEINLINE uint64 RotateBitsRight64( uint64 nValue, int nRotateBits ) } #endif -#if !defined COMPILER_MSVC && !defined HMODULE -#define HMODULE void * -#endif - -typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode); -PLATFORM_INTERFACE HMODULE Plat_LoadModule( const char *pModuleName ); -PLATFORM_INTERFACE void Plat_UnloadModule( HMODULE module ); -PLATFORM_INTERFACE HMODULE Plat_FindModuleByAddress( void *pAddress ); -PLATFORM_INTERFACE CreateInterfaceFn Plat_GetModuleInterfaceFactory( HMODULE module, int *pReturnCode = NULL ); - #include "tier0/valve_on.h" #if defined(TIER0_DLL_EXPORT) diff --git a/public/tier1/datamanager.h b/public/tier1/datamanager.h index a48dfa64..932bafbe 100644 --- a/public/tier1/datamanager.h +++ b/public/tier1/datamanager.h @@ -18,6 +18,10 @@ DECLARE_HANDLE_32BIT( datamanhandle_t ); #define INVALID_MEMHANDLE (datamanhandle_t::MakeHandle(~0)) +#ifdef _WIN32 +#undef UnlockResource +#endif + class CDataManagerBase { public: diff --git a/public/tier1/interface.h b/public/tier1/interface.h deleted file mode 100644 index 089f0ffe..00000000 --- a/public/tier1/interface.h +++ /dev/null @@ -1,197 +0,0 @@ -//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -// -//=============================================================================// - -// This header defines the interface convention used in the valve engine. -// To make an interface and expose it: -// 1. The interface must be ALL pure virtuals, and have no data members. -// 2. Define a name for it. -// 3. In its implementation file, use EXPOSE_INTERFACE or EXPOSE_SINGLE_INTERFACE. - -// Versioning -// There are two versioning cases that are handled by this: -// 1. You add functions to the end of an interface, so it is binary compatible with the previous interface. In this case, -// you need two EXPOSE_INTERFACEs: one to expose your class as the old interface and one to expose it as the new interface. -// 2. You update an interface so it's not compatible anymore (but you still want to be able to expose the old interface -// for legacy code). In this case, you need to make a new version name for your new interface, and make a wrapper interface and -// expose it for the old interface. - -// Static Linking: -// Must mimic unique seperate class 'InterfaceReg' constructors per subsystem. -// Each subsystem can then import and export interfaces as expected. -// This is achieved through unique namespacing 'InterfaceReg' via symbol _SUBSYSTEM. -// Static Linking also needs to generate unique symbols per interface so as to -// provide a 'stitching' method whereby these interface symbols can be referenced -// via the lib's primary module (usually the lib's interface exposure) -// therby stitching all of that lib's code/data together for eventual final exe link inclusion. - -#ifndef INTERFACE_H -#define INTERFACE_H - -#ifdef _WIN32 -#pragma once -#endif - -#ifdef POSIX -#include // dlopen,dlclose, et al -#include - -#define GetProcAddress dlsym - -#endif - -// TODO: move interface.cpp into tier0 library. -#include "tier0/platform.h" - -// All interfaces derive from this. -class IBaseInterface -{ -public: - virtual ~IBaseInterface() {} -}; - -typedef void* (*InstantiateInterfaceFn)(); - -// Used internally to register classes. -class InterfaceReg -{ -public: - InterfaceReg(InstantiateInterfaceFn fn, const char *pName); - -public: - InstantiateInterfaceFn m_CreateFn; - const char *m_pName; - - InterfaceReg *m_pNext; // For the global list. -}; - -// Use this to expose an interface that can have multiple instances. -// e.g.: -// EXPOSE_INTERFACE( CInterfaceImp, IInterface, "MyInterface001" ) -// This will expose a class called CInterfaceImp that implements IInterface (a pure class) -// clients can receive a pointer to this class by calling CreateInterface( "MyInterface001" ) -// -// In practice, the shared header file defines the interface (IInterface) and version name ("MyInterface001") -// so that each component can use these names/vtables to communicate -// -// A single class can support multiple interfaces through multiple inheritance -// -// Use this if you want to write the factory function. -#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) -#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \ - static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); -#else -#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \ - namespace _SUBSYSTEM \ - { \ - static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); \ - } -#endif - -#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) -#define EXPOSE_INTERFACE(className, interfaceName, versionName) \ - static void* __Create##className##_interface() {return static_cast( new className );} \ - static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); -#else -#define EXPOSE_INTERFACE(className, interfaceName, versionName) \ - namespace _SUBSYSTEM \ - { \ - static void* __Create##className##_interface() {return static_cast( new className );} \ - static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); \ - } -#endif - -// Use this to expose a singleton interface with a global variable you've created. -#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) -#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \ - static void* __Create##className##interfaceName##_interface() {return static_cast( &globalVarName );} \ - static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); -#else -#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \ - namespace _SUBSYSTEM \ - { \ - static void* __Create##className##interfaceName##_interface() {return static_cast( &globalVarName );} \ - static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); \ - } -#endif - -// Use this to expose a singleton interface. This creates the global variable for you automatically. -#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) -#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \ - static className __g_##className##_singleton; \ - EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton) -#else -#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \ - namespace _SUBSYSTEM \ - { \ - static className __g_##className##_singleton; \ - } \ - EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton) -#endif - -// load/unload components -class CSysModule; - -// interface return status -enum -{ - IFACE_OK = 0, - IFACE_FAILED -}; - -//----------------------------------------------------------------------------- -// This function is automatically exported and allows you to access any interfaces exposed with the above macros. -// if pReturnCode is set, it will return one of the following values (IFACE_OK, IFACE_FAILED) -// extend this for other error conditions/code -//----------------------------------------------------------------------------- -DLL_EXPORT void* CreateInterface(const char *pName, int *pReturnCode); - -#if defined( _X360 ) -DLL_EXPORT void *CreateInterfaceThunk( const char *pName, int *pReturnCode ); -#endif - -// Determines if current process is running with any debug modules -extern bool Sys_RunningWithDebugModules(); - -// This is a helper function to load a module, get its factory, and get a specific interface. -// You are expected to free all of these things. -// Returns false and cleans up if any of the steps fail. -bool Sys_LoadInterface( - const char *pModuleName, - const char *pInterfaceVersionName, - HMODULE *pOutModule, - void **pOutInterface ); - -bool Sys_IsDebuggerPresent(); - -//----------------------------------------------------------------------------- -// Purpose: Place this as a singleton at module scope (e.g.) and use it to get the factory from the specified module name. -// -// When the singleton goes out of scope (.dll unload if at module scope), -// then it'll call Sys_UnloadModule on the module so that the refcount is decremented -// and the .dll actually can unload from memory. -//----------------------------------------------------------------------------- -class CDllDemandLoader -{ -public: - CDllDemandLoader( char const *pchModuleName ); - virtual ~CDllDemandLoader(); - CreateInterfaceFn GetFactory(); - void Unload(); - -private: - - char const *m_pchModuleName; - HMODULE m_hModule; - bool m_bLoadAttempted; -}; - - -#endif - - - diff --git a/public/unitlib/unitlib.h b/public/unitlib/unitlib.h index 9b83552f..d6426ff7 100644 --- a/public/unitlib/unitlib.h +++ b/public/unitlib/unitlib.h @@ -14,7 +14,6 @@ #endif #include "tier0/platform.h" -#include "tier1/interface.h" #include "appframework/IAppSystem.h" diff --git a/public/vstdlib/random.h b/public/vstdlib/random.h index cace9fa9..6e85a828 100644 --- a/public/vstdlib/random.h +++ b/public/vstdlib/random.h @@ -12,7 +12,6 @@ #include "vstdlib/vstdlib.h" #include "tier0/basetypes.h" #include "tier0/threadtools.h" -#include "tier1/interface.h" #define NTAB 32 diff --git a/tier1/interface.cpp b/tier1/interface.cpp deleted file mode 100644 index db20830d..00000000 --- a/tier1/interface.cpp +++ /dev/null @@ -1,207 +0,0 @@ -//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// -// -// Purpose: -// -//===========================================================================// -#if defined( _WIN32 ) && !defined( _X360 ) -#include -#endif - -#if !defined( DONT_PROTECT_FILEIO_FUNCTIONS ) -#define DONT_PROTECT_FILEIO_FUNCTIONS // for protected_things.h -#endif - -#if defined( PROTECTED_THINGS_ENABLE ) -#undef PROTECTED_THINGS_ENABLE // from protected_things.h -#endif - -#include -#include "interface.h" -#include "basetypes.h" -#include "tier0/dbg.h" -#include -#include -#include "tier1/strtools.h" -#include "tier0/icommandline.h" -#include "tier0/dbg.h" -#include "tier0/threadtools.h" -#ifdef _WIN32 -#include // getcwd -#elif defined _LINUX || defined __APPLE__ -#define _getcwd getcwd -#endif -#if defined( _X360 ) -#include "xbox/xbox_win32stubs.h" -#endif - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#if !defined COMPILER_MSVC && !defined HMODULE -#define HMODULE void * -#endif - -// ------------------------------------------------------------------------------------ // -// InterfaceReg. -// ------------------------------------------------------------------------------------ // -InterfaceReg *s_pInterfaceRegs = NULL; - -InterfaceReg::InterfaceReg( InstantiateInterfaceFn fn, const char *pName ) : - m_pName(pName) -{ - m_CreateFn = fn; - m_pNext = s_pInterfaceRegs; - s_pInterfaceRegs = this; -} - -// ------------------------------------------------------------------------------------ // -// CreateInterface. -// This is the primary exported function by a dll, referenced by name via dynamic binding -// that exposes an opqaue function pointer to the interface. -// ------------------------------------------------------------------------------------ // -void* CreateInterface( const char *pName, int *pReturnCode ) -{ - InterfaceReg *pCur; - - for (pCur=s_pInterfaceRegs; pCur; pCur=pCur->m_pNext) - { - if (strcmp(pCur->m_pName, pName) == 0) - { - if (pReturnCode) - { - *pReturnCode = IFACE_OK; - } - return pCur->m_CreateFn(); - } - } - - if (pReturnCode) - { - *pReturnCode = IFACE_FAILED; - } - return NULL; -} - - -#if defined _LINUX || defined __APPLE__ -// Linux doesn't have this function so this emulates its functionality -void *GetModuleHandle(const char *name) -{ - void *handle; - - if( name == NULL ) - { - // hmm, how can this be handled under linux.... - // is it even needed? - return NULL; - } - - if( (handle=dlopen(name, RTLD_NOW))==NULL) - { - printf("DLOPEN Error:%s\n",dlerror()); - // couldn't open this file - return NULL; - } - - // read "man dlopen" for details - // in short dlopen() inc a ref count - // so dec the ref count by performing the close - dlclose(handle); - return handle; -} -#endif - -#if defined( _WIN32 ) && !defined( _X360 ) -#define WIN32_LEAN_AND_MEAN -#include "windows.h" -#endif - -bool Sys_IsDebuggerPresent() -{ - return Plat_IsInDebugSession(); -} - -struct ThreadedLoadLibaryContext_t -{ - const char *m_pLibraryName; - HMODULE m_hLibrary; -}; - -//----------------------------------------------------------------------------- -// Purpose: get the interface for the specified module and version -// Input : -// Output : -//----------------------------------------------------------------------------- -bool Sys_LoadInterface( - const char *pModuleName, - const char *pInterfaceVersionName, - HMODULE *pOutModule, - void **pOutInterface ) -{ - HMODULE pMod = Plat_LoadModule( pModuleName ); - if ( !pMod ) - return false; - - CreateInterfaceFn fn = Plat_GetModuleInterfaceFactory( pMod ); - if ( !fn ) - { - Plat_UnloadModule( pMod ); - return false; - } - - *pOutInterface = fn( pInterfaceVersionName, NULL ); - if ( !( *pOutInterface ) ) - { - Plat_UnloadModule( pMod ); - return false; - } - - if ( pOutModule ) - *pOutModule = pMod; - - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: Place this as a singleton at module scope (e.g.) and use it to get the factory from the specified module name. -// -// When the singleton goes out of scope (.dll unload if at module scope), -// then it'll call Sys_UnloadModule on the module so that the refcount is decremented -// and the .dll actually can unload from memory. -//----------------------------------------------------------------------------- -CDllDemandLoader::CDllDemandLoader( char const *pchModuleName ) : - m_pchModuleName( pchModuleName ), - m_hModule( 0 ), - m_bLoadAttempted( false ) -{ -} - -CDllDemandLoader::~CDllDemandLoader() -{ - Unload(); -} - -CreateInterfaceFn CDllDemandLoader::GetFactory() -{ - if ( !m_hModule && !m_bLoadAttempted ) - { - m_bLoadAttempted = true; - m_hModule = Plat_LoadModule( m_pchModuleName ); - } - - if ( !m_hModule ) - { - return NULL; - } - - return Plat_GetModuleInterfaceFactory( m_hModule ); -} - -void CDllDemandLoader::Unload() -{ - if ( m_hModule ) - { - Plat_UnloadModule( m_hModule ); - m_hModule = 0; - } -} diff --git a/tier1/tier1.vcxproj b/tier1/tier1.vcxproj index be30b789..497be0cd 100644 --- a/tier1/tier1.vcxproj +++ b/tier1/tier1.vcxproj @@ -327,7 +327,6 @@ - @@ -366,7 +365,6 @@ - diff --git a/tier1/tier1.vcxproj.filters b/tier1/tier1.vcxproj.filters index 4668aac2..5f57bdbe 100644 --- a/tier1/tier1.vcxproj.filters +++ b/tier1/tier1.vcxproj.filters @@ -41,9 +41,6 @@ Source Files - - Source Files - Source Files @@ -139,9 +136,6 @@ Header Files - - Header Files - Header Files diff --git a/tier1/uniqueid.cpp b/tier1/uniqueid.cpp index 3fa2661d..feb2dc20 100644 --- a/tier1/uniqueid.cpp +++ b/tier1/uniqueid.cpp @@ -10,7 +10,7 @@ #include "tier0/platform.h" #ifdef IS_WINDOWS_PC -#include // UUIDCreate +#include // UUIDCreate #else #include "checksum_crc.h" #endif