Team Fortress 2 Source Code as on 22/4/2020
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.

181 lines
6.4 KiB

  1. //====== Copyright �, Valve Corporation, All rights reserved. =================
  2. //
  3. // Purpose: Defines the GC interface exposed to the host
  4. //
  5. //=============================================================================
  6. #ifndef GCINTERFACE_H
  7. #define GCINTERFACE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "gamecoordinator/igamecoordinator.h"
  12. #include "gamecoordinator/igamecoordinatorhost.h"
  13. namespace GCSDK
  14. {
  15. class CGCDirProcess;
  16. class CGCBase;
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Defines the GC interface exposed to the host. This is here to find
  19. // out from the host which actual GC class to instantiate, and to pass through
  20. // all other calls
  21. //-----------------------------------------------------------------------------
  22. class CGCInterface : public IGameCoordinator
  23. {
  24. public:
  25. CGCInterface();
  26. ~CGCInterface();
  27. //message sources that we tag message tracking with so they can be filtered accordingly
  28. enum EMsgSource
  29. {
  30. eMsgSource_System = ( 1 << 0 ),
  31. eMsgSource_Client = ( 1 << 1 ),
  32. eMsgSource_GC = ( 1 << 2 ),
  33. };
  34. // Simple accessors
  35. IGameCoordinator *GetGC();
  36. AppId_t GetAppID() const;
  37. const char *GetDebugName() const;
  38. EUniverse GetUniverse() const;
  39. bool BIsDevMode() const;
  40. const char *GetGCDLLPath() const;
  41. //returns the process ID of the parent process, or 0 if it isn't specified
  42. HANDLE GetParentProcess() const { return m_hParentProcess; }
  43. // Exposed functions from IGameCoordinatorHost
  44. bool BProcessSystemMessage( uint32 unGCSysMsgType, const void *pubData, uint32 cubData );
  45. bool BSendMessageToClient( uint64 ullSteamID, uint32 unMsgType, const void *pubData, uint32 cubData );
  46. bool BSendMessageToGC( int iGCServerIDTarget, uint32 unMsgType, const void *pubData, uint32 cubData );
  47. void EmitSpew( const char *pchGroupName, SpewType_t spewType, int iSpewLevel, int iLevelLog, const char *pchMsg );
  48. void AsyncSQLQuery( IGCSQLQuery *pQuery, int eSchemaCatalog );
  49. void SetStartupComplete( bool bSuccess );
  50. void SetShutdownComplete();
  51. // Additional services
  52. uint64 GenerateGID();
  53. static uint32 GetGCDirIndexFromGID( GID_t gid );
  54. bool BSaveConvars();
  55. void RecordAssert( const char *pchFile, int nLine, const char *pchMessage, bool *pbShouldWriteMinidump );
  56. CSteamID ConstructSteamIDForClient( AccountID_t unAccountID ) const;
  57. // Implementation of IGameCoordinator
  58. virtual bool BAsyncInit( uint32 unAppID, const char *pchDebugName, int iGCIndex, IGameCoordinatorHost *pHost ) OVERRIDE;
  59. virtual bool BMainLoopOncePerFrame( uint64 ulLimitMicroseconds ) OVERRIDE;
  60. virtual bool BMainLoopUntilFrameCompletion( uint64 ulLimitMicroseconds ) OVERRIDE;
  61. virtual bool BAsyncShutdown() OVERRIDE;
  62. virtual void Unload() OVERRIDE;
  63. virtual void HandleMessageFromClient( uint64 ullSenderID, uint32 unMsgType, void *pubData, uint32 cubData ) OVERRIDE;
  64. virtual void HandleMessageFromSystem( uint32 unGCSysMsgType, void *pubData, uint32 cubData ) OVERRIDE;
  65. virtual void HandleMessageFromGC( int iGCServerIDSender, uint32 unMsgType, void *pubData, uint32 cubData ) OVERRIDE;
  66. // Allows temporary capturing of log spew for ease of generating alerts
  67. void StartLogCapture();
  68. void EndLogCapture();
  69. const CUtlVector<CUtlString> *GetLogCapture();
  70. void ClearLogCapture();
  71. //the current version of the GC used for reporting purposes only
  72. uint32 GetVersion() const { return m_nVersion; }
  73. const char* GetMachineName() const { return m_sMachineName; }
  74. //provides access to the name of the binary for this GC for development builds. This is blank for non-development builds
  75. const char* GetDevBinaryName() const { return m_sDevBinaryName; }
  76. //access to stats recorded about various asserts triggered in the system
  77. struct AssertInfo_t
  78. {
  79. //the line the assert fired from
  80. uint32 m_nLine;
  81. //how many actually fired and recorded
  82. uint32 m_nTotalFired;
  83. uint32 m_nTotalRecorded;
  84. //how many fired since the last clear
  85. uint32 m_nWindowFired;
  86. //the string associated with the first firing
  87. CUtlString m_sMsg;
  88. //the times we recorded last
  89. CUtlVector< RTime32 > m_vRecordTimes;
  90. };
  91. typedef CUtlDict< CUtlVector< AssertInfo_t* >* > AssertInfoDict_t;
  92. const AssertInfoDict_t& GetAssertInfo() const { return m_dictAsserts; }
  93. //called to reset the assert window, this is useful for tracking how many asserts fired within a specific time range
  94. void ClearAssertWindowCounts();
  95. //called to add a substring that console output will be filtered against. This is only intended for urgent text squelching
  96. void AddBlockEmitString( const char* pszStr, bool bBlockConsole, bool bBlockLog );
  97. void ClearBlockEmitStrings();
  98. //asserts are always rate limited. If you absolutely need to avoid that, you can use this object to force asserts to be recorded regardless of rate limiting
  99. class CDisableAssertRateLimit
  100. {
  101. public:
  102. CDisableAssertRateLimit() { s_nDisabledCount++; }
  103. ~CDisableAssertRateLimit() { s_nDisabledCount--; }
  104. static int32 s_nDisabledCount;
  105. };
  106. private:
  107. //the list of substrings we want to filter text based upon
  108. struct BlockString_t
  109. {
  110. CUtlString m_sStr;
  111. bool m_bBlockLog;
  112. bool m_bBlockConsole;
  113. };
  114. CUtlVector< BlockString_t* > m_BlockEmitStrings;
  115. //called to clear all existing assert stats
  116. void ClearAssertInfo();
  117. //this will handle loading the config file for the GC and initializing the directory, and will return the config key values
  118. //so that it can be used to load the convars from
  119. bool BReadConfigDirectory( KeyValuesAD& configValues );
  120. //handles loading in the convars from the key values loaded with BReadConfigDirectory, and will setup the convars based upon
  121. //what GC type this is
  122. bool BReadConvars( KeyValuesAD& configValues );
  123. void InitConVars( KeyValues *pkvConvars );
  124. IGameCoordinatorHost *m_pGCHost;
  125. CGCBase *m_pGC;
  126. const CGCDirProcess *m_pGCDirProcess;
  127. //the version of the GC. This is for reporting purposes only, and will be zero for development builds
  128. uint32 m_nVersion;
  129. AppId_t m_nAppID;
  130. CUtlConstString m_sDebugName;
  131. EUniverse m_eUniverse;
  132. bool m_bDevMode;
  133. CUtlConstString m_sGCDLLPath;
  134. uint64 m_ullGID;
  135. HANDLE m_hParentProcess;
  136. //all the asserts that have fired
  137. AssertInfoDict_t m_dictAsserts;
  138. CUtlVector<CUtlString> m_vecLogCapture;
  139. bool m_bLogCaptureEnabled;
  140. //the name of the binary, set for development build
  141. CUtlString m_sDevBinaryName;
  142. //the name of the machine we are running on
  143. CUtlString m_sMachineName;
  144. };
  145. extern CGCInterface *GGCInterface();
  146. } // namespace GCSDK
  147. #endif // GCINTERFACE_H