summaryrefslogtreecommitdiff
path: root/maximus
diff options
context:
space:
mode:
authorburet2008-02-28 14:54:50 +0000
committerburet2008-02-28 14:54:50 +0000
commitcb888d3b0579a8729e7b7fcf66916fc71eb0fa84 (patch)
treede9c5a989a01ea1297a173c9568cdc71971ead73 /maximus
parenta91e59dd5b3dfe8613aa7df491f247fc71ea13a7 (diff)
Maximus V2: modify the Sta::set_name() method to avoid user to wait for IDLE message.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1500 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'maximus')
-rw-r--r--maximus/common/interfaces/Sta.h10
-rw-r--r--maximus/coreengine/inc/StaTest.h6
-rw-r--r--maximus/coreengine/src/Maximus.cpp4
-rw-r--r--maximus/coreengine/src/Sta.cpp122
-rw-r--r--maximus/coreengine/src/StaTest.cpp12
-rw-r--r--maximus/python/maximus/station/sta.py2
-rw-r--r--maximus/python/py/test_false_alarm.py4
-rw-r--r--maximus/python/src/interface_module.cpp2
8 files changed, 124 insertions, 38 deletions
diff --git a/maximus/common/interfaces/Sta.h b/maximus/common/interfaces/Sta.h
index 3b160fe1d5..43c9379178 100644
--- a/maximus/common/interfaces/Sta.h
+++ b/maximus/common/interfaces/Sta.h
@@ -36,6 +36,7 @@ The original location of this file is /home/buret/eclipse/maximus/common/interfa
#include <map> // for 'map'
#include <string>
+class Maximus;
class ISystem;
typedef std::map<const Sci_Msg_Station_Id, unsigned short int> StaCounter;
@@ -57,7 +58,7 @@ public:
/**
* Constructor
*/
- Sta ( ISystem * p_system_manager, const std::string & station_executable );
+ Sta ( Maximus * p_maximus, ISystem * p_system_manager, const std::string & station_executable );
/**
* Copy constructors
@@ -115,6 +116,7 @@ private:
// private attributes
//
+ Maximus * mpMaximus; // used for 'Maximus::process()' method only
ISystem * mpSystemManager;
Sci_Msg_Station_Id mStationId;
@@ -133,6 +135,12 @@ private:
//
/**
+ * Gets a pointer to Maximus.
+ * @return mpMaximus
+ */
+ Maximus * getMaximus ( ) const;
+
+ /**
* @return ISystem *
*/
ISystem * getSystemManager ( ) const;
diff --git a/maximus/coreengine/inc/StaTest.h b/maximus/coreengine/inc/StaTest.h
index 17eea026fe..10ac4e75a3 100644
--- a/maximus/coreengine/inc/StaTest.h
+++ b/maximus/coreengine/inc/StaTest.h
@@ -5,6 +5,7 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
+class Maximus;
class ISci;
class SystemManager;
class INetworkClock;
@@ -40,12 +41,13 @@ protected:
void set_name_test (void);
private:
-
+
+ Maximus * mpMaximus;
ISci * mpSci;
SystemManager * mpSystemManager;
INetworkClock * mpNetworkClock;
Sta * mpSta;
-
+
};
diff --git a/maximus/coreengine/src/Maximus.cpp b/maximus/coreengine/src/Maximus.cpp
index a824a2a36c..2216735233 100644
--- a/maximus/coreengine/src/Maximus.cpp
+++ b/maximus/coreengine/src/Maximus.cpp
@@ -397,11 +397,11 @@ Sta & Maximus::create_sta ( const string & station_executable )
{
if (!station_executable.empty())
{
- pSta = new Sta(getSystemManager(), station_executable);
+ pSta = new Sta(this, getSystemManager(), station_executable);
}
else
{
- pSta = new Sta(getSystemManager(), getSystemManager()->getDefaultStationExecutable());
+ pSta = new Sta(this, getSystemManager(), getSystemManager()->getDefaultStationExecutable());
}
if (NULL == pSta)
{
diff --git a/maximus/coreengine/src/Sta.cpp b/maximus/coreengine/src/Sta.cpp
index 0ab0bff213..86545eb75d 100644
--- a/maximus/coreengine/src/Sta.cpp
+++ b/maximus/coreengine/src/Sta.cpp
@@ -30,6 +30,7 @@ The original location of this file is /home/buret/eclipse/maximus/coreengine/src
#include "Sta.h"
+#include "Maximus.h"
#include "ISystem.h"
#include "Error.h"
@@ -46,14 +47,16 @@ using namespace std;
StaCounter Sta::mStaCounter;
-Sta::Sta ( ISystem * p_system_manager, const string & station_executable ):
+Sta::Sta ( Maximus * p_maximus, ISystem * p_system_manager, const string & station_executable ):
+mpMaximus(NULL),
mpSystemManager(NULL),
mStationId(0)
{
logFunction();
- if (NULL != p_system_manager)
+ if ( (NULL != p_maximus) && (NULL != p_system_manager) )
{
+ mpMaximus = p_maximus;
mpSystemManager = p_system_manager;
mStationId = mpSystemManager->createStation(station_executable);
mStaCounter[getStationId()] = 1;
@@ -61,7 +64,7 @@ mStationId(0)
else
{
errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "System manager pointer is NULL", errno);
+ throw Error(__PRETTY_FUNCTION__, "Maximus and/or System manager pointers are NULL", errno);
}
}
@@ -71,7 +74,8 @@ mpSystemManager(NULL),
mStationId(0)
{
logFunction();
-
+
+ mpMaximus = sta.getMaximus();
mpSystemManager = sta.getSystemManager();
mStationId = sta.getStationId();
mStaCounter[getStationId()] += 1;
@@ -83,6 +87,10 @@ Sta::~Sta ( )
logFunction();
remove();
+ if (NULL != mpMaximus)
+ {
+ mpMaximus = NULL;
+ }
if (NULL != mpSystemManager)
{
mpSystemManager = NULL;
@@ -102,26 +110,34 @@ Sta::~Sta ( )
void Sta::remove ( )
{
logFunction();
-
- if (0 == mStaCounter[getStationId()])
+
+ try
{
- if (0 == getStationId())
+ if (0 == mStaCounter[getStationId()])
{
- clog << logger(LOG_INFO) << "station already removed" << endl;
+ if (0 == getStationId())
+ {
+ clog << logger(LOG_INFO) << "station already removed" << endl;
+ }
+ else
+ {
+ throw Error(__PRETTY_FUNCTION__, "Problem while deleting station");
+ }
+ }
+ else if (1 == mStaCounter[getStationId()])
+ {
+ getSystemManager()->removeStation(getStationId());
+ resetStationId();
}
else
{
- throw Error(__PRETTY_FUNCTION__, "Problem while deleting station");
+ mStaCounter[getStationId()] -= 1;
}
}
- else if (1 == mStaCounter[getStationId()])
- {
- getSystemManager()->removeStation(getStationId());
- resetStationId();
- }
- else
+ catch (Error & e)
{
- mStaCounter[getStationId()] -= 1;
+ e.display();
+ getMaximus()->stop();
}
}
@@ -129,32 +145,67 @@ void Sta::remove ( )
void Sta::deactivate ( )
{
logFunction();
-
- getSystemManager()->deactivateStation(getStationId());
+
+ try
+ {
+ getSystemManager()->deactivateStation(getStationId());
+ }
+ catch (Error & e)
+ {
+ e.display();
+ getMaximus()->stop();
+ }
}
void Sta::activate ( )
{
logFunction();
-
- getSystemManager()->activateStation(getStationId());
+
+ try
+ {
+ getSystemManager()->activateStation(getStationId());
+ }
+ catch (Error & e)
+ {
+ e.display();
+ getMaximus()->stop();
+ }
}
void Sta::debug ( )
{
logFunction();
-
- getSystemManager()->debugStation(getStationId());
+
+ try
+ {
+ getSystemManager()->debugStation(getStationId());
+ }
+ catch (Error & e)
+ {
+ e.display();
+ getMaximus()->stop();
+ }
}
const bool Sta::is_idle ( ) const
{
logFunction();
+ bool isIdle = false;
+
+ try
+ {
+ isIdle = getSystemManager()->isStationIdle(getStationId());
+ }
+ catch (Error & e)
+ {
+ e.display();
+ getMaximus()->stop();
+ }
- return getSystemManager()->isStationIdle(getStationId());
+ return isIdle;
}
@@ -162,7 +213,19 @@ void Sta::set_name ( const std::string & station_name )
{
logFunction();
- getSystemManager()->setStationName(getStationId(), station_name);
+ try
+ {
+ while (!is_idle())
+ {
+ getMaximus()->process();
+ }
+ getSystemManager()->setStationName(getStationId(), station_name);
+ }
+ catch (Error & e)
+ {
+ e.display();
+ getMaximus()->stop();
+ }
}
@@ -174,6 +237,17 @@ void Sta::set_name ( const std::string & station_name )
//
+Maximus * Sta::getMaximus ( ) const
+{
+ if (NULL == mpMaximus)
+ {
+ throw Error(__PRETTY_FUNCTION__, "Maximus pointer is NULL");
+ }
+
+ return mpMaximus;
+}
+
+
ISystem * Sta::getSystemManager ( ) const
{
if (NULL == mpSystemManager)
diff --git a/maximus/coreengine/src/StaTest.cpp b/maximus/coreengine/src/StaTest.cpp
index 820c4ff2ad..5294e0b292 100644
--- a/maximus/coreengine/src/StaTest.cpp
+++ b/maximus/coreengine/src/StaTest.cpp
@@ -2,6 +2,7 @@
#include "StaTest.h"
#include "Sta.h"
+#include "Maximus.h"
#include "SystemManager.h"
#include "SciServer.h"
#include "NetworkClockProcessor.h"
@@ -17,12 +18,13 @@ CPPUNIT_TEST_SUITE_REGISTRATION (StaTest);
void StaTest::setUp (void)
{
logTest();
-
+
+ mpMaximus = new Maximus();
mpSci = new SciServer();
mpSystemManager = new SystemManager(mpSci);
mpNetworkClock = new NetworkClockProcessor();
mpSystemManager->setNetworkClock(mpNetworkClock);
- mpSta = new Sta (mpSystemManager, mpSystemManager->getDefaultStationExecutable());
+ mpSta = new Sta (mpMaximus, mpSystemManager, mpSystemManager->getDefaultStationExecutable());
}
@@ -35,6 +37,11 @@ void StaTest::tearDown (void)
delete (mpSta);
mpSta = NULL;
}
+ if (NULL != mpMaximus)
+ {
+ delete (mpMaximus);
+ mpMaximus = NULL;
+ }
if (NULL != mpSystemManager)
{
delete (mpSystemManager);
@@ -167,6 +174,7 @@ void StaTest::set_name_test (void)
if (NULL != mpSta)
{
+ mpSystemManager->updateStationStatus(mpSta->getStationId(), MAXIMUS_STATION_STATUS_IDLE);
mpSta->set_name("station name");
}
else
diff --git a/maximus/python/maximus/station/sta.py b/maximus/python/maximus/station/sta.py
index 491e656fc0..0e1e56f0c6 100644
--- a/maximus/python/maximus/station/sta.py
+++ b/maximus/python/maximus/station/sta.py
@@ -176,8 +176,6 @@ class STA:
# Configure the station name
if self.get_name() is not None:
- while not self.is_idle():
- self.__get_maximus().process()
self.get().set_name(name)
def set_mme_buffer_nb(self, mme_buffer_nb):
diff --git a/maximus/python/py/test_false_alarm.py b/maximus/python/py/test_false_alarm.py
index a3c259ef95..876c5cc3aa 100644
--- a/maximus/python/py/test_false_alarm.py
+++ b/maximus/python/py/test_false_alarm.py
@@ -20,13 +20,9 @@ m.init(sys.argv)
# Create station(s)
sta1 = m.create_sta()
-while not sta1.is_idle():
- m.process()
sta1.set_name("sta1")
sta1.debug()
sta2 = m.create_sta()
-while not sta1.is_idle():
- m.process()
sta2.set_name("sta2")
sta2.debug()
diff --git a/maximus/python/src/interface_module.cpp b/maximus/python/src/interface_module.cpp
index caa2795c97..de5e89a8a6 100644
--- a/maximus/python/src/interface_module.cpp
+++ b/maximus/python/src/interface_module.cpp
@@ -592,7 +592,7 @@ BOOST_PYTHON_MODULE(interface)
/* class Sta */
- class_<Sta>("Sta", init< ISystem *, const string & >())
+ class_<Sta>("Sta", init< Maximus *, ISystem *, const string & >())
.def("remove", &Sta::remove)
.def("deactivate", &Sta::deactivate)
.def("activate", &Sta::activate)