
/*****************************************************************************
 * Copyright (c) 1988-96 Digi International Inc., All Rights Reserved
 * 
 * This  software  contains  proprietary  and  confidential   information   of
 * Digi International  Inc.   By  accepting  transfer  of this copy, Recipient
 * agrees to retain this software in  confidence,  to  prevent  disclosure  to
 * others,  and  to make no  use of this software other than that for which it
 * was delivered.  This is an unpublished copyright work  Digi   International
 * Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is
 * strictly prohibited.
 * 
 * Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc.
 * Confidential  when   combined   with   the   aggregated  modules  for  this
 * product) OBJECT CODE ONLY SOURCE MATERIALS
 * 
 * (C) COPYRIGHT Digi International Inc. 1995
 * 
 * All Rights Reserved
 * 
 * US   Government   Users   Restricted   Rights   -   Use,   duplication   or
 * disclosure  restricted by GSA ADP Schedule Contract with Digi International
 * Inc.
 * 
 *****************************************************************************/

#ifndef _SOHALLOC_D
#define _SOHALLOC_D

#define SOH_STRING_BUFFER_SIZE	16

#define SOH_NDB_MIN		25
#define SOH_NDB_MAX		100


#define SOH_NDBCLASSES	10
#define SOH_DBSIZE_MIN	16
#define SOH_DBSIZE_MAX	8192

typedef struct SohDBAlloc
{
	int32 DataBsMin;
	int32 DataBsMax;
	int32 Size;
} SOHDBALLOC, *PSOHDBALLOC;

typedef struct SohAllocTable
{
	int32 QPairsMin;
	int32 QPairsMax;

	int32 StreamsMin;
	int32 StreamsMax;

	int32 MsgBsMin;
	int32 MsgBsMax;

	SOHDBALLOC aDBAlloc[SOH_NDBCLASSES];
	int32 LoPriMsgLimit;	// don't alloc if free resources below this percentage 
	int32 MedPriMsgLimit;	// don't alloc if free resources below this percentage 

	int32 BufCallMin;
	int32 BufCallMax;

	int32 TimeoutMax;

} SOHALLOCTABLE, *PSOHALLOCTABLE;

// Data Block Mins and Maxs
typedef struct SohDataBlkSizes
{

	ULONG			ulMin;
	ULONG			ulMax;

} DATABLK_SIZES, *PDATABLK_SIZES;


// prototypes

NTSTATUS 
SohAllocInit( PSOHALLOCTABLE pAlloc );

void 
SohAllocUnload( );

void
SohAllocInitTable( PSOHALLOCTABLE pAlloc,
				   ULONG ulPortCount,
				   HANDLE hParametersKey,
				   PDRIVER_OBJECT pDriverObject);

VOID 
SohLogComponentUsage(
	IN PSOHALLOCTABLE	pAlloc, 
	IN PVOID			pObject
	);

VOID 
SohLogDataBlockUsage(
	IN PSOHALLOCTABLE	pAlloc, 
	IN PVOID			pObject
	);

VOID 
SohReadMsgBlkSizes(
	IN DATABLK_SIZES	*pDataBlkSizesArray, 
	IN HANDLE			hParametersKey
	);

NTSTATUS
SohAllocGetStreams( IN PIRP pIrp
	);

NTSTATUS
SohAllocGetDataBlocks( IN PIRP pIrp
	);

#if DBG
void
SohAllocTest( PSOHALLOCTABLE pAlloc,
			  PDRIVER_OBJECT pDriverObject
	);
#endif //DBG

PMSGB allocb(int sz, int priority);
PMSGB allocm(int Priority);
PQUEUE allocq();
PSTREAM allocs();

void freeb(PMSGB pMsgB);
void freemsg(PMSGB pMsgB);
void freeq(PQUEUE pQ);
void frees(PSTREAM pStream);

int runbcq();
int bufcall( int Size, int Priority, PFI pFunc, caddr_t Arg );
void runtoq();
int timeout( PFI pFunc, caddr_t Arg, int Ticks );
void untimeout( int TimeoutId );

#endif

