COMQUEUE.H 8.8 KB

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