COMBUF.CPP 43 KB

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