|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "timing.hpp" |
|
|
#include "timing.hpp" |
|
|
|
|
|
|
|
|
// Introduce the standard namespace //////////////////////////////////////////// |
|
|
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
namespace codedweller { |
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////// |
|
|
/////////////////////////////////////////////////////////////////////////////// |
|
|
// class Sleeper - An object that remembers how long it is supposed to sleep. |
|
|
// class Sleeper - An object that remembers how long it is supposed to sleep. |
|
|
|
|
|
|
|
|
if(x < MinimumSleeperTime || |
|
|
if(x < MinimumSleeperTime || |
|
|
x > MaximumSleeperTime) // If it's not a good time value |
|
|
x > MaximumSleeperTime) // If it's not a good time value |
|
|
throw BadSleeperValue(); // then throw the exception. |
|
|
throw BadSleeperValue(); // then throw the exception. |
|
|
MillisecondsToSleep = x; // If it is good - set it.
|
|
|
|
|
|
|
|
|
MillisecondsToSleep = x; // If it is good - set it. |
|
|
return MillisecondsToSleep; // Return the set value. |
|
|
return MillisecondsToSleep; // Return the set value. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// a natural spiral. |
|
|
// a natural spiral. |
|
|
/////////////////////////////////////////////////////////////////////////////// |
|
|
/////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
PollTimer::PollTimer(int Nom, int Max) :
|
|
|
|
|
|
NominalPollTime(MinimumSleeperTime),
|
|
|
|
|
|
|
|
|
PollTimer::PollTimer(int Nom, int Max) : |
|
|
|
|
|
NominalPollTime(MinimumSleeperTime), |
|
|
MaximumPollTime(MinimumSleeperTime) { // Construction requires a |
|
|
MaximumPollTime(MinimumSleeperTime) { // Construction requires a |
|
|
setNominalPollTime(Nom); // nominal delay to use and |
|
|
setNominalPollTime(Nom); // nominal delay to use and |
|
|
setMaximumPollTime(Max); // a maximum delay to allow. |
|
|
setMaximumPollTime(Max); // a maximum delay to allow. |
|
|
|
|
|
|
|
|
bool Timeout::isExpired() { // Return true if time is up. |
|
|
bool Timeout::isExpired() { // Return true if time is up. |
|
|
return (!(myTimer.getElapsedTime() < myDuration)); // Check the elapsed time against myDuration. |
|
|
return (!(myTimer.getElapsedTime() < myDuration)); // Check the elapsed time against myDuration. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // End namespace codedweller |