CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

COMBUF.CPP (44492B)


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