pipe.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. ** Command & Conquer Renegade(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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /G/wwlib/PIPE.CPP $*
  25. * *
  26. * $Author:: Eric_c $*
  27. * *
  28. * $Modtime:: 4/15/99 10:15a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * Pipe::Put_To -- Connect a pipe to flow data into from this pipe. *
  35. * Pipe::Flush -- Flush all pending data out the pipe. *
  36. * Pipe::Put -- Feed some data through the pipe. *
  37. * Pipe::~Pipe -- Destructor for pipe class object. *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #include "always.h"
  40. #include "pipe.h"
  41. #include <stddef.h>
  42. //#include <string.h>
  43. /***********************************************************************************************
  44. * Pipe::~Pipe -- Destructor for pipe class object. *
  45. * *
  46. * This destructor will unlink itself from any other pipes that it may be chained to. In *
  47. * the process, it will flush any output it may have pending. *
  48. * *
  49. * INPUT: none *
  50. * *
  51. * OUTPUT: none *
  52. * *
  53. * WARNINGS: none *
  54. * *
  55. * HISTORY: *
  56. * 07/03/1996 JLB : Created. *
  57. *=============================================================================================*/
  58. Pipe::~Pipe(void)
  59. {
  60. if (ChainTo != NULL) {
  61. ChainTo->ChainFrom = ChainFrom;
  62. }
  63. if (ChainFrom != NULL) {
  64. ChainFrom->Put_To(ChainTo);
  65. }
  66. ChainFrom = NULL;
  67. ChainTo = NULL;
  68. }
  69. /***********************************************************************************************
  70. * Pipe::Put_To -- Connect a pipe to flow data into from this pipe. *
  71. * *
  72. * This routine will link two pipes together. The specified pipe will be fed data from *
  73. * this pipe. *
  74. * *
  75. * INPUT: pipe -- Pointer to the pipe that data will flow to. *
  76. * *
  77. * OUTPUT: none *
  78. * *
  79. * WARNINGS: none *
  80. * *
  81. * HISTORY: *
  82. * 07/03/1996 JLB : Created. *
  83. *=============================================================================================*/
  84. void Pipe::Put_To(Pipe * pipe)
  85. {
  86. if (ChainTo != pipe) {
  87. if (pipe != NULL && pipe->ChainFrom != NULL) {
  88. pipe->ChainFrom->Put_To(NULL);
  89. pipe->ChainFrom = NULL;
  90. }
  91. if (ChainTo != NULL) {
  92. ChainTo->ChainFrom = NULL;
  93. ChainTo->Flush();
  94. }
  95. ChainTo = pipe;
  96. if (ChainTo != NULL) {
  97. ChainTo->ChainFrom = this;
  98. }
  99. }
  100. }
  101. /***********************************************************************************************
  102. * Pipe::Put -- Feed some data through the pipe. *
  103. * *
  104. * Use this to force feed data through the pipe. It is guaranteed to accept data as fast *
  105. * as you can supply it. *
  106. * *
  107. * INPUT: source -- Pointer to the data to feed to this routine. *
  108. * *
  109. * length -- The number of bytes of data to submit. *
  110. * *
  111. * OUTPUT: Returns with the number of bytes actually output at the other far distant final *
  112. * end of the pipe. *
  113. * *
  114. * WARNINGS: none *
  115. * *
  116. * HISTORY: *
  117. * 07/03/1996 JLB : Created. *
  118. *=============================================================================================*/
  119. int Pipe::Put(void const * source, int length)
  120. {
  121. if (ChainTo != NULL) {
  122. return(ChainTo->Put(source, length));
  123. }
  124. return(length);
  125. }
  126. /***********************************************************************************************
  127. * Pipe::Flush -- Flush all pending data out the pipe. *
  128. * *
  129. * Then the pipe needs to be flushed, this routine will be called. Since pipe segments *
  130. * might have internal staging buffer for the data, this routine is necessary to force *
  131. * all staging buffers to be clear. This routine is called when the pipe is being *
  132. * destroyed. *
  133. * *
  134. * INPUT: none *
  135. * *
  136. * OUTPUT: Returns with the number of bytes output at the far distant final end of the pipe *
  137. * chain. *
  138. * *
  139. * WARNINGS: none *
  140. * *
  141. * HISTORY: *
  142. * 07/03/1996 JLB : Created. *
  143. *=============================================================================================*/
  144. int Pipe::Flush(void)
  145. {
  146. if (ChainTo != NULL) {
  147. return(ChainTo->Flush());
  148. }
  149. return(0);
  150. }