102 lines
2.9 KiB
C++
102 lines
2.9 KiB
C++
|
#include "precomp.h"
|
||
|
#include "fsdiag.h"
|
||
|
DEBUG_FILEZONE(ZONE_T120_MCSNC);
|
||
|
/*
|
||
|
* randchnl.cpp
|
||
|
*
|
||
|
* Copyright (c) 1995 by DataBeam Corporation, Lexington, KY
|
||
|
*
|
||
|
* Abstract:
|
||
|
* This is the implementation file for the RandomChannelGenerator class,
|
||
|
* which inherits from the RandomNumberGenerator class. On instantiation,
|
||
|
* instances of this class will internally generate a random number which
|
||
|
* falls within the allowable range of dynamic channels values. Channel
|
||
|
* assignments are then generated by incrementing this value each time a
|
||
|
* new assignment is requested. Once the maximum allowable value has been
|
||
|
* assigned, the next value to be generated "wraps around" to the minimum
|
||
|
* allowable value.
|
||
|
*
|
||
|
* Obviously, this class does not generate completely random channel
|
||
|
* values for each request. With a completely random generator, it is
|
||
|
* possible to delete a channel in MCS, and then have the random number
|
||
|
* generator assign the same value as the deleted channel before all
|
||
|
* components of the system even know that the channel was deleted to
|
||
|
* start with, thus causing erratic behavior in the system. In this
|
||
|
* class, no channel can be reassigned until all other possible channels
|
||
|
* have been assigned.
|
||
|
*
|
||
|
* This class can be modifed in the future to incorporate additional
|
||
|
* "randomness" into the algorithm and still not reassign any channel
|
||
|
* numbers before all other possible values are used. This, however,
|
||
|
* would be at the expense of performance and/or memory resources.
|
||
|
*
|
||
|
* Caveats:
|
||
|
* None.
|
||
|
*
|
||
|
* Author:
|
||
|
* Alan D. May
|
||
|
*/
|
||
|
#include "randchnl.h"
|
||
|
|
||
|
/*
|
||
|
* These macros define the mimimum and maximum allowable dynamic channel
|
||
|
* values.
|
||
|
*/
|
||
|
#define MINIMUM_DYNAMIC_CHANNEL 1001
|
||
|
#define MAXIMUM_DYNAMIC_CHANNEL 65535
|
||
|
|
||
|
/*
|
||
|
* RandomChannelGenerator ()
|
||
|
*
|
||
|
* Public
|
||
|
*
|
||
|
* Functional Description:
|
||
|
* This version of the constructor is used to create a random channel
|
||
|
* generator object that has been automatically seeded with the current
|
||
|
* time.
|
||
|
*/
|
||
|
RandomChannelGenerator::RandomChannelGenerator()
|
||
|
{
|
||
|
Current_Channel = (GetTickCount() % (MAXIMUM_DYNAMIC_CHANNEL + 1 - MINIMUM_DYNAMIC_CHANNEL)) + MINIMUM_DYNAMIC_CHANNEL;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* ~RandomChannelGenerator ()
|
||
|
*
|
||
|
* Public
|
||
|
*
|
||
|
* Functional Description:
|
||
|
* This is the destructor for the RandomChannelGenerator class.
|
||
|
*/
|
||
|
RandomChannelGenerator::~RandomChannelGenerator ()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* GetRandomChannel ()
|
||
|
*
|
||
|
* Public
|
||
|
*
|
||
|
* Functional Description:
|
||
|
* This method returns a valid dynamic channel number.
|
||
|
*/
|
||
|
RandomValue RandomChannelGenerator::GetRandomChannel (Void)
|
||
|
{
|
||
|
/*
|
||
|
* Increment the current channel value.
|
||
|
*/
|
||
|
++Current_Channel;
|
||
|
|
||
|
/*
|
||
|
* Determine if the current channel value needs to wrap around.
|
||
|
*/ if (Current_Channel > MAXIMUM_DYNAMIC_CHANNEL)
|
||
|
{
|
||
|
Current_Channel = MINIMUM_DYNAMIC_CHANNEL;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Return the current channel value.
|
||
|
*/
|
||
|
return (Current_Channel);
|
||
|
}
|