summaryrefslogtreecommitdiff
path: root/maximus
diff options
context:
space:
mode:
authorburet2007-12-04 13:58:25 +0000
committerburet2007-12-04 13:58:25 +0000
commit14810c9800c48888fd58d2a82fc68ef7ed41394b (patch)
tree88201d1d6131a069de8095c44e336210d8b3a23c /maximus
parent9d28543ac05c84453ce6293a4a1f34d4574c487b (diff)
Maximus V2: fixes #47.
Modify the Boost Pyhton interface and C++ code to handle message callbacks and messages life time. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1083 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'maximus')
-rw-r--r--maximus/common/interfaces/Maximus.h24
-rw-r--r--maximus/common/interfaces/Msg.h53
-rw-r--r--maximus/coreengine/inc/Msg.tpp2
-rw-r--r--maximus/coreengine/src/Maximus.cpp90
-rw-r--r--maximus/coreengine/src/MaximusTest.cpp4
-rw-r--r--maximus/coreengine/src/Msg.cpp290
-rw-r--r--maximus/functioncall/inc/FunctionSciMsg.h7
-rw-r--r--maximus/functioncall/src/FunctionSciMsg.cpp34
-rw-r--r--maximus/phy/src/PhyProcessor.cpp2
-rw-r--r--maximus/python/py/test_cb.py51
-rw-r--r--maximus/python/py/test_tx_rx.py137
-rw-r--r--maximus/python/src/interface_module.cpp44
-rw-r--r--maximus/stationtest/Makefile5
-rw-r--r--maximus/stationtest/src/test_cb.c42
14 files changed, 425 insertions, 360 deletions
diff --git a/maximus/common/interfaces/Maximus.h b/maximus/common/interfaces/Maximus.h
index 403a25c24b..ee375b7f32 100644
--- a/maximus/common/interfaces/Maximus.h
+++ b/maximus/common/interfaces/Maximus.h
@@ -37,6 +37,7 @@ The original location of this file is /home/buret/eclipse/maximus/common/interfa
#include <fstream> // for 'std::ofstream'
#include <string> // for 'std::string'
+#include <vector> // for 'std::vector'
class CoreEngine;
class ISystem;
@@ -50,6 +51,9 @@ class PhySciMsgMpdu;
typedef Network_Clock_Tick tick_t;
+typedef std::vector<Msg *> MsgsList;
+typedef std::vector<Sta *> StasList;
+
/**
* class Maximus
@@ -104,26 +108,26 @@ public:
void process ( );
/**
- * @return Sta
+ * @return Sta &
* Create a new station.
- * Return a station object.
+ * Return a reference on 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.
+ * Return a reference on 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.
+ * Return a reference on a message object.
*/
- Msg create_probe ( );
+ Msg & create_probe ( );
/**
* Creates a PHY SCI message MPDU.
@@ -164,6 +168,8 @@ private:
std::ofstream mMaximusLogFile;
Network_Clock_Tick mMaxTickValue;
Network_Clock_Tick mWaitTickValue;
+ MsgsList mListOfMsgs;
+ StasList mListOfStas;
// private methods
//
diff --git a/maximus/common/interfaces/Msg.h b/maximus/common/interfaces/Msg.h
index c4c76064f0..907703dcc6 100644
--- a/maximus/common/interfaces/Msg.h
+++ b/maximus/common/interfaces/Msg.h
@@ -193,6 +193,7 @@ public:
*/
Msg & send ( Sta & sta );
+
/**
* @return bool
* @param name
@@ -219,6 +220,18 @@ public:
*/
template <typename T> T & bind_param ( const std::string & name ) const;
+ /**
+ * @return Function_Call_Msg_Id
+ * Return mpFunctionSciMsg->mSpecializedSciMsgId.
+ */
+ Function_Call_Msg_Id get_tx_msg_id ( ) const;
+
+ /**
+ * @return Function_Call_Msg_Id
+ * Return mpFunctionSciMsg->mpSpecializedSciMsgHeader->msg_id.
+ */
+ Function_Call_Msg_Id get_rx_msg_id ( ) const;
+
private:
// private attributes
@@ -227,21 +240,16 @@ private:
Maximus * mpMaximus;
IFunctionCall * mpFunctionCallManager;
ISystem * mpSystemManager;
- std::string mName;
- ParametersList mListOfParameters;
cb_t mCallback;
- Sci_Msg_Station_Id mStationId;
FunctionSciMsg * mpFunctionSciMsg;
bool mResponseReceived;
-
+
// private methods
//
-
- bool bindParameter ( const std::string name_of_parameter_to_get, unsigned long & data_length, unsigned char * & p_data ) const;
-
+
// private attributes accessor methods
//
-
+
/**
* @return Maximus *
*/
@@ -258,36 +266,20 @@ private:
ISystem * getSystemManager ( ) const;
/**
- * @return const ParametersList &
- */
- const ParametersList & getListOfParameters ( ) const;
-
- /**
- * @return bool
- * @param ParametersList &
- */
- bool setListOfParameters ( const ParametersList & list_of_parameters );
-
- /**
* @return cb_t
*/
cb_t getCallback ( ) const;
-
- /**
- * @return Sci_Msg_Station_Id
- */
- Sci_Msg_Station_Id getStationId ( ) const;
/**
* @return bool
- * @param Sci_Msg_Station_Id
+ * @param cb_t
*/
- bool setStationId ( const Sci_Msg_Station_Id station_id );
+ bool setCallback ( const cb_t callback );
/**
* @return FunctionSciMsg *
*/
- const FunctionSciMsg * getFunctionSciMsg ( ) const;
+ FunctionSciMsg * getFunctionSciMsg ( ) const;
/**
* @return bool
@@ -299,7 +291,7 @@ private:
* @return bool
*/
bool isResponseReceived ( ) const;
-
+
/**
* @return bool
* @param bool
@@ -307,11 +299,6 @@ private:
bool setResponseReceived ( const bool response_received );
public:
-
- /**
- * @return std::string
- */
- std::string getName ( ) const;
void receiveResponse ( const FunctionSciMsg & function_sci_msg );
diff --git a/maximus/coreengine/inc/Msg.tpp b/maximus/coreengine/inc/Msg.tpp
index 69b17b6ed9..022fd172f3 100644
--- a/maximus/coreengine/inc/Msg.tpp
+++ b/maximus/coreengine/inc/Msg.tpp
@@ -64,7 +64,7 @@ template <typename T> Msg & Msg::add_param ( const string & name, T const & valu
{
param = value;
}
- mListOfParameters.push_back(FunctionCallParameter(name, sizeof(value), (unsigned char *)&param));
+ add_param(name, sizeof(value), (unsigned char *)&param);
}
else
{
diff --git a/maximus/coreengine/src/Maximus.cpp b/maximus/coreengine/src/Maximus.cpp
index 93932ab68f..ebfbefa807 100644
--- a/maximus/coreengine/src/Maximus.cpp
+++ b/maximus/coreengine/src/Maximus.cpp
@@ -124,17 +124,35 @@ Maximus::~Maximus ( )
logFunction();
clog << logger(LOG_FATAL) << "*** Exit Fulminata Maximus simulator ***" << endl;
-
- if (NULL != mpCoreEngine)
- {
- delete mpCoreEngine;
- mpCoreEngine = NULL;
- }
+
if (mMaximusLogFile.is_open())
{
mMaximusLogFile.flush();
mMaximusLogFile.close();
}
+ for (unsigned int i=0; i<mListOfMsgs.size(); i++)
+ {
+ if (NULL != mListOfMsgs[i])
+ {
+ delete (mListOfMsgs[i]);
+ }
+ }
+ mListOfMsgs.clear();
+ for (unsigned int i=0; i<mListOfStas.size(); i++)
+ {
+ if (NULL != mListOfStas[i])
+ {
+ delete (mListOfStas[i]);
+ }
+ }
+ mListOfStas.clear();
+
+ // Warning: delete the Core Engine is the last task to do!
+ if (NULL != mpCoreEngine)
+ {
+ delete mpCoreEngine;
+ mpCoreEngine = NULL;
+ }
}
@@ -342,27 +360,75 @@ void Maximus::process ( )
}
-Sta Maximus::create_sta ( )
+Sta & Maximus::create_sta ( )
{
logFunction();
+ Sta * pSta = NULL;
+
+ try
+ {
+ pSta = new Sta(getSystemManager());
+ if (NULL == pSta)
+ {
+ throw Error(__PRETTY_FUNCTION__, "Station pointer is NULL");
+ }
+ mListOfStas.push_back(pSta);
+ }
+ catch ( Error &e )
+ {
+ e.display();
+ stop();
+ }
- return Sta(getSystemManager());
+ return *pSta;
}
-Msg Maximus::create_fc ( const string & name )
+Msg & Maximus::create_fc ( const string & name )
{
logFunction();
+ Msg * pMsg = NULL;
- return Msg(this, getFunctionCallManager(), getSystemManager(), name);
+ try
+ {
+ pMsg = new Msg(this, getFunctionCallManager(), getSystemManager(), name);
+ if (NULL == pMsg)
+ {
+ throw Error(__PRETTY_FUNCTION__, "Message pointer is NULL");
+ }
+ mListOfMsgs.push_back(pMsg);
+ }
+ catch ( Error &e )
+ {
+ e.display();
+ stop();
+ }
+
+ return *pMsg;
}
-Msg Maximus::create_probe ( )
+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);
+ }
+ catch ( Error &e )
+ {
+ e.display();
+ stop();
+ }
- return Msg(this, getFunctionCallManager(), getSystemManager());
+ return *pMsg;
}
diff --git a/maximus/coreengine/src/MaximusTest.cpp b/maximus/coreengine/src/MaximusTest.cpp
index a37491728f..6247616d23 100644
--- a/maximus/coreengine/src/MaximusTest.cpp
+++ b/maximus/coreengine/src/MaximusTest.cpp
@@ -80,7 +80,7 @@ void MaximusTest::create_fc_test (void)
Msg msg = mpMaximus->create_fc("function");
CPPUNIT_ASSERT_MESSAGE ( "create_fc failed",
- !msg.getName().compare("function") );
+ 0 != msg.get_tx_msg_id() );
}
else
{
@@ -98,7 +98,7 @@ void MaximusTest::create_probe_test (void)
Msg msg = mpMaximus->create_probe();
CPPUNIT_ASSERT_MESSAGE ( "create_probe failed",
- !msg.getName().compare(PROBE_ID) );
+ 0 != msg.get_tx_msg_id() );
}
else
{
diff --git a/maximus/coreengine/src/Msg.cpp b/maximus/coreengine/src/Msg.cpp
index d017f72189..9ceb13e571 100644
--- a/maximus/coreengine/src/Msg.cpp
+++ b/maximus/coreengine/src/Msg.cpp
@@ -55,13 +55,11 @@ mpMaximus(NULL),
mpFunctionCallManager(NULL),
mpSystemManager(NULL),
mCallback(NULL),
-mStationId(0),
mpFunctionSciMsg(NULL),
mResponseReceived(false)
{
logFunction();
-
- mName.assign(name);
+
if ( (NULL != p_maximus)
&& (NULL != p_function_call_manager)
&& (NULL != p_system_manager) )
@@ -69,6 +67,9 @@ mResponseReceived(false)
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
{
@@ -82,45 +83,20 @@ mpMaximus(NULL),
mpFunctionCallManager(NULL),
mpSystemManager(NULL),
mCallback(NULL),
-mStationId(0),
mpFunctionSciMsg(NULL),
mResponseReceived(false)
{
logFunction();
- mName.assign(msg.mName);
- if ( (NULL != msg.mpMaximus)
- && (NULL != msg.mpFunctionCallManager)
- && (NULL != msg.mpSystemManager) )
- {
- mpMaximus = msg.mpMaximus;
- mpFunctionCallManager = msg.mpFunctionCallManager;
- mpSystemManager = msg.mpSystemManager;
- }
- else
- {
- throw Error(__PRETTY_FUNCTION__, "Maximus, function call manager and/or system manager pointer(s) is/are NULL");
- }
-
- try
- {
- if (NULL != msg.getFunctionSciMsg())
- {
- setListOfParameters(msg.getFunctionSciMsg()->getListOfParameters());
- }
- else
- {
- setListOfParameters(msg.getListOfParameters());
- }
- set_cb(msg.getCallback());
- setStationId(msg.getStationId());
- setResponseReceived(msg.isResponseReceived());
- }
- catch ( Error &e )
- {
- e.display();
- getMaximus()->stop();
- }
+ 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());
}
@@ -145,11 +121,6 @@ Msg::~Msg ( )
delete(mpFunctionSciMsg);
mpFunctionSciMsg = NULL;
}
- if (!mListOfParameters.empty())
- {
- mListOfParameters.clear();
- }
- mName.clear();
}
@@ -165,20 +136,17 @@ Msg::~Msg ( )
Msg & Msg::operator= ( const Msg & msg )
{
logFunction();
-
+
try
{
- mName.assign(msg.getName());
- if (NULL != msg.getFunctionSciMsg())
- {
- setListOfParameters(msg.getFunctionSciMsg()->getListOfParameters());
- }
- else
- {
- setListOfParameters(msg.getListOfParameters());
- }
- set_cb(msg.getCallback());
- setStationId(msg.getStationId());
+ 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());
}
catch ( Error &e )
@@ -186,7 +154,7 @@ Msg & Msg::operator= ( const Msg & msg )
e.display();
getMaximus()->stop();
}
-
+
return *this;
}
@@ -197,7 +165,7 @@ Msg & Msg::add_param ( const string & name )
try
{
- mListOfParameters.push_back(FunctionCallParameter(name, 0, NULL));
+ getFunctionSciMsg()->addParameter(FunctionCallParameter(name, 0, NULL));
}
catch ( Error &e )
{
@@ -217,7 +185,7 @@ Msg & Msg::add_param ( const string & name, const unsigned long length, const un
{
if ( FUNCTION_CALL_PARAM_MAX_SIZE >= length)
{
- mListOfParameters.push_back(FunctionCallParameter(name, length, const_cast<unsigned char *>(p_value)));
+ getFunctionSciMsg()->addParameter(FunctionCallParameter(name, length, const_cast<unsigned char *>(p_value)));
}
else
{
@@ -242,7 +210,7 @@ Msg & Msg::add_param ( const string & name, const string & value )
{
if ( FUNCTION_CALL_PARAM_MAX_SIZE >= value.length()+1)
{
- mListOfParameters.push_back(FunctionCallParameter(name, value.length()+1, (unsigned char *)value.c_str()));
+ getFunctionSciMsg()->addParameter(FunctionCallParameter(name, value.length()+1, (unsigned char *)value.c_str()));
}
else
{
@@ -265,17 +233,7 @@ Msg & Msg::remove_param ( const string & name )
try
{
- if (!mListOfParameters.empty())
- {
- for (ParametersList::iterator it = mListOfParameters.begin(); it < mListOfParameters.end(); ++it)
- {
- if ( !it->getName().compare(name) )
- {
- mListOfParameters.erase(it);
- it = mListOfParameters.end()-1;
- }
- }
- }
+ getFunctionSciMsg()->removeParameter(name);
}
catch ( Error &e )
{
@@ -329,7 +287,7 @@ Msg & Msg::set_sta ( Sta & sta )
try
{
- mStationId = sta.getStationId();
+ getFunctionSciMsg()->setSciMsgStationId(sta.getStationId());
}
catch ( Error &e )
{
@@ -347,30 +305,14 @@ void Msg::send_async ( )
try
{
- // Create, configure and send message
- if (NULL != getFunctionSciMsg())
- {
- delete(mpFunctionSciMsg);
- mpFunctionSciMsg = NULL;
- }
- mpFunctionSciMsg = getFunctionCallManager()->createMsg();
- if (NULL != getFunctionSciMsg())
+ // Register callback and send message
+ getFunctionCallManager()->registerCallback( getFunctionSciMsg()->getSpecializedSciMsgId(),
+ (boost::bind(&Msg::receiveAsynchronousResponse, this, _1)) );
+ while(!getSystemManager()->isStationIdle(getFunctionSciMsg()->getSciMsgStationId()))
{
- mpFunctionSciMsg->setFunctionName(getName());
- mpFunctionSciMsg->setListOfParameters(getListOfParameters());
- getFunctionCallManager()->registerCallback( getFunctionSciMsg()->getSpecializedSciMsgId()+1,
- (boost::bind(&Msg::receiveAsynchronousResponse, this, _1)) );
- mpFunctionSciMsg->setSciMsgStationId(getStationId());
- while(!getSystemManager()->isStationIdle(getStationId()))
- {
- getMaximus()->process();
- }
- getFunctionCallManager()->sendMsg(mpFunctionSciMsg);
- }
- else
- {
- throw Error(__PRETTY_FUNCTION__, "Function SCI message pointer is NULL");
+ getMaximus()->process();
}
+ getFunctionCallManager()->sendMsg(getFunctionSciMsg());
}
catch ( Error &e )
{
@@ -386,7 +328,7 @@ void Msg::send_async ( Sta & sta )
try
{
- mStationId = sta.getStationId();
+ set_sta(sta);
send_async();
}
catch ( Error &e )
@@ -400,43 +342,27 @@ void Msg::send_async ( Sta & sta )
Msg & Msg::send ( )
{
logFunction();
-
+
try
{
- // Create, configure and send message
- if (NULL != getFunctionSciMsg())
+ // Register callback and send message
+ getFunctionCallManager()->registerCallback( getFunctionSciMsg()->getSpecializedSciMsgId(),
+ (boost::bind(&Msg::receiveResponse, this, _1)) );
+ while(!getSystemManager()->isStationIdle(getFunctionSciMsg()->getSciMsgStationId()))
{
- delete(mpFunctionSciMsg);
- mpFunctionSciMsg = NULL;
+ getMaximus()->process();
}
- mpFunctionSciMsg = getFunctionCallManager()->createMsg();
- if (NULL != getFunctionSciMsg())
+ getFunctionCallManager()->sendMsg(getFunctionSciMsg());
+
+ // Wait for response
+ while(!isResponseReceived())
{
- mpFunctionSciMsg->setFunctionName(getName());
- mpFunctionSciMsg->setListOfParameters(getListOfParameters());
- getFunctionCallManager()->registerCallback(getFunctionSciMsg()->getSpecializedSciMsgId()+1,
- (boost::bind(&Msg::receiveResponse, this, _1)));
- mpFunctionSciMsg->setSciMsgStationId(getStationId());
- while(!getSystemManager()->isStationIdle(getStationId()))
- {
- getMaximus()->process();
- }
- getFunctionCallManager()->sendMsg(mpFunctionSciMsg);
-
- // Wait for response
- while(!isResponseReceived())
- {
- getMaximus()->process();
- }
- setResponseReceived(false);
- if (NULL != getCallback())
- {
- getCallback()(*this);
- }
+ getMaximus()->process();
}
- else
+ setResponseReceived(false);
+ if (NULL != getCallback())
{
- throw Error(__PRETTY_FUNCTION__, "Function SCI message pointer is NULL");
+ getCallback()(*this);
}
}
catch ( Error &e )
@@ -444,7 +370,7 @@ Msg & Msg::send ( )
e.display();
getMaximus()->stop();
}
-
+
return *this;
}
@@ -452,17 +378,17 @@ Msg & Msg::send ( )
Msg & Msg::send ( Sta & sta )
{
logFunction();
-
+
try
{
- mStationId = sta.getStationId();
+ set_sta(sta);
}
catch ( Error &e )
{
e.display();
getMaximus()->stop();
}
-
+
return send();
}
@@ -497,24 +423,13 @@ unsigned char * Msg::bind_param ( const string & name, unsigned long & length, u
{
logFunction();
unsigned char * pData = NULL; // parameter not found => return NULL
-
+
try
{
- if (NULL != getFunctionSciMsg())
+ if (getFunctionSciMsg()->bindParameter(name, length, p_data))
{
- if (getFunctionSciMsg()->bindParameter(name, length, p_data))
- {
- // Parameter found => return p_data
- pData = p_data;
- }
- }
- else
- {
- if (bindParameter(name, length, p_data))
- {
- // Parameter found => return p_data
- pData = p_data;
- }
+ // Parameter found => return p_data
+ pData = p_data;
}
}
catch ( Error &e )
@@ -522,46 +437,20 @@ unsigned char * Msg::bind_param ( const string & name, unsigned long & length, u
e.display();
getMaximus()->stop();
}
-
+
return pData;
}
-bool Msg::bindParameter ( const string name_of_parameter_to_get, unsigned long & data_length, unsigned char * & p_data ) const
+Function_Call_Msg_Id Msg::get_tx_msg_id ( ) const
{
- logFunction();
- bool bBindParameter = false;
+ return getFunctionSciMsg()->getSpecializedSciMsgId();
+}
- FunctionCallParameter tempParameter;
- for (unsigned int i=0; i<mListOfParameters.size(); ++i)
- {
- tempParameter = mListOfParameters[i];
- if ( !tempParameter.getName().compare(name_of_parameter_to_get) )
- {
- bBindParameter = true;
- if (data_length < tempParameter.getValueLength())
- {
- clog << logger(LOG_WARNING) << "bind_param: parameter value length too small to get the parameter value" << endl;
- clog << logger(LOG_WARNING) << "\t(given data length = " << data_length << " and needed data length = " << tempParameter.getValueLength() << ")" << endl;
- clog << logger(LOG_WARNING) << "\t=> parameter value will be cut" << endl;
- }
- else if (data_length > tempParameter.getValueLength())
- {
- clog << logger(LOG_WARNING) << "bind_param: parameter value length too large to get the parameter value" << endl;
- clog << logger(LOG_WARNING) << "\t=> update length from " << data_length << " to " << tempParameter.getValueLength() << endl;
- data_length = tempParameter.getValueLength();
- }
- if ( (NULL != tempParameter.getValue()) && (NULL != p_data) )
- {
- memcpy(p_data, tempParameter.getValue(), data_length);
- clog << logger(LOG_COM) << "bind parameter = " << endl;
- tempParameter.displayParameter();
- i = mListOfParameters.size()-1;
- }
- }
- }
- return bBindParameter;
+Function_Call_Msg_Id Msg::get_rx_msg_id ( ) const
+{
+ return getFunctionSciMsg()->getSpecializedSciMsgHeader()->msg_id;
}
@@ -622,44 +511,35 @@ ISystem * Msg::getSystemManager ( ) const
}
-const ParametersList & Msg::getListOfParameters ( ) const
-{
- return mListOfParameters;
-}
-
-
-bool Msg::setListOfParameters ( const ParametersList & list_of_parameters )
-{
- if (!mListOfParameters.empty())
- {
- mListOfParameters.clear();
- }
- mListOfParameters = ParametersList(list_of_parameters);
- return true;
-}
-
-
cb_t Msg::getCallback ( ) const
{
return mCallback;
}
-
-Sci_Msg_Station_Id Msg::getStationId ( ) const
-{
- return mStationId;
-}
-
-bool Msg::setStationId ( const Sci_Msg_Station_Id station_id )
+bool Msg::setCallback ( const cb_t callback )
{
- mStationId = station_id;
+ mCallback = callback;
+
return true;
}
-const FunctionSciMsg * Msg::getFunctionSciMsg ( ) const
+FunctionSciMsg * Msg::getFunctionSciMsg ( ) const
{
+ try
+ {
+ if (NULL == mpFunctionSciMsg)
+ {
+ throw Error(__PRETTY_FUNCTION__, "Function SCI message pointer is NULL");
+ }
+ }
+ catch ( Error &e )
+ {
+ e.display();
+ getMaximus()->stop();
+ }
+
return mpFunctionSciMsg;
}
@@ -667,7 +547,7 @@ const FunctionSciMsg * Msg::getFunctionSciMsg ( ) const
bool Msg::setFunctionSciMsg ( const FunctionSciMsg & function_sci_msg )
{
// If a function message had already been created, delete it before setting the new one
- if (NULL != getFunctionSciMsg())
+ if (NULL != mpFunctionSciMsg)
{
delete (mpFunctionSciMsg);
mpFunctionSciMsg = NULL;
@@ -694,12 +574,6 @@ bool Msg::setResponseReceived ( const bool response_received )
//
-string Msg::getName ( ) const
-{
- return mName;
-}
-
-
void Msg::receiveResponse ( const FunctionSciMsg & function_sci_msg )
{
logFunction();
diff --git a/maximus/functioncall/inc/FunctionSciMsg.h b/maximus/functioncall/inc/FunctionSciMsg.h
index d9ca6da1ee..c97e9d1064 100644
--- a/maximus/functioncall/inc/FunctionSciMsg.h
+++ b/maximus/functioncall/inc/FunctionSciMsg.h
@@ -144,6 +144,13 @@ public:
/**
* @return bool
+ * @param name
+ * Remove the parameter named name from the function SCI message.
+ */
+ bool removeParameter ( const std::string & name );
+
+ /**
+ * @return bool
* @param name_of_parameter_to_get
* @param p_data
*/
diff --git a/maximus/functioncall/src/FunctionSciMsg.cpp b/maximus/functioncall/src/FunctionSciMsg.cpp
index 098c802b68..519584cae8 100644
--- a/maximus/functioncall/src/FunctionSciMsg.cpp
+++ b/maximus/functioncall/src/FunctionSciMsg.cpp
@@ -57,7 +57,7 @@ mpSpecializedSciMsgHeader(NULL),
mpFunctionCallManager(NULL)
{
logFunction();
-
+
initAttributes ();
}
@@ -78,7 +78,7 @@ mpFunctionCallManager(NULL)
{
throw Error(__PRETTY_FUNCTION__, "Function call manager pointer is NULL");
}
-
+
initAttributes ();
}
@@ -86,7 +86,7 @@ mpFunctionCallManager(NULL)
void FunctionSciMsg::initAttributes ( )
{
logFunction();
-
+
mpSpecializedSciMsgHeader = new Function_Call_Header;
if (NULL != mpSpecializedSciMsgHeader)
{
@@ -103,7 +103,7 @@ void FunctionSciMsg::initAttributes ( )
FunctionSciMsg::FunctionSciMsg ( const FunctionSciMsg & function_sci_msg ) : SciMsg ( )
{
logFunction();
-
+
initAttributes ();
setSpecializedSciMsgType (function_sci_msg.getSpecializedSciMsgType());
setSpecializedSciMsgParametersNumber (function_sci_msg.getSpecializedSciMsgParametersNumber());
@@ -117,7 +117,7 @@ FunctionSciMsg::FunctionSciMsg ( const FunctionSciMsg & function_sci_msg ) : Sci
FunctionSciMsg::~FunctionSciMsg ( )
{
logFunction();
-
+
if (NULL != mpSpecializedSciMsgHeader)
{
delete (mpSpecializedSciMsgHeader);
@@ -262,6 +262,27 @@ bool FunctionSciMsg::addParameter ( const FunctionCallParameter & function_argum
}
+// Called by user to configure a message to send
+//
+bool FunctionSciMsg::removeParameter ( const std::string & name )
+{
+ logFunction();
+ bool bRemoveParameter = false;
+
+ for (ParametersList::iterator it = mListOfParameters.begin(); it < mListOfParameters.end(); ++it)
+ {
+ if ( !it->getName().compare(name) )
+ {
+ mListOfParameters.erase(it);
+ bRemoveParameter = true;
+ break;
+ }
+ }
+
+ return bRemoveParameter;
+}
+
+
// 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
@@ -542,8 +563,7 @@ bool FunctionSciMsg::fillSpecializedSciMsgToSend ( )
bFill &= setSpecializedSciMsgParametersNumber(numberOfParameters);
bFill &= setSpecializedSciMsgDataLength(dataLength);
bFill &= setSpecializedSciMsgData(pData);
- bFill &= incrementSpecializedSciMsgId(); // to have an updated msg id
-
+
// Free temporary allocated memory
//
free(pData);
diff --git a/maximus/phy/src/PhyProcessor.cpp b/maximus/phy/src/PhyProcessor.cpp
index adf742afc5..2e51c2166a 100644
--- a/maximus/phy/src/PhyProcessor.cpp
+++ b/maximus/phy/src/PhyProcessor.cpp
@@ -198,7 +198,7 @@ bool PhyProcessor::sendMsgToDestStations ( PhySciMsg & phy_sci_msg_to_send )
{
RxStationsList::iterator pos = it;
listOfDestStations.push_back(pos->second);
- if (PHY_TYPE_MPDU_PAYLOAD == phy_sci_msg_to_send.getSpecializedSciMsgType())
+ if (phy_sci_msg_to_send.isSent())
{
mListOfRxStations.erase(pos);
}
diff --git a/maximus/python/py/test_cb.py b/maximus/python/py/test_cb.py
new file mode 100644
index 0000000000..d8ebe920f4
--- /dev/null
+++ b/maximus/python/py/test_cb.py
@@ -0,0 +1,51 @@
+#! usr/bin/env python
+
+print __name__
+
+import sys
+sys.path.append('./test')
+sys.path.append('../test')
+import startup
+
+
+# TICKET #47
+
+from interface import *
+
+# Instantiate a Maximus object and initialize it.
+maximus = Maximus()
+argv = ['test_cb.py', '-e', '../../stationtest/obj/test_cb.elf', '-l', '0']
+maximus.init(argv)
+
+# Create three stations.
+sta = maximus.create_sta()
+
+def get_seg_cb1 (msg):
+ print "=> get_seg_cb1"
+m1 = maximus.create_fcall ('get_seg')
+m1.set_cb (get_seg_cb1)
+m1.send_async (sta)
+maximus.wait()
+
+def get_seg_cb2 (msg):
+ print "=> get_seg_cb2"
+def a():
+ m2 = maximus.create_fcall ('get_seg')
+ m2.set_cb (get_seg_cb2)
+ m2.send_async (sta)
+a()
+maximus.wait()
+
+def b():
+ s = "=> get_seg_cb3"
+ def get_seg_cb3 (msg):
+ print s
+ m3 = maximus.create_fcall ('get_seg')
+ m3.set_cb (get_seg_cb3)
+ m3.send_async (sta)
+b()
+maximus.wait()
+
+sta.remove()
+
+print "END"
diff --git a/maximus/python/py/test_tx_rx.py b/maximus/python/py/test_tx_rx.py
index 16cfebea64..41da209caf 100644
--- a/maximus/python/py/test_tx_rx.py
+++ b/maximus/python/py/test_tx_rx.py
@@ -29,68 +29,76 @@ m.disturb_channel()
fcall = m.create_fcall('set_tonemask')
fcall.send(sta1)
-# Create a fcall for an MPDU containing one PB of 128 octets
-fc_mode = 2 # PHY_FC_MODE_AV_1
-short_ppdu = False
-mod = 2 # PHY_MOD_MINI_ROBO
-fecrate = 0 # PHY_FEC_RATE_1_2
-pb_size = 0 # PHY_PB_SIZE_136
-gil = 1 # PHY_GIL_567
-pb_nb = 1
-fcall_128 = m.create_fcall('prepare_rx')
-fcall_128.add_param_ushort("fc_mode", fc_mode)
-fcall_128.add_param_bool("short_ppdu", short_ppdu)
-fcall_128.add_param_ushort("mod", mod)
-fcall_128.add_param_ushort("fecrate", fecrate)
-fcall_128.add_param_ushort("pb_size", pb_size)
-fcall_128.add_param_ushort("gil", gil)
-fcall_128.add_param_ushort("pb_nb", pb_nb)
-
-# Create a fcall for an MPDU containing one PB of 512 octets with a FC 1.0
-fc_mode = 0 # PHY_FC_MODE_HYBRID_1
-short_ppdu = False
-mod = 0 # PHY_MOD_ROBO
-fecrate = 0 # PHY_FEC_RATE_1_2
-pb_size = 1 # PHY_PB_SIZE_520
-gil = 1 # PHY_GIL_567
-pb_nb = 1
-fcall_512_1 = m.create_fcall('prepare_rx')
-fcall_512_1.add_param_ushort("fc_mode", fc_mode)
-fcall_512_1.add_param_bool("short_ppdu", short_ppdu)
-fcall_512_1.add_param_ushort("mod", mod)
-fcall_512_1.add_param_ushort("fecrate", fecrate)
-fcall_512_1.add_param_ushort("pb_size", pb_size)
-fcall_512_1.add_param_ushort("gil", gil)
-fcall_512_1.add_param_ushort("pb_nb", pb_nb)
-
-# Create a fcall for an MPDU containing 3 PBs of 512 octets
-fc_mode = 2 # PHY_FC_MODE_AV_1
-short_ppdu = False
-mod = 0 # PHY_MOD_ROBO
-fecrate = 0 # PHY_FEC_RATE_1_2
-pb_size = 1 # PHY_PB_SIZE_520
-gil = 0 # PHY_GIL_417
-pb_nb = 3
-fcall_512_3 = m.create_fcall('prepare_rx')
-fcall_512_3.add_param_ushort("fc_mode", fc_mode)
-fcall_512_3.add_param_bool("short_ppdu", short_ppdu)
-fcall_512_3.add_param_ushort("mod", mod)
-fcall_512_3.add_param_ushort("fecrate", fecrate)
-fcall_512_3.add_param_ushort("pb_size", pb_size)
-fcall_512_3.add_param_ushort("gil", gil)
-fcall_512_3.add_param_ushort("pb_nb", pb_nb)
-
-# Create a fcall for a short PPDU with a FC 1.0
-fc_mode = 0 # PHY_FC_MODE_HYBRID_1
-short_ppdu = True
-fcall_short_fc10 = m.create_fcall('prepare_rx')
-fcall_short_fc10.add_param_ushort("fc_mode", fc_mode)
-fcall_short_fc10.add_param_bool("short_ppdu", short_ppdu)
-fcall_short_fc10.add_param_ushort("mod", mod)
-fcall_short_fc10.add_param_ushort("fecrate", fecrate)
-fcall_short_fc10.add_param_ushort("pb_size", pb_size)
-fcall_short_fc10.add_param_ushort("gil", gil)
-fcall_short_fc10.add_param_ushort("pb_nb", pb_nb)
+def create_fcall_128():
+ # Create a fcall for an MPDU containing one PB of 128 octets
+ fc_mode = 2 # PHY_FC_MODE_AV_1
+ short_ppdu = False
+ mod = 2 # PHY_MOD_MINI_ROBO
+ fecrate = 0 # PHY_FEC_RATE_1_2
+ pb_size = 0 # PHY_PB_SIZE_136
+ gil = 1 # PHY_GIL_567
+ pb_nb = 1
+ fcall_128 = m.create_fcall('prepare_rx')
+ fcall_128.add_param_ushort("fc_mode", fc_mode)
+ fcall_128.add_param_bool("short_ppdu", short_ppdu)
+ fcall_128.add_param_ushort("mod", mod)
+ fcall_128.add_param_ushort("fecrate", fecrate)
+ fcall_128.add_param_ushort("pb_size", pb_size)
+ fcall_128.add_param_ushort("gil", gil)
+ fcall_128.add_param_ushort("pb_nb", pb_nb)
+ return fcall_128
+
+def create_fcall_512_1():
+ # Create a fcall for an MPDU containing one PB of 512 octets with a FC 1.0
+ fc_mode = 0 # PHY_FC_MODE_HYBRID_1
+ short_ppdu = False
+ mod = 0 # PHY_MOD_ROBO
+ fecrate = 0 # PHY_FEC_RATE_1_2
+ pb_size = 1 # PHY_PB_SIZE_520
+ gil = 1 # PHY_GIL_567
+ pb_nb = 1
+ fcall_512_1 = m.create_fcall('prepare_rx')
+ fcall_512_1.add_param_ushort("fc_mode", fc_mode)
+ fcall_512_1.add_param_bool("short_ppdu", short_ppdu)
+ fcall_512_1.add_param_ushort("mod", mod)
+ fcall_512_1.add_param_ushort("fecrate", fecrate)
+ fcall_512_1.add_param_ushort("pb_size", pb_size)
+ fcall_512_1.add_param_ushort("gil", gil)
+ fcall_512_1.add_param_ushort("pb_nb", pb_nb)
+ return fcall_512_1
+
+def create_fcall_512_3():
+ # Create a fcall for an MPDU containing 3 PBs of 512 octets
+ fc_mode = 2 # PHY_FC_MODE_AV_1
+ short_ppdu = False
+ mod = 0 # PHY_MOD_ROBO
+ fecrate = 0 # PHY_FEC_RATE_1_2
+ pb_size = 1 # PHY_PB_SIZE_520
+ gil = 0 # PHY_GIL_417
+ pb_nb = 3
+ fcall_512_3 = m.create_fcall('prepare_rx')
+ fcall_512_3.add_param_ushort("fc_mode", fc_mode)
+ fcall_512_3.add_param_bool("short_ppdu", short_ppdu)
+ fcall_512_3.add_param_ushort("mod", mod)
+ fcall_512_3.add_param_ushort("fecrate", fecrate)
+ fcall_512_3.add_param_ushort("pb_size", pb_size)
+ fcall_512_3.add_param_ushort("gil", gil)
+ fcall_512_3.add_param_ushort("pb_nb", pb_nb)
+ return fcall_512_3
+
+def create_fcall_short_fc10():
+ # Create a fcall for a short PPDU with a FC 1.0
+ fc_mode = 0 # PHY_FC_MODE_HYBRID_1
+ short_ppdu = True
+ fcall_short_fc10 = m.create_fcall('prepare_rx')
+ fcall_short_fc10.add_param_ushort("fc_mode", fc_mode)
+ fcall_short_fc10.add_param_bool("short_ppdu", short_ppdu)
+ fcall_short_fc10.add_param_ushort("mod", 0)
+ fcall_short_fc10.add_param_ushort("fecrate", 0)
+ fcall_short_fc10.add_param_ushort("pb_size", 0)
+ fcall_short_fc10.add_param_ushort("gil", 0)
+ fcall_short_fc10.add_param_ushort("pb_nb", 0)
+ return fcall_short_fc10
# Test following functions:
# - send(self, maximus, fc_mode=4, short_ppdu=0, mod=4, file=None)
@@ -98,6 +106,7 @@ fcall_short_fc10.add_param_ushort("pb_nb", pb_nb)
# - recv(maximus, timeout=None, filter=None, count=1)
# Send an MPDU containing one PB of 128 octets
+fcall_128 = create_fcall_128()
fcall_128.send(sta1)
macFrame1 = macframe.MACFrame()
fc_av_1 = (0, 456, 789, 10)
@@ -116,6 +125,7 @@ if rsp1[0].get_msdu() != msdu1:
m.wait(100000)
# Send an MPDU containing 3 PBs of 512 octets
+fcall_512_3 = create_fcall_512_3()
fcall_512_3.send(sta1)
macFrame2 = macframe.MACFrame()
fc_av_2 = fc_av_1
@@ -133,6 +143,7 @@ if rsp2[0].get_msdu() != msdu2:
m.wait(100000)
# Send a short PPDU with a FC 1.0
+fcall_short_fc10 = create_fcall_short_fc10()
fcall_short_fc10.send(sta1)
macFrame3 = macframe.MACFrame()
fc_10_3 = 1
@@ -144,6 +155,7 @@ macFrame3.send(maximus=m, short_ppdu=True)
m.wait(100000)
# Send an MPDU containing one PB of 512 octets with a FC 1.0
+fcall_512_1 = create_fcall_512_1()
fcall_512_1.send(sta1)
macFrame4 = macframe.MACFrame()
fc_10_4 = 10
@@ -167,6 +179,7 @@ if rsp4[0].get_msdu() != msdu4:
m.wait(100000)
# Send an MPDU containing one PB of 128 octets, created from an MME
+fcall_128 = create_fcall_128()
fcall_128.send(sta1)
icv5 = 'ICV!'
macFrame5 = macframe.MACFrame(ICV=icv5)
diff --git a/maximus/python/src/interface_module.cpp b/maximus/python/src/interface_module.cpp
index 85504bce2e..678f591edc 100644
--- a/maximus/python/src/interface_module.cpp
+++ b/maximus/python/src/interface_module.cpp
@@ -7,6 +7,7 @@
#include <boost/python/return_value_policy.hpp>
#include <boost/python/copy_non_const_reference.hpp>
+#include <boost/python/return_internal_reference.hpp>
#include <boost/python/detail/api_placeholder.hpp>
@@ -34,14 +35,7 @@ extern Logger logger;
// To catch signals
extern Maximus * pMaximus;
-struct compareMsg
-{
- bool operator( ) ( const Msg * msg1, const Msg * msg2 ) const
- {
- return msg1 < msg2;
- }
-};
-typedef std::multimap<const Msg *, PyObject *, compareMsg> CbsList;
+typedef std::multimap<Function_Call_Msg_Id, object, compareMsgId> CbsList;
CbsList listOfCbs;
typedef struct rx_param
@@ -53,9 +47,9 @@ typedef struct rx_param
rx_param_t phy_rx_param, ether_rx_param;
-void set_fcall_cb ( const Msg & msg, PyObject * user_cb )
+void set_fcall_cb ( const Msg & msg, object user_cb )
{
- listOfCbs.insert(CbsList::value_type(&msg, user_cb));
+ listOfCbs.insert(CbsList::value_type(msg.get_tx_msg_id(), user_cb));
}
@@ -63,9 +57,10 @@ void remove_fcall_cb ( const Msg & msg )
{
for (CbsList::const_iterator it = listOfCbs.begin(); it != listOfCbs.end(); ++it)
{
- if (&msg == it->first)
+ if (msg.get_tx_msg_id() == it->first)
{
- listOfCbs.erase(&msg);
+ listOfCbs.erase(it->first);
+ break;
}
}
}
@@ -75,10 +70,11 @@ void recv_fcall_cb ( Msg & msg )
{
for (CbsList::const_iterator it = listOfCbs.begin(); it != listOfCbs.end(); ++it)
{
- if (&msg == it->first)
+ if (msg.get_rx_msg_id() == it->first)
{
- call<void>((it->second), msg);
- listOfCbs.erase(&msg);
+ (it->second)(msg);
+ listOfCbs.erase(it->first);
+ break;
}
}
}
@@ -178,21 +174,21 @@ void init_wrap ( Maximus & m, object args )
PyObject * create_sta_wrap ( Maximus & m )
{
- return_by_value::apply<Sta>::type converter;
+ return_internal_reference<1, Maximus>::result_converter::apply<Sta &>::type converter;
return converter(m.create_sta());
}
PyObject * create_fcall_wrap ( Maximus & m, const string name )
{
- return_by_value::apply<Msg>::type converter;
+ return_internal_reference<1, Maximus>::result_converter::apply<Msg &>::type converter;
return converter(m.create_fc(name));
}
PyObject * create_probe_wrap ( Maximus & m )
{
- return_by_value::apply<Msg>::type converter;
+ return_internal_reference<1, Maximus>::result_converter::apply<Msg &>::type converter;
return converter(m.create_probe());
}
@@ -238,19 +234,19 @@ void send_phy ( Maximus & m, object macframe )
pMpdu->setMpduFormat((Phy_Mpdu_Format)((fc_av[0] & 0x07) + 1)); // +1 to have the correspondance with our own MPDU format definition (of 'phy_types.h')
// Extract and set FC mode
- int fcMode = extract<int>(mpdu.attr("fc_mode"));
- if ( PHY_FC_MODE_NONE == (Phy_Fc_Mode)fcMode )
+ int fc_mode = extract<int>(mpdu.attr("fc_mode"));
+ if ( PHY_FC_MODE_NONE == (Phy_Fc_Mode)fc_mode )
{
if (0 == fc_10)
{
- fcMode = PHY_FC_MODE_AV_1;
+ fc_mode = PHY_FC_MODE_AV_1;
}
else
{
- fcMode = PHY_FC_MODE_HYBRID_1;
+ fc_mode = PHY_FC_MODE_HYBRID_1;
}
}
- pMpdu->setFcMode((Phy_Fc_Mode)fcMode);
+ pMpdu->setFcMode((Phy_Fc_Mode)fc_mode);
// Extract and set short PPDU
pMpdu->setShortPpdu((Phy_Short_Ppdu)extract<int>(mpdu.attr("short_ppdu")));
@@ -359,7 +355,7 @@ PyObject * add_param_ulong ( Msg & msg, const string name, const unsigned long i
}
-PyObject * set_cb_wrap ( Msg & msg, PyObject * user_cb )
+PyObject * set_cb_wrap ( Msg & msg, object user_cb )
{
copy_non_const_reference::apply<Msg &>::type converter;
remove_fcall_cb(msg);
diff --git a/maximus/stationtest/Makefile b/maximus/stationtest/Makefile
index 5a3455293e..d93a60c2cd 100644
--- a/maximus/stationtest/Makefile
+++ b/maximus/stationtest/Makefile
@@ -2,7 +2,7 @@ BASE = ../..
ECOS = y
-TARGET_PROGRAMS = hello_world one_thread exception threaddelay stationtest test_send test_tx_rx
+TARGET_PROGRAMS = hello_world one_thread exception threaddelay stationtest test_send test_tx_rx test_cb
hello_world_SOURCES = hello_world.c
hello_world_MODULES = lib host
@@ -25,4 +25,7 @@ test_send_MODULES = lib host hal/phy/maximus
test_tx_rx_SOURCES = test_tx_rx.c
test_tx_rx_MODULES = lib host hal/phy/maximus
+test_cb_SOURCES = test_cb.c
+test_cb_MODULES = lib host hal/phy/maximus
+
include $(BASE)/common/make/top.mk
diff --git a/maximus/stationtest/src/test_cb.c b/maximus/stationtest/src/test_cb.c
new file mode 100644
index 0000000000..e202467966
--- /dev/null
+++ b/maximus/stationtest/src/test_cb.c
@@ -0,0 +1,42 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hello_world.c
+ * \brief hello world program
+ * \ingroup
+ */
+
+#include <cyg/infra/diag.h>
+#include <cyg/kernel/kapi.h>
+#include <errno.h>
+#include "common/std.h"
+#include "host/station.h"
+
+extern station_ctx_t my_station;
+
+int get_seg (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
+{
+ diag_write_string("=> get_seg\n");
+
+ /* now make the return parameter list */
+ fcall_param_reset(*param);
+
+ return 0;
+}
+
+int main(void)
+{
+ station_log_set_level(&my_station, STATION_LOG_DEBUG);
+ station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
+ my_station.pipe_log_fd = 1;
+ diag_write_string("hello by eCos\n");
+
+ fcall_register(my_station.fcall, "get_seg", (void*)&get_seg, NULL);
+
+ return 0;
+}