COMQUEUE.CPP 44 KB

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