PIPE.CPP 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/PIPE.CPP 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** 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 ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : PIPE.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 06/29/96 *
  26. * *
  27. * Last Update : July 3, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * Pipe::Put_To -- Connect a pipe to flow data into from this pipe. *
  32. * Pipe::Flush -- Flush all pending data out the pipe. *
  33. * Pipe::Put -- Feed some data through the pipe. *
  34. * Pipe::~Pipe -- Destructor for pipe class object. *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #include "pipe.h"
  37. #include <stddef.h>
  38. #include <string.h>
  39. /***********************************************************************************************
  40. * Pipe::~Pipe -- Destructor for pipe class object. *
  41. * *
  42. * This destructor will unlink itself from any other pipes that it may be chained to. In *
  43. * the process, it will flush any output it may have pending. *
  44. * *
  45. * INPUT: none *
  46. * *
  47. * OUTPUT: none *
  48. * *
  49. * WARNINGS: none *
  50. * *
  51. * HISTORY: *
  52. * 07/03/1996 JLB : Created. *
  53. *=============================================================================================*/
  54. Pipe::~Pipe(void)
  55. {
  56. if (ChainTo != NULL) {
  57. ChainTo->ChainFrom = ChainFrom;
  58. }
  59. if (ChainFrom != NULL) {
  60. ChainFrom->Put_To(ChainTo);
  61. }
  62. ChainFrom = NULL;
  63. ChainTo = NULL;
  64. }
  65. /***********************************************************************************************
  66. * Pipe::Put_To -- Connect a pipe to flow data into from this pipe. *
  67. * *
  68. * This routine will link two pipes together. The specified pipe will be fed data from *
  69. * this pipe. *
  70. * *
  71. * INPUT: pipe -- Pointer to the pipe that data will flow to. *
  72. * *
  73. * OUTPUT: none *
  74. * *
  75. * WARNINGS: none *
  76. * *
  77. * HISTORY: *
  78. * 07/03/1996 JLB : Created. *
  79. *=============================================================================================*/
  80. void Pipe::Put_To(Pipe * pipe)
  81. {
  82. if (ChainTo != pipe) {
  83. if (pipe != NULL && pipe->ChainFrom != NULL) {
  84. pipe->ChainFrom->Put_To(NULL);
  85. pipe->ChainFrom = NULL;
  86. }
  87. if (ChainTo != NULL) {
  88. ChainTo->ChainFrom = NULL;
  89. ChainTo->Flush();
  90. }
  91. ChainTo = pipe;
  92. if (ChainTo != NULL) {
  93. ChainTo->ChainFrom = this;
  94. }
  95. }
  96. }
  97. /***********************************************************************************************
  98. * Pipe::Put -- Feed some data through the pipe. *
  99. * *
  100. * Use this to force feed data through the pipe. It is guaranteed to accept data as fast *
  101. * as you can supply it. *
  102. * *
  103. * INPUT: source -- Pointer to the data to feed to this routine. *
  104. * *
  105. * length -- The number of bytes of data to submit. *
  106. * *
  107. * OUTPUT: Returns with the number of bytes actually output at the other far distant final *
  108. * end of the pipe. *
  109. * *
  110. * WARNINGS: none *
  111. * *
  112. * HISTORY: *
  113. * 07/03/1996 JLB : Created. *
  114. *=============================================================================================*/
  115. int Pipe::Put(void const * source, int length)
  116. {
  117. if (ChainTo != NULL) {
  118. return(ChainTo->Put(source, length));
  119. }
  120. return(length);
  121. }
  122. /***********************************************************************************************
  123. * Pipe::Flush -- Flush all pending data out the pipe. *
  124. * *
  125. * Then the pipe needs to be flushed, this routine will be called. Since pipe segments *
  126. * might have internal staging buffer for the data, this routine is necessary to force *
  127. * all staging buffers to be clear. This routine is called when the pipe is being *
  128. * destroyed. *
  129. * *
  130. * INPUT: none *
  131. * *
  132. * OUTPUT: Returns with the number of bytes output at the far distant final end of the pipe *
  133. * chain. *
  134. * *
  135. * WARNINGS: none *
  136. * *
  137. * HISTORY: *
  138. * 07/03/1996 JLB : Created. *
  139. *=============================================================================================*/
  140. int Pipe::Flush(void)
  141. {
  142. if (ChainTo != NULL) {
  143. return(ChainTo->Flush());
  144. }
  145. return(0);
  146. }