This repository has been archived by the owner on Feb 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy pathCOMBUF.H
181 lines (163 loc) · 7.83 KB
/
COMBUF.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
** Command & Conquer(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* $Header: F:\projects\c&c\vcs\code\combuf.h_v 1.6 16 Oct 1995 16:46:00 JOE_BOSTIC $ */
/***************************************************************************
** 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 **
***************************************************************************
* *
* Project Name : Command & Conquer *
* *
* File Name : COMBUF.H *
* *
* Programmer : Bill Randolph *
* *
* Start Date : December 19, 1994 *
* *
* Last Update : April 1, 1995 [BR] *
* *
*-------------------------------------------------------------------------*
* *
* This class's job is to store outgoing messages & incoming messages, *
* and serves as a storage area for various flags for ACK & Retry logic. *
* *
* This class stores buffers in a non-sequenced order; it allows freeing *
* any entry, so the buffers can be kept clear, even if packets come in *
* out of order. *
* *
* The class also contains routines to maintain a cumulative response time *
* for this queue. It's up to the caller to call Add_Delay() whenever *
* it detects that an outgoing message has been ACK'd; this class adds *
* that delay into a computed average delay over the last few message *
* delays. *
* *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#ifndef COMBUF_H
#define COMBUF_H
/*
********************************** Defines **********************************
*/
/*---------------------------------------------------------------------------
This is one output queue entry
---------------------------------------------------------------------------*/
typedef struct {
unsigned int IsActive : 1; // 1 = this entry is ready to be processed
unsigned int IsACK : 1; // 1 = ACK received for this packet
unsigned long FirstTime; // time this packet was first sent
unsigned long LastTime; // time this packet was last sent
unsigned long SendCount; // # of times this packet has been sent
int BufLen; // size of the packet stored in this entry
char *Buffer; // the data packet
} SendQueueType;
/*---------------------------------------------------------------------------
This is one input queue entry
---------------------------------------------------------------------------*/
typedef struct {
unsigned int IsActive : 1; // 1 = this entry is ready to be processed
unsigned int IsRead : 1; // 1 = caller has read this entry
unsigned int IsACK : 1; // 1 = ACK sent for this packet
int BufLen; // size of the packet stored in this entry
char *Buffer; // the data packet
} ReceiveQueueType;
/*
***************************** Class Declaration *****************************
*/
class CommBufferClass
{
/*
---------------------------- Public Interface ----------------------------
*/
public:
/*
....................... Constructor/Destructor ........................
*/
CommBufferClass(int numsend, int numrecieve, int maxlen);
virtual ~CommBufferClass();
void Init(void);
void Init_Send_Queue(void);
/*
......................... Send Queue routines .........................
*/
int Queue_Send(void *buf, int buflen); // add to Send queue
int UnQueue_Send(void *buf, int *buflen, int index); // remove from Send queue
int Num_Send(void) {return (SendCount);} // # entries in queue
int Max_Send(void) { return (MaxSend);} // max # send queue entries
SendQueueType * Get_Send(int index); // random access to queue
unsigned long Send_Total(void) {return (SendTotal);}
/*
....................... Receive Queue routines ........................
*/
int Queue_Receive(void *buf, int buflen); // add to Receive queue
int UnQueue_Receive(void *buf, int *buflen, int index); // remove from Receive queue
int Num_Receive(void) {return (ReceiveCount);} // # entries in queue
int Max_Receive(void) { return (MaxReceive); } // max # recv queue entries
ReceiveQueueType * Get_Receive(int index); // random access to queue
unsigned long Receive_Total(void) {return (ReceiveTotal);}
/*
....................... Response time routines ........................
*/
void Add_Delay(unsigned long delay); // accumulates response time
unsigned long Avg_Response_Time(void); // gets mean response time
unsigned long Max_Response_Time(void); // gets max response time
void Reset_Response_Time(void); // resets computations
/*
........................ Debug output routines ........................
*/
void Configure_Debug(int offset, int size, char **names, int maxnames);
void Mono_Debug_Print(int refresh = 0);
void Mono_Debug_Print2(int refresh = 0);
/*
--------------------------- Private Interface ----------------------------
*/
private:
/*
.......................... Limiting variables .........................
*/
int MaxSend; // max # send queue entries
int MaxReceive; // max # receive queue entries
int MaxPacketSize; // max size of a packet, in bytes
/*
....................... Response time variables .......................
*/
unsigned long DelaySum; // sum of last 4 delay times
unsigned long NumDelay; // current # delay times summed
unsigned long MeanDelay; // current average delay time
unsigned long MaxDelay; // max delay ever for this queue
/*
........................ Send Queue variables .........................
*/
SendQueueType * SendQueue; // incoming packets
int SendCount; // # packets in the queue
unsigned long SendTotal; // total # added to send queue
int *SendIndex; // array of Send entry indices
/*
....................... Receive Queue variables .......................
*/
ReceiveQueueType * ReceiveQueue; // outgoing packets
int ReceiveCount; // # packets in the queue
unsigned long ReceiveTotal; // total # added to receive queue
int *ReceiveIndex; // array of Receive entry indices
/*
......................... Debugging Variables .........................
*/
int DebugOffset; // offset into app's packet for ID
int DebugSize; // size of app's ID
char **DebugNames; // ptr to array of app-specific names
int DebugMaxNames; // max # of names in array
};
#endif
/**************************** end of combuf.h ******************************/