Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.3 KiB

  1. //===== Copyright � 1996-2009, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "mm_extensions.h"
  7. // memdbgon must be the last include file in a .cpp file!!!
  8. #include "tier0/memdbgon.h"
  9. CMatchExtensions::CMatchExtensions()
  10. {
  11. ;
  12. }
  13. CMatchExtensions::~CMatchExtensions()
  14. {
  15. ;
  16. }
  17. static CMatchExtensions g_MatchExtensions;
  18. CMatchExtensions *g_pMatchExtensions = &g_MatchExtensions;
  19. //
  20. // Implementation
  21. //
  22. void CMatchExtensions::RegisterExtensionInterface( char const *szInterfaceString, void *pvInterface )
  23. {
  24. Assert( szInterfaceString );
  25. Assert( pvInterface );
  26. if ( !szInterfaceString || !pvInterface )
  27. return;
  28. RegisteredInterface_t &rInfo = m_mapRegisteredInterfaces[ szInterfaceString ];
  29. Assert( rInfo.m_nRefCount >= 0 );
  30. if ( rInfo.m_nRefCount > 0 )
  31. {
  32. // Interface already registered
  33. Assert( pvInterface == rInfo.m_pvInterface );
  34. }
  35. else
  36. {
  37. // Fresh registration of the interface
  38. Assert( !rInfo.m_pvInterface );
  39. rInfo.m_pvInterface = pvInterface;
  40. }
  41. // Increment refcount
  42. ++ rInfo.m_nRefCount;
  43. // Fire a callback for interface registration
  44. OnExtensionInterfaceUpdated( szInterfaceString, pvInterface );
  45. }
  46. void CMatchExtensions::UnregisterExtensionInterface( char const *szInterfaceString, void *pvInterface )
  47. {
  48. Assert( szInterfaceString );
  49. Assert( pvInterface );
  50. if ( !szInterfaceString || !pvInterface )
  51. return;
  52. RegisteredInterface_t &rInfo = m_mapRegisteredInterfaces[ szInterfaceString ];
  53. Assert( rInfo.m_nRefCount > 0 );
  54. if ( rInfo.m_nRefCount <= 0 )
  55. return;
  56. Assert( pvInterface == rInfo.m_pvInterface );
  57. -- rInfo.m_nRefCount;
  58. if ( 0 == rInfo.m_nRefCount )
  59. {
  60. rInfo.m_pvInterface = NULL;
  61. OnExtensionInterfaceUpdated( szInterfaceString, NULL );
  62. }
  63. }
  64. void * CMatchExtensions::GetRegisteredExtensionInterface( char const *szInterfaceString )
  65. {
  66. RegisteredInterface_t &rInfo = m_mapRegisteredInterfaces[ szInterfaceString ];
  67. if ( rInfo.m_nRefCount > 0 && rInfo.m_pvInterface )
  68. return rInfo.m_pvInterface;
  69. else
  70. return NULL;
  71. }
  72. //
  73. // Known interfaces recognition
  74. //
  75. void CMatchExtensions::OnExtensionInterfaceUpdated( char const *szInterfaceString, void *pvInterface )
  76. {
  77. typedef void * Exts_t::* Ext_t;
  78. struct CachedInterfacePtr_t
  79. {
  80. char const *m_szName;
  81. Ext_t m_ppInterface;
  82. };
  83. static CachedInterfacePtr_t s_table[] =
  84. {
  85. { LOCALIZE_INTERFACE_VERSION, (Ext_t) &Exts_t::m_pILocalize },
  86. { INETSUPPORT_VERSION_STRING, (Ext_t) &Exts_t::m_pINetSupport },
  87. { IENGINEVOICE_INTERFACE_VERSION, (Ext_t) &Exts_t::m_pIEngineVoice },
  88. { VENGINE_CLIENT_INTERFACE_VERSION, (Ext_t) &Exts_t::m_pIVEngineClient },
  89. { INTERFACEVERSION_VENGINESERVER, (Ext_t) &Exts_t::m_pIVEngineServer },
  90. { INTERFACEVERSION_SERVERGAMEDLL, (Ext_t) &Exts_t::m_pIServerGameDLL },
  91. { INTERFACEVERSION_GAMEEVENTSMANAGER2, (Ext_t) &Exts_t::m_pIGameEventManager2 },
  92. { CLIENT_DLL_INTERFACE_VERSION, ( Ext_t ) &Exts_t::m_pIBaseClientDLL },
  93. #ifdef _X360
  94. { XBOXSYSTEM_INTERFACE_VERSION, (Ext_t) &Exts_t::m_pIXboxSystem },
  95. { XONLINE_INTERFACE_VERSION, (Ext_t) &Exts_t::m_pIXOnline },
  96. #endif
  97. { NULL, NULL }
  98. };
  99. for ( CachedInterfacePtr_t *ptr = s_table; ptr->m_szName; ++ ptr )
  100. {
  101. if ( !Q_stricmp( ptr->m_szName, szInterfaceString ) )
  102. {
  103. m_exts.*(ptr->m_ppInterface) = pvInterface;
  104. }
  105. }
  106. }