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