COMBUF.H 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. ** Command & Conquer(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. /* $Header: F:\projects\c&c\vcs\code\combuf.h_v 1.6 16 Oct 1995 16:46:00 JOE_BOSTIC $ */
  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. * File Name : COMBUF.H *
  26. * *
  27. * Programmer : Bill Randolph *
  28. * *
  29. * Start Date : December 19, 1994 *
  30. * *
  31. * Last Update : April 1, 1995 [BR] *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * *
  35. * This class's job is to store outgoing messages & incoming messages, *
  36. * and serves as a storage area for various flags for ACK & Retry logic. *
  37. * *
  38. * This class stores buffers in a non-sequenced order; it allows freeing *
  39. * any entry, so the buffers can be kept clear, even if packets come in *
  40. * out of order. *
  41. * *
  42. * The class also contains routines to maintain a cumulative response time *
  43. * for this queue. It's up to the caller to call Add_Delay() whenever *
  44. * it detects that an outgoing message has been ACK'd; this class adds *
  45. * that delay into a computed average delay over the last few message *
  46. * delays. *
  47. * *
  48. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  49. #ifndef COMBUF_H
  50. #define COMBUF_H
  51. /*
  52. ********************************** Defines **********************************
  53. */
  54. /*---------------------------------------------------------------------------
  55. This is one output queue entry
  56. ---------------------------------------------------------------------------*/
  57. typedef struct {
  58. unsigned int IsActive : 1; // 1 = this entry is ready to be processed
  59. unsigned int IsACK : 1; // 1 = ACK received for this packet
  60. unsigned long FirstTime; // time this packet was first sent
  61. unsigned long LastTime; // time this packet was last sent
  62. unsigned long SendCount; // # of times this packet has been sent
  63. int BufLen; // size of the packet stored in this entry
  64. char *Buffer; // the data packet
  65. } SendQueueType;
  66. /*---------------------------------------------------------------------------
  67. This is one input queue entry
  68. ---------------------------------------------------------------------------*/
  69. typedef struct {
  70. unsigned int IsActive : 1; // 1 = this entry is ready to be processed
  71. unsigned int IsRead : 1; // 1 = caller has read this entry
  72. unsigned int IsACK : 1; // 1 = ACK sent for this packet
  73. int BufLen; // size of the packet stored in this entry
  74. char *Buffer; // the data packet
  75. } ReceiveQueueType;
  76. /*
  77. ***************************** Class Declaration *****************************
  78. */
  79. class CommBufferClass
  80. {
  81. /*
  82. ---------------------------- Public Interface ----------------------------
  83. */
  84. public:
  85. /*
  86. ....................... Constructor/Destructor ........................
  87. */
  88. CommBufferClass(int numsend, int numrecieve, int maxlen);
  89. virtual ~CommBufferClass();
  90. void Init(void);
  91. void Init_Send_Queue(void);
  92. /*
  93. ......................... Send Queue routines .........................
  94. */
  95. int Queue_Send(void *buf, int buflen); // add to Send queue
  96. int UnQueue_Send(void *buf, int *buflen, int index); // remove from Send queue
  97. int Num_Send(void) {return (SendCount);} // # entries in queue
  98. int Max_Send(void) { return (MaxSend);} // max # send queue entries
  99. SendQueueType * Get_Send(int index); // random access to queue
  100. unsigned long Send_Total(void) {return (SendTotal);}
  101. /*
  102. ....................... Receive Queue routines ........................
  103. */
  104. int Queue_Receive(void *buf, int buflen); // add to Receive queue
  105. int UnQueue_Receive(void *buf, int *buflen, int index); // remove from Receive queue
  106. int Num_Receive(void) {return (ReceiveCount);} // # entries in queue
  107. int Max_Receive(void) { return (MaxReceive); } // max # recv queue entries
  108. ReceiveQueueType * Get_Receive(int index); // random access to queue
  109. unsigned long Receive_Total(void) {return (ReceiveTotal);}
  110. /*
  111. ....................... Response time routines ........................
  112. */
  113. void Add_Delay(unsigned long delay); // accumulates response time
  114. unsigned long Avg_Response_Time(void); // gets mean response time
  115. unsigned long Max_Response_Time(void); // gets max response time
  116. void Reset_Response_Time(void); // resets computations
  117. /*
  118. ........................ Debug output routines ........................
  119. */
  120. void Configure_Debug(int offset, int size, char **names, int maxnames);
  121. void Mono_Debug_Print(int refresh = 0);
  122. void Mono_Debug_Print2(int refresh = 0);
  123. /*
  124. --------------------------- Private Interface ----------------------------
  125. */
  126. private:
  127. /*
  128. .......................... Limiting variables .........................
  129. */
  130. int MaxSend; // max # send queue entries
  131. int MaxReceive; // max # receive queue entries
  132. int MaxPacketSize; // max size of a packet, in bytes
  133. /*
  134. ....................... Response time variables .......................
  135. */
  136. unsigned long DelaySum; // sum of last 4 delay times
  137. unsigned long NumDelay; // current # delay times summed
  138. unsigned long MeanDelay; // current average delay time
  139. unsigned long MaxDelay; // max delay ever for this queue
  140. /*
  141. ........................ Send Queue variables .........................
  142. */
  143. SendQueueType * SendQueue; // incoming packets
  144. int SendCount; // # packets in the queue
  145. unsigned long SendTotal; // total # added to send queue
  146. int *SendIndex; // array of Send entry indices
  147. /*
  148. ....................... Receive Queue variables .......................
  149. */
  150. ReceiveQueueType * ReceiveQueue; // outgoing packets
  151. int ReceiveCount; // # packets in the queue
  152. unsigned long ReceiveTotal; // total # added to receive queue
  153. int *ReceiveIndex; // array of Receive entry indices
  154. /*
  155. ......................... Debugging Variables .........................
  156. */
  157. int DebugOffset; // offset into app's packet for ID
  158. int DebugSize; // size of app's ID
  159. char **DebugNames; // ptr to array of app-specific names
  160. int DebugMaxNames; // max # of names in array
  161. };
  162. #endif
  163. /**************************** end of combuf.h ******************************/