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.

117 lines
3.1 KiB

  1. //====== Copyright � 1996-2006, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose: Command sink interface implementation.
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef CMDSINK_H
  9. #define CMDSINK_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include <stdio.h>
  14. #include <tier1/utlbuffer.h>
  15. namespace CmdSink
  16. {
  17. /*
  18. struct IResponse
  19. Interface to give back command execution results.
  20. */
  21. struct IResponse
  22. {
  23. virtual ~IResponse( void ) {}
  24. virtual void Release( void ) { delete this; }
  25. // Returns whether the command succeeded
  26. virtual bool Succeeded( void ) = 0;
  27. // If the command succeeded returns the result buffer length, otherwise zero
  28. virtual size_t GetResultBufferLen( void ) = 0;
  29. // If the command succeeded returns the result buffer base pointer, otherwise NULL
  30. virtual const void * GetResultBuffer( void ) = 0;
  31. // Returns a zero-terminated string of messages reported during command execution, or NULL if nothing was reported
  32. virtual const char * GetListing( void ) = 0;
  33. };
  34. /*
  35. Response implementation when the result should appear in
  36. one file and the listing should appear in another file.
  37. */
  38. class CResponseFiles : public IResponse
  39. {
  40. public:
  41. explicit CResponseFiles( char const *szFileResult, char const *szFileListing );
  42. ~CResponseFiles( void );
  43. public:
  44. // Returns whether the command succeeded
  45. virtual bool Succeeded( void );
  46. // If the command succeeded returns the result buffer length, otherwise zero
  47. virtual size_t GetResultBufferLen( void );
  48. // If the command succeeded returns the result buffer base pointer, otherwise NULL
  49. virtual const void * GetResultBuffer( void );
  50. // Returns a zero-terminated string of messages reported during command execution
  51. virtual const char * GetListing( void );
  52. protected:
  53. void OpenResultFile( void ); //!< Opens the result file if not open yet
  54. void ReadResultFile( void ); //!< Reads the result buffer if not read yet
  55. void ReadListingFile( void ); //!< Reads the listing buffer if not read yet
  56. protected:
  57. char m_szFileResult[MAX_PATH]; //!< Name of the result file
  58. char m_szFileListing[MAX_PATH]; //!< Name of the listing file
  59. FILE *m_fResult; //!< Result file (NULL if not open)
  60. FILE *m_fListing; //!< Listing file (NULL if not open)
  61. CUtlBuffer m_bufResult; //!< Buffer holding the result data
  62. size_t m_lenResult; //!< Result data length (0 if result not read yet)
  63. const void *m_dataResult; //!< Data buffer pointer (NULL if result not read yet)
  64. CUtlBuffer m_bufListing; //!< Buffer holding the listing
  65. const char *m_dataListing; //!< Listing buffer pointer (NULL if listing not read yet)
  66. };
  67. /*
  68. Response implementation when the result is a generic error.
  69. */
  70. class CResponseError : public IResponse
  71. {
  72. public:
  73. explicit CResponseError( void ) {}
  74. ~CResponseError( void ) {}
  75. public:
  76. virtual bool Succeeded( void ) { return false; }
  77. virtual size_t GetResultBufferLen( void ) { return 0; }
  78. virtual const void * GetResultBuffer( void ) { return NULL; }
  79. virtual const char * GetListing( void ) { return NULL; }
  80. };
  81. }; // namespace CmdSink
  82. #endif // #ifndef CMDSINK_H