COMQUEUE.CPP 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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.cpv 4.1 11 Apr 1996 18:28:16 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.CPP *
  22. * *
  23. * Programmer : Bill Randolph *
  24. * *
  25. * Start Date : December 19, 1994 *
  26. * *
  27. * Last Update : May 31, 1995 [BRR] *
  28. * *
  29. *-------------------------------------------------------------------------*
  30. * Functions: *
  31. * CommQueueClass::Add_Delay -- adds a new delay value for response time *
  32. * CommQueueClass::Avg_Response_Time -- returns average response time *
  33. * CommQueueClass::CommQueueClass -- class constructor *
  34. * CommQueueClass::Configure_Debug -- sets up special debug values *
  35. * CommQueueClass::Get_Receive -- gets ptr to queue entry *
  36. * CommQueueClass::Get_Send -- gets ptr to queue entry *
  37. * CommQueueClass::Init -- initializes this queue *
  38. * CommQueueClass::Max_Response_Time -- returns max response time *
  39. * CommQueueClass::Mono_Debug_Print -- Debug output routine *
  40. * CommQueueClass::Mono_Debug_Print2 -- Debug output; alternate format *
  41. * CommQueueClass::Next_Receive -- gets ptr to next entry in send queue *
  42. * CommQueueClass::Next_Send -- gets ptr to next entry in send queue *
  43. * CommQueueClass::Queue_Receive -- queues a received message *
  44. * CommQueueClass::Queue_Send -- queues a message for sending *
  45. * CommQueueClass::Reset_Response_Time -- resets computations *
  46. * CommQueueClass::UnQueue_Receive -- removes next entry from send queue *
  47. * CommQueueClass::UnQueue_Send -- removes next entry from send queue *
  48. * CommQueueClass::~CommQueueClass -- class destructor *
  49. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  50. #if (0)
  51. #include "function.h"
  52. /***************************************************************************
  53. * CommQueueClass::CommQueueClass -- class constructor *
  54. * *
  55. * INPUT: *
  56. * numsend # queue entries for sending *
  57. * numreceive # queue entries for receiving *
  58. * maxlen maximum desired packet length, in bytes *
  59. * *
  60. * OUTPUT: *
  61. * none. *
  62. * *
  63. * WARNINGS: *
  64. * none. *
  65. * *
  66. * HISTORY: *
  67. * 12/19/1994 BR : Created. *
  68. *=========================================================================*/
  69. CommQueueClass::CommQueueClass(int numsend, int numreceive, int maxlen)
  70. {
  71. int i;
  72. /*
  73. ** Init variables
  74. */
  75. MaxSend = numsend;
  76. MaxReceive = numreceive;
  77. MaxPacketSize = maxlen;
  78. /*
  79. ** Allocate the queue entries
  80. */
  81. SendQueue = new SendQueueType[numsend];
  82. ReceiveQueue = new ReceiveQueueType[numreceive];
  83. /*
  84. ** Allocate queue entry buffers
  85. */
  86. for (i = 0; i < MaxSend; i++) {
  87. SendQueue[i].Buffer = new char[maxlen];
  88. }
  89. for (i = 0; i < MaxReceive; i++) {
  90. ReceiveQueue[i].Buffer = new char[maxlen];
  91. }
  92. Init();
  93. }
  94. /***************************************************************************
  95. * CommQueueClass::~CommQueueClass -- class destructor *
  96. * *
  97. * INPUT: *
  98. * none. *
  99. * *
  100. * OUTPUT: *
  101. * none. *
  102. * *
  103. * WARNINGS: *
  104. * none. *
  105. * *
  106. * HISTORY: *
  107. * 12/19/1994 BR : Created. *
  108. *=========================================================================*/
  109. CommQueueClass::~CommQueueClass()
  110. {
  111. int i;
  112. /*
  113. ** Free queue entry buffers
  114. */
  115. for (i = 0; i < MaxSend; i++) {
  116. delete [] SendQueue[i].Buffer;
  117. }
  118. for (i = 0; i < MaxReceive; i++) {
  119. delete [] ReceiveQueue[i].Buffer;
  120. }
  121. delete [] SendQueue;
  122. delete [] ReceiveQueue;
  123. }
  124. /***************************************************************************
  125. * CommQueueClass::Init -- initializes this queue *
  126. * *
  127. * INPUT: *
  128. * none. *
  129. * *
  130. * OUTPUT: *
  131. * none. *
  132. * *
  133. * WARNINGS: *
  134. * none. *
  135. * *
  136. * HISTORY: *
  137. * 01/20/1995 BR : Created. *
  138. *=========================================================================*/
  139. void CommQueueClass::Init(void)
  140. {
  141. int i;
  142. /*
  143. ** Init data members
  144. */
  145. SendTotal = 0L;
  146. ReceiveTotal = 0L;
  147. DelaySum = 0L;
  148. NumDelay = 0L;
  149. MeanDelay = 0L;
  150. MaxDelay = 0L;
  151. SendCount = 0;
  152. SendNext = 0;
  153. SendEmpty = 0;
  154. ReceiveCount = 0;
  155. ReceiveNext = 0;
  156. ReceiveEmpty = 0;
  157. /*
  158. ** Init the queue entries
  159. */
  160. for (i = 0; i < MaxSend; i++) {
  161. SendQueue[i].IsActive = 0;
  162. SendQueue[i].IsACK = 0;
  163. SendQueue[i].FirstTime = 0L;
  164. SendQueue[i].LastTime = 0L;
  165. SendQueue[i].SendCount = 0L;
  166. ReceiveQueue[i].BufLen = 0;
  167. }
  168. for (i = 0; i < MaxReceive; i++) {
  169. ReceiveQueue[i].IsActive = 0;
  170. ReceiveQueue[i].IsRead = 0;
  171. ReceiveQueue[i].IsACK = 0;
  172. ReceiveQueue[i].BufLen = 0;
  173. }
  174. /*
  175. ** Init debug values
  176. */
  177. DebugOffset = 0;
  178. DebugSize = 0;
  179. DebugNames = NULL;
  180. DebugMaxNames = 0;
  181. }
  182. /***************************************************************************
  183. * CommQueueClass::Queue_Send -- queues a message for sending *
  184. * *
  185. * INPUT: *
  186. * buf buffer containing the message *
  187. * buflen length of 'buf' *
  188. * *
  189. * OUTPUT: *
  190. * 1 = OK, 0 = no room in the queue *
  191. * *
  192. * WARNINGS: *
  193. * none. *
  194. * *
  195. * HISTORY: *
  196. * 12/20/1994 BR : Created. *
  197. *=========================================================================*/
  198. int CommQueueClass::Queue_Send(void *buf, int buflen)
  199. {
  200. /*
  201. ** Error if no room in the queue
  202. */
  203. if (SendCount==MaxSend || SendQueue[SendEmpty].IsActive!=0) {
  204. return(0);
  205. }
  206. /*
  207. ** Set entry flags
  208. */
  209. SendQueue[SendEmpty].IsActive = 1; // entry is now active
  210. SendQueue[SendEmpty].IsACK = 0; // entry hasn't been ACK'd
  211. SendQueue[SendEmpty].FirstTime = 0L; // filled in by Manager when sent
  212. SendQueue[SendEmpty].LastTime = 0L; // filled in by Manager when sent
  213. SendQueue[SendEmpty].SendCount = 0L; // filled in by Manager when sent
  214. SendQueue[SendEmpty].BufLen = buflen; // save buffer size
  215. /*
  216. ** Copy the packet data
  217. */
  218. memcpy(SendQueue[SendEmpty].Buffer,buf,buflen);
  219. /*
  220. ** Increment counters & entry ptr
  221. */
  222. SendCount++;
  223. SendEmpty++;
  224. if (SendEmpty==MaxSend) {
  225. SendEmpty = 0;
  226. }
  227. SendTotal++;
  228. return(1);
  229. }
  230. /***************************************************************************
  231. * CommQueueClass::UnQueue_Send -- removes next entry from send queue *
  232. * *
  233. * INPUT: *
  234. * buf buffer to store entry's data in; if NULL, it's discarded *
  235. * buflen filled in with length of entry retrieved *
  236. * *
  237. * OUTPUT: *
  238. * 1 = OK, 0 = no entry to retreive *
  239. * *
  240. * WARNINGS: *
  241. * none. *
  242. * *
  243. * HISTORY: *
  244. * 12/20/1994 BR : Created. *
  245. *=========================================================================*/
  246. int CommQueueClass::UnQueue_Send(void *buf, int *buflen)
  247. {
  248. /*
  249. ** Error if no entry to retrieve
  250. */
  251. if (SendCount==0 || SendQueue[SendNext].IsActive==0) {
  252. return(0);
  253. }
  254. /*
  255. ** Copy the data from the entry
  256. */
  257. if (buf!=NULL) {
  258. memcpy(buf,SendQueue[SendNext].Buffer,SendQueue[SendNext].BufLen);
  259. (*buflen) = SendQueue[SendNext].BufLen;
  260. }
  261. /*
  262. ** Set entry flags
  263. */
  264. SendQueue[SendNext].IsActive = 0;
  265. SendQueue[SendNext].IsACK = 0;
  266. SendQueue[SendNext].FirstTime = 0L;
  267. SendQueue[SendNext].LastTime = 0L;
  268. SendQueue[SendNext].SendCount = 0L;
  269. SendQueue[SendNext].BufLen = 0;
  270. SendCount--;
  271. SendNext++;
  272. if (SendNext==MaxSend) {
  273. SendNext = 0;
  274. }
  275. return(1);
  276. }
  277. /***************************************************************************
  278. * CommQueueClass::Next_Send -- gets ptr to next entry in send queue *
  279. * *
  280. * INPUT: *
  281. * none. *
  282. * *
  283. * OUTPUT: *
  284. * ptr to entry, NULL if there is none. *
  285. * *
  286. * WARNINGS: *
  287. * none. *
  288. * *
  289. * HISTORY: *
  290. * 12/20/1994 BR : Created. *
  291. *=========================================================================*/
  292. SendQueueType * CommQueueClass::Next_Send(void)
  293. {
  294. if (SendCount==0) {
  295. return(NULL);
  296. } else {
  297. return(&SendQueue[SendNext]);
  298. }
  299. }
  300. /***************************************************************************
  301. * CommQueueClass::Get_Send -- gets ptr to queue entry *
  302. * *
  303. * This routine gets a pointer to the indicated queue entry. The index *
  304. * value is relative to the next-accessable queue entry; 0 = get the *
  305. * next available queue entry, 1 = get the one behind that, etc. *
  306. * *
  307. * INPUT: *
  308. * index index of entry to get (0 = 1st available) *
  309. * *
  310. * OUTPUT: *
  311. * ptr to entry *
  312. * *
  313. * WARNINGS: *
  314. * none. *
  315. * *
  316. * HISTORY: *
  317. * 12/21/1994 BR : Created. *
  318. *=========================================================================*/
  319. SendQueueType * CommQueueClass::Get_Send(int index)
  320. {
  321. int i;
  322. i = SendNext + index;
  323. if (i >= MaxSend) {
  324. i -= MaxSend;
  325. }
  326. if (SendQueue[i].IsActive==0) {
  327. return(NULL);
  328. } else {
  329. return(&SendQueue[i]);
  330. }
  331. }
  332. /***************************************************************************
  333. * CommQueueClass::Queue_Receive -- queues a received message *
  334. * *
  335. * INPUT: *
  336. * buf buffer containing the message *
  337. * buflen length of 'buf' *
  338. * *
  339. * OUTPUT: *
  340. * 1 = OK, 0 = no room in the queue *
  341. * *
  342. * WARNINGS: *
  343. * none. *
  344. * *
  345. * HISTORY: *
  346. * 12/20/1994 BR : Created. *
  347. *=========================================================================*/
  348. int CommQueueClass::Queue_Receive(void *buf, int buflen)
  349. {
  350. /*
  351. ** Error if no room in the queue
  352. */
  353. if (ReceiveCount==MaxReceive || ReceiveQueue[ReceiveEmpty].IsActive!=0) {
  354. return(0);
  355. }
  356. /*
  357. ** Set entry flags
  358. */
  359. ReceiveQueue[ReceiveEmpty].IsActive = 1;
  360. ReceiveQueue[ReceiveEmpty].IsRead = 0;
  361. ReceiveQueue[ReceiveEmpty].IsACK = 0;
  362. ReceiveQueue[ReceiveEmpty].BufLen = buflen;
  363. /*
  364. ** Copy the packet data
  365. */
  366. memcpy(ReceiveQueue[ReceiveEmpty].Buffer,buf,buflen);
  367. /*
  368. ** Increment counters & entry ptr
  369. */
  370. ReceiveCount++;
  371. ReceiveEmpty++;
  372. if (ReceiveEmpty==MaxReceive) {
  373. ReceiveEmpty = 0;
  374. }
  375. ReceiveTotal++;
  376. return(1);
  377. }
  378. /***************************************************************************
  379. * CommQueueClass::UnQueue_Receive -- removes next entry from send queue *
  380. * *
  381. * INPUT: *
  382. * buf buffer to store entry's data in; if NULL, it's discarded *
  383. * buflen filled in with length of entry retrieved *
  384. * *
  385. * OUTPUT: *
  386. * 1 = OK, 0 = no entry to retreive *
  387. * *
  388. * WARNINGS: *
  389. * none. *
  390. * *
  391. * HISTORY: *
  392. * 12/20/1994 BR : Created. *
  393. *=========================================================================*/
  394. int CommQueueClass::UnQueue_Receive(void *buf, int *buflen)
  395. {
  396. /*
  397. ** Error if no entry to retrieve
  398. */
  399. if (ReceiveCount==0 || ReceiveQueue[ReceiveNext].IsActive==0) {
  400. return(0);
  401. }
  402. /*
  403. ** Copy the data from the entry
  404. */
  405. if (buf!=NULL) {
  406. memcpy(buf,ReceiveQueue[ReceiveNext].Buffer,
  407. ReceiveQueue[ReceiveNext].BufLen);
  408. (*buflen) = ReceiveQueue[ReceiveNext].BufLen;
  409. }
  410. /*
  411. ** Set entry flags
  412. */
  413. ReceiveQueue[ReceiveNext].IsActive = 0;
  414. ReceiveQueue[ReceiveNext].IsRead = 0;
  415. ReceiveQueue[ReceiveNext].IsACK = 0;
  416. ReceiveQueue[ReceiveNext].BufLen = 0;
  417. ReceiveCount--;
  418. ReceiveNext++;
  419. if (ReceiveNext==MaxReceive) {
  420. ReceiveNext = 0;
  421. }
  422. return(1);
  423. }
  424. /***************************************************************************
  425. * CommQueueClass::Next_Receive -- gets ptr to next entry in send queue *
  426. * *
  427. * INPUT: *
  428. * none. *
  429. * *
  430. * OUTPUT: *
  431. * ptr to entry, NULL if there is none. *
  432. * *
  433. * WARNINGS: *
  434. * none. *
  435. * *
  436. * HISTORY: *
  437. * 12/20/1994 BR : Created. *
  438. *=========================================================================*/
  439. ReceiveQueueType * CommQueueClass::Next_Receive(void)
  440. {
  441. if (ReceiveCount==0) {
  442. return(NULL);
  443. } else {
  444. return(&ReceiveQueue[ReceiveNext]);
  445. }
  446. }
  447. /***************************************************************************
  448. * CommQueueClass::Get_Receive -- gets ptr to queue entry *
  449. * *
  450. * This routine gets a pointer to the indicated queue entry. The index *
  451. * value is relative to the next-accessable queue entry; 0 = get the *
  452. * next available queue entry, 1 = get the one behind that, etc. *
  453. * *
  454. * INPUT: *
  455. * index index of entry to get (0 = 1st available) *
  456. * *
  457. * OUTPUT: *
  458. * ptr to entry *
  459. * *
  460. * WARNINGS: *
  461. * none. *
  462. * *
  463. * HISTORY: *
  464. * 12/21/1994 BR : Created. *
  465. *=========================================================================*/
  466. ReceiveQueueType * CommQueueClass::Get_Receive(int index)
  467. {
  468. int i;
  469. i = ReceiveNext + index;
  470. if (i >= MaxReceive) {
  471. i -= MaxReceive;
  472. }
  473. if (ReceiveQueue[i].IsActive==0) {
  474. return(NULL);
  475. } else {
  476. return(&ReceiveQueue[i]);
  477. }
  478. }
  479. /***************************************************************************
  480. * CommQueueClass::Add_Delay -- adds a new delay value for response time *
  481. * *
  482. * This routine updates the average response time for this queue. The *
  483. * computation is based on the average of the last 'n' delay values given, *
  484. * It computes a running total of the last n delay values, then divides *
  485. * that by n to compute the average. *
  486. * *
  487. * When the number of values given exceeds the max, the mean is subtracted *
  488. * off the total, then the new value is added in. Thus, any single delay *
  489. * value will have an effect on the total that approaches 0 over time, and *
  490. * the new delay value contributes to 1/n of the mean. *
  491. * *
  492. * INPUT: *
  493. * delay value to add into the response time computation *
  494. * *
  495. * OUTPUT: *
  496. * none. *
  497. * *
  498. * WARNINGS: *
  499. * none. *
  500. * *
  501. * HISTORY: *
  502. * 01/19/1995 BR : Created. *
  503. *=========================================================================*/
  504. void CommQueueClass::Add_Delay(unsigned long delay)
  505. {
  506. int roundoff = 0;
  507. if (NumDelay==256) {
  508. DelaySum -= MeanDelay;
  509. DelaySum += delay;
  510. if ( (DelaySum & 0x00ff) > 127) {
  511. roundoff = 1;
  512. }
  513. MeanDelay = (DelaySum >> 8) + roundoff;
  514. } else {
  515. NumDelay++;
  516. DelaySum += delay;
  517. MeanDelay = DelaySum / NumDelay;
  518. }
  519. if (delay > MaxDelay) {
  520. MaxDelay = delay;
  521. }
  522. }
  523. /***************************************************************************
  524. * CommQueueClass::Avg_Response_Time -- returns average response time *
  525. * *
  526. * INPUT: *
  527. * none. *
  528. * *
  529. * OUTPUT: *
  530. * latest computed average response time *
  531. * *
  532. * WARNINGS: *
  533. * none. *
  534. * *
  535. * HISTORY: *
  536. * 01/19/1995 BR : Created. *
  537. *=========================================================================*/
  538. unsigned long CommQueueClass::Avg_Response_Time(void)
  539. {
  540. return(MeanDelay);
  541. }
  542. /***************************************************************************
  543. * CommQueueClass::Max_Response_Time -- returns max response time *
  544. * *
  545. * INPUT: *
  546. * none. *
  547. * *
  548. * OUTPUT: *
  549. * latest computed average response time *
  550. * *
  551. * WARNINGS: *
  552. * none. *
  553. * *
  554. * HISTORY: *
  555. * 01/19/1995 BR : Created. *
  556. *=========================================================================*/
  557. unsigned long CommQueueClass::Max_Response_Time(void)
  558. {
  559. return(MaxDelay);
  560. }
  561. /***************************************************************************
  562. * CommQueueClass::Reset_Response_Time -- resets computations *
  563. * *
  564. * INPUT: *
  565. * none. *
  566. * *
  567. * OUTPUT: *
  568. * none. *
  569. * *
  570. * WARNINGS: *
  571. * none. *
  572. * *
  573. * HISTORY: *
  574. * 01/19/1995 BR : Created. *
  575. *=========================================================================*/
  576. void CommQueueClass::Reset_Response_Time(void)
  577. {
  578. DelaySum = 0L;
  579. NumDelay = 0L;
  580. MeanDelay = 0L;
  581. MaxDelay = 0L;
  582. }
  583. /***************************************************************************
  584. * CommQueueClass::Configure_Debug -- sets up special debug values *
  585. * *
  586. * Mono_Debug_Print2() can look into a packet to pull out a particular *
  587. * ID, and can print both that ID and a string corresponding to *
  588. * that ID. This routine configures these values so it can find *
  589. * and decode the ID. This ID is used in addition to the normal *
  590. * CommHeaderType values. *
  591. * *
  592. * INPUT: *
  593. * offset ID's byte offset into packet *
  594. * size size of ID, in bytes; 0 if none *
  595. * names ptr to array of names; use ID as an index into this *
  596. * maxnames max # in the names array; 0 if none. *
  597. * *
  598. * OUTPUT: *
  599. * none. *
  600. * *
  601. * WARNINGS: *
  602. * Names shouldn't be longer than 12 characters. *
  603. * *
  604. * HISTORY: *
  605. * 05/31/1995 BRR : Created. *
  606. *=========================================================================*/
  607. void CommQueueClass::Configure_Debug(int offset, int size, char **names,
  608. int maxnames)
  609. {
  610. DebugOffset = offset;
  611. DebugSize = size;
  612. DebugNames = names;
  613. DebugMaxNames = maxnames;
  614. }
  615. /***************************************************************************
  616. * Mono_Debug_Print -- Debug output routine *
  617. * *
  618. * This routine leaves 5 lines at the top for the caller's use. *
  619. * *
  620. * INPUT: *
  621. * refresh 1 = clear screen & completely refresh *
  622. * *
  623. * OUTPUT: *
  624. * none. *
  625. * *
  626. * WARNINGS: *
  627. * none. *
  628. * *
  629. * HISTORY: *
  630. * 05/02/1995 BRR : Created. *
  631. *=========================================================================*/
  632. void CommQueueClass::Mono_Debug_Print(int refresh)
  633. {
  634. #ifdef WWLIB32_H
  635. int i; // loop counter
  636. static int send_col[] = {1,14,28}; // coords of send queue columns
  637. static int receive_col[] = {40,54,68}; // coords of recv queue columns
  638. int row,col; // current row,col for printing
  639. int num; // max # items to print
  640. struct CommHdr { // this mirrors the CommHeaderType
  641. unsigned short MagicNumber;
  642. unsigned char Code;
  643. unsigned long PacketID;
  644. } *hdr;
  645. /*
  646. ** If few enough entries, call the verbose debug version
  647. */
  648. if (MaxSend <= 16) {
  649. Mono_Debug_Print2(refresh);
  650. return;
  651. }
  652. /*
  653. ** Refresh the screen
  654. */
  655. if (refresh) {
  656. Mono_Clear_Screen ();
  657. Mono_Printf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n");
  658. Mono_Printf("³ ³\n");
  659. Mono_Printf("³ ³\n");
  660. Mono_Printf("³ ³\n");
  661. Mono_Printf("ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´\n");
  662. Mono_Printf("³ Send Queue ³ Receive Queue ³\n");
  663. Mono_Printf("³ ³ ³\n");
  664. Mono_Printf("³ ID Ct ACK ID Ct ACK ID Ct ACK³ ID Rd ACK ID Rd ACK ID Rd ACK³\n");
  665. Mono_Printf("³ ³ ³\n");
  666. Mono_Printf("³ ³ ³\n");
  667. Mono_Printf("³ ³ ³\n");
  668. Mono_Printf("³ ³ ³\n");
  669. Mono_Printf("³ ³ ³\n");
  670. Mono_Printf("³ ³ ³\n");
  671. Mono_Printf("³ ³ ³\n");
  672. Mono_Printf("³ ³ ³\n");
  673. Mono_Printf("³ ³ ³\n");
  674. Mono_Printf("³ ³ ³\n");
  675. Mono_Printf("³ ³ ³\n");
  676. Mono_Printf("³ ³ ³\n");
  677. Mono_Printf("³ ³ ³\n");
  678. Mono_Printf("³ ³ ³\n");
  679. Mono_Printf("³ ³ ³\n");
  680. Mono_Printf("³ ³ ³\n");
  681. Mono_Printf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");
  682. }
  683. /*
  684. ** Print Send Queue items
  685. */
  686. if (MaxSend <= 48) {
  687. num = MaxSend;
  688. } else {
  689. num = 48;
  690. }
  691. col = 0;
  692. row = 0;
  693. for (i = 0; i < MaxSend; i++) {
  694. Mono_Set_Cursor (send_col[col],row + 8);
  695. if (SendQueue[i].IsActive) {
  696. hdr = (CommHdr *)SendQueue[i].Buffer;
  697. hdr->MagicNumber = hdr->MagicNumber;
  698. hdr->Code = hdr->Code;
  699. Mono_Printf ("%4d %2d %d",hdr->PacketID, SendQueue[i].SendCount,
  700. SendQueue[i].IsACK);
  701. } else {
  702. Mono_Printf ("____ __ _ ");
  703. }
  704. row++;
  705. if (row > 15) {
  706. row = 0;
  707. col++;
  708. }
  709. }
  710. /*
  711. ** Print Receive Queue items
  712. */
  713. if (MaxReceive <= 48) {
  714. num = MaxSend;
  715. } else {
  716. num = 48;
  717. }
  718. col = 0;
  719. row = 0;
  720. for (i = 0; i < MaxReceive; i++) {
  721. Mono_Set_Cursor (receive_col[col],row + 8);
  722. if (ReceiveQueue[i].IsActive) {
  723. hdr = (CommHdr *)ReceiveQueue[i].Buffer;
  724. Mono_Printf ("%4d %d %d",hdr->PacketID, ReceiveQueue[i].IsRead,
  725. ReceiveQueue[i].IsACK);
  726. } else {
  727. Mono_Printf ("____ _ _ ");
  728. }
  729. row++;
  730. if (row > 15) {
  731. row = 0;
  732. col++;
  733. }
  734. }
  735. #else
  736. refresh = refresh;
  737. #endif
  738. }
  739. /***************************************************************************
  740. * CommQueueClass::Mono_Debug_Print2 -- Debug output; alternate format *
  741. * *
  742. * This routine prints more information than the other version; it's *
  743. * called only if the number of queue entries is small enough to support *
  744. * this format. *
  745. * *
  746. * INPUT: *
  747. * refresh 1 = clear screen & completely refresh *
  748. * *
  749. * OUTPUT: *
  750. * none. *
  751. * *
  752. * WARNINGS: *
  753. * none. *
  754. * *
  755. * HISTORY: *
  756. * 05/31/1995 BRR : Created. *
  757. *=========================================================================*/
  758. void CommQueueClass::Mono_Debug_Print2(int refresh)
  759. {
  760. #ifdef WWLIB32_H
  761. int i; // loop counter
  762. char txt[80];
  763. int val;
  764. struct CommHdr { // this mirrors the CommHeaderType
  765. unsigned short MagicNumber;
  766. unsigned char Code;
  767. unsigned long PacketID;
  768. } *hdr;
  769. /*
  770. ** Refresh the screen
  771. */
  772. if (refresh) {
  773. Mono_Clear_Screen ();
  774. Mono_Printf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n");
  775. Mono_Printf("³ ³\n");
  776. Mono_Printf("³ ³\n");
  777. Mono_Printf("³ ³\n");
  778. Mono_Printf("ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´\n");
  779. Mono_Printf("³ Send Queue ³ Receive Queue ³\n");
  780. Mono_Printf("³ ³ ³\n");
  781. Mono_Printf("³ ID Ct Type Data Name ACK ³ ID Rd Type Data Name ACK ³\n");
  782. Mono_Printf("³ ³ ³\n");
  783. Mono_Printf("³ ³ ³\n");
  784. Mono_Printf("³ ³ ³\n");
  785. Mono_Printf("³ ³ ³\n");
  786. Mono_Printf("³ ³ ³\n");
  787. Mono_Printf("³ ³ ³\n");
  788. Mono_Printf("³ ³ ³\n");
  789. Mono_Printf("³ ³ ³\n");
  790. Mono_Printf("³ ³ ³\n");
  791. Mono_Printf("³ ³ ³\n");
  792. Mono_Printf("³ ³ ³\n");
  793. Mono_Printf("³ ³ ³\n");
  794. Mono_Printf("³ ³ ³\n");
  795. Mono_Printf("³ ³ ³\n");
  796. Mono_Printf("³ ³ ³\n");
  797. Mono_Printf("³ ³ ³\n");
  798. Mono_Printf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");
  799. }
  800. /*
  801. ** Print Send Queue items
  802. */
  803. for (i = 0; i < MaxSend; i++) {
  804. Mono_Set_Cursor (1,8 + i);
  805. /*
  806. ** Print an active entry
  807. */
  808. if (SendQueue[i].IsActive) {
  809. /*
  810. ** Get header info
  811. */
  812. hdr = (CommHdr *)SendQueue[i].Buffer;
  813. hdr->MagicNumber = hdr->MagicNumber;
  814. hdr->Code = hdr->Code;
  815. sprintf(txt,"%4d %2d %-5s ",
  816. hdr->PacketID,
  817. SendQueue[i].SendCount,
  818. ConnectionClass::Command_Name(hdr->Code));
  819. /*
  820. ** Decode app's ID & its name
  821. */
  822. if (DebugSize && (DebugOffset + DebugSize) <= SendQueue[i].BufLen) {
  823. if (DebugSize==1) {
  824. val = *(SendQueue[i].Buffer + DebugOffset);
  825. } else {
  826. if (DebugSize==2) {
  827. val = *((short *)(SendQueue[i].Buffer + DebugOffset));
  828. } else {
  829. if (DebugSize==4) {
  830. val = *((int *)(SendQueue[i].Buffer + DebugOffset));
  831. }
  832. }
  833. }
  834. sprintf(txt + strlen(txt),"%4d ",val);
  835. if (DebugMaxNames && val > 0 && val < DebugMaxNames) {
  836. sprintf(txt + strlen(txt),"%-12s %x",
  837. DebugNames[val],
  838. SendQueue[i].IsACK);
  839. } else {
  840. sprintf(txt + strlen(txt)," %x",SendQueue[i].IsACK);
  841. }
  842. }
  843. } else {
  844. /*
  845. ** Entry isn't active; print blanks
  846. */
  847. Mono_Printf("____ __ _");
  848. }
  849. }
  850. /*
  851. ** Print Receive Queue items
  852. */
  853. for (i = 0; i < MaxReceive; i++) {
  854. Mono_Set_Cursor (40,8 + i);
  855. /*
  856. ** Print an active entry
  857. */
  858. if (ReceiveQueue[i].IsActive) {
  859. /*
  860. ** Get header info
  861. */
  862. hdr = (CommHdr *)ReceiveQueue[i].Buffer;
  863. hdr->MagicNumber = hdr->MagicNumber;
  864. hdr->Code = hdr->Code;
  865. sprintf(txt,"%4d %2d %-5s ",
  866. hdr->PacketID,
  867. ReceiveQueue[i].IsRead,
  868. ConnectionClass::Command_Name(hdr->Code));
  869. /*
  870. ** Decode app's ID & its name
  871. */
  872. if (DebugSize && (DebugOffset + DebugSize) <= SendQueue[i].BufLen) {
  873. if (DebugSize==1) {
  874. val = *(ReceiveQueue[i].Buffer + DebugOffset);
  875. } else {
  876. if (DebugSize==2) {
  877. val = *((short *)(ReceiveQueue[i].Buffer + DebugOffset));
  878. } else {
  879. if (DebugSize==4) {
  880. val = *((int *)(ReceiveQueue[i].Buffer + DebugOffset));
  881. }
  882. }
  883. }
  884. sprintf(txt + strlen(txt),"%4d ",val);
  885. if (DebugMaxNames && val > 0 && val < DebugMaxNames) {
  886. sprintf(txt + strlen(txt),"%-12s %x", DebugNames[val], ReceiveQueue[i].IsACK);
  887. } else {
  888. sprintf(txt + strlen(txt)," %x",ReceiveQueue[i].IsACK);
  889. }
  890. }
  891. } else {
  892. /*
  893. ** Entry isn't active; print blanks
  894. */
  895. Mono_Printf("____ __ _");
  896. }
  897. }
  898. #else
  899. refresh = refresh;
  900. #endif
  901. }
  902. #endif