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