summaryrefslogtreecommitdiff
path: root/maximus/coreengine/src/Maximus.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'maximus/coreengine/src/Maximus.cpp')
-rw-r--r--maximus/coreengine/src/Maximus.cpp68
1 files changed, 45 insertions, 23 deletions
diff --git a/maximus/coreengine/src/Maximus.cpp b/maximus/coreengine/src/Maximus.cpp
index 579b20070f..044b2cc882 100644
--- a/maximus/coreengine/src/Maximus.cpp
+++ b/maximus/coreengine/src/Maximus.cpp
@@ -47,6 +47,7 @@ The original location of this file is /home/buret/eclipse/maximus/coreengine/src
#include <fstream> // for 'ofstream'
#include <getopt.h> // for 'getopt_long()'
#include <signal.h> // for 'signal()' and 'SIGINT'
+#include <algorithm> // for 'min()'
using namespace std;
// For unitary tests
@@ -67,7 +68,8 @@ Maximus * pMaximus;
Maximus::Maximus ( ):
mpCoreEngine(NULL),
mMaximusLogFile(0),
-mMaxTickValue(0)
+mMaxTickValue(0),
+mWaitTickValue(0)
{
logFunction();
@@ -162,7 +164,7 @@ void Maximus::init ( int argc, char * argv[] )
while (EOF != optionChar)
{
- optionChar = getopt_long(argc, argv, "e:s:m:l:t:d", longOptions, &optionIndex);
+ optionChar = getopt_long(argc, argv, "e:s:m:l:t:d:", longOptions, &optionIndex);
switch (optionChar)
{
@@ -244,17 +246,22 @@ void Maximus::process ( )
try
{
+ Network_Clock_Tick tickValue = 0; // tick value until which to process
+
if (0 == getMaxTickValue())
{
- getCoreEngine()->process();
+ tickValue = getWaitTickValue();
}
- else
+ else if (0 != getWaitTickValue())
{
- if (getNetworkClockProcessor()->getCurrentTickValue() < getMaxTickValue())
- {
- getCoreEngine()->process();
- }
- else
+ tickValue = min(getMaxTickValue(), getWaitTickValue());
+ }
+
+ getCoreEngine()->process(tickValue);
+
+ if (0 != getMaxTickValue())
+ {
+ if (getMaxTickValue() <= getNetworkClockProcessor()->getCurrentTickValue())
{
stop();
}
@@ -265,7 +272,6 @@ void Maximus::process ( )
e.display();
stop();
}
-
}
@@ -332,10 +338,12 @@ void Maximus::wait ( const tick_t value )
try
{
- while(getNetworkClockProcessor()->getCurrentTickValue() > value)
+ setWaitTickValue(getNetworkClockProcessor()->getCurrentTickValue() + value);
+ while (getWaitTickValue() > getNetworkClockProcessor()->getCurrentTickValue())
{
process();
}
+ setWaitTickValue(0);
}
catch ( Error &e )
{
@@ -493,6 +501,32 @@ SciServer * Maximus::getSciServer ( )
}
+Network_Clock_Tick Maximus::getMaxTickValue ( ) const
+{
+ return mMaxTickValue;
+}
+
+
+bool Maximus::setMaxTickValue ( const Network_Clock_Tick max_tick_value )
+{
+ mMaxTickValue = max_tick_value;
+ return true;
+}
+
+
+Network_Clock_Tick Maximus::getWaitTickValue ( ) const
+{
+ return mWaitTickValue;
+}
+
+
+bool Maximus::setWaitTickValue ( const Network_Clock_Tick wait_tick_value )
+{
+ mWaitTickValue = wait_tick_value;
+ return true;
+}
+
+
// public methods
//
@@ -541,15 +575,3 @@ void Maximus::stop ( )
}
}
-Network_Clock_Tick Maximus::getMaxTickValue ( ) const
-{
- return mMaxTickValue;
-}
-
-
-bool Maximus::setMaxTickValue ( const Network_Clock_Tick max_tick_value )
-{
- mMaxTickValue = max_tick_value;
- return true;
-}
-