summaryrefslogtreecommitdiff
path: root/cesar/maximus/coreengine/src
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/coreengine/src')
-rw-r--r--cesar/maximus/coreengine/src/CoreEngine.cpp293
-rw-r--r--cesar/maximus/coreengine/src/CoreEngineTest.cpp71
-rw-r--r--cesar/maximus/coreengine/src/Maximus.cpp1348
-rw-r--r--cesar/maximus/coreengine/src/MaximusTest.cpp505
-rw-r--r--cesar/maximus/coreengine/src/Msg.cpp544
-rw-r--r--cesar/maximus/coreengine/src/MsgTest.cpp302
-rw-r--r--cesar/maximus/coreengine/src/Sta.cpp264
-rw-r--r--cesar/maximus/coreengine/src/StaTest.cpp184
8 files changed, 0 insertions, 3511 deletions
diff --git a/cesar/maximus/coreengine/src/CoreEngine.cpp b/cesar/maximus/coreengine/src/CoreEngine.cpp
deleted file mode 100644
index f5ec159595..0000000000
--- a/cesar/maximus/coreengine/src/CoreEngine.cpp
+++ /dev/null
@@ -1,293 +0,0 @@
-/************************************************************************
- CoreEngine.cpp - Copyright buret
-
-Here you can write a license for your code, some comments or any other
-information you want to have in your generated code. To to this simply
-configure the "headings" directory in uml to point to a directory
-where you have your heading files.
-
-or you can just replace the contents of this file with your own.
-If you want to do this, this file is located at
-
-/usr/share/apps/umbrello/headings/heading.cpp
-
--->Code Generators searches for heading files based on the file extension
- i.e. it will look for a file name ending in ".h" to include in C++ header
- files, and for a file name ending in ".java" to include in all generated
- java code.
- If you name the file "heading.<extension>", Code Generator will always
- choose this file even if there are other files with the same extension in the
- directory. If you name the file something else, it must be the only one with that
- extension in the directory to guarantee that Code Generator will choose it.
-
-you can use variables in your heading files which are replaced at generation
-time. possible variables are : author, date, time, filename and filepath.
-just write %variable_name%
-
-This file was generated on %date% at %time%
-The original location of this file is /home/buret/eclipse/maximus/coreengine/src/CoreEngine.cpp
-**************************************************************************/
-
-#include "CoreEngine.h"
-
-#include "PhyProcessor.h"
-#include "FunctionCallManager.h"
-#include "NetworkClockProcessor.h"
-#include "SystemManager.h"
-#include "SciServer.h"
-#include "ChannelComputer.h"
-#include "EthernetProcessor.h"
-
-#include "Logger.h"
-#include "Error.h"
-
-using namespace std;
-
-
-// Constructors/Destructors
-//
-
-
-CoreEngine::CoreEngine ( ):
-mpFunctionCall(NULL),
-mpSystem(NULL),
-mpNetworkClock(NULL),
-mpPhy(NULL),
-mpSci(NULL),
-mpChannel(NULL),
-mpEthernet(NULL)
-{
- logFunction();
-
- initAttributes();
-}
-
-
-void CoreEngine::initAttributes ( )
-{
- logFunction();
-
- // Create all packages: at first Sci; then FunctionCall, Phy, and System; and lastly NetworkClock
- //
- mpSci = new SciServer();
- mpFunctionCall = new FunctionCallManager(mpSci);
- mpSystem = new SystemManager(mpSci);
- mpPhy = new PhyProcessor(mpSci);
- mpEthernet = new EthernetProcessor(mpSci);
- mpNetworkClock = new NetworkClockProcessor(mpSci, mpSystem, mpFunctionCall, mpPhy, mpEthernet);
-}
-
-
-CoreEngine::~CoreEngine ( )
-{
- logFunction();
-
- if (NULL != mpNetworkClock)
- {
- delete (mpNetworkClock);
- mpNetworkClock = NULL;
- }
- if (NULL != mpFunctionCall)
- {
- delete (mpFunctionCall);
- mpFunctionCall = NULL;
- }
- if (NULL != mpSystem)
- {
- delete (mpSystem);
- mpSystem = NULL;
- }
- if (NULL != mpPhy)
- {
- delete (mpPhy);
- mpPhy = NULL;
- }
- if (NULL != mpSci)
- {
- delete (mpSci);
- mpSci = NULL;
- }
- if (NULL != mpChannel)
- {
- delete (mpChannel);
- mpChannel = NULL;
- }
- if (NULL != mpEthernet)
- {
- delete (mpEthernet);
- mpEthernet = NULL;
- }
-}
-
-
-//
-// Methods
-//
-
-
-// Other methods
-//
-
-
-// public methods
-//
-
-
-bool CoreEngine::init ( const std::string station_executable,
- const std::string station_log,
- const std::string debugger,
- const float frequency )
-{
- logFunction();
- bool bInit = false;
-
- // station executable and debugger
- bInit = getSystem()->init(station_executable, debugger);
-
- // station log file
- bInit &= getSci()->init(station_log);
-
- // frequency
- bInit &= getPhy()->init(frequency);
-
- return bInit;
-}
-
-
-bool CoreEngine::process ( const Network_Clock_Tick max_tick_value )
-{
- logFunction();
- bool bProcess = false;
-
- if ( getNetworkClock()->processNextEvt(max_tick_value) )
- {
- bProcess = getSci()->process();
- }
-
- return bProcess;
-}
-
-
-bool CoreEngine::disturbChannel ( const bool enable )
-{
- logFunction();
-
- if (enable)
- {
- if (NULL == mpChannel)
- {
- mpChannel = new ChannelComputer(getPhy(), getSystem());
- }
-
- // Set beacon period to Channel
- getChannel()->setBeaconPeriod(getPhy()->getFrequency());
- }
- if (NULL == mpChannel)
- {
- throw Error(__PRETTY_FUNCTION__, "Channel pointer is NULL");
- }
-
- return getPhy()->setIsChannelEnabled(enable);
-}
-
-
-// private methods
-//
-
-
-// protected methods
-//
-
-
-// Accessor methods
-//
-
-
-// public attribute accessor methods
-//
-
-
-// private attribute accessor methods
-//
-
-
-IFunctionCall * CoreEngine::getFunctionCall ( ) const
-{
- if (NULL == mpFunctionCall)
- {
- throw Error(__PRETTY_FUNCTION__, "Function Call pointer is NULL");
- }
-
- return mpFunctionCall;
-}
-
-
-ISystem * CoreEngine::getSystem ( ) const
-{
- if (NULL == mpSystem)
- {
- throw Error(__PRETTY_FUNCTION__, "System pointer is NULL");
- }
-
- return mpSystem;
-}
-
-
-INetworkClock * CoreEngine::getNetworkClock ( ) const
-{
- if (NULL == mpNetworkClock)
- {
- throw Error(__PRETTY_FUNCTION__, "Network Clock pointer is NULL");
- }
-
- return mpNetworkClock;
-}
-
-
-IPhy * CoreEngine::getPhy ( ) const
-{
- if (NULL == mpPhy)
- {
- throw Error(__PRETTY_FUNCTION__, "PHY pointer is NULL");
- }
-
- return mpPhy;
-}
-
-
-ISci * CoreEngine::getSci ( ) const
-{
- if (NULL == mpSci)
- {
- throw Error(__PRETTY_FUNCTION__, "SCI pointer is NULL");
- }
-
- return mpSci;
-}
-
-
-IChannel * CoreEngine::getChannel ( ) const
-{
- if (NULL == mpChannel)
- {
- throw Error(__PRETTY_FUNCTION__, "Channel pointer is NULL");
- }
-
- return mpChannel;
-}
-
-
-IEthernet * CoreEngine::getEthernet ( ) const
-{
- if (NULL == mpEthernet)
- {
- throw Error(__PRETTY_FUNCTION__, "Ethernet pointer is NULL");
- }
-
- return mpEthernet;
-}
-
-
-// protected attribute accessor methods
-//
-
diff --git a/cesar/maximus/coreengine/src/CoreEngineTest.cpp b/cesar/maximus/coreengine/src/CoreEngineTest.cpp
deleted file mode 100644
index 16193e8b6f..0000000000
--- a/cesar/maximus/coreengine/src/CoreEngineTest.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-
-#include "CoreEngineTest.h"
-
-#include "CoreEngine.h"
-
-#include "Logger.h"
-
-#include <iostream>
-using namespace std;
-
-CPPUNIT_TEST_SUITE_REGISTRATION (CoreEngineTest);
-
-
-void CoreEngineTest::setUp (void)
-{
- logTest();
-
- mpCoreEngine = new CoreEngine ();
-}
-
-
-void CoreEngineTest::tearDown (void)
-{
- logTest();
-
- if (NULL != mpCoreEngine)
- {
- delete (mpCoreEngine);
- mpCoreEngine = NULL;
- }
-}
-
-
-void CoreEngineTest::initTest (void)
-{
- logTest();
-
- if (NULL != mpCoreEngine)
- {
- string stationExecutable("../stationtest/obj/stationtest.elf");
- string stationLog("station_log");
- string debugger("false");
- unsigned short int frequency = 50;
-
- CPPUNIT_ASSERT_MESSAGE("init failed",
- (mpCoreEngine->init(stationExecutable, stationLog, debugger, frequency)));
- }
- else
- {
- CPPUNIT_FAIL ("Core engine pointer is NULL");
- }
-}
-
-
-void CoreEngineTest::disturbChannelTest (void)
-{
- logTest();
-
- if (NULL != mpCoreEngine)
- {
- mpCoreEngine->init("station_executable", "station_log", "debugger", 50);
- CPPUNIT_ASSERT_MESSAGE("disturbChannel failed",
- (mpCoreEngine->disturbChannel(true))
- && (NULL != mpCoreEngine->getChannel()));
- }
- else
- {
- CPPUNIT_FAIL ("Core engine pointer is NULL");
- }
-}
-
diff --git a/cesar/maximus/coreengine/src/Maximus.cpp b/cesar/maximus/coreengine/src/Maximus.cpp
deleted file mode 100644
index 316439ba00..0000000000
--- a/cesar/maximus/coreengine/src/Maximus.cpp
+++ /dev/null
@@ -1,1348 +0,0 @@
-/************************************************************************
- Maximus.cpp - Copyright buret
-
-Here you can write a license for your code, some comments or any other
-information you want to have in your generated code. To to this simply
-configure the "headings" directory in uml to point to a directory
-where you have your heading files.
-
-or you can just replace the contents of this file with your own.
-If you want to do this, this file is located at
-
-/usr/share/apps/umbrello/headings/heading.cpp
-
--->Code Generators searches for heading files based on the file extension
- i.e. it will look for a file name ending in ".h" to include in C++ header
- files, and for a file name ending in ".java" to include in all generated
- java code.
- If you name the file "heading.<extension>", Code Generator will always
- choose this file even if there are other files with the same extension in the
- directory. If you name the file something else, it must be the only one with that
- extension in the directory to guarantee that Code Generator will choose it.
-
-you can use variables in your heading files which are replaced at generation
-time. possible variables are : author, date, time, filename and filepath.
-just write %variable_name%
-
-This file was generated on %date% at %time%
-The original location of this file is /home/buret/eclipse/maximus/coreengine/src/Maximus.cpp
-**************************************************************************/
-
-#include "Maximus.h"
-
-#include "Sta.h"
-#include "Msg.h"
-#include "CoreEngine.h"
-#include "ISystem.h"
-#include "IFunctionCall.h"
-#include "INetworkClock.h"
-#include "ISci.h"
-#include "IChannel.h"
-#include "PhySciMsgMpdu.h"
-#include "ChannelSettings.h"
-
-#include "Error.h"
-#include "Logger.h"
-
-#include <stdio.h> // for 'remove()'
-#include <iostream> // for 'cout', 'cerr' and 'clog'
-#include <fstream> // for 'ifstream'
-#include <getopt.h> // for 'getopt_long()'
-#include <signal.h> // for 'signal()', 'SIGINT', 'raise()', 'SIGTERM'
-#include <algorithm> // for 'min()'
-using namespace std;
-
-// For unitary tests
-bool UNITTEST = false;
-string stationTest;
-
-#if CONFIG_LOG
-// For Maximus log
-Logger logger(LOG_WARNING);
-#endif /* CONFIG_LOG */
-
-// To catch signals
-Maximus * pMaximus;
-
-
-// Constructors/Destructors
-//
-
-
-Maximus::Maximus ( ):
-mpCoreEngine(NULL),
-mMaxTickValue(0),
-mWaitTickValue(0),
-mIsWireshark(false),
-mEtherLogFileDescriptor(-1)
-{
- logFunction();
-
- try
- {
- if (UNITTEST)
- {
-#if CONFIG_LOG
- // For unitary tests log
- logger.setLogLevel(LOG_DEBUG);
-#endif /* CONFIG_LOG */
- }
-
- mpCoreEngine = new CoreEngine();
- }
- catchFunction(this);
-}
-
-
-Maximus::Maximus ( CoreEngine * p_core_engine ):
-mpCoreEngine(NULL),
-mMaxTickValue(0),
-mWaitTickValue(0)
-{
- logFunction();
-
- try
- {
- if (UNITTEST)
- {
-#if CONFIG_LOG
- // For unitary tests log
- logger.setLogLevel(LOG_DEBUG);
-#endif /* CONFIG_LOG */
-
- mpCoreEngine = p_core_engine;
- }
- else
- {
- errno = EBADRQC;
- throw Error(__PRETTY_FUNCTION__, "FOR UNITARY TESTS ONLY", errno);
- }
- }
- catchFunction(this);
-}
-
-
-Maximus::~Maximus ( )
-{
- logFunction();
-
- stop();
-}
-
-
-//
-// Methods
-//
-
-
-// public methods
-
-
-void Maximus::init ( int argc, char * argv[] )
-{
- logFunction();
-
- try
- {
- // To catch signals
- pMaximus = this;
- signal(SIGINT, Maximus::wrapper);
-
- struct option longOptions[] = {
- {"station-executable", required_argument, 0, 'e'},
- {"station-log", required_argument, 0, 's'},
- {"maximus-log", required_argument, 0, 'm'},
- {"log-level", required_argument, 0, 'l'},
- {"max-tick-value", required_argument, 0, 't'},
- {"debugger", required_argument, 0, 'd'},
- {"frequency", required_argument, 0, 'f'},
- {"wireshark", required_argument, 0, 'w'}
- };
- int optionIndex = 0;
- int optionChar = 0;
- optind = 0;
-
- // Station executable
- string stationExecutable;
- bool isStationExecutableSet = false;
-
- // Station log
- string stationLog("-");
-
-#if CONFIG_LOG
- // Maximus log
- string maximusLog("maximus_log");
-
- // Log level
- int logLevel = LOG_WARNING;
-#endif /* CONFIG_LOG */
-
- // Debugger
- string debugger("xterm -title '\"%n\" debug' -e gdb %e %p & sleep 1");
-
- // Frequency
- float frequency = 50; // in Hz
-
- // Wireshark
- string wireshark;
-
- while (EOF != optionChar)
- {
- optionChar = getopt_long(argc, argv, "e:s:m:l:t:d:f:w:", longOptions, &optionIndex);
-
- switch (optionChar)
- {
- case 'e':
-#if CONFIG_LOG
- clog << logger(LOG_INFO) << "station executable = " << optarg << endl;
-#endif /* CONFIG_LOG */
- stationExecutable = optarg;
- isStationExecutableSet = true;
- break;
- case 's':
-#if CONFIG_LOG
- clog << logger(LOG_INFO) << "station log = " << optarg << endl;
-#endif /* CONFIG_LOG */
- stationLog = optarg;
- break;
- case 'm':
-#if CONFIG_LOG
- clog << logger(LOG_INFO) << "maximus log = " << optarg << endl;
- maximusLog = optarg;
-#endif /* CONFIG_LOG */
- break;
- case 'l':
-#if CONFIG_LOG
- clog << logger(LOG_INFO) << "log level = " << optarg << endl;
- if ((LOG_DEBUG <= atoi(optarg)) && (LOG_NONE >= atoi(optarg)))
- {
- logLevel = atoi(optarg);
- }
- else
- {
- clog << logger(LOG_ERROR) << "usage: -l log_level with log_level in range from 0 to 6!" << endl;
- clog << logger(LOG_ERROR) << "user value is not taken into account => apply default value!" << endl;
- }
-#endif /* CONFIG_LOG */
- break;
- case 't':
-#if CONFIG_LOG
- clog << logger(LOG_INFO) << "max tick value = " << optarg << endl;
-#endif /* CONFIG_LOG */
- setMaxTickValue(strtoull(optarg, NULL, 0));
- break;
- case 'd':
-#if CONFIG_LOG
- clog << logger(LOG_INFO) << "debugger = " << optarg << endl;
-#endif /* CONFIG_LOG */
- debugger = optarg;
- break;
- case 'f':
-#if CONFIG_LOG
- clog << logger(LOG_INFO) << "frequency = " << optarg << endl;
-#endif /* CONFIG_LOG */
- if ((50 == atof(optarg)) || (60 == atof(optarg)) || (0 == atof(optarg)))
- {
- frequency = atof(optarg);
- }
- else
- {
-#if CONFIG_LOG
- clog << logger(LOG_ERROR) << "usage: -f frequency with frequency 50 or 60 Hz, or 0!" << endl;
- clog << logger(LOG_ERROR) << "user value is not taken into account => apply default value (50 Hz)!" << endl;
-#endif /* CONFIG_LOG */
- }
- break;
- case 'w':
-#if CONFIG_LOG
- clog << logger(LOG_INFO) << "wireshark = " << optarg << endl;
-#endif /* CONFIG_LOG */
- wireshark = optarg;
- if ( (0 == wireshark.compare("on"))
- || (0 == wireshark.compare("On"))
- || (0 == wireshark.compare("ON")) )
- {
- mIsWireshark = true;
- }
- else if ( (0 == wireshark.compare("off"))
- || (0 == wireshark.compare("Off"))
- || (0 == wireshark.compare("OFF")) )
- {
- mIsWireshark = false;
- }
- else
- {
-#if CONFIG_LOG
- clog << logger(LOG_ERROR) << "usage: -w wireshark with wireshark on or off!" << endl;
- clog << logger(LOG_ERROR) << "user value is not taken into account => apply default value (off)!" << endl;
-#endif /* CONFIG_LOG */
- }
- break;
- case '?':
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Usage: -e station_executable [-s station_log -m maximus_log -l log_level -t max_tick_value -d debugger -f frequency -w wireshark]", errno);
- break;
- }
- }
-
- if (!isStationExecutableSet)
- {
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Usage: -e station_executable [-s station_log -m maximus_log -l log_level -t max_tick_value -d debugger -f frequency -w wireshark]", errno);
- }
-
-#if CONFIG_LOG
- // Maximus log
- if ( (!maximusLog.empty()) && (maximusLog.compare("-")) )
- {
- // In case of the file already exists, delete it
- remove(maximusLog.c_str());
-
- mMaximusLogFile.open(maximusLog.c_str(), ios_base::app | ios_base::out);
- if (mMaximusLogFile.is_open())
- {
- clog << logger(LOG_INFO) << "Maximus logs will be output into " << maximusLog << endl;
- logger.setLogFile(mMaximusLogFile);
- }
- else
- {
- clog << logger(LOG_ERROR) << "error while opening Maximus log file!" << endl;
- clog << logger(LOG_ERROR) << "Maximus logs will be output on standard output!" << endl;
- }
- }
- else
- {
- clog << logger(LOG_ERROR) << "Maximus logs will be output on standard output!" << endl;
- }
-
- // Log level
- logger.setLogLevel(logLevel);
-#endif /* CONFIG_LOG */
-
- mpCoreEngine->init(stationExecutable, stationLog, debugger, frequency);
- }
- catchFunction(this);
-}
-
-
-void Maximus::init_phy ( PhyMpduCb interface_cb )
-{
- logFunction();
-
- try
- {
- if (!getPhyProcessor()->init(interface_cb))
- {
- throw Error(__PRETTY_FUNCTION__, "PHY initialization failed");
- }
- }
- catchFunction(this);
-}
-
-
-File_Descriptor Maximus::init_ether ( EtherCb interface_cb )
-{
- logFunction();
-
- try
- {
- if (!getEthernet()->init(interface_cb))
- {
- throw Error(__PRETTY_FUNCTION__, "Ethernet initialization failed");
- }
- if (isWireshark())
- {
- char dev[] = "tap10\0";
- if (0 > (mEtherLogFileDescriptor = getEthernet()->allocTap(dev)))
- {
- throw Error(__PRETTY_FUNCTION__, "Bad Ether log file descriptor", errno);
- }
- }
- }
- catchFunction(this);
-
- return mEtherLogFileDescriptor;
-}
-
-
-void Maximus::process ( )
-{
- logFunction();
-
- try
- {
- Network_Clock_Tick tickValue = 0; // tick value until which to process
-
- if (0 == getMaxTickValue())
- {
- tickValue = getWaitTickValue();
- }
- else if (0 != getWaitTickValue())
- {
- tickValue = min(getMaxTickValue(), getWaitTickValue());
- }
-
- getCoreEngine()->process(tickValue);
-
- if (0 != getMaxTickValue())
- {
- if (getMaxTickValue() <= getNetworkClockProcessor()->getCurrentTickValue())
- {
-#if CONFIG_LOG
- clog << logger(LOG_FATAL) << "Max tick value is reached!" << endl;
-#endif /* CONFIG_LOG */
- stop();
- exit(1);
- }
- }
- }
- catchFunction(this);
-}
-
-
-Sta & Maximus::create_sta ( const string & station_executable, uint32_t seed )
-{
- logFunction();
- Sta * pSta = NULL;
-
- try
- {
- if (!station_executable.empty())
- {
- pSta = new Sta(this, getSystemManager(), station_executable, seed);
- }
- else
- {
- pSta = new Sta(this, getSystemManager(), getSystemManager()->getDefaultStationExecutable(), seed);
- }
- if (NULL == pSta)
- {
- throw Error(__PRETTY_FUNCTION__, "Station pointer is NULL");
- }
- mListOfStas.push_back(pSta);
-
- // If channel perturbation is enabled,
- // inform the channel package that a new station has been created
- if (getPhyProcessor()->isChannelEnabled())
- {
- getChannel()->addChannelSettings(pSta->getStationId());
- }
- }
- catchFunction(this);
-
- return *pSta;
-}
-
-
-Msg & Maximus::create_fc ( const string & name )
-{
- logFunction();
- Msg * pMsg = NULL;
-
- try
- {
- pMsg = new Msg(this, getFunctionCallManager(), getSystemManager(), name);
- if (NULL == pMsg)
- {
- throw Error(__PRETTY_FUNCTION__, "Message pointer is NULL");
- }
- mListOfMsgs.push_back(pMsg);
- }
- catchFunction(this);
-
- return *pMsg;
-}
-
-
-Msg & Maximus::create_probe ( )
-{
- logFunction();
- Msg * pMsg = NULL;
-
- try
- {
- pMsg = new Msg(this, getFunctionCallManager(), getSystemManager());
- if (NULL == pMsg)
- {
- throw Error(__PRETTY_FUNCTION__, "Message pointer is NULL");
- }
- mListOfMsgs.push_back(pMsg);
- }
- catchFunction(this);
-
- return *pMsg;
-}
-
-
-PhySciMsgMpdu * Maximus::create_mpdu ( )
-{
- logFunction();
-
- return getPhyProcessor()->createMpdu();
-}
-
-
-void Maximus::send_mpdu ( PhySciMsgMpdu * p_mpdu )
-{
- logFunction();
-
- try
- {
- if (NULL == p_mpdu)
- {
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "PHY SCI message MPDU pointer is NULL", errno);
- }
- if (!getPhyProcessor()->sendMpdu(p_mpdu))
- {
- throw Error(__PRETTY_FUNCTION__, "MPDU has not been sent correctly", errno);
- }
- }
- catchFunction(this);
-}
-
-
-EtherSciMsg * Maximus::create_ether ( )
-{
- logFunction();
-
- return getEthernet()->createEther();
-}
-
-
-void Maximus::send_ether ( EtherSciMsg & ether )
-{
- logFunction();
-
- try
- {
- if (!getEthernet()->sendEther(ether))
- {
- throw Error(__PRETTY_FUNCTION__, "Ethernet SCI message has not been sent correctly", errno);
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::wait ( const tick_t value )
-{
- logFunction();
-
- try
- {
- setWaitTickValue(getNetworkClockProcessor()->getCurrentTickValue() + value);
- while (getWaitTickValue() > getNetworkClockProcessor()->getCurrentTickValue())
- {
- process();
- }
- setWaitTickValue(0);
- }
- catchFunction(this);
-}
-
-
-void Maximus::wait ( )
-{
- logFunction();
-
- try
- {
- while ( (NULL != getFunctionCallManager()->getListOfCallbacks())
- && (!getFunctionCallManager()->getListOfCallbacks()->empty()) )
- {
- process();
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::disturb_channel ( const bool enable )
-{
- logFunction();
-
- try
- {
- getCoreEngine()->disturbChannel(enable);
- }
- catchFunction(this);
-}
-
-
-tick_t Maximus::get_date ( )
-{
- logFunction();
- tick_t date = 0;
-
- try
- {
- date = getNetworkClockProcessor()->getCurrentTickValue();
- }
- catchFunction(this);
-
- return date;
-}
-
-
-void Maximus::set_freq ( const float frequency )
-{
- logFunction();
-
- try
- {
- getPhyProcessor()->setFrequency(frequency);
- }
- catchFunction(this);
-}
-
-
-float Maximus::get_freq ( )
-{
- logFunction();
- float frequency = 0;
-
- try
- {
- frequency = getPhyProcessor()->getFrequency();
- }
- catchFunction(this);
-
- return frequency;
-}
-
-
-void Maximus::set_snr ( const float snr_value )
-{
- logFunction();
-
- try
- {
- // If channel perturbation is enabled, set the SNR value
- if (getPhyProcessor()->isChannelEnabled())
- {
- std::vector<ChannelSettings *> listOfChannelSettings = getChannel()->findChannelSettings(0 /* tx_station_id */, 0 /* rx_station_id */, false);
- std::vector<ChannelSettings *>::size_type size = listOfChannelSettings.size();
- for (std::vector<ChannelSettings *>::size_type s=0; s<size; s++)
- {
- if (NULL == listOfChannelSettings.back())
- {
- throw Error(__PRETTY_FUNCTION__, "A channel settings pointer is NULL");
- }
- else
- {
- listOfChannelSettings.back()->setSnr(snr_value);
- }
- listOfChannelSettings.pop_back();
- }
- }
- else
- {
- errno = EPROTO;
- throw Error(__PRETTY_FUNCTION__, "Channel perturbation is disabled", errno);
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::set_snr ( const string & snr_file )
-{
- logFunction();
-
- try
- {
- // Read the user SNR file
- float snrArray[MAXIMUS_CHANNEL_INTERVAL_MAX_NB][PHY_CARRIER_NB + 1];
- if (!readSnrFile(snr_file, snrArray))
- {
- for (int j=0; j<= PHY_CARRIER_NB; j++)
- {
- for (int i=0; i<MAXIMUS_CHANNEL_INTERVAL_MAX_NB; i++)
- {
- cerr << snrArray[i][j] << " ";
- }
- cerr << endl;
- }
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Error while reading SNR file", errno);
- }
-
- // If channel perturbation is enabled, set the SNR values
- if (getPhyProcessor()->isChannelEnabled())
- {
- std::vector<ChannelSettings *> listOfChannelSettings = getChannel()->findChannelSettings(0 /* tx_station_id */, 0 /* rx_station_id */, false);
- std::vector<ChannelSettings *>::size_type size = listOfChannelSettings.size();
- for (std::vector<ChannelSettings *>::size_type s=0; s<size; s++)
- {
- if (NULL == listOfChannelSettings.back())
- {
- throw Error(__PRETTY_FUNCTION__, "A channel settings pointer is NULL");
- }
- else
- {
- listOfChannelSettings.back()->setSnr(snrArray);
- }
- listOfChannelSettings.pop_back();
- }
- }
- else
- {
- errno = EPROTO;
- throw Error(__PRETTY_FUNCTION__, "Channel perturbation is disabled", errno);
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::set_snr_from_src ( const float snr_value, const Sta & src, const bool both_directions )
-{
- logFunction();
-
- try
- {
- // If channel perturbation is enabled, set the SNR value
- if (getPhyProcessor()->isChannelEnabled())
- {
- std::vector<ChannelSettings *> listOfChannelSettings = getChannel()->findChannelSettings(src.getStationId() /* tx_station_id */, 0 /* rx_station_id */, both_directions);
- std::vector<ChannelSettings *>::size_type size = listOfChannelSettings.size();
- for (std::vector<ChannelSettings *>::size_type s=0; s<size; s++)
- {
- if (NULL == listOfChannelSettings.back())
- {
- throw Error(__PRETTY_FUNCTION__, "A channel settings pointer is NULL");
- }
- else
- {
- listOfChannelSettings.back()->setSnr(snr_value);
- }
- listOfChannelSettings.pop_back();
- }
- }
- else
- {
- errno = EPROTO;
- throw Error(__PRETTY_FUNCTION__, "Channel perturbation is disabled", errno);
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::set_snr_from_src ( const string & snr_file, const Sta & src, const bool both_directions )
-{
- logFunction();
-
- try
- {
- // Read the user SNR file
- float snrArray[MAXIMUS_CHANNEL_INTERVAL_MAX_NB][PHY_CARRIER_NB + 1];
- if (!readSnrFile(snr_file, snrArray))
- {
- for (int j=0; j<= PHY_CARRIER_NB; j++)
- {
- for (int i=0; i<MAXIMUS_CHANNEL_INTERVAL_MAX_NB; i++)
- {
- cerr << snrArray[i][j] << " ";
- }
- cerr << endl;
- }
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Error while reading SNR file", errno);
- }
-
- // If channel perturbation is enabled, set the SNR values
- if (getPhyProcessor()->isChannelEnabled())
- {
- std::vector<ChannelSettings *> listOfChannelSettings = getChannel()->findChannelSettings(src.getStationId() /* tx_station_id */, 0 /* rx_station_id */, both_directions);
- std::vector<ChannelSettings *>::size_type size = listOfChannelSettings.size();
- for (std::vector<ChannelSettings *>::size_type s=0; s<size; s++)
- {
- if (NULL == listOfChannelSettings.back())
- {
- throw Error(__PRETTY_FUNCTION__, "A channel settings pointer is NULL");
- }
- else
- {
- listOfChannelSettings.back()->setSnr(snrArray);
- }
- listOfChannelSettings.pop_back();
- }
- }
- else
- {
- errno = EPROTO;
- throw Error(__PRETTY_FUNCTION__, "Channel perturbation is disabled", errno);
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::set_snr_to_dst ( const float snr_value, const Sta & dst, const bool both_directions )
-{
- logFunction();
-
- try
- {
- // If channel perturbation is enabled, set the SNR value
- if (getPhyProcessor()->isChannelEnabled())
- {
- std::vector<ChannelSettings *> listOfChannelSettings = getChannel()->findChannelSettings(0 /* tx_station_id */, dst.getStationId() /* rx_station_id */, both_directions);
- std::vector<ChannelSettings *>::size_type size = listOfChannelSettings.size();
- for (std::vector<ChannelSettings *>::size_type s=0; s<size; s++)
- {
- if (NULL == listOfChannelSettings.back())
- {
- throw Error(__PRETTY_FUNCTION__, "A channel settings pointer is NULL");
- }
- else
- {
- listOfChannelSettings.back()->setSnr(snr_value);
- }
- listOfChannelSettings.pop_back();
- }
- }
- else
- {
- errno = EPROTO;
- throw Error(__PRETTY_FUNCTION__, "Channel perturbation is disabled", errno);
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::set_snr_to_dst ( const string & snr_file, const Sta & dst, const bool both_directions )
-{
- logFunction();
-
- try
- {
- // Read the user SNR file
- float snrArray[MAXIMUS_CHANNEL_INTERVAL_MAX_NB][PHY_CARRIER_NB + 1];
- if (!readSnrFile(snr_file, snrArray))
- {
- for (int j=0; j<= PHY_CARRIER_NB; j++)
- {
- for (int i=0; i<MAXIMUS_CHANNEL_INTERVAL_MAX_NB; i++)
- {
- cerr << snrArray[i][j] << " ";
- }
- cerr << endl;
- }
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Error while reading SNR file", errno);
- }
-
- // If channel perturbation is enabled, set the SNR values
- if (getPhyProcessor()->isChannelEnabled())
- {
- std::vector<ChannelSettings *> listOfChannelSettings = getChannel()->findChannelSettings(0 /* tx_station_id */, dst.getStationId() /* rx_station_id */, both_directions);
- std::vector<ChannelSettings *>::size_type size = listOfChannelSettings.size();
- for (std::vector<ChannelSettings *>::size_type s=0; s<size; s++)
- {
- if (NULL == listOfChannelSettings.back())
- {
- throw Error(__PRETTY_FUNCTION__, "A channel settings pointer is NULL");
- }
- else
- {
- listOfChannelSettings.back()->setSnr(snrArray);
- }
- listOfChannelSettings.pop_back();
- }
- }
- else
- {
- errno = EPROTO;
- throw Error(__PRETTY_FUNCTION__, "Channel perturbation is disabled", errno);
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::set_snr_from_src_to_dst ( const float snr_value, const Sta & src, const Sta & dst, const bool both_directions )
-{
- logFunction();
-
- try
- {
- // If channel perturbation is enabled, set the SNR value
- if (getPhyProcessor()->isChannelEnabled())
- {
- std::vector<ChannelSettings *> listOfChannelSettings = getChannel()->findChannelSettings(src.getStationId() /* tx_station_id */, dst.getStationId() /* rx_station_id */, both_directions);
- std::vector<ChannelSettings *>::size_type size = listOfChannelSettings.size();
- for (std::vector<ChannelSettings *>::size_type s=0; s<size; s++)
- {
- if (NULL == listOfChannelSettings.back())
- {
- throw Error(__PRETTY_FUNCTION__, "A channel settings pointer is NULL");
- }
- else
- {
- listOfChannelSettings.back()->setSnr(snr_value);
- }
- listOfChannelSettings.pop_back();
- }
- }
- else
- {
- errno = EPROTO;
- throw Error(__PRETTY_FUNCTION__, "Channel perturbation is disabled", errno);
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::set_snr_from_src_to_dst ( const string & snr_file, const Sta & src, const Sta & dst, const bool both_directions )
-{
- logFunction();
-
- try
- {
- float snrArray[MAXIMUS_CHANNEL_INTERVAL_MAX_NB][PHY_CARRIER_NB + 1];
- if (!readSnrFile(snr_file, snrArray))
- {
- for (int j=0; j<= PHY_CARRIER_NB; j++)
- {
- for (int i=0; i<MAXIMUS_CHANNEL_INTERVAL_MAX_NB; i++)
- {
- cerr << snrArray[i][j] << " ";
- }
- cerr << endl;
- }
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Error while reading SNR file", errno);
- }
-
- // If channel perturbation is enabled, set the SNR values
- if (getPhyProcessor()->isChannelEnabled())
- {
- std::vector<ChannelSettings *> listOfChannelSettings = getChannel()->findChannelSettings(src.getStationId() /* tx_station_id */, dst.getStationId() /* rx_station_id */, both_directions);
- std::vector<ChannelSettings *>::size_type size = listOfChannelSettings.size();
- for (std::vector<ChannelSettings *>::size_type s=0; s<size; s++)
- {
- if (NULL == listOfChannelSettings.back())
- {
- throw Error(__PRETTY_FUNCTION__, "A channel settings pointer is NULL");
- }
- else
- {
- listOfChannelSettings.back()->setSnr(snrArray);
- }
- listOfChannelSettings.pop_back();
- }
- }
- else
- {
- errno = EPROTO;
- throw Error(__PRETTY_FUNCTION__, "Channel perturbation is disabled", errno);
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::activate_false_alarm ( const Network_Clock_Tick average_duration,
- const float std_deviation )
-{
- logFunction();
-
- try
- {
- if (!getPhyProcessor()->activateFalseAlarm(average_duration, std_deviation))
- {
- throw Error(__PRETTY_FUNCTION__, "Cannot activate false alarm");
- }
- }
- catchFunction(this);
-}
-
-
-void Maximus::deactivate_false_alarm ( )
-{
- logFunction();
-
- try
- {
- if (!getPhyProcessor()->deactivateFalseAlarm())
- {
- throw Error(__PRETTY_FUNCTION__, "Cannot deactivate false alarm");
- }
- }
- catchFunction(this);
-}
-
-
-bool Maximus::is_station_idle ( Sci_Msg_Station_Id station_id )
-{
- logFunction();
- bool isIdle = false;
-
- try
- {
- isIdle = getSystemManager()->isStationIdle(station_id);
- }
- catchFunction(this);
-
- return isIdle;
-}
-
-
-void Maximus::hide_sta (const Sta & sta1, const Sta & sta2, bool hidden)
-{
- logFunction();
-
- try
- {
- if (!getSystemManager()->hideStation (sta1.getStationId (),
- sta2.getStationId (),
- hidden))
- {
- throw Error (__PRETTY_FUNCTION__, "Cannot hide station", errno);
- }
- }
- catchFunction(this);
-}
-
-
-// private methods
-//
-
-
-CoreEngine * Maximus::getCoreEngine ( )
-{
- try
- {
- if (NULL == mpCoreEngine)
- {
- throw Error(__PRETTY_FUNCTION__, "Core engine pointer is NULL");
- }
- }
- catchFunction(this);
-
- return mpCoreEngine;
-}
-
-
-ISystem * Maximus::getSystemManager ( )
-{
- ISystem * pSystemManager = NULL;
-
- try
- {
- if ( NULL == (pSystemManager = getCoreEngine()->getSystem()) )
- {
- throw Error(__PRETTY_FUNCTION__, "System manager pointer is NULL");
- }
- }
- catchFunction(this);
-
- return pSystemManager;
-}
-
-
-IFunctionCall * Maximus::getFunctionCallManager ( )
-{
- IFunctionCall * pFunctionCallManager = NULL;
-
- try
- {
- if ( NULL == (pFunctionCallManager = getCoreEngine()->getFunctionCall()) )
- {
- throw Error(__PRETTY_FUNCTION__, "Function call manager pointer is NULL");
- }
- }
- catchFunction(this);
-
- return pFunctionCallManager;
-}
-
-
-INetworkClock * Maximus::getNetworkClockProcessor ( )
-{
- INetworkClock * pNetworkClockProcessor = NULL;
-
- try
- {
- if ( NULL == (pNetworkClockProcessor = getCoreEngine()->getNetworkClock()) )
- {
- throw Error(__PRETTY_FUNCTION__, "Network clock processor pointer is NULL");
- }
- }
- catchFunction(this);
-
- return pNetworkClockProcessor;
-}
-
-
-IPhy * Maximus::getPhyProcessor ( )
-{
- IPhy * pPhyProcessor = NULL;
-
- try
- {
- if ( NULL == (pPhyProcessor = getCoreEngine()->getPhy()) )
- {
- throw Error(__PRETTY_FUNCTION__, "Phy processor pointer is NULL");
- }
- }
- catchFunction(this);
-
- return pPhyProcessor;
-}
-
-
-ISci * Maximus::getSciServer ( )
-{
- ISci * pSciServer = NULL;
-
- try
- {
- if ( NULL == (pSciServer = getCoreEngine()->getSci()) )
- {
- throw Error(__PRETTY_FUNCTION__, "SCI server pointer is NULL");
- }
- }
- catchFunction(this);
-
- return pSciServer;
-}
-
-
-IChannel * Maximus::getChannel ( )
-{
- IChannel * pChannel = NULL;
-
- try
- {
- if ( NULL == (pChannel = getCoreEngine()->getChannel()) )
- {
- throw Error(__PRETTY_FUNCTION__, "Channel pointer is NULL");
- }
- }
- catchFunction(this);
-
- return pChannel;
-}
-
-
-IEthernet * Maximus::getEthernet ( )
-{
- IEthernet * pEthernet = NULL;
-
- try
- {
- if ( NULL == (pEthernet = getCoreEngine()->getEthernet()) )
- {
- throw Error(__PRETTY_FUNCTION__, "Ethernet pointer is NULL");
- }
- }
- catchFunction(this);
-
- return pEthernet;
-}
-
-
-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;
-}
-
-
-bool Maximus::readSnrFile ( const string & snr_file, float snr_array[MAXIMUS_CHANNEL_INTERVAL_MAX_NB][PHY_CARRIER_NB + 1] )
-{
- logFunction();
- bool bRead = true;
-
- try
- {
- // Read file
- //
- memset(snr_array, '\0', MAXIMUS_CHANNEL_INTERVAL_MAX_NB * (PHY_CARRIER_NB + 1) * sizeof(float));
- ifstream snrFile(snr_file.c_str(), ifstream::in);
- if (snrFile.is_open())
- {
- /* Read end times (in ticks) of each interval of the beacon period. */
- char c;
- float tempEndTimeOfLastInterval = (2 * 1000000) / (getPhyProcessor()->getFrequency());
- unsigned short int endTimeOfLastInterval = (unsigned short int)tempEndTimeOfLastInterval;
- unsigned short int numberOfIntervals = MAXIMUS_CHANNEL_INTERVAL_MAX_NB;
- for (int i=0; i<MAXIMUS_CHANNEL_INTERVAL_MAX_NB; i++)
- {
- snrFile >> snr_array[i][0];
- if (endTimeOfLastInterval <= snr_array[i][0])
- {
- snr_array[i][0] = endTimeOfLastInterval;
- numberOfIntervals = i + 1;
- break;
- }
- c = snrFile.peek();
- while ( ('\t' == c) || (' ' == c) || (EOF == c) )
- {
- snrFile.ignore();
- c = snrFile.peek();
- }
- if ('#' == c)
- {
- while ( ('\n' != c) && (EOF != c) )
- {
- snrFile.ignore();
- c = snrFile.peek();
- }
- }
- if ('\n' == c)
- {
- snrFile.ignore();
- numberOfIntervals = i + 1;
- if (endTimeOfLastInterval != snr_array[i][0])
- {
- if (MAXIMUS_CHANNEL_INTERVAL_MAX_NB > i+1)
- {
- snr_array[i+1][0] = endTimeOfLastInterval;
- numberOfIntervals++;
- }
- else
- {
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Too many time intervals in SNR file", errno);
- }
- }
- break;
- }
- }
-
- /* Read SNR values (in dB) for each carrier. */
- for (int j=1; j<=PHY_CARRIER_NB; j++)
- {
- for (int i=0; i<numberOfIntervals; i++)
- {
- snrFile >> snr_array[i][j];
- }
- c = snrFile.peek();
- while ( ('\n' != c) && (EOF != c) )
- {
- snrFile.ignore();
- c = snrFile.peek();
- }
- }
- }
- else
- {
- throw Error(__PRETTY_FUNCTION__, "Error while opening SNR file", errno);
- }
- snrFile.close();
- }
- catchFunction(this);
-
- return bRead;
-}
-
-
-bool Maximus::isWireshark ( ) const
-{
- return mIsWireshark;
-}
-
-
-// public methods
-//
-
-
-void Maximus::wrapper ( int n )
-{
- logFunction();
-
- if (NULL != pMaximus)
- {
-#if CONFIG_LOG
- clog << logger(LOG_FATAL) << "Catch CTRL+C!" << endl;
-#endif /* CONFIG_LOG */
- pMaximus->stop();
- raise(SIGTERM);
- }
-}
-
-
-void Maximus::stop ( )
-{
- logFunction();
- unsigned int counter = 0;
-
-#if CONFIG_LOG
- clog << logger(LOG_FATAL) << "*** Exit Fulminata Maximus simulator ***" << endl;
-#endif /* CONFIG_LOG */
-
- for (unsigned int i=0; i<mListOfMsgs.size(); i++)
- {
- if (NULL != mListOfMsgs[i])
- {
- delete (mListOfMsgs[i]);
- counter ++;
- }
- }
- mListOfMsgs.clear();
-#if CONFIG_LOG
- clog << logger(LOG_FATAL) << "delete " << counter << " messages" << endl;
-#endif /* CONFIG_LOG */
- counter = 0;
-
- for (unsigned int i=0; i<mListOfStas.size(); i++)
- {
- if (NULL != mListOfStas[i])
- {
- delete (mListOfStas[i]);
- counter++;
- }
- }
- mListOfStas.clear();
-#if CONFIG_LOG
- clog << logger(LOG_FATAL) << "delete " << counter << " stations" << endl;
-
- if (mMaximusLogFile.is_open())
- {
- mMaximusLogFile.flush();
- mMaximusLogFile.close();
- }
-#endif /* CONFIG_LOG */
-
- if (0 <= mEtherLogFileDescriptor)
- {
- close(mEtherLogFileDescriptor);
- mEtherLogFileDescriptor = -1;
- }
-
- // Warning: delete the Core Engine is the last task to do!
- if (NULL != mpCoreEngine)
- {
- delete mpCoreEngine;
- mpCoreEngine = NULL;
- }
-}
-
diff --git a/cesar/maximus/coreengine/src/MaximusTest.cpp b/cesar/maximus/coreengine/src/MaximusTest.cpp
deleted file mode 100644
index 449c4a6d61..0000000000
--- a/cesar/maximus/coreengine/src/MaximusTest.cpp
+++ /dev/null
@@ -1,505 +0,0 @@
-
-#include "MaximusTest.h"
-
-#include "Maximus.h"
-#include "Msg.h"
-#include "Sta.h"
-#include "PhySciMsgPre.h"
-#include "PhySciMsgFc.h"
-#include "PhySciMsgMpdu.h"
-#include "EtherSciMsg.h"
-#include "Station.h"
-#include "ISystem.h"
-#include "CoreEngine.h"
-
-#include "Logger.h"
-
-#include "functioncall_types.h" // for 'PROBE_ID'
-
-#include <iostream>
-using namespace std;
-
-CPPUNIT_TEST_SUITE_REGISTRATION (MaximusTest);
-
-void phyCb (PhySciMsg & phy_sci_msg)
-{
-
-}
-
-void etherCb (EtherSciMsg & ether_sci_msg)
-{
-
-}
-
-
-void MaximusTest::setUp (void)
-{
- logTest();
-
- mpCoreEngine = new CoreEngine ();
- mpMaximus = new Maximus (mpCoreEngine);
-}
-
-
-void MaximusTest::tearDown (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- delete (mpMaximus);
- mpMaximus = NULL;
- }
-}
-
-
-void MaximusTest::init_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- //mpMaximus->init(argc, argv);
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::init_phy_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- mpMaximus->init_phy(&phyCb);
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::init_ether_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- CPPUNIT_ASSERT_MESSAGE ( "init_ether failed",
- -1 == mpMaximus->init_ether(&etherCb) );
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::process_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- mpMaximus->process();
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::create_sta_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- Sta sta = mpMaximus->create_sta();
-
- CPPUNIT_ASSERT_MESSAGE ( "create_sta failed",
- 0 != sta.getStationId() );
-
- sta.remove();
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::create_fc_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- Msg msg = mpMaximus->create_fc("function");
-
- CPPUNIT_ASSERT_MESSAGE ( "create_fc failed",
- 0 != msg.get_tx_msg_id() );
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::create_probe_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- Msg msg = mpMaximus->create_probe();
-
- CPPUNIT_ASSERT_MESSAGE ( "create_probe failed",
- 0 != msg.get_tx_msg_id() );
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::create_mpdu_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- PhySciMsgMpdu * pMpdu = mpMaximus->create_mpdu();
-
- CPPUNIT_ASSERT_MESSAGE ( "create_mpdu failed",
- NULL != pMpdu );
-
- delete (pMpdu);
- pMpdu = NULL;
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::send_mpdu_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- // create MPDU
- PhySciMsgMpdu * pMpdu = mpMaximus->create_mpdu();
- CPPUNIT_ASSERT_MESSAGE ( "PHY SCI message MPDU pointer is NULL", NULL != pMpdu );
-
- /* Configure MPDU. */
- unsigned long length = 5;
- unsigned char payload[length];
- memset(payload, 'P', length);
-
- pMpdu->setMpdu(length, payload);
-
- // create the transmitting station
- Sta staTx = mpMaximus->create_sta();
-
- // create the destination station
- Sta staRx = mpMaximus->create_sta();
-
- // set the destination station
- pMpdu->setSciMsgStationId(staRx.getStationId());
-
- // set FC
- uint32_t fc_av[4];
- memset(fc_av, 'A', 4*sizeof(uint32_t));
- uint32_t fc_10 = 10;
- pMpdu->setFc10(fc_10);
- pMpdu->setFcAv(fc_av);
-
- // set FC mode
- pMpdu->setFcMode(PHY_FC_MODE_HYBRID_1);
-
- // set short PPDU
- pMpdu->setShortPpdu(1);
-
- mpMaximus->send_mpdu(pMpdu);
-
- while (!pMpdu->isSent() && !pMpdu->getFc()->isSent())
- {
- mpMaximus->process();
- }
-
- if (NULL != pMpdu)
- {
- delete (pMpdu);
- pMpdu = NULL;
- }
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::create_ether_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- EtherSciMsg * pEther = mpMaximus->create_ether();
-
- CPPUNIT_ASSERT_MESSAGE ( "create_ether failed", NULL != pEther );
-
- delete (pEther);
- pEther = NULL;
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::send_ether_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- // create Ether SCI message
- EtherSciMsg * pEtherSciMsg = mpMaximus->create_ether();
-
- // create the destination station
- Sta staRx = mpMaximus->create_sta();
- mpMaximus->wait(5);
-
- /* Configure Ether SCI message. */
- pEtherSciMsg->setSpecializedSciMsgType(ETHERNET_TYPE_DATA);
- unsigned long length = 5;
- unsigned char payload[length];
- memset(payload, 'E', length);
- pEtherSciMsg->setSpecializedSciMsgDataLength(length);
- pEtherSciMsg->setSpecializedSciMsgData(payload);
- pEtherSciMsg->setSciMsgStationId(staRx.getStationId());
-
- // send Ether SCI message
- mpMaximus->send_ether(*pEtherSciMsg);
-
- // remove the destination station
- staRx.remove();
-
- if (NULL != pEtherSciMsg)
- {
- delete (pEtherSciMsg);
- pEtherSciMsg = NULL;
- }
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::wait_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- Sta sta = mpMaximus->create_sta();
- mpMaximus->wait(10);
- mpMaximus->wait();
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::disturb_channel_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- //mpMaximus->disturb_channel();
- //mpMaximus->disturb_channel(false);
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::get_date_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- tick_t date = mpMaximus->get_date();
- tick_t offset = 100;
- Sta sta = mpMaximus->create_sta();
- mpMaximus->wait(offset);
- CPPUNIT_ASSERT_MESSAGE ( "get_date failed", date + offset == mpMaximus->get_date() );
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::set_freq_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- Sta sta = mpMaximus->create_sta();
-
- float freq = 0;
- mpMaximus->set_freq(freq);
- CPPUNIT_ASSERT_MESSAGE ( "set_freq failed", freq == mpMaximus->get_freq() );
- mpMaximus->wait(100000);
-
- sta.remove();
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::activate_false_alarm_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- Sta sta = mpMaximus->create_sta();
-
- Network_Clock_Tick averageDuration = 10;
- float stdDeviation = 0.1;
- mpMaximus->activate_false_alarm(averageDuration, stdDeviation);
- mpMaximus->wait(2*averageDuration);
-
- sta.remove();
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::deactivate_false_alarm_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- Sta sta = mpMaximus->create_sta();
-
- mpMaximus->deactivate_false_alarm();
- mpMaximus->wait(1000);
-
- sta.remove();
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::is_station_idle_test (void)
-{
- logTest();
-
- if (NULL != mpMaximus)
- {
- Sta sta = mpMaximus->create_sta();
-
- CPPUNIT_ASSERT_MESSAGE ( "is_station_idle failed", !mpMaximus->is_station_idle(sta.getStationId()) );
- mpMaximus->wait(1);
- CPPUNIT_ASSERT_MESSAGE ( "is_station_idle failed", mpMaximus->is_station_idle(sta.getStationId()) );
-
- sta.remove();
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
-
-void MaximusTest::hide_sta_test (void)
-{
- logTest ();
-
- if (NULL != mpMaximus)
- {
- Sta sta1 = mpMaximus->create_sta ();
- Sta sta2 = mpMaximus->create_sta ();
-
- mpMaximus->hide_sta (sta1, sta2, true);
-
- /* retrieve stations 1 and 2 */
- Station *pStation1 = NULL, *pStation2 = NULL;
- for (StationsList::const_iterator it = mpCoreEngine->getSystem ()->getListOfStations ()->begin ();
- it != mpCoreEngine->getSystem ()->getListOfStations ()->end (); ++it)
- {
- if (NULL != *it)
- {
- Sci_Msg_Station_Id id = (*it)->getStationId ();
- if (sta1.getStationId () == id)
- pStation1 = *it;
- else if (sta2.getStationId () == id)
- pStation2 = *it;
- }
- }
- CPPUNIT_ASSERT_MESSAGE ("Cannot retrieve stations",
- (pStation1 != NULL)
- && (pStation2 != NULL));
-
- set<Sci_Msg_Station_Id>::iterator it1, it2;
- /* check that station 2 is hidden from station 1 */
- it2 = pStation1->getHiddenStationsList ().find (sta2.getStationId ());
- CPPUNIT_ASSERT_MESSAGE ("hide_sta 2 from 1 failed", *it2 == sta2.getStationId ());
- /* check that station 1 is hidden from station 2 */
- it1 = pStation2->getHiddenStationsList ().find (sta1.getStationId ());
- CPPUNIT_ASSERT_MESSAGE ("hide_sta 1 from 2 failed", *it1 == sta1.getStationId ());
-
- mpMaximus->hide_sta (sta1, sta2, false);
- /* check that stations are visible from each other */
- it2 = pStation1->getHiddenStationsList ().find (sta2.getStationId ());
- CPPUNIT_ASSERT_MESSAGE ("hide_sta FALSE failed", it2 == pStation1->getHiddenStationsList ().end ());
- /* check that station 1 is hidden from station 2 */
- it1 = pStation2->getHiddenStationsList ().find (sta1.getStationId ());
- CPPUNIT_ASSERT_MESSAGE ("hide_sta FALSE failed", it1 == pStation2->getHiddenStationsList ().end ());
-
- /* clean */
- sta1.remove ();
- sta2.remove ();
- }
- else
- {
- CPPUNIT_FAIL ("Maximus pointer is NULL");
- }
-}
-
diff --git a/cesar/maximus/coreengine/src/Msg.cpp b/cesar/maximus/coreengine/src/Msg.cpp
deleted file mode 100644
index 6af40f8bf0..0000000000
--- a/cesar/maximus/coreengine/src/Msg.cpp
+++ /dev/null
@@ -1,544 +0,0 @@
-/************************************************************************
- Msg.cpp - Copyright buret
-
-Here you can write a license for your code, some comments or any other
-information you want to have in your generated code. To to this simply
-configure the "headings" directory in uml to point to a directory
-where you have your heading files.
-
-or you can just replace the contents of this file with your own.
-If you want to do this, this file is located at
-
-/usr/share/apps/umbrello/headings/heading.cpp
-
--->Code Generators searches for heading files based on the file extension
- i.e. it will look for a file name ending in ".h" to include in C++ header
- files, and for a file name ending in ".java" to include in all generated
- java code.
- If you name the file "heading.<extension>", Code Generator will always
- choose this file even if there are other files with the same extension in the
- directory. If you name the file something else, it must be the only one with that
- extension in the directory to guarantee that Code Generator will choose it.
-
-you can use variables in your heading files which are replaced at generation
-time. possible variables are : author, date, time, filename and filepath.
-just write %variable_name%
-
-This file was generated on %date% at %time%
-The original location of this file is /home/buret/eclipse/maximus/coreengine/src/Msg.cpp
-**************************************************************************/
-
-#include "Msg.h"
-
-#include "Sta.h"
-#include "IFunctionCall.h"
-#include "Maximus.h"
-#include "ISystem.h"
-
-#include "Error.h"
-#include "Logger.h"
-
-#include <boost/bind.hpp> // for 'boost::bind()'
-using namespace std;
-
-
-// Constructors/Destructors
-//
-
-
-Msg::Msg ( Maximus * p_maximus,
- IFunctionCall * p_function_call_manager,
- ISystem * p_system_manager,
- const string & name ):
-mpMaximus(NULL),
-mpFunctionCallManager(NULL),
-mpSystemManager(NULL),
-mCallback(NULL),
-mpFunctionSciMsg(NULL),
-mResponseReceived(false)
-{
- logFunction();
-
- if ( (NULL != p_maximus)
- && (NULL != p_function_call_manager)
- && (NULL != p_system_manager) )
- {
- mpMaximus = p_maximus;
- mpFunctionCallManager = p_function_call_manager;
- mpSystemManager = p_system_manager;
- mpFunctionSciMsg = getFunctionCallManager()->createMsg();
- getFunctionSciMsg()->incrementSpecializedSciMsgId(); // to have an updated msg id
- getFunctionSciMsg()->setFunctionName(name);
- }
- else
- {
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Maximus, function call manager and/or system manager pointer(s) is/are NULL", errno);
- }
-}
-
-
-Msg::Msg ( const Msg & msg ):
-mpMaximus(NULL),
-mpFunctionCallManager(NULL),
-mpSystemManager(NULL),
-mCallback(NULL),
-mpFunctionSciMsg(NULL),
-mResponseReceived(false)
-{
- logFunction();
-
- mpMaximus = msg.getMaximus();
- mpFunctionCallManager = msg.getFunctionCallManager();
- mpSystemManager = msg.getSystemManager();
- mpFunctionSciMsg = getFunctionCallManager()->createMsg();
- getFunctionSciMsg()->setFunctionName(msg.getFunctionSciMsg()->getFunctionName());
- getFunctionSciMsg()->setListOfParameters(msg.getFunctionSciMsg()->getListOfParameters());
- getFunctionSciMsg()->setSciMsgStationId(msg.getFunctionSciMsg()->getSciMsgStationId());
- setCallback(msg.getCallback());
- setResponseReceived(msg.isResponseReceived());
-}
-
-
-Msg::~Msg ( )
-{
- logFunction();
-
- if (NULL != mpMaximus)
- {
- mpMaximus = NULL;
- }
- if (NULL != mpFunctionCallManager)
- {
- mpFunctionCallManager = NULL;
- }
- if (NULL != mpSystemManager)
- {
- mpSystemManager = NULL;
- }
- if (NULL != mpFunctionSciMsg)
- {
- delete(mpFunctionSciMsg);
- mpFunctionSciMsg = NULL;
- }
-}
-
-
-//
-// Methods
-//
-
-
-// public methods
-//
-
-
-Msg & Msg::operator= ( const Msg & msg )
-{
- logFunction();
-
- try
- {
- mpMaximus = msg.getMaximus();
- mpFunctionCallManager = msg.getFunctionCallManager();
- mpSystemManager = msg.getSystemManager();
- mpFunctionSciMsg = getFunctionCallManager()->createMsg();
- getFunctionSciMsg()->setFunctionName(msg.getFunctionSciMsg()->getFunctionName());
- getFunctionSciMsg()->setListOfParameters(msg.getFunctionSciMsg()->getListOfParameters());
- getFunctionSciMsg()->setSciMsgStationId(msg.getFunctionSciMsg()->getSciMsgStationId());
- setCallback(msg.getCallback());
- setResponseReceived(msg.isResponseReceived());
- }
- catchFunction(getMaximus());
-
- return *this;
-}
-
-
-Msg & Msg::add_param ( const string & name )
-{
- logFunction();
-
- try
- {
- getFunctionSciMsg()->addParameter(FunctionCallParameter(name, 0, NULL));
- }
- catchFunction(getMaximus());
-
- return *this;
-}
-
-
-Msg & Msg::add_param ( const string & name, const unsigned long length, const unsigned char * p_value )
-{
- logFunction();
-
- try
- {
- if ( FUNCTION_CALL_PARAM_MAX_SIZE >= length)
- {
- getFunctionSciMsg()->addParameter(FunctionCallParameter(name, length, const_cast<unsigned char *>(p_value)));
- }
- else
- {
- errno = EMSGSIZE;
- throw Error(__PRETTY_FUNCTION__, "Length of parameter value exceeds max size", errno);
- }
- }
- catchFunction(getMaximus());
-
- return *this;
-}
-
-
-Msg & Msg::add_param ( const string & name, const string & value )
-{
- logFunction();
-
- try
- {
- if ( FUNCTION_CALL_PARAM_MAX_SIZE >= value.length()+1)
- {
- getFunctionSciMsg()->addParameter(FunctionCallParameter(name, value.length()+1, (unsigned char *)value.c_str()));
- }
- else
- {
- errno = EMSGSIZE;
- throw Error(__PRETTY_FUNCTION__, "Length of parameter value exceeds max size", errno);
- }
- }
- catchFunction(getMaximus());
-
- return *this;
-}
-
-
-Msg & Msg::remove_param ( const string & name )
-{
- logFunction();
-
- try
- {
- getFunctionSciMsg()->removeParameter(name);
- }
- catchFunction(getMaximus());
-
- return *this;
-}
-
-
-Msg & Msg::set_cb ( const cb_t & user_cb )
-{
- logFunction();
-
- try
- {
- mCallback = user_cb;
- }
- catchFunction(getMaximus());
-
- return *this;
-}
-
-
-Msg & Msg::remove_cb ( )
-{
- logFunction();
-
- try
- {
- mCallback = NULL;
- }
- catchFunction(getMaximus());
-
- return *this;
-}
-
-
-Msg & Msg::set_sta ( Sta & sta )
-{
- logFunction();
-
- try
- {
- getFunctionSciMsg()->setSciMsgStationId(sta.getStationId());
- }
- catchFunction(getMaximus());
-
- return *this;
-}
-
-
-void Msg::send_async ( )
-{
- logFunction();
-
- try
- {
- // Register callback and send message
- getFunctionCallManager()->registerCallback( getFunctionSciMsg()->getSpecializedSciMsgId(),
- (boost::bind(&Msg::receiveAsynchronousResponse, this, _1)) );
- while(!getSystemManager()->isStationIdle(getFunctionSciMsg()->getSciMsgStationId()))
- {
- getMaximus()->process();
- }
- getFunctionCallManager()->sendMsg(getFunctionSciMsg());
- }
- catchFunction(getMaximus());
-}
-
-
-void Msg::send_async ( Sta & sta )
-{
- logFunction();
-
- try
- {
- set_sta(sta);
- send_async();
- }
- catchFunction(getMaximus());
-}
-
-
-Msg & Msg::send ( )
-{
- logFunction();
-
- try
- {
- // Register callback and send message
- getFunctionCallManager()->registerCallback( getFunctionSciMsg()->getSpecializedSciMsgId(),
- (boost::bind(&Msg::receiveResponse, this, _1)) );
- while(!getSystemManager()->isStationIdle(getFunctionSciMsg()->getSciMsgStationId()))
- {
- getMaximus()->process();
- }
- getFunctionCallManager()->sendMsg(getFunctionSciMsg());
-
- // Wait for response
- while(!isResponseReceived())
- {
- getMaximus()->process();
- }
- setResponseReceived(false);
- if (NULL != getCallback())
- {
- getCallback()(*this);
- }
- }
- catchFunction(getMaximus());
-
- return *this;
-}
-
-
-Msg & Msg::send ( Sta & sta )
-{
- logFunction();
-
- try
- {
- set_sta(sta);
- }
- catchFunction(getMaximus());
-
- return send();
-}
-
-
-bool Msg::is_param ( const string & name ) const
-{
- logFunction();
- bool bIsParam;
-
- try
- {
- unsigned long length = FUNCTION_CALL_PARAM_MAX_SIZE; /* max size of 1 parameter */
- unsigned char * pParam = new unsigned char [length];
- bIsParam = (NULL != bind_param(name, length, pParam));
- if (NULL != pParam)
- {
- delete [] pParam;
- pParam = NULL;
- }
- }
- catchFunction(getMaximus());
-
- return bIsParam;
-}
-
-
-unsigned char * Msg::bind_param ( const string & name, unsigned long & length, unsigned char * p_data ) const
-{
- logFunction();
- unsigned char * pData = NULL; // parameter not found => return NULL
-
- try
- {
- if (getFunctionSciMsg()->bindParameter(name, length, p_data))
- {
- // Parameter found => return p_data
- pData = p_data;
- }
- }
- catchFunction(getMaximus());
-
- return pData;
-}
-
-
-Function_Call_Msg_Id Msg::get_tx_msg_id ( ) const
-{
- return getFunctionSciMsg()->getSpecializedSciMsgId();
-}
-
-
-Function_Call_Msg_Id Msg::get_rx_msg_id ( ) const
-{
- return getFunctionSciMsg()->getSpecializedSciMsgHeader().msg_id;
-}
-
-
-// private methods
-//
-
-
-// private attributes accessor methods
-//
-
-
-Maximus * Msg::getMaximus ( ) const
-{
- if (NULL == mpMaximus)
- {
- throw Error(__PRETTY_FUNCTION__, "Maximus pointer is NULL");
- }
-
- return mpMaximus;
-}
-
-
-IFunctionCall * Msg::getFunctionCallManager ( ) const
-{
- try
- {
- if (NULL == mpFunctionCallManager)
- {
- throw Error(__PRETTY_FUNCTION__, "Function call manager pointer is NULL");
- }
- }
- catchFunction(getMaximus());
-
- return mpFunctionCallManager;
-}
-
-
-ISystem * Msg::getSystemManager ( ) const
-{
- try
- {
- if (NULL == mpSystemManager)
- {
- throw Error(__PRETTY_FUNCTION__, "System manager pointer is NULL");
- }
- }
- catchFunction(getMaximus());
-
- return mpSystemManager;
-}
-
-
-cb_t Msg::getCallback ( ) const
-{
- return mCallback;
-}
-
-
-bool Msg::setCallback ( const cb_t callback )
-{
- mCallback = callback;
-
- return true;
-}
-
-
-FunctionSciMsg * Msg::getFunctionSciMsg ( ) const
-{
- try
- {
- if (NULL == mpFunctionSciMsg)
- {
- throw Error(__PRETTY_FUNCTION__, "Function SCI message pointer is NULL");
- }
- }
- catchFunction(getMaximus());
-
- return mpFunctionSciMsg;
-}
-
-
-bool Msg::setFunctionSciMsg ( const FunctionSciMsg & function_sci_msg )
-{
- try
- {
- // If a function message had already been created, delete it before setting the new one
- if (NULL != mpFunctionSciMsg)
- {
- delete (mpFunctionSciMsg);
- mpFunctionSciMsg = NULL;
- }
- mpFunctionSciMsg = new FunctionSciMsg(function_sci_msg);
- }
- catchFunction(getMaximus());
-
- return true;
-}
-
-
-bool Msg::isResponseReceived ( ) const
-{
- return mResponseReceived;
-}
-
-
-bool Msg::setResponseReceived ( const bool response_received )
-{
- mResponseReceived = response_received;
-
- return true;
-}
-
-
-// public methods
-//
-
-
-void Msg::receiveResponse ( const FunctionSciMsg & function_sci_msg )
-{
- logFunction();
-
- try
- {
- setFunctionSciMsg(function_sci_msg);
- setResponseReceived(true);
- }
- catchFunction(getMaximus());
-}
-
-
-void Msg::receiveAsynchronousResponse ( const FunctionSciMsg & function_sci_msg )
-{
- logFunction();
-
- try
- {
- setFunctionSciMsg(function_sci_msg);
- if (NULL != getCallback())
- {
- getCallback()(*this);
- }
- }
- catchFunction(getMaximus());
-}
-
diff --git a/cesar/maximus/coreengine/src/MsgTest.cpp b/cesar/maximus/coreengine/src/MsgTest.cpp
deleted file mode 100644
index 9b5cc048f6..0000000000
--- a/cesar/maximus/coreengine/src/MsgTest.cpp
+++ /dev/null
@@ -1,302 +0,0 @@
-
-#include "MsgTest.h"
-
-#include "Msg.h"
-#include "Maximus.h"
-#include "FunctionSciMsg.h"
-#include "FunctionCallParameter.h"
-#include "Sta.h"
-#include "CoreEngine.h"
-
-#include "system_types.h" // for 'MAXIMUS_STATION_STATUS_IDLE'
-
-#include <iostream>
-using namespace std;
-
-CPPUNIT_TEST_SUITE_REGISTRATION (MsgTest);
-
-void callback1 (Msg & msg)
-{
- logTest();
-}
-
-void callback2 (Msg & msg)
-{
- logTest();
-}
-
-
-void MsgTest::setUp (void)
-{
- logTest();
-
- mpCoreEngine = new CoreEngine();
- mpMaximus = new Maximus(mpCoreEngine);
- mpMsg = new Msg(mpMaximus, mpCoreEngine->getFunctionCall(), mpCoreEngine->getSystem());
-}
-
-
-void MsgTest::tearDown (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- delete (mpMsg);
- mpMsg = NULL;
- }
- if (NULL != mpMaximus)
- {
- delete (mpMaximus);
- mpMaximus = NULL;
- }
- mpCoreEngine = NULL;
-}
-
-
-void MsgTest::add_param_test (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- mpMsg->add_param("name");
- mpMsg->add_param("unsigned char *", 6, (unsigned char *)"hello\0");
- string str("hello");
- mpMsg->add_param("string", str);
- mpMsg->add_param<int>("<int>", 123);
- unsigned int i = 456;
- mpMsg->add_param("<unsigned int>", i);
- mpMsg->add_param<bool>("<bool>", true);
-
- CPPUNIT_ASSERT_MESSAGE ( "add_param failed",
- (mpMsg->is_param("name"))
- && (mpMsg->is_param("unsigned char *"))
- && (mpMsg->is_param("string"))
- && (mpMsg->is_param("<int>"))
- && (mpMsg->is_param("<unsigned int>"))
- && (mpMsg->is_param("<bool>")) );
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::remove_param_test (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- mpMsg->add_param("name");
- mpMsg->remove_param("name");
-
- CPPUNIT_ASSERT_MESSAGE ( "remove_param failed",
- !mpMsg->is_param("name") );
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::set_cb_test (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- mpMsg->set_cb(&callback1);
- mpMsg->set_cb(&callback2);
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::remove_cb_test (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- mpMsg->set_cb(&callback1);
- mpMsg->remove_cb();
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::set_sta_test (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- Sta sta1 = mpMaximus->create_sta();
- Sta sta2 = mpMaximus->create_sta();
- mpMsg->set_sta(sta1);
- mpMsg->set_sta(sta2);
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::send_async_test (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- Sta sta = mpMaximus->create_sta();
- mpMsg->send_async(sta);
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::send_test (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- Sta sta = mpMaximus->create_sta();
- mpMsg->send(sta);
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::is_param_test (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- mpMsg->add_param("name");
-
- CPPUNIT_ASSERT_MESSAGE ( "is_param failed",
- mpMsg->is_param("name") );
-
- mpMsg->remove_param("name");
-
- CPPUNIT_ASSERT_MESSAGE ( "is_param failed",
- !mpMsg->is_param("name") );
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::bind_param_test (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- string str("hello");
- mpMsg->add_param("string", str);
- mpMsg->add_param<int>("int", 123);
- mpMsg->add_param<bool>("false", false);
- mpMsg->add_param<bool>("true", true);
-
- unsigned long length = str.length();
- unsigned char * pParam = new unsigned char [length];
- int i = mpMsg->bind_param<int>("int");
- bool bFalse = mpMsg->bind_param<bool>("false");
- bool bTrue = mpMsg->bind_param<bool>("true");
-
- CPPUNIT_ASSERT_MESSAGE ( "bind_param failed",
- (NULL != mpMsg->bind_param("string", length, pParam))
- && (0 == memcmp(pParam, str.c_str(), str.length()))
- && (mpMsg->is_param("int"))
- && (123 == i)
- && (mpMsg->is_param("false"))
- && !bFalse
- && (mpMsg->is_param("true"))
- && bTrue );
-
- if (NULL != pParam)
- {
- delete [] pParam;
- pParam = NULL;
- }
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::receiveResponseTest (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- FunctionSciMsg * pFunctionSciMsg = new FunctionSciMsg(mpCoreEngine->getFunctionCall());
- pFunctionSciMsg->addParameter(FunctionCallParameter("name", 6, (unsigned char *)"hello\0"));
- mpMsg->receiveResponse(*pFunctionSciMsg);
-
- CPPUNIT_ASSERT_MESSAGE ( "receiveResponse failed",
- mpMsg->is_param("name") );
-
- if (NULL != pFunctionSciMsg)
- {
- delete(pFunctionSciMsg);
- pFunctionSciMsg = NULL;
- }
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
-
-void MsgTest::receiveAsynchronousResponseTest (void)
-{
- logTest();
-
- if (NULL != mpMsg)
- {
- FunctionSciMsg * pFunctionSciMsg = new FunctionSciMsg(mpCoreEngine->getFunctionCall());
- pFunctionSciMsg->addParameter(FunctionCallParameter("name", 6, (unsigned char *)"hello\0"));
- mpMsg->receiveAsynchronousResponse(*pFunctionSciMsg);
-
- CPPUNIT_ASSERT_MESSAGE ( "receiveAsynchronousResponse failed",
- mpMsg->is_param("name") );
-
- if (NULL != pFunctionSciMsg)
- {
- delete(pFunctionSciMsg);
- pFunctionSciMsg = NULL;
- }
- }
- else
- {
- CPPUNIT_FAIL ("Msg pointer is NULL");
- }
-}
-
diff --git a/cesar/maximus/coreengine/src/Sta.cpp b/cesar/maximus/coreengine/src/Sta.cpp
deleted file mode 100644
index 35f2bbf163..0000000000
--- a/cesar/maximus/coreengine/src/Sta.cpp
+++ /dev/null
@@ -1,264 +0,0 @@
-/************************************************************************
- Sta.cpp - Copyright buret
-
-Here you can write a license for your code, some comments or any other
-information you want to have in your generated code. To to this simply
-configure the "headings" directory in uml to point to a directory
-where you have your heading files.
-
-or you can just replace the contents of this file with your own.
-If you want to do this, this file is located at
-
-/usr/share/apps/umbrello/headings/heading.cpp
-
--->Code Generators searches for heading files based on the file extension
- i.e. it will look for a file name ending in ".h" to include in C++ header
- files, and for a file name ending in ".java" to include in all generated
- java code.
- If you name the file "heading.<extension>", Code Generator will always
- choose this file even if there are other files with the same extension in the
- directory. If you name the file something else, it must be the only one with that
- extension in the directory to guarantee that Code Generator will choose it.
-
-you can use variables in your heading files which are replaced at generation
-time. possible variables are : author, date, time, filename and filepath.
-just write %variable_name%
-
-This file was generated on %date% at %time%
-The original location of this file is /home/buret/eclipse/maximus/coreengine/src/Sta.cpp
-**************************************************************************/
-
-#include "Sta.h"
-
-#include "Maximus.h"
-#include "ISystem.h"
-
-#include "Error.h"
-#include "Logger.h"
-
-#include <iostream> // for 'cout', 'cerr' and 'clog'
-using namespace std;
-
-
-// Constructors/Destructors
-//
-
-
-StaCounter Sta::mStaCounter;
-
-
-Sta::Sta ( Maximus * p_maximus, ISystem * p_system_manager, const string & station_executable, uint32_t seed ):
-mpMaximus(NULL),
-mpSystemManager(NULL),
-mStationId(0)
-{
- logFunction();
-
- if ( (NULL != p_maximus) && (NULL != p_system_manager) )
- {
- mpMaximus = p_maximus;
- mpSystemManager = p_system_manager;
- mStationId = mpSystemManager->createStation(station_executable, seed);
- mStaCounter[getStationId()] = 1;
- }
- else
- {
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Maximus and/or System manager pointers are NULL", errno);
- }
-}
-
-
-Sta::Sta ( const Sta & sta ):
-mpSystemManager(NULL),
-mStationId(0)
-{
- logFunction();
-
- mpMaximus = sta.getMaximus();
- mpSystemManager = sta.getSystemManager();
- mStationId = sta.getStationId();
- mStaCounter[getStationId()] += 1;
-}
-
-
-Sta::~Sta ( )
-{
- logFunction();
-
- remove();
- if (NULL != mpMaximus)
- {
- mpMaximus = NULL;
- }
- if (NULL != mpSystemManager)
- {
- mpSystemManager = NULL;
- }
-}
-
-
-//
-// Methods
-//
-
-
-// public methods
-//
-
-
-void Sta::remove ( )
-{
- logFunction();
-
- try
- {
- if (0 == mStaCounter[getStationId()])
- {
- if (0 == getStationId())
- {
-#if CONFIG_LOG
- clog << logger(LOG_INFO) << "station already removed" << endl;
-#endif /* CONFIG_LOG */
- }
- else
- {
- throw Error(__PRETTY_FUNCTION__, "Problem while deleting station");
- }
- }
- else if (1 == mStaCounter[getStationId()])
- {
- getSystemManager()->removeStation(getStationId());
- resetStationId();
- }
- else
- {
- mStaCounter[getStationId()] -= 1;
- }
- }
- catchFunction(getMaximus());
-}
-
-
-void Sta::deactivate ( )
-{
- logFunction();
-
- try
- {
- getSystemManager()->deactivateStation(getStationId());
- }
- catchFunction(getMaximus());
-}
-
-
-void Sta::activate ( )
-{
- logFunction();
-
- try
- {
- getSystemManager()->activateStation(getStationId());
- }
- catchFunction(getMaximus());
-}
-
-
-void Sta::debug ( )
-{
- logFunction();
-
- try
- {
- getSystemManager()->debugStation(getStationId());
- }
- catchFunction(getMaximus());
-}
-
-
-bool Sta::is_idle ( ) const
-{
- logFunction();
- bool isIdle = false;
-
- try
- {
- isIdle = getSystemManager()->isStationIdle(getStationId());
- }
- catchFunction(getMaximus());
-
- return isIdle;
-}
-
-
-void Sta::set_name ( const std::string & station_name )
-{
- logFunction();
-
- try
- {
- while (!is_idle())
- {
- getMaximus()->process();
- }
- getSystemManager()->setStationName(getStationId(), station_name);
- }
- catchFunction(getMaximus());
-}
-
-
-// private methods
-//
-
-
-// private attribute accessor methods
-//
-
-
-Maximus * Sta::getMaximus ( ) const
-{
- if (NULL == mpMaximus)
- {
- throw Error(__PRETTY_FUNCTION__, "Maximus pointer is NULL");
- }
-
- return mpMaximus;
-}
-
-
-ISystem * Sta::getSystemManager ( ) const
-{
- try
- {
- if (NULL == mpSystemManager)
- {
- throw Error(__PRETTY_FUNCTION__, "System manager pointer is NULL");
- }
- }
- catchFunction(getMaximus());
-
- return mpSystemManager;
-}
-
-
-bool Sta::resetStationId ( )
-{
- mStationId = 0;
-
- return true;
-}
-
-
-// public methods
-//
-
-
-// private attribute accessor methods
-//
-
-
-Sci_Msg_Station_Id Sta::getStationId ( ) const
-{
- return mStationId;
-}
-
diff --git a/cesar/maximus/coreengine/src/StaTest.cpp b/cesar/maximus/coreengine/src/StaTest.cpp
deleted file mode 100644
index 1af29a5430..0000000000
--- a/cesar/maximus/coreengine/src/StaTest.cpp
+++ /dev/null
@@ -1,184 +0,0 @@
-
-#include "StaTest.h"
-
-#include "Sta.h"
-#include "Maximus.h"
-#include "SystemManager.h"
-#include "SciServer.h"
-#include "NetworkClockProcessor.h"
-
-#include "Logger.h"
-
-using namespace std;
-
-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 (mpMaximus, mpSystemManager, mpSystemManager->getDefaultStationExecutable());
-}
-
-
-void StaTest::tearDown (void)
-{
- logTest();
-
- if (NULL != mpSta)
- {
- delete (mpSta);
- mpSta = NULL;
- }
- if (NULL != mpMaximus)
- {
- delete (mpMaximus);
- mpMaximus = NULL;
- }
- if (NULL != mpSystemManager)
- {
- delete (mpSystemManager);
- mpSystemManager = NULL;
- }
- if (NULL != mpNetworkClock)
- {
- delete (mpNetworkClock);
- mpNetworkClock = NULL;
- }
- if (NULL != mpSci)
- {
- delete (mpSci);
- mpSci = NULL;
- }
-}
-
-
-void StaTest::remove_test (void)
-{
- logTest();
-
- if (NULL != mpSta)
- {
- mpSta->remove();
-
- CPPUNIT_ASSERT_MESSAGE ( "remove failed",
- (mpSystemManager->getListOfStations()->empty())
- && (0 == mpSta->getStationId()) );
- }
- else
- {
- CPPUNIT_FAIL ("Sta pointer is NULL");
- }
-}
-
-
-void StaTest::deactivate_test (void)
-{
- logTest();
-
- if (NULL != mpSta)
- {
- mpSta->deactivate();
-
- CPPUNIT_ASSERT_MESSAGE ( "deactivate failed",
- MAXIMUS_STATION_STATUS_DEACTIVATED == mpSystemManager->getStationStatus(mpSta->getStationId()) );
- }
- else
- {
- CPPUNIT_FAIL ("Sta pointer is NULL");
- }
-}
-
-
-void StaTest::activate_test (void)
-{
- logTest();
-
- if (NULL != mpSta)
- {
- mpSta->deactivate();
- mpSta->activate();
-
- CPPUNIT_ASSERT_MESSAGE ( "activate failed",
- MAXIMUS_STATION_STATUS_DEACTIVATED != mpSystemManager->getStationStatus(mpSta->getStationId()) );
- }
- else
- {
- CPPUNIT_FAIL ("Sta pointer is NULL");
- }
-}
-
-
-void StaTest::debug_test (void)
-{
- logTest();
-
- if (NULL != mpSta)
- {
- mpSta->debug();
- }
- else
- {
- CPPUNIT_FAIL ("Sta pointer is NULL");
- }
-}
-
-
-void StaTest::is_idle_test (void)
-{
- logTest();
-
- if (NULL != mpSta)
- {
- // Set the station status and test the function
- mpSystemManager->updateStationStatus(mpSta->getStationId(), MAXIMUS_STATION_STATUS_IDLE);
- CPPUNIT_ASSERT_MESSAGE ( "is_idle failed", mpSta->is_idle() );
-
- // Set the station status and test the function
- mpSystemManager->updateStationStatus(mpSta->getStationId(), MAXIMUS_STATION_STATUS_BUSY);
- CPPUNIT_ASSERT_MESSAGE ( "is_idle failed", !mpSta->is_idle() );
- }
- else
- {
- CPPUNIT_FAIL ("Sta pointer is NULL");
- }
-}
-
-
-void StaTest::getStationIdTest (void)
-{
- logTest();
-
- if (NULL != mpSta)
- {
- CPPUNIT_ASSERT_MESSAGE ( "getStationId failed",
- 0 != mpSta->getStationId() );
- }
- else
- {
- CPPUNIT_FAIL ("Sta pointer is NULL");
- }
-}
-
-
-void StaTest::set_name_test (void)
-{
- logTest();
-
- if (NULL != mpSta)
- {
- mpSystemManager->updateStationStatus(mpSta->getStationId(), MAXIMUS_STATION_STATUS_IDLE);
- mpSta->set_name("station name");
- }
- else
- {
- CPPUNIT_FAIL ("Sta pointer is NULL");
- }
-}
-