Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.0 KiB

  1. #include "precomp.h"
  2. #include "fsdiag.h"
  3. DEBUG_FILEZONE(ZONE_T120_MCSNC);
  4. /*
  5. * randchnl.cpp
  6. *
  7. * Copyright (c) 1995 by DataBeam Corporation, Lexington, KY
  8. *
  9. * Abstract:
  10. * This is the implementation file for the RandomChannelGenerator class,
  11. * which inherits from the RandomNumberGenerator class. On instantiation,
  12. * instances of this class will internally generate a random number which
  13. * falls within the allowable range of dynamic channels values. Channel
  14. * assignments are then generated by incrementing this value each time a
  15. * new assignment is requested. Once the maximum allowable value has been
  16. * assigned, the next value to be generated "wraps around" to the minimum
  17. * allowable value.
  18. *
  19. * Obviously, this class does not generate completely random channel
  20. * values for each request. With a completely random generator, it is
  21. * possible to delete a channel in MCS, and then have the random number
  22. * generator assign the same value as the deleted channel before all
  23. * components of the system even know that the channel was deleted to
  24. * start with, thus causing erratic behavior in the system. In this
  25. * class, no channel can be reassigned until all other possible channels
  26. * have been assigned.
  27. *
  28. * This class can be modifed in the future to incorporate additional
  29. * "randomness" into the algorithm and still not reassign any channel
  30. * numbers before all other possible values are used. This, however,
  31. * would be at the expense of performance and/or memory resources.
  32. *
  33. * Caveats:
  34. * None.
  35. *
  36. * Author:
  37. * Alan D. May
  38. */
  39. #include "randchnl.h"
  40. /*
  41. * These macros define the mimimum and maximum allowable dynamic channel
  42. * values.
  43. */
  44. #define MINIMUM_DYNAMIC_CHANNEL 1001
  45. #define MAXIMUM_DYNAMIC_CHANNEL 65535
  46. /*
  47. * RandomChannelGenerator ()
  48. *
  49. * Public
  50. *
  51. * Functional Description:
  52. * This version of the constructor is used to create a random channel
  53. * generator object that has been automatically seeded with the current
  54. * time.
  55. */
  56. RandomChannelGenerator::RandomChannelGenerator()
  57. {
  58. Current_Channel = (GetTickCount() % (MAXIMUM_DYNAMIC_CHANNEL + 1 - MINIMUM_DYNAMIC_CHANNEL)) + MINIMUM_DYNAMIC_CHANNEL;
  59. }
  60. /*
  61. * ~RandomChannelGenerator ()
  62. *
  63. * Public
  64. *
  65. * Functional Description:
  66. * This is the destructor for the RandomChannelGenerator class.
  67. */
  68. RandomChannelGenerator::~RandomChannelGenerator ()
  69. {
  70. }
  71. /*
  72. * GetRandomChannel ()
  73. *
  74. * Public
  75. *
  76. * Functional Description:
  77. * This method returns a valid dynamic channel number.
  78. */
  79. RandomValue RandomChannelGenerator::GetRandomChannel (Void)
  80. {
  81. /*
  82. * Increment the current channel value.
  83. */
  84. ++Current_Channel;
  85. /*
  86. * Determine if the current channel value needs to wrap around.
  87. */ if (Current_Channel > MAXIMUM_DYNAMIC_CHANNEL)
  88. {
  89. Current_Channel = MINIMUM_DYNAMIC_CHANNEL;
  90. }
  91. /*
  92. * Return the current channel value.
  93. */
  94. return (Current_Channel);
  95. }