COMQUEUE.H 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. ** Command & Conquer Red Alert(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&c0\vcs\code\comqueue.h_v 4.1 11 Apr 1996 18:26:02 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 : COMQUEUE.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 queue up outgoing messages & incoming messages, *
  36. * and serves as a storage area for various flags for ACK & Retry logic. *
  37. * It allows the application to keep track of how many messages have *
  38. * passed through this queue, in & out, so packets can use this as a *
  39. * unique ID. (If packets have a unique ID, the application can use this *
  40. * to detect re-sends.) *
  41. * *
  42. * The queues act as FIFO buffers (First-In, First-Out). The first entry *
  43. * placed in a queue is the first one read from it, and so on. The *
  44. * controlling application must ensure it places the entries on the queue *
  45. * in the order it wants to access them. *
  46. * *
  47. * The queue is implemented as an array of Queue Entries. Index 0 is the *
  48. * first element placed on the queue, and is the first retrieved. Index *
  49. * 1 is the next, and so on. When Index 0 is retrieved, the next-available*
  50. * entry becomes Index 1. The array is circular; when the end is reached, *
  51. * the indices wrap around to the beginning. *
  52. * *
  53. * The class also contains routines to maintain a cumulative response time *
  54. * for this queue. It's up to the caller to call Add_Delay() whenever *
  55. * it detects that an outgoing message has been ACK'd; this class adds *
  56. * that delay into a computed average delay over the last few message *
  57. * delays. *
  58. * *
  59. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  60. #ifndef COMQUEUE_H
  61. #define COMQUEUE_H
  62. /*---------------------------------------------------------------------------
  63. This is one output queue entry
  64. ---------------------------------------------------------------------------*/
  65. typedef struct {
  66. unsigned int IsActive : 1; // 1 = this entry is ready to be processed
  67. unsigned int IsACK : 1; // 1 = ACK received for this packet
  68. unsigned long FirstTime; // time this packet was first sent
  69. unsigned long LastTime; // time this packet was last sent
  70. unsigned long SendCount; // # of times this packet has been sent
  71. int BufLen; // size of the packet stored in this entry
  72. char *Buffer; // the data packet
  73. } SendQueueType;
  74. /*---------------------------------------------------------------------------
  75. This is one input queue entry
  76. ---------------------------------------------------------------------------*/
  77. typedef struct {
  78. unsigned int IsActive : 1; // 1 = this entry is ready to be processed
  79. unsigned int IsRead : 1; // 1 = caller has read this entry
  80. unsigned int IsACK : 1; // 1 = ACK sent for this packet
  81. int BufLen; // size of the packet stored in this entry
  82. char *Buffer; // the data packet
  83. } ReceiveQueueType;
  84. /*
  85. ***************************** Class Declaration *****************************
  86. */
  87. class CommQueueClass
  88. {
  89. /*
  90. ---------------------------- Public Interface ----------------------------
  91. */
  92. public:
  93. /*
  94. ....................... Constructor/Destructor ........................
  95. */
  96. CommQueueClass(int numsend, int numrecieve, int maxlen);
  97. virtual ~CommQueueClass();
  98. void Init(void);
  99. /*
  100. ......................... Send Queue routines .........................
  101. */
  102. int Queue_Send(void *buf, int buflen); // add to Send queue
  103. int UnQueue_Send(void *buf, int *buflen); // remove from Send queue
  104. SendQueueType * Next_Send(void); // ptr to next avail entry
  105. int Num_Send(void) {return (SendCount);} // # entries in queue
  106. int Max_Send(void) { return (MaxSend);} // max # send queue entries
  107. SendQueueType * Get_Send(int index); // random access to queue
  108. unsigned long Send_Total(void) {return (SendTotal);}
  109. /*
  110. ....................... Receive Queue routines ........................
  111. */
  112. int Queue_Receive(void *buf, int buflen); // add to Receive queue
  113. int UnQueue_Receive(void *buf, int *buflen); // remove from Receive queue
  114. ReceiveQueueType * Next_Receive(void); // ptr to next avail entry
  115. int Num_Receive(void) {return (ReceiveCount);} // # entries in queue
  116. int Max_Receive(void) { return (MaxReceive); } // max # recv queue entries
  117. ReceiveQueueType * Get_Receive(int index); // random access to queue
  118. unsigned long Receive_Total(void) {return (ReceiveTotal);}
  119. /*
  120. ....................... Response time routines ........................
  121. */
  122. void Add_Delay(unsigned long delay); // accumulates response time
  123. unsigned long Avg_Response_Time(void); // gets mean response time
  124. unsigned long Max_Response_Time(void); // gets max response time
  125. void Reset_Response_Time(void); // resets computations
  126. /*
  127. ........................ Debug output routines ........................
  128. */
  129. void Configure_Debug(int offset, int size, char **names, int maxnames);
  130. void Mono_Debug_Print(int refresh = 0);
  131. void Mono_Debug_Print2(int refresh = 0);
  132. /*
  133. --------------------------- Private Interface ----------------------------
  134. */
  135. private:
  136. /*
  137. .......................... Limiting variables .........................
  138. */
  139. int MaxSend; // max # send queue entries
  140. int MaxReceive; // max # receive queue entries
  141. int MaxPacketSize; // max size of a packet, in bytes
  142. /*
  143. ....................... Response time variables .......................
  144. */
  145. unsigned long DelaySum; // sum of last 4 delay times
  146. unsigned long NumDelay; // current # delay times summed
  147. unsigned long MeanDelay; // current average delay time
  148. unsigned long MaxDelay; // max delay ever for this queue
  149. /*
  150. ........................ Send Queue variables .........................
  151. */
  152. SendQueueType * SendQueue; // incoming packets
  153. int SendCount; // # packets in the queue
  154. int SendNext; // next entry read from queue
  155. int SendEmpty; // next empty spot in queue
  156. unsigned long SendTotal; // total # added to send queue
  157. /*
  158. ....................... Receive Queue variables .......................
  159. */
  160. ReceiveQueueType * ReceiveQueue; // outgoing packets
  161. int ReceiveCount; // # packets in the queue
  162. int ReceiveNext; // next entry read from queue
  163. int ReceiveEmpty; // next empty spot in queue
  164. unsigned long ReceiveTotal; // total # added to receive queue
  165. /*
  166. ......................... Debugging Variables .........................
  167. */
  168. int DebugOffset; // offset into app's packet for ID
  169. int DebugSize; // size of app's ID
  170. char **DebugNames; // ptr to array of app-specific names
  171. int DebugMaxNames; // max # of names in array
  172. };
  173. #endif
  174. /*************************** end of comqueue.h *****************************/