summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--maximus/common/interfaces/Maximus.h17
-rw-r--r--maximus/common/interfaces/Msg.h11
-rw-r--r--maximus/common/interfaces/Sta.h13
-rw-r--r--maximus/coreengine/inc/MsgTest.h4
-rw-r--r--maximus/coreengine/src/Maximus.cpp78
-rw-r--r--maximus/coreengine/src/Msg.cpp32
-rw-r--r--maximus/coreengine/src/MsgTest.cpp12
-rw-r--r--maximus/coreengine/src/Sta.cpp30
-rw-r--r--maximus/functioncall/inc/FunctionSciMsg.h2
-rw-r--r--maximus/functioncall/src/FunctionCallParameter.cpp27
-rw-r--r--maximus/functioncall/src/FunctionCallParameterTest.cpp2
-rw-r--r--maximus/functioncall/src/FunctionSciMsg.cpp37
-rw-r--r--maximus/functioncall/src/IFunctionCallTest.cpp20
-rw-r--r--maximus/networkclock/src/NetworkClockEvtList.cpp3
-rw-r--r--maximus/phy/src/PhyProcessor.cpp11
-rw-r--r--maximus/sci/src/SciMsg.cpp72
-rw-r--r--maximus/sci/src/SciMsgTest.cpp5
-rw-r--r--maximus/sci/src/SciServer.cpp5
-rw-r--r--maximus/system/src/Station.cpp8
-rw-r--r--maximus/system/src/SystemManager.cpp1
-rw-r--r--maximus/usertest/src/main_example.cpp19
21 files changed, 259 insertions, 150 deletions
diff --git a/maximus/common/interfaces/Maximus.h b/maximus/common/interfaces/Maximus.h
index 77459ab7cd..585ea35b7c 100644
--- a/maximus/common/interfaces/Maximus.h
+++ b/maximus/common/interfaces/Maximus.h
@@ -90,26 +90,26 @@ public:
void process ( );
/**
- * @return Sta &
+ * @return Sta
* Create a new station.
* Return a station object.
*/
- Sta & create_sta ( );
+ Sta create_sta ( );
/**
- * @return Msg &
+ * @return Msg
* @param name
* Create a function message, which name is set to name.
* Return a message object.
*/
- Msg & create_fc ( const std::string & name );
+ Msg create_fc ( const std::string & name );
/**
- * @return Msg &
+ * @return Msg
* Create a probe message.
* Return a message object.
*/
- Msg & create_probe ( );
+ Msg create_probe ( );
/**
* @param value
@@ -192,6 +192,11 @@ public:
// public methods
//
+ /**
+ * Constructor (FOR UNITARY TESTS ONLY)
+ */
+ Maximus ( CoreEngine * p_core_engine );
+
static void wrapper ( int n );
void stop ( );
diff --git a/maximus/common/interfaces/Msg.h b/maximus/common/interfaces/Msg.h
index 6173ca7b70..82d24be8f7 100644
--- a/maximus/common/interfaces/Msg.h
+++ b/maximus/common/interfaces/Msg.h
@@ -66,8 +66,13 @@ public:
Msg ( Maximus * p_maximus,
FunctionCallManager * p_function_call_manager,
SystemManager * p_system_manager,
- const std::string name = PROBE_ID );
-
+ const std::string & name = PROBE_ID );
+
+ /**
+ * Copy constructor
+ */
+ Msg ( const Msg & msg );
+
/**
* Empty Destructor
*/
@@ -206,7 +211,7 @@ public:
* Note that user has to allocate enough memory for parameter value.
* If parameter value length is unknown, user has to allocate FUNCTION_CALL_PARAM_MAX_SIZE bytes.
*/
- unsigned char * bind_param ( const std::string & name, unsigned long & length, unsigned char * & p_data ) const;
+ unsigned char * bind_param ( const std::string & name, unsigned long & length, unsigned char * p_data ) const;
/**
* @param name
diff --git a/maximus/common/interfaces/Sta.h b/maximus/common/interfaces/Sta.h
index 34f408dbf0..7667819405 100644
--- a/maximus/common/interfaces/Sta.h
+++ b/maximus/common/interfaces/Sta.h
@@ -51,7 +51,12 @@ public:
/**
* Constructor
*/
- Sta ( SystemManager * p_system_manager );
+ Sta ( SystemManager * p_system_manager = 0 );
+
+ /**
+ * Copy constructors
+ */
+ Sta ( const Sta & sta );
/**
* Empty Destructor
@@ -62,6 +67,12 @@ public:
//
/**
+ * @return Sta &
+ * @param sta
+ */
+ Sta & operator= ( const Sta & sta );
+
+ /**
* Remove an existing station.
*/
void remove ( );
diff --git a/maximus/coreengine/inc/MsgTest.h b/maximus/coreengine/inc/MsgTest.h
index 5f420308eb..63091e16c9 100644
--- a/maximus/coreengine/inc/MsgTest.h
+++ b/maximus/coreengine/inc/MsgTest.h
@@ -7,6 +7,7 @@
class Msg;
class Maximus;
+class CoreEngine;
class MsgTest : public CPPUNIT_NS::TestFixture
@@ -49,7 +50,8 @@ private:
Msg * mpMsg;
Maximus * mpMaximus;
-
+ CoreEngine * mpCoreEngine;
+
};
diff --git a/maximus/coreengine/src/Maximus.cpp b/maximus/coreengine/src/Maximus.cpp
index e6a644cdb6..b423c5be0a 100644
--- a/maximus/coreengine/src/Maximus.cpp
+++ b/maximus/coreengine/src/Maximus.cpp
@@ -67,7 +67,6 @@ Maximus * pMaximus;
Maximus::Maximus ( ):
mpCoreEngine(NULL),
-mMaximusLogFile(0),
mMaxTickValue(0),
mWaitTickValue(0)
{
@@ -90,6 +89,34 @@ mWaitTickValue(0)
}
}
+Maximus::Maximus ( CoreEngine * p_core_engine ):
+mpCoreEngine(NULL),
+mMaxTickValue(0),
+mWaitTickValue(0)
+{
+ logFunction();
+
+ try
+ {
+ if (UNITTEST)
+ {
+ // For unitary tests log
+ logger.setLogLevel(LOG_DEBUG);
+
+ mpCoreEngine = p_core_engine;
+ }
+ else
+ {
+ throw Error(__PRETTY_FUNCTION__, "FOR UNITARY TESTS ONLY");
+ }
+ }
+ catch ( Error &e )
+ {
+ e.display();
+ stop();
+ }
+}
+
Maximus::~Maximus ( )
{
@@ -283,60 +310,27 @@ void Maximus::process ( )
}
-Sta & Maximus::create_sta ( )
+Sta Maximus::create_sta ( )
{
logFunction();
- static Sta * pCreatedSta;
-
- try
- {
- pCreatedSta = new Sta(getSystemManager());
- }
- catch ( Error &e )
- {
- e.display();
- stop();
- }
-
- return (*pCreatedSta);
+
+ return Sta(getSystemManager());
}
-Msg & Maximus::create_fc ( const std::string & name )
+Msg Maximus::create_fc ( const string & name )
{
logFunction();
- static Msg * pCreatedMsg;
-
- try
- {
- pCreatedMsg = new Msg(this, getFunctionCallManager(), getSystemManager(), name);
- }
- catch ( Error &e )
- {
- e.display();
- stop();
- }
-
- return (*pCreatedMsg);
+
+ return Msg(this, getFunctionCallManager(), getSystemManager(), name);
}
-Msg & Maximus::create_probe ( )
+Msg Maximus::create_probe ( )
{
logFunction();
- static Msg * pCreatedMsg;
-
- try
- {
- pCreatedMsg = new Msg(this, getFunctionCallManager(), getSystemManager());
- }
- catch ( Error &e )
- {
- e.display();
- stop();
- }
- return (*pCreatedMsg);
+ return Msg(this, getFunctionCallManager(), getSystemManager());
}
diff --git a/maximus/coreengine/src/Msg.cpp b/maximus/coreengine/src/Msg.cpp
index b1edf75999..7fdf3e42ad 100644
--- a/maximus/coreengine/src/Msg.cpp
+++ b/maximus/coreengine/src/Msg.cpp
@@ -50,7 +50,7 @@ using namespace std;
Msg::Msg ( Maximus * p_maximus,
FunctionCallManager * p_function_call_manager,
SystemManager * p_system_manager,
- const string name ):
+ const string & name ):
mpMaximus(NULL),
mpFunctionCallManager(NULL),
mpSystemManager(NULL),
@@ -61,7 +61,7 @@ mResponseReceived(false)
{
logFunction();
- mName = name;
+ mName.assign(name);
if ( (NULL != p_maximus)
&& (NULL != p_function_call_manager)
&& (NULL != p_system_manager) )
@@ -77,6 +77,29 @@ mResponseReceived(false)
}
+Msg::Msg ( const Msg & msg )
+{
+ logFunction();
+
+ mName.assign(msg.mName);
+ mpMaximus = msg.mpMaximus;
+ mpFunctionCallManager = msg.mpFunctionCallManager;
+ mpSystemManager = msg.mpSystemManager;
+
+ if (NULL != msg.getFunctionSciMsg())
+ {
+ setListOfParameters(msg.getFunctionSciMsg()->getListOfParameters());
+ }
+ else
+ {
+ setListOfParameters(msg.getListOfParameters());
+ }
+ set_cb(msg.getCallback());
+ setStationId(msg.getStationId());
+ setResponseReceived(msg.isResponseReceived());
+}
+
+
Msg::~Msg ( )
{
logFunction();
@@ -104,6 +127,7 @@ Msg::~Msg ( )
{
mListOfParameters.clear();
}
+ mName.clear();
}
catch ( Error &e )
{
@@ -451,7 +475,7 @@ bool Msg::is_param ( const string & name ) const
}
-unsigned char * Msg::bind_param ( const string & name, unsigned long & length, unsigned char * & p_data ) const
+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
@@ -663,7 +687,7 @@ bool Msg::setResponseReceived ( const bool response_received )
string Msg::getName ( ) const
{
- return mName;
+ return mName;
}
diff --git a/maximus/coreengine/src/MsgTest.cpp b/maximus/coreengine/src/MsgTest.cpp
index 8c5c8fec9f..fd5681031f 100644
--- a/maximus/coreengine/src/MsgTest.cpp
+++ b/maximus/coreengine/src/MsgTest.cpp
@@ -6,7 +6,7 @@
#include "FunctionSciMsg.h"
#include "FunctionCallParameter.h"
#include "Sta.h"
-#include "SystemManager.h"
+#include "CoreEngine.h"
#include "system_types.h" // for 'MAXIMUS_STATION_STATUS_IDLE'
@@ -29,9 +29,10 @@ void callback2 (Msg & msg)
void MsgTest::setUp (void)
{
logTest();
-
- mpMaximus = new Maximus();
- mpMsg = &mpMaximus->create_probe();
+
+ mpCoreEngine = new CoreEngine();
+ mpMaximus = new Maximus(mpCoreEngine);
+ mpMsg = new Msg(mpMaximus, mpCoreEngine->getFunctionCallManager(), mpCoreEngine->getSystemManager());
}
@@ -49,6 +50,7 @@ void MsgTest::tearDown (void)
delete (mpMaximus);
mpMaximus = NULL;
}
+ mpCoreEngine = NULL;
}
@@ -140,7 +142,7 @@ void MsgTest::set_sta_test (void)
if (NULL != mpMsg)
{
Sta sta1 = mpMaximus->create_sta();
- Sta sta2 = mpMaximus->create_sta();
+ Sta sta2 = mpMaximus->create_sta();
mpMsg->set_sta(sta1);
mpMsg->set_sta(sta2);
}
diff --git a/maximus/coreengine/src/Sta.cpp b/maximus/coreengine/src/Sta.cpp
index 08c001df5b..15c0935e1f 100644
--- a/maximus/coreengine/src/Sta.cpp
+++ b/maximus/coreengine/src/Sta.cpp
@@ -61,6 +61,21 @@ mStationId(0)
}
+Sta::Sta ( const Sta & sta ):
+mpSystemManager(NULL),
+mStationId(0)
+{
+ logFunction();
+
+ throw Error(__PRETTY_FUNCTION__, "NOT YET IMPLEMENTED");
+
+ /*
+ mpSystemManager = sta.getSystemManager();
+ mStationId = sta.getStationId();
+ */
+}
+
+
Sta::~Sta ( )
{
logFunction();
@@ -89,6 +104,21 @@ Sta::~Sta ( )
//
+Sta & Sta::operator= ( const Sta & sta )
+{
+ logFunction();
+
+ throw Error(__PRETTY_FUNCTION__, "NOT YET IMPLEMENTED");
+
+ /*
+ mpSystemManager = sta.getSystemManager();
+ mStationId = sta.getStationId();
+ */
+
+ return *this;
+}
+
+
void Sta::remove ( )
{
logFunction();
diff --git a/maximus/functioncall/inc/FunctionSciMsg.h b/maximus/functioncall/inc/FunctionSciMsg.h
index 9d3dae6208..d9ca6da1ee 100644
--- a/maximus/functioncall/inc/FunctionSciMsg.h
+++ b/maximus/functioncall/inc/FunctionSciMsg.h
@@ -147,7 +147,7 @@ public:
* @param name_of_parameter_to_get
* @param p_data
*/
- bool bindParameter ( const std::string name_of_parameter_to_get, unsigned long & data_length, unsigned char * & p_data ) const;
+ bool bindParameter ( const std::string name_of_parameter_to_get, unsigned long & data_length, unsigned char * p_data ) const;
/**
* @return bool
diff --git a/maximus/functioncall/src/FunctionCallParameter.cpp b/maximus/functioncall/src/FunctionCallParameter.cpp
index e98832e753..640c6fd19b 100644
--- a/maximus/functioncall/src/FunctionCallParameter.cpp
+++ b/maximus/functioncall/src/FunctionCallParameter.cpp
@@ -97,7 +97,7 @@ FunctionCallParameter::~FunctionCallParameter ( )
mName.clear();
if (NULL != mpValue)
{
- delete (mpValue);
+ delete [] mpValue;
mpValue = NULL;
}
}
@@ -246,16 +246,19 @@ bool FunctionCallParameter::setValue ( const unsigned char * p_value )
{
logFunction();
bool bSetValue = false;
-
+
+ // Free memory
+ //
+ if (NULL != mpValue)
+ {
+ delete [] mpValue;
+ mpValue = NULL;
+ }
+
if (NULL != p_value)
{
- // Allocate (and free) memory
+ // Allocate memory
//
- if (NULL != mpValue)
- {
- delete(mpValue);
- mpValue = NULL;
- }
mpValue = new unsigned char [getValueLength()];
// Copy value
@@ -264,13 +267,7 @@ bool FunctionCallParameter::setValue ( const unsigned char * p_value )
bSetValue = true;
}
- else
- {
- // Set value
- //
- mpValue = NULL;
- }
-
+
return bSetValue;
}
diff --git a/maximus/functioncall/src/FunctionCallParameterTest.cpp b/maximus/functioncall/src/FunctionCallParameterTest.cpp
index 7f2c19abe5..6d139b73e9 100644
--- a/maximus/functioncall/src/FunctionCallParameterTest.cpp
+++ b/maximus/functioncall/src/FunctionCallParameterTest.cpp
@@ -83,7 +83,7 @@ void FunctionCallParameterTest::setValueTest (void)
mpFunctionCallParameter->displayParameter();
CPPUNIT_ASSERT_MESSAGE ( "setValue failed",
- 0 == memcmp(value, mpFunctionCallParameter->getValue(), length+1) );
+ 0 == memcmp(value, mpFunctionCallParameter->getValue(), length) );
}
catch (Error &e)
{
diff --git a/maximus/functioncall/src/FunctionSciMsg.cpp b/maximus/functioncall/src/FunctionSciMsg.cpp
index b712ee13d1..098c802b68 100644
--- a/maximus/functioncall/src/FunctionSciMsg.cpp
+++ b/maximus/functioncall/src/FunctionSciMsg.cpp
@@ -264,7 +264,7 @@ bool FunctionSciMsg::addParameter ( const FunctionCallParameter & function_argum
// Called by user when a message is received to retrieve function parameters
//
-bool FunctionSciMsg::bindParameter ( const string name_of_parameter_to_get, unsigned long & data_length, unsigned char * & p_data ) const
+bool FunctionSciMsg::bindParameter ( const string name_of_parameter_to_get, unsigned long & data_length, unsigned char * p_data ) const
{
logFunction();
bool bBindParameter = false;
@@ -334,14 +334,22 @@ bool FunctionSciMsg::identifyFunctionName ( )
// Remove function name from specialized SCI msg data
//
unsigned long tempDataLength = getSpecializedSciMsgDataLength();
- unsigned char * pTempData = getSpecializedSciMsgData();
+ unsigned char * pTempData = new unsigned char [tempDataLength];
+ memcpy(pTempData, getSpecializedSciMsgData(), tempDataLength);
bName = SciMsg::removeData (functionNameLength+1, tempDataLength, &pTempData);
if (0 != bName)
{
bName &= setSpecializedSciMsgDataLength(tempDataLength);
bName &= setSpecializedSciMsgData(pTempData);
}
- pTempData = NULL; // free pointer
+
+ // Free pointer
+ //
+ if (NULL != pTempData)
+ {
+ delete [] pTempData;
+ pTempData = NULL;
+ }
}
else
{
@@ -388,14 +396,20 @@ bool FunctionSciMsg::identifyParameters ( )
// Remove parameter name from specialized SCI msg data
//
unsigned long tempDataLength = getSpecializedSciMsgDataLength();
- unsigned char * pTempData = getSpecializedSciMsgData();
+ unsigned char * pTempData = new unsigned char [tempDataLength];
+ memcpy(pTempData, getSpecializedSciMsgData(), tempDataLength);
bParam = SciMsg::removeData (parameterNameLength+1, tempDataLength, &pTempData);
if (0 != bParam)
{
bParam &= setSpecializedSciMsgDataLength(tempDataLength);
bParam &= setSpecializedSciMsgData(pTempData);
- }
-
+ }
+ if (NULL != pTempData)
+ {
+ delete [] pTempData;
+ pTempData = NULL;
+ }
+
// Find parameter value length (coded on 2 bytes)
//
uint16_t tempLength = (static_cast<uint8_t>(*(getSpecializedSciMsgData()))<<8) + static_cast<uint8_t>(*(getSpecializedSciMsgData()+1));
@@ -417,14 +431,19 @@ bool FunctionSciMsg::identifyParameters ( )
// Remove parameter value length and parameter value from specialized SCI msg data
//
tempDataLength = getSpecializedSciMsgDataLength();
- pTempData = getSpecializedSciMsgData();
+ pTempData = new unsigned char [tempDataLength];
+ memcpy(pTempData, getSpecializedSciMsgData(), tempDataLength);
bParam &= SciMsg::removeData (2+parameterToFill.getValueLength(), tempDataLength, &pTempData); // +2 because parameter value length is coded on 2 bytes
if (0 != bParam)
{
bParam &= setSpecializedSciMsgDataLength(tempDataLength);
bParam &= setSpecializedSciMsgData(pTempData);
}
- pTempData = NULL; // free pointer
+ if (NULL != pTempData)
+ {
+ delete [] pTempData;
+ pTempData = NULL;
+ }
if (NULL != pTempParameterValue)
{
delete [] pTempParameterValue;
@@ -527,7 +546,7 @@ bool FunctionSciMsg::fillSpecializedSciMsgToSend ( )
// Free temporary allocated memory
//
- delete [] pData;
+ free(pData);
pData = NULL;
}
diff --git a/maximus/functioncall/src/IFunctionCallTest.cpp b/maximus/functioncall/src/IFunctionCallTest.cpp
index d705eee590..0dfb3af456 100644
--- a/maximus/functioncall/src/IFunctionCallTest.cpp
+++ b/maximus/functioncall/src/IFunctionCallTest.cpp
@@ -37,29 +37,35 @@ void IFunctionCallTest::userTest (void)
{
SciServer sciServer;
FunctionCallManager functionCallManager(&sciServer);
- FunctionSciMsg * functionSciMsg = functionCallManager.createMsg();
+ FunctionSciMsg * pFunctionSciMsg = functionCallManager.createMsg();
- CPPUNIT_ASSERT_MESSAGE ( "createMsg failed", (NULL != functionSciMsg) );
+ CPPUNIT_ASSERT_MESSAGE ( "createMsg failed", (NULL != pFunctionSciMsg) );
CPPUNIT_ASSERT_MESSAGE ( "registerCallback failed",
- functionCallManager.registerCallback(functionSciMsg->getSpecializedSciMsgId(), &userFunction) );
+ functionCallManager.registerCallback(pFunctionSciMsg->getSpecializedSciMsgId(), &userFunction) );
CPPUNIT_ASSERT_MESSAGE ( "setFunctionName failed",
- functionSciMsg->setFunctionName("function_to_call") );
+ pFunctionSciMsg->setFunctionName("function_to_call") );
FunctionCallParameter parameter ("parameter", 25, (unsigned char *)"1234567890123456789012345");
CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
- functionSciMsg->addParameter (parameter) );
+ pFunctionSciMsg->addParameter (parameter) );
SystemManager systemManager(&sciServer);
Sci_Msg_Station_Id stationId = 0;
stationId = systemManager.createStation();
- functionSciMsg->setSciMsgStationId(stationId);
+ pFunctionSciMsg->setSciMsgStationId(stationId);
systemManager.updateStationStatus ( stationId, MAXIMUS_STATION_STATUS_IDLE );
CPPUNIT_ASSERT_MESSAGE ( "sendMsg failed",
- functionCallManager.sendMsg(functionSciMsg) );
+ functionCallManager.sendMsg(pFunctionSciMsg) );
+
+ if (NULL != pFunctionSciMsg)
+ {
+ delete pFunctionSciMsg;
+ pFunctionSciMsg = NULL;
+ }
}
catch ( Error &e )
{
diff --git a/maximus/networkclock/src/NetworkClockEvtList.cpp b/maximus/networkclock/src/NetworkClockEvtList.cpp
index 6630b97791..dd45c82955 100644
--- a/maximus/networkclock/src/NetworkClockEvtList.cpp
+++ b/maximus/networkclock/src/NetworkClockEvtList.cpp
@@ -158,11 +158,12 @@ bool NetworkClockEvtList::addElement ( const NetworkClockEvt & evt_to_add )
bool NetworkClockEvtList::getNextElement ( Network_Clock_Tick & tick_value, NetworkClockEvt & next_evt_to_process )
{
logFunction();
- static EvtsList::iterator evtIterator;
bool bGet = false;
if (!mListOfEvts.empty())
{
+ EvtsList::iterator evtIterator;
+
if (0 != mListOfEvts.count(tick_value))
{
/* Finds an element whose key is tick_value. */
diff --git a/maximus/phy/src/PhyProcessor.cpp b/maximus/phy/src/PhyProcessor.cpp
index 0224bbceee..1600adc602 100644
--- a/maximus/phy/src/PhyProcessor.cpp
+++ b/maximus/phy/src/PhyProcessor.cpp
@@ -76,15 +76,6 @@ mpSciServer(NULL)
void PhyProcessor::initAttributes ( )
{
logFunction();
-
- if (NULL != mpSciServer)
- {
- mpSciServer->registerSpecializedSciMsg(SCI_MSG_TYPE_PHY, new PhySciMsg(this));
- }
- else
- {
- throw Error(__PRETTY_FUNCTION__, "SCI server pointer is NULL");
- }
}
@@ -261,7 +252,7 @@ void PhyProcessor::registerPhySciMsg ( )
}
else
{
- throw Error(__PRETTY_FUNCTION__, "SCi server pointer is NULL");
+ throw Error(__PRETTY_FUNCTION__, "SCI server pointer is NULL");
}
}
diff --git a/maximus/sci/src/SciMsg.cpp b/maximus/sci/src/SciMsg.cpp
index d352cd60f5..bc40dea953 100644
--- a/maximus/sci/src/SciMsg.cpp
+++ b/maximus/sci/src/SciMsg.cpp
@@ -211,7 +211,7 @@ bool SciMsg::identifySpecializedSciMsgData ( )
{
logFunction();
bool bIdentifyData = false;
-
+
if (NULL != getSciMsgData())
{
// Check data lengths coherence
@@ -222,20 +222,22 @@ bool SciMsg::identifySpecializedSciMsgData ( )
//
unsigned long tempDataLength = getSciMsgDataLength();
unsigned char * pTempData = new unsigned char [tempDataLength];
-
+
if (NULL != pTempData)
{
for (unsigned long i=0; i<tempDataLength; i++)
{
*(pTempData+i) = *(getSciMsgData()+i);
}
+
bIdentifyData = removeData (getSpecializedSciMsgHeaderSize(), tempDataLength, &pTempData);
+
if (0 != bIdentifyData)
{
bIdentifyData &= setSpecializedSciMsgDataLength (tempDataLength);
bIdentifyData &= setSpecializedSciMsgData (pTempData);
}
-
+
// Free temporary allocated memory
//
delete [] pTempData;
@@ -255,7 +257,7 @@ bool SciMsg::identifySpecializedSciMsgData ( )
{
throw Error(__PRETTY_FUNCTION__, "Received data pointer is NULL");
}
-
+
return bIdentifyData;
}
@@ -424,40 +426,41 @@ bool SciMsg::removeData ( const unsigned long data_length_to_remove, unsigned lo
{
logFunction();
bool bRemoveData = false;
-
+
if ( (data_length >= data_length_to_remove) // check that there are enough data to remove the required data length
&& (NULL != *pp_data) )
{
- // Create temporary variable
+ // Create temporary variable and copy data
//
unsigned char * remainingData = new unsigned char [data_length-data_length_to_remove];
for (unsigned long i=data_length_to_remove; i<data_length; i++)
{
*(remainingData+i-data_length_to_remove) = *((*pp_data)+i);
}
- for (unsigned long i=0; i<(data_length-data_length_to_remove); i++)
+
+ // Update data length
+ //
+ data_length -= data_length_to_remove;
+
+ // Fill data
+ //
+ for (unsigned long i=0; i<data_length; i++)
{
*((*pp_data)+i) = *(remainingData+i);
}
-
- data_length -= data_length_to_remove; // update data length
- if (0 == data_length)
- {
- *pp_data = NULL;
- }
-
+
// Free temporary allocated memory
//
delete [] remainingData;
remainingData = NULL;
-
+
bRemoveData = true;
}
else
{
throw Error(__PRETTY_FUNCTION__, "Not enough data");
}
-
+
return bRemoveData;
}
@@ -612,16 +615,22 @@ bool SciMsg::setSciMsgData ( const unsigned char * p_data )
logFunction();
bool bSetData = false;
+ if (NULL != mpSciMsgData)
+ {
+ delete [] mpSciMsgData;
+ mpSciMsgData = NULL;
+ }
+
if (NULL != p_data)
{
mpSciMsgData = new unsigned char [getSciMsgDataLength()];
if (NULL != mpSciMsgData)
{
- for (unsigned long i=0; i<getSciMsgDataLength(); i++)
+ for (unsigned int i=0; i<getSciMsgDataLength(); i++)
{
*(mpSciMsgData+i) = *(p_data+i);
}
-
+
displaySciMsgData();
bSetData = true;
}
@@ -634,7 +643,7 @@ bool SciMsg::setSciMsgData ( const unsigned char * p_data )
{
throw Error(__PRETTY_FUNCTION__, "Received data pointer is NULL");
}
-
+
return bSetData;
}
@@ -680,20 +689,25 @@ unsigned char * SciMsg::getSpecializedSciMsgData ( ) const
bool SciMsg::setSpecializedSciMsgData ( const unsigned char * p_data )
{
logFunction();
-
- mpSpecializedSciMsgData = new unsigned char [getSpecializedSciMsgDataLength()];
- if ( (NULL != p_data) && (NULL != mpSpecializedSciMsgData) )
+
+ if (NULL != mpSpecializedSciMsgData)
{
- for (unsigned long i=0; i<getSpecializedSciMsgDataLength(); i++)
- {
- *(mpSpecializedSciMsgData+i) = *(p_data+i);
- }
+ delete [] mpSpecializedSciMsgData;
+ mpSpecializedSciMsgData = NULL;
}
- else
+
+ if (NULL != p_data)
{
- mpSpecializedSciMsgData = NULL;
+ mpSpecializedSciMsgData = new unsigned char [getSpecializedSciMsgDataLength()];
+ if (NULL != mpSpecializedSciMsgData)
+ {
+ for (unsigned long i=0; i<getSpecializedSciMsgDataLength(); i++)
+ {
+ *(mpSpecializedSciMsgData+i) = *(p_data+i);
+ }
+ }
}
-
+
return true;
}
diff --git a/maximus/sci/src/SciMsgTest.cpp b/maximus/sci/src/SciMsgTest.cpp
index 527ea4649a..c7cffcc678 100644
--- a/maximus/sci/src/SciMsgTest.cpp
+++ b/maximus/sci/src/SciMsgTest.cpp
@@ -71,6 +71,11 @@ void SciMsgTest::tearDown (void)
delete mpPhySciMsg;
mpPhySciMsg = NULL;
}
+ if (NULL != mpSystemManager)
+ {
+ delete mpSystemManager;
+ mpSystemManager = NULL;
+ }
if (NULL != mpSystemSciMsg)
{
delete mpSystemSciMsg;
diff --git a/maximus/sci/src/SciServer.cpp b/maximus/sci/src/SciServer.cpp
index 731a5f8136..6f06891e40 100644
--- a/maximus/sci/src/SciServer.cpp
+++ b/maximus/sci/src/SciServer.cpp
@@ -523,6 +523,11 @@ bool SciServer::registerSpecializedSciMsg ( const Sci_Msg_Type sci_msg_type, Sci
{
if (NULL != getSpecializedSciMsgArray())
{
+ if (NULL != *(mpSpecializedSciMsgArray + (unsigned int)sci_msg_type))
+ {
+ delete(*(mpSpecializedSciMsgArray + (unsigned int)sci_msg_type));
+ *(mpSpecializedSciMsgArray + (unsigned int)sci_msg_type) = NULL;
+ }
*(mpSpecializedSciMsgArray + (unsigned int)sci_msg_type) = sci_msg; // set mpSpecializedSciMsgArray
bRegister = true;
}
diff --git a/maximus/system/src/Station.cpp b/maximus/system/src/Station.cpp
index 3b15a43670..aa248c285f 100644
--- a/maximus/system/src/Station.cpp
+++ b/maximus/system/src/Station.cpp
@@ -187,11 +187,15 @@ bool Station::launchDebugger ( const string command_line, const string station_e
}
}
while (found != string::npos);
-
+
+ if (!commandLine.empty())
+ {
+ commandLine.append(" &");
+ }
clog << logger(LOG_INFO) << "debugger command line = " << commandLine << endl;
system(commandLine.c_str());
-
+
return bLaunch;
}
diff --git a/maximus/system/src/SystemManager.cpp b/maximus/system/src/SystemManager.cpp
index 86be7e5e23..aea146babd 100644
--- a/maximus/system/src/SystemManager.cpp
+++ b/maximus/system/src/SystemManager.cpp
@@ -119,6 +119,7 @@ Sci_Msg_Station_Id SystemManager::createStation ( )
{
mListOfStations.push_back(createdStation);
stationId = createdStation->getStationId();
+ createdStation = NULL;
}
clog << logger(LOG_COM) << "create station " \
<< stationId << " (0x" << setfill('0') << setw(4) << uppercase << hex << stationId << ")" << dec << endl;
diff --git a/maximus/usertest/src/main_example.cpp b/maximus/usertest/src/main_example.cpp
index d0ed05022d..7b384d09ec 100644
--- a/maximus/usertest/src/main_example.cpp
+++ b/maximus/usertest/src/main_example.cpp
@@ -25,7 +25,7 @@ my_cb (Msg & msg)
unsigned long length = sizeof(my_type_t);
my_type_t result2;
my_type_t * p_result2 = &result2;
- if (NULL != msg.bind_param("result_2", length, (unsigned char * &)p_result2))
+ if (NULL != msg.bind_param("result_2", length, (unsigned char *)p_result2))
{
cout << "result 2 = " << result2 << endl;
}
@@ -53,7 +53,7 @@ main ( int argc, char * argv[] )
/** Create a function message and set the name of the function to call of station A. **/
Msg fc1 = maximus.create_fc("function_1");
-
+
/** Add a first parameter to the created message. **/
my_struct_t param1 = { 1, 2, true };
fc1.add_param("param_1", sizeof(my_struct_t), (unsigned char *)&param1);
@@ -92,11 +92,11 @@ main ( int argc, char * argv[] )
fc2 = fc2.send(stationB);
/** Get the function result. **/
- char * result1 = new char [FUNCTION_CALL_PARAM_MAX_SIZE];
+ char result1[FUNCTION_CALL_PARAM_MAX_SIZE];
unsigned long length = FUNCTION_CALL_PARAM_MAX_SIZE*sizeof(char);
- fc2.bind_param("result_1", length, (unsigned char * &)result1);
+ fc2.bind_param("result_1", length, (unsigned char *)result1);
cout << "result1 = " << result1 << endl;
-
+
/* Set a parameter value of station B. */
Msg probe1 = maximus.create_probe();
unsigned int param6 = 789;
@@ -152,13 +152,6 @@ main ( int argc, char * argv[] )
/* Wait during 10000 ticks before terminating the program. */
maximus.wait(10000);
-
- /* Free allocated memory. */
- if (NULL != result1)
- {
- delete(result1);
- result1 = NULL;
- }
-
+
return 0;
}