debug_io.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /////////////////////////////////////////////////////////////////////////EA-V1
  19. // $File: //depot/GeneralsMD/Staging/code/Libraries/Source/debug/debug_io.h $
  20. // $Author: mhoffe $
  21. // $Revision: #1 $
  22. // $DateTime: 2003/07/03 11:55:26 $
  23. //
  24. // ©2003 Electronic Arts
  25. //
  26. // Debug I/O interface
  27. //////////////////////////////////////////////////////////////////////////////
  28. #ifdef _MSC_VER
  29. # pragma once
  30. #endif
  31. #ifndef DEBUG_IO_H // Include guard
  32. #define DEBUG_IO_H
  33. /**
  34. \interface DebugIOInterface debug.h <rts/debug.h>
  35. \brief Debug I/O interface.
  36. A Debug I/O interface implementation must register itself
  37. using Debug::AddIOFactory. Typically this is done
  38. by using the \ref DEBUG_DECLARE_IO_INTERFACE and
  39. \ref DEBUG_IMPLEMENT_IO_INTERFACE macros (recommended, but
  40. not mandatory.)
  41. */
  42. class DebugIOInterface
  43. {
  44. // no copy/assign op
  45. DebugIOInterface(const &DebugIOInterface);
  46. DebugIOInterface& operator=(const DebugIOInterface&);
  47. protected:
  48. /**
  49. \brief I/O class destructor.
  50. The destructor must always be protected. Destruction is
  51. done by calling the Delete member function.
  52. */
  53. virtual ~DebugIOInterface() {}
  54. public:
  55. // interface only so no functionality here
  56. explicit DebugIOInterface(void) {}
  57. /// List of possible log string types
  58. enum StringType
  59. {
  60. /// DASSERT etc
  61. Assert = 0,
  62. /// DCHECK etc
  63. Check,
  64. /// DLOG etc
  65. Log,
  66. /// DCRASH etc
  67. Crash,
  68. /// Exception
  69. Exception,
  70. /// Regular command reply
  71. CmdReply,
  72. /// Structured command reply, see \ref debug_structcmd
  73. StructuredCmdReply,
  74. /// some other message
  75. Other,
  76. MAX
  77. };
  78. /**
  79. \brief Retrieves up to the given number of characters from a command input source.
  80. This source can be e.g. keyboard or a network pipe. This function must
  81. not block.
  82. \param buf buffer to place read characters in
  83. \param maxchar maximum number of characters to return
  84. \return numbers of characters written to buffer
  85. \note There is no terminating NUL char written to the buffer
  86. */
  87. virtual int Read(char *buf, int maxchar)=0;
  88. /**
  89. \brief Write out some characters differentiated by the log string type.
  90. \param type possible string type
  91. \param src string source, may be NULL, content depends on type:
  92. <table><tr>
  93. <td><b>type</b></td><td><b>src</b></td></tr><tr>
  94. <td>Assert</td><td>file(line)</td></tr><tr>
  95. <td>Check</td><td>file(line)</td></tr><tr>
  96. <td>Log</td><td>log group</td></tr><tr>
  97. <td>Crash</td><td>file(line)</td></tr><tr>
  98. <td>Exception</td><td>NULL</td></tr><tr>
  99. <td>CmdReply</td><td>group.command</td></tr><tr>
  100. <td>StructuredCmdReply</td><td>group.command</td></tr><tr>
  101. <td>Other</td><td>NULL</td>
  102. </tr></table>
  103. \param str string to output, NUL delimited, if NULL then simply flush
  104. output (if applicable)
  105. */
  106. virtual void Write(StringType type, const char *src, const char *str)=0;
  107. /**
  108. \brief Emergency shutdown function.
  109. This function gets called during an exception and should perform the
  110. absolute bare minimum (e.g. just flushing and closing the output file).
  111. */
  112. virtual void EmergencyFlush(void)=0;
  113. /**
  114. \brief I/O class specific command.
  115. All io \<class\> commands are passed into this function, with the
  116. exception of remove which results in simply calling the class
  117. destructor.
  118. \param dbg debug instance
  119. \param cmd command issued
  120. \param structuredCmd true if structured command reply, false if not
  121. \param argn number of additional arguments passed in
  122. \param argv argument list
  123. */
  124. virtual void Execute(class Debug& dbg, const char *cmd, bool structuredCmd,
  125. unsigned argn, const char * const * argv)=0;
  126. /**
  127. \brief Destroys the current I/O class instance.
  128. Use this function instead of just delete'ing the instance.
  129. */
  130. virtual void Delete(void)=0;
  131. };
  132. /**
  133. \addtogroup debug_io_macros Debug I/O interface helper macros
  134. */
  135. ///@{
  136. #ifdef DOXYGEN
  137. /**
  138. \brief Helper macro used in I/O class declaration to declare
  139. a factory function.
  140. \param type type name of class we're implementing
  141. \note This macro changes the access method to private.
  142. */
  143. #define DEBUG_DECLARE_IO_INTERFACE(type)
  144. /**
  145. \brief Helper macro for registering I/O class factory with
  146. the Debug module.
  147. \param io_id name of I/O class as it should be registered with Debug module
  148. (without quotes)
  149. \param descr short I/O class description
  150. \param type type name of class we're implementing
  151. */
  152. #define DEBUG_IMPLEMENT_IO_INTERFACE(io_id,descr,type)
  153. #else
  154. #define DEBUG_DECLARE_IO_INTERFACE(type) \
  155. public: \
  156. static bool __RegisterClassFactory; \
  157. static DebugIOInterface *__ClassFactory(void) { return new type; }
  158. #define DEBUG_IMPLEMENT_IO_INTERFACE(io_id,descr,type) \
  159. static bool type::__RegisterClassFactory=Debug::AddIOFactory(#io_id,descr,type::__ClassFactory);
  160. #endif
  161. ///@}
  162. #endif // DEBUG_IO_H