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.

71 lines
2.2 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. //
  3. // Tier2 logging helpers. Adds support for file I/O
  4. //
  5. //===============================================================================
  6. #ifndef TIER2_LOGGING_H
  7. #define TIER2_LOGGING_H
  8. #if defined( COMPILER_MSVC )
  9. #pragma once
  10. #endif
  11. #include "logging.h"
  12. const int MAX_SIMULTANEOUS_LOGGING_FILE_COUNT = 16;
  13. const int INVALID_LOGGING_FILE_HANDLE = -1;
  14. typedef int LoggingFileHandle_t;
  15. typedef void * FileHandle_t;
  16. #define FILELOGGINGLISTENER_INTERFACE_VERSION "FileLoggingListener001"
  17. abstract_class IFileLoggingListener : public ILoggingListener
  18. {
  19. public:
  20. virtual void Log( const LoggingContext_t *pContext, const char *pMessage ) = 0;
  21. virtual LoggingFileHandle_t BeginLoggingToFile( const char *pFilename, const char *pOptions, const char *pPathID = NULL ) = 0;
  22. virtual void EndLoggingToFile( LoggingFileHandle_t fileHandle ) = 0;
  23. virtual void AssignLogChannel( LoggingChannelID_t channelID, LoggingFileHandle_t loggingFileHandle ) = 0;
  24. virtual void UnassignLogChannel( LoggingChannelID_t channelID ) = 0;
  25. virtual void AssignAllLogChannels( LoggingFileHandle_t loggingFileHandle ) = 0;
  26. virtual void UnassignAllLogChannels() = 0;
  27. };
  28. class CFileLoggingListener : public IFileLoggingListener
  29. {
  30. public:
  31. CFileLoggingListener();
  32. ~CFileLoggingListener();
  33. virtual void Log( const LoggingContext_t *pContext, const char *pMessage );
  34. virtual LoggingFileHandle_t BeginLoggingToFile( const char *pFilename, const char *pOptions, const char *pPathID = NULL );
  35. virtual void EndLoggingToFile( LoggingFileHandle_t fileHandle );
  36. virtual void AssignLogChannel( LoggingChannelID_t channelID, LoggingFileHandle_t loggingFileHandle );
  37. virtual void UnassignLogChannel( LoggingChannelID_t channelID );
  38. virtual void AssignAllLogChannels( LoggingFileHandle_t loggingFileHandle );
  39. virtual void UnassignAllLogChannels();
  40. private:
  41. int GetUnusedFileInfo() const;
  42. struct FileInfo_t
  43. {
  44. FileHandle_t m_FileHandle;
  45. bool IsOpen() const { return m_FileHandle != 0; }
  46. void Reset() { m_FileHandle = 0; }
  47. };
  48. FileInfo_t m_OpenFiles[MAX_SIMULTANEOUS_LOGGING_FILE_COUNT];
  49. // Table which maps logging channel IDs to open files
  50. int m_FileIndices[MAX_LOGGING_CHANNEL_COUNT];
  51. };
  52. #endif // TIER2_LOGGING_H