summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--maximus/common/types/functioncall_types.h7
-rw-r--r--maximus/coreengine/Makefile10
-rw-r--r--maximus/coreengine/src/CoreEngine.cpp36
-rw-r--r--maximus/coreengine/src/CoreEngineTest.cpp2
-rw-r--r--maximus/coreengine/src/main.cpp2
-rw-r--r--maximus/functioncall/Module2
-rw-r--r--maximus/functioncall/inc/FunctionCallParameter.h167
-rw-r--r--maximus/functioncall/inc/FunctionSciMsg.h26
-rw-r--r--maximus/functioncall/src/FunctionCallParameter.cpp279
-rw-r--r--maximus/functioncall/src/FunctionSciMsg.cpp360
-rw-r--r--maximus/functioncall/src/FunctionSciMsgTest.cpp35
-rw-r--r--maximus/functioncall/src/IFunctionCallTest.cpp7
-rw-r--r--maximus/sci/inc/SciServer.h2
-rw-r--r--maximus/sci/src/SciServer.cpp16
-rw-r--r--maximus/system/inc/Station.h20
-rw-r--r--maximus/system/src/Station.cpp45
-rw-r--r--maximus/unittest/Makefile11
-rw-r--r--maximus/unittest/src/main.cpp69
18 files changed, 783 insertions, 313 deletions
diff --git a/maximus/common/types/functioncall_types.h b/maximus/common/types/functioncall_types.h
index 8776249557..b9b7c2cf0c 100644
--- a/maximus/common/types/functioncall_types.h
+++ b/maximus/common/types/functioncall_types.h
@@ -10,13 +10,6 @@
#define FUNCTION_CALL_FUNCTION_MAX_NB 64 /* max number of registred functions */
#define FUNCTION_CALL_PARAM_MAX_SIZE 1024
-struct Function_Call_Parameter
-{
- char * p_name;
- unsigned long length;
- unsigned char * p_value;
-};
-
struct Function_Call_Header
{
uint8_t version;
diff --git a/maximus/coreengine/Makefile b/maximus/coreengine/Makefile
new file mode 100644
index 0000000000..26fb582dc7
--- /dev/null
+++ b/maximus/coreengine/Makefile
@@ -0,0 +1,10 @@
+BASE = ../..
+
+HOST_PROGRAMS = maximus
+maximus_SOURCES = main.cpp CoreEngine.cpp
+maximus_MODULES = maximus/error maximus/functioncall maximus/networkclock maximus/phy maximus/sci maximus/system
+INCLUDES = maximus/error/inc maximus/coreengine/inc maximus/networkclock/inc maximus/sci/inc maximus/functioncall/inc maximus/phy/inc maximus/system/inc maximus/common/interfaces maximus/common/types
+
+include $(BASE)/common/make/top.mk
+
+HOST_LDFLAGS += -lpthread
diff --git a/maximus/coreengine/src/CoreEngine.cpp b/maximus/coreengine/src/CoreEngine.cpp
index ded48e20da..a3e1095814 100644
--- a/maximus/coreengine/src/CoreEngine.cpp
+++ b/maximus/coreengine/src/CoreEngine.cpp
@@ -35,6 +35,7 @@ The original location of this file is /home/buret/eclipse/maximus/coreengine/src
#include "SystemManager.h"
#include "SciServer.h"
#include "Error.h"
+#include "Station.h"
#include <iostream> // for 'cout', 'cerr' and 'clog'
using namespace std;
@@ -61,21 +62,19 @@ void CoreEngine::initAttributes ( )
{
clog << "CoreEngine::initAttributes" << endl;
- // Create all packages: FunctionCall, NetworkClock, Phy, System, SCI
+ // Create all packages: at first SCI; then FunctionCall, Phy, and System; and lastly NetworkClock
//
- mpSciServer = new SciServer();
- if (NULL != mpSciServer)
+ try
{
+ mpSciServer = new SciServer();
mpFunctionCallManager = new FunctionCallManager(mpSciServer);
mpSystemManager = new SystemManager(mpSciServer);
mpPhyProcessor = new PhyProcessor(mpSciServer);
-
- if ( (NULL != mpFunctionCallManager)
- && (NULL != mpSystemManager)
- && (NULL != mpPhyProcessor) )
- {
- mpNetworkClockProcessor = new NetworkClockProcessor(mpSciServer, mpSystemManager, mpFunctionCallManager, mpPhyProcessor);
- }
+ mpNetworkClockProcessor = new NetworkClockProcessor(mpSciServer, mpSystemManager, mpFunctionCallManager, mpPhyProcessor);
+ }
+ catch ( Error &e )
+ {
+ e.display();
}
}
@@ -128,18 +127,19 @@ CoreEngine::~CoreEngine ( )
void CoreEngine::run ( )
{
clog << "CoreEngine::run" << endl;
-
- bool b = true;
- while(b)
+
+ try
{
- try
+ mpSystemManager->createStation(); // FOR TESTS PURPOSE ONLY, TO REMOVE
+ bool b = true;
+ while(b)
{
b = mpNetworkClockProcessor->processNextEvt();
}
- catch ( Error &e )
- {
- e.display();
- }
+ }
+ catch ( Error &e )
+ {
+ e.display();
}
}
diff --git a/maximus/coreengine/src/CoreEngineTest.cpp b/maximus/coreengine/src/CoreEngineTest.cpp
index 6869034d62..0ec44488a7 100644
--- a/maximus/coreengine/src/CoreEngineTest.cpp
+++ b/maximus/coreengine/src/CoreEngineTest.cpp
@@ -42,7 +42,7 @@ void CoreEngineTest::simpleTest (void)
}
else
{
- CPPUNIT_FAIL ("CoreEngine pointer is NULL");
+ CPPUNIT_FAIL ("Core engine pointer is NULL");
}
clog << "-------------------------------------------------------------------------------------" << endl;
diff --git a/maximus/coreengine/src/main.cpp b/maximus/coreengine/src/main.cpp
index 0cb8a837bc..8f1a0c613c 100644
--- a/maximus/coreengine/src/main.cpp
+++ b/maximus/coreengine/src/main.cpp
@@ -14,12 +14,12 @@ int main (void)
ofstream logFile ("maximuslog.txt");
if (logFile)
{
- //clog.rdbuf(cout.rdbuf());
clog.rdbuf(logFile.rdbuf());
}
else
{
cerr << "Error while opening log file" << endl;
+ clog.rdbuf(cout.rdbuf());
}
cout << "-------------------------------------------------------------------------------------" << endl;
diff --git a/maximus/functioncall/Module b/maximus/functioncall/Module
index 9d8ca5b89d..3519101a56 100644
--- a/maximus/functioncall/Module
+++ b/maximus/functioncall/Module
@@ -1 +1 @@
-SOURCES := FunctionCallManager.cpp FunctionSciMsg.cpp
+SOURCES := FunctionCallManager.cpp FunctionSciMsg.cpp FunctionCallParameter.cpp
diff --git a/maximus/functioncall/inc/FunctionCallParameter.h b/maximus/functioncall/inc/FunctionCallParameter.h
new file mode 100644
index 0000000000..f96b5c75b0
--- /dev/null
+++ b/maximus/functioncall/inc/FunctionCallParameter.h
@@ -0,0 +1,167 @@
+/************************************************************************
+ FunctionCallParameter.h - 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.h
+
+-->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/functioncall/inc/FunctionCallParameter.h
+**************************************************************************/
+
+#ifndef FUNCTIONCALLPARAMETER_H
+#define FUNCTIONCALLPARAMETER_H
+
+#include <string>
+
+
+/**
+ * class FunctionCallParameter
+ */
+
+class FunctionCallParameter
+{
+
+public:
+
+ // public attributes
+ //
+
+private:
+
+ // private attributes
+ //
+
+ std::string mName;
+ unsigned long mValueLength;
+ unsigned char * mpValue;
+
+protected:
+
+ // protected attributes
+ //
+
+public:
+
+ // Constructors/Destructors
+ //
+
+ /**
+ * Empty Constructor
+ */
+ FunctionCallParameter ( );
+
+ /**
+ * Copy Constructor
+ */
+ FunctionCallParameter ( const FunctionCallParameter & parameter );
+
+ /**
+ * Constructor
+ */
+ FunctionCallParameter ( std::string name,
+ unsigned long value_length,
+ unsigned char * p_value );
+
+ /**
+ * Empty Destructor
+ */
+ virtual ~FunctionCallParameter ( );
+
+ // public methods
+ //
+
+ bool operator== ( const FunctionCallParameter & parameter ) const;
+
+ FunctionCallParameter & operator= ( const FunctionCallParameter & parameter );
+
+ void displayParameter ( ) const;
+
+ // public attribute accessor methods
+ //
+
+ // private attribute accessor methods
+ //
+
+ /**
+ * Get the value of mName
+ * @return the value of mName
+ */
+ std::string getName ( ) const;
+
+ /**
+ * Set the value of mName
+ * @return bool
+ * @param name the new value of mName
+ */
+ bool setName ( const std::string name );
+
+ /**
+ * Set the value of mName
+ * @return bool
+ * @param name the new value of mName
+ */
+ bool setName ( const char * p_name );
+
+ /**
+ * Get the value of mValue Length
+ * @return the value of mValueLength
+ */
+ unsigned long getValueLength ( ) const;
+
+ /**
+ * Set the value of mValueLength
+ * @return bool
+ * @param value_length the new value of mValueLength
+ */
+ bool setValueLength ( const unsigned long value_length );
+
+ /**
+ * @return mpValue
+ */
+ unsigned char * getValue ( ) const;
+
+ /**
+ * @return bool
+ * @param p_value the new value of mpValue
+ */
+ bool setValue ( const unsigned char * p_value );
+
+ // protected attribute accessor methods
+ //
+
+private:
+
+ // private methods
+ //
+
+ void initAttributes ( );
+
+protected:
+
+ // protected methods
+ //
+
+};
+
+
+#endif // FUNCTIONCALLPARAMETER_H
diff --git a/maximus/functioncall/inc/FunctionSciMsg.h b/maximus/functioncall/inc/FunctionSciMsg.h
index a8c52325f4..da27e9504c 100644
--- a/maximus/functioncall/inc/FunctionSciMsg.h
+++ b/maximus/functioncall/inc/FunctionSciMsg.h
@@ -32,14 +32,16 @@ The original location of this file is /home/buret/eclipse/maximus/functioncall/i
#define FUNCTIONSCIMSG_H
#include <vector>
+#include <string>
#include "SciMsg.h"
#include "functioncall_types.h"
#include "sci_types.h"
class FunctionCallManager;
+class FunctionCallParameter;
-typedef std::vector<Function_Call_Parameter *> ParametersList;
+typedef std::vector<FunctionCallParameter> ParametersList;
/**
@@ -74,7 +76,7 @@ private:
// Function parameters
//
- ParametersList * mpListOfParameters;
+ ParametersList mListOfParameters;
FunctionCallManager * mpFunctionCallManager;
@@ -102,7 +104,7 @@ public:
* Copy Constructors
*/
FunctionSciMsg ( const FunctionSciMsg & function_sci_msg );
- FunctionSciMsg ( const FunctionSciMsg * function_sci_msg );
+ //FunctionSciMsg ( const FunctionSciMsg * function_sci_msg );
/**
* Empty Destructor
@@ -136,14 +138,14 @@ public:
* @return bool
* @param function_argument_to_add
*/
- bool addParameter ( Function_Call_Parameter & function_argument_to_add );
+ bool addParameter ( const FunctionCallParameter & function_argument_to_add );
/**
* @return bool
* @param name_of_parameter_to_get
* @param p_data
*/
- bool bindParameter ( const char * name_of_parameter_to_get, unsigned long & data_length, void ** pp_data ) const;
+ bool bindParameter ( const std::string name_of_parameter_to_get, unsigned long & data_length, void * & p_data ) const;
/**
* @return bool
@@ -219,17 +221,17 @@ public:
bool setFunctionName ( const char * name );
/**
- * Get the value of mpListOfParameters
- * @return the value of mpListOfParameters
+ * Get the value of mListOfParameters
+ * @return the value of mListOfParameters
*/
- ParametersList * getListOfParameters ( ) const;
+ const ParametersList & getListOfParameters ( ) const;
/**
- * Set the value of mpListOfParameters
+ * Set the value of mListOfParameters
* @return bool
- * @param p_list_of_parameters the new value of mpListOfParameters
+ * @param list_of_parameters the new value of mListOfParameters
*/
- bool setListOfParameters ( ParametersList * p_list_of_parameters );
+ bool setListOfParameters ( const ParametersList & list_of_parameters );
/**
* Get the value of mpFunctionCallManager
@@ -259,8 +261,6 @@ private:
void displayParameter ( unsigned int parameter_iterator ) const;
void displayListOfParameters ( ) const;
-
- void deleteParameters ( );
protected:
diff --git a/maximus/functioncall/src/FunctionCallParameter.cpp b/maximus/functioncall/src/FunctionCallParameter.cpp
new file mode 100644
index 0000000000..5e79c269f5
--- /dev/null
+++ b/maximus/functioncall/src/FunctionCallParameter.cpp
@@ -0,0 +1,279 @@
+/************************************************************************
+ FunctionCallParameter.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/functioncall/src/FunctionCallParameter.cpp
+**************************************************************************/
+
+#include "FunctionCallParameter.h"
+
+#include <iostream> // for 'clog'
+using namespace std;
+
+
+// Constructors/Destructors
+//
+
+
+FunctionCallParameter::FunctionCallParameter ( ):
+mName("none"),
+mValueLength(0),
+mpValue(NULL)
+{
+ //clog << "FunctionCallParameter()" << endl;
+
+ initAttributes ();
+}
+
+
+FunctionCallParameter::FunctionCallParameter ( const FunctionCallParameter & parameter ):
+mName("none"),
+mValueLength(0),
+mpValue(NULL)
+{
+ //clog << "FunctionCallParameter(FunctionCallParameter&)" << endl;
+
+ setName (parameter.getName());
+ setValueLength (parameter.getValueLength());
+ setValue (parameter.getValue());
+
+ initAttributes ();
+}
+
+
+FunctionCallParameter::FunctionCallParameter ( string name,
+ unsigned long value_length,
+ unsigned char * p_value ):
+mName("none"),
+mValueLength(0),
+mpValue(NULL)
+{
+ //clog << "FunctionCallParameter(...)" << endl;
+
+ setName (name);
+ setValueLength (value_length);
+ setValue (p_value);
+
+ initAttributes ();
+}
+
+
+void FunctionCallParameter::initAttributes ( )
+{
+ //clog << "FunctionCallParameter::initAttributes" << endl;
+}
+
+FunctionCallParameter::~FunctionCallParameter ( )
+{
+ //clog << "~FunctionCallParameter" << endl;
+
+ mName.clear();
+ if (NULL != mpValue)
+ {
+ delete (mpValue);
+ mpValue = NULL;
+ }
+}
+
+
+//
+// Methods
+//
+
+
+// Other methods
+//
+
+
+// public methods
+//
+
+
+bool FunctionCallParameter::operator== ( const FunctionCallParameter & parameter ) const
+{
+ bool bOperator = false;
+
+ if ( (!getName().compare(parameter.getName()))
+ && (getValueLength() == parameter.getValueLength())
+ && (!strcmp((char*)getValue(), (char*)parameter.getValue())) )
+ {
+ bOperator = true;
+ }
+
+ return bOperator;
+}
+
+
+FunctionCallParameter & FunctionCallParameter::operator= ( const FunctionCallParameter & parameter )
+{
+ setName (parameter.getName());
+ setValueLength (parameter.getValueLength());
+ setValue (parameter.getValue());
+
+ return *this;
+}
+
+
+void FunctionCallParameter::displayParameter ( ) const
+{
+ clog << "[name = " << getName() << ", value length = " << dec << getValueLength() << ", value = ";
+ if (NULL != getValue())
+ {
+ for (unsigned int i=0; i<static_cast<unsigned int>(getValueLength()); i++)
+ {
+ clog << *(getValue()+i);
+ }
+ }
+ else
+ {
+ clog << "NULL";
+ }
+ clog << "]";
+}
+
+
+// protected methods
+//
+
+
+// Accessor methods
+//
+
+
+// public attribute accessor methods
+//
+
+
+// private attribute accessor methods
+//
+
+
+string FunctionCallParameter::getName ( ) const
+{
+ return mName;
+}
+
+
+bool FunctionCallParameter::setName ( const string name )
+{
+ //clog << "FunctionCallParameter::setName" << endl;
+
+ mName.clear();
+ mName = name;
+ //clog << "\tname = " << getName() << endl;
+
+ return true;
+}
+
+
+bool FunctionCallParameter::setName ( const char * p_name )
+{
+ //clog << "FunctionCallParameter::setName" << endl;
+
+ if (NULL != p_name)
+ {
+ mName.clear();
+ mName = p_name;
+ //clog << "\tname = " << getName() << endl;
+ }
+
+ return true;
+}
+
+
+unsigned long FunctionCallParameter::getValueLength ( ) const
+{
+ return mValueLength;
+}
+
+
+bool FunctionCallParameter::setValueLength ( const unsigned long value_length )
+{
+ //clog << "FunctionCallParameter::setValueLength" << endl;
+
+ mValueLength = value_length;
+ //clog << "\tvalue length = " << getValueLength() << endl;
+
+ return true;
+}
+
+
+unsigned char * FunctionCallParameter::getValue ( ) const
+{
+ return mpValue;
+}
+
+
+bool FunctionCallParameter::setValue ( const unsigned char * p_value )
+{
+ //clog << "FunctionCallParameter::setValue" << endl;
+ bool bSetValue = false;
+
+ if (NULL != p_value)
+ {
+ // Check value length
+ //
+ unsigned int length = 0;
+ if ( getValueLength()<=strlen((char*)p_value) )
+ {
+ length = static_cast<unsigned int>(getValueLength());
+ }
+ else
+ {
+ setValueLength (static_cast<unsigned long>(strlen((char*)p_value)));
+ length = static_cast<unsigned int>(strlen((char*)p_value));
+ }
+
+ // Allocate (and free) memory
+ //
+ if (NULL != mpValue)
+ {
+ delete(mpValue);
+ mpValue = NULL;
+ }
+ mpValue = new unsigned char [length+1];
+
+ // Copy value
+ //
+ for (unsigned int i=0; i<length; i++)
+ {
+ *(mpValue+i) = *(p_value+i);
+ }
+ mpValue[length] = '\0';
+ bSetValue = true;
+ }
+ else
+ {
+ mpValue = NULL;
+ }
+
+ return bSetValue;
+}
+
+
+// protected attribute accessor methods
+//
+
diff --git a/maximus/functioncall/src/FunctionSciMsg.cpp b/maximus/functioncall/src/FunctionSciMsg.cpp
index abc49de373..d92f68a249 100644
--- a/maximus/functioncall/src/FunctionSciMsg.cpp
+++ b/maximus/functioncall/src/FunctionSciMsg.cpp
@@ -30,6 +30,7 @@ The original location of this file is /home/buret/eclipse/maximus/functioncall/s
#include "FunctionSciMsg.h"
#include "FunctionCallManager.h"
+#include "FunctionCallParameter.h"
#include "Error.h"
// For 'cout'
@@ -51,7 +52,6 @@ mSpecializedSciMsgType(FUNCTION_CALL_TYPE_NONE),
mSpecializedSciMsgParametersNumber(0),
mpSpecializedSciMsgHeader(NULL),
mpFunctionName(NULL),
-mpListOfParameters(NULL),
mpFunctionCallManager(NULL)
{
//clog << "FunctionSciMsg()" << endl;
@@ -65,7 +65,6 @@ mSpecializedSciMsgType(FUNCTION_CALL_TYPE_NONE),
mSpecializedSciMsgParametersNumber(0),
mpSpecializedSciMsgHeader(NULL),
mpFunctionName(NULL),
-mpListOfParameters(NULL),
mpFunctionCallManager(NULL)
{
//clog << "FunctionSciMsg(FunctionCallManager*)" << endl;
@@ -88,8 +87,6 @@ void FunctionSciMsg::initAttributes ( )
//clog << "FunctionSciMsg::initAttributes" << endl;
mpSpecializedSciMsgHeader = new Function_Call_Header;
- mpListOfParameters = new ParametersList ();
-
if (NULL != mpSpecializedSciMsgHeader)
{
mpSpecializedSciMsgHeader->version = FUNCTION_CALL_VERSION;
@@ -117,7 +114,7 @@ FunctionSciMsg::FunctionSciMsg ( const FunctionSciMsg & function_sci_msg ) : Sci
setFunctionCallManager (function_sci_msg.getFunctionCallManager());
}
-
+/*
FunctionSciMsg::FunctionSciMsg ( const FunctionSciMsg * function_sci_msg ) : SciMsg ( function_sci_msg )
{
//clog << "FunctionSciMsg(FunctionSciMsg*)" << endl;
@@ -141,7 +138,7 @@ FunctionSciMsg::FunctionSciMsg ( const FunctionSciMsg * function_sci_msg ) : Sci
throw Error("FunctionSciMsg(FunctionSciMsg*)", "Received function SCI msg pointer is NULL");
}
}
-
+*/
FunctionSciMsg::~FunctionSciMsg ( )
{
@@ -158,15 +155,9 @@ FunctionSciMsg::~FunctionSciMsg ( )
delete [] mpFunctionName;
mpFunctionName = NULL;
}
- if (NULL != mpListOfParameters)
+ if (!mListOfParameters.empty())
{
- if (!mpListOfParameters->empty())
- {
- deleteParameters();
- mpListOfParameters->clear();
- }
- //delete (mpListOfParameters);
- mpListOfParameters = NULL;
+ mListOfParameters.clear();
}
if (NULL != mpFunctionCallManager)
@@ -176,31 +167,6 @@ FunctionSciMsg::~FunctionSciMsg ( )
}
-void FunctionSciMsg::deleteParameters ( )
-{
- //clog << "FunctionSciMsg::deleteParameters" << endl;
-
- for (unsigned int i=0; i<mpListOfParameters->size(); ++i)
- {
- if (NULL != (*mpListOfParameters)[i])
- { /*
- if ( NULL != (*mpListOfParameters)[i]->p_name )
- {
- delete [] (*mpListOfParameters)[i]->p_name;
- (*mpListOfParameters)[i]->p_name = NULL;
- }
- if ( NULL != (*mpListOfParameters)[i]->p_value )
- {
- delete [] (*mpListOfParameters)[i]->p_value;
- (*mpListOfParameters)[i]->p_value = NULL;
- }*/
- delete ((*mpListOfParameters)[i]);
- //((*mpListOfParameters)[i])= NULL;
- }
- }
-}
-
-
//
// Methods
//
@@ -308,114 +274,66 @@ bool FunctionSciMsg::checkCompatibility ( ) const
// Called by user to configure a message to send
//
-bool FunctionSciMsg::addParameter ( Function_Call_Parameter & function_argument_to_add )
+bool FunctionSciMsg::addParameter ( const FunctionCallParameter & function_argument_to_add )
{
clog << "FunctionSciMsg::addParameter" << endl;
bool bAddParameter = false;
-
- if (NULL != mpListOfParameters)
+
+ if ( FUNCTION_CALL_PARAM_MAX_SIZE >= function_argument_to_add.getValueLength())
{
- Function_Call_Parameter * parameterToAdd = new Function_Call_Parameter;
- if (NULL != parameterToAdd)
- {
- parameterToAdd->p_name = new char [strlen(function_argument_to_add.p_name)+1];
- if ( (NULL != parameterToAdd->p_name) && (NULL != function_argument_to_add.p_name) )
- {
- strcpy(parameterToAdd->p_name, function_argument_to_add.p_name);
-
- if ( FUNCTION_CALL_PARAM_MAX_SIZE >= function_argument_to_add.length)
- {
- parameterToAdd->length = function_argument_to_add.length;
- }
- else
- {
- throw Error("FunctionSciMsg::addParameter", "Length of parameter value exceeds max size");
- }
-
- parameterToAdd->p_value = new unsigned char [parameterToAdd->length+1];
- if ( (NULL != parameterToAdd->p_value) && (NULL != function_argument_to_add.p_value) )
- {
- strncpy((char*)parameterToAdd->p_value, (char*)function_argument_to_add.p_value, parameterToAdd->length);
- parameterToAdd->p_value[parameterToAdd->length] = '\0';
- mpListOfParameters->push_back(parameterToAdd);
-
- displayListOfParameters();
- bAddParameter = true;
- }
- else
- {
- throw Error("FunctionSciMsg::addParameter", "Function call parameter value pointer is NULL");
- }
- }
- else
- {
- throw Error("FunctionSciMsg::addParameter", "Function call parameter name pointer is NULL");
- }
- }
- else
- {
- throw Error("FunctionSciMsg::addParameter", "Initialized function call parameter pointer is NULL");
- }
+ FunctionCallParameter parameterToAdd = function_argument_to_add;
+ mListOfParameters.push_back(parameterToAdd);
+ displayListOfParameters();
+ bAddParameter = true;
}
else
{
- throw Error("FunctionSciMsg::addParameter", "Initialized parameters list pointer is NULL");
+ throw Error("FunctionSciMsg::addParameter", "Length of parameter value exceeds max size");
}
-
+
return bAddParameter;
}
// Called by user when a message is received to retrieve function parameters
//
-bool FunctionSciMsg::bindParameter ( const char * name_of_parameter_to_get, unsigned long & data_length, void ** pp_data ) const
+bool FunctionSciMsg::bindParameter ( const string name_of_parameter_to_get, unsigned long & data_length, void * & p_data ) const
{
clog << "FunctionSciMsg::bindParameter" << endl;
bool bBindParameter = false;
- if (NULL != pp_data)
+ displayListOfParameters();
+ FunctionCallParameter tempParameter;
+
+ for (unsigned int i=0; i<mListOfParameters.size(); ++i)
{
- displayListOfParameters();
- if (NULL != mpListOfParameters)
+ tempParameter = mListOfParameters[i];
+ if ( !tempParameter.getName().compare(name_of_parameter_to_get) )
{
- for (unsigned int i=0; i<mpListOfParameters->size(); ++i)
+ data_length = tempParameter.getValueLength();
+ if (NULL != p_data)
{
- if (!strcmp(name_of_parameter_to_get, (*mpListOfParameters)[i]->p_name))
+ if (NULL != tempParameter.getValue())
+ {
+ p_data = tempParameter.getValue();
+ }
+ else
{
- data_length = (*mpListOfParameters)[i]->length;
- *pp_data = malloc(data_length);
- if (NULL != *pp_data)
- {
- if (NULL != (*mpListOfParameters)[i]->p_value)
- {
- *pp_data = (void*)((*mpListOfParameters)[i]->p_value);
- }
- else
- {
- *pp_data = NULL;
- }
- clog << "\tbind parameter = ";
- displayParameter(i);
- i = mpListOfParameters->size()-1;
- bBindParameter = true;
- }
- else
- {
- throw Error("FunctionSciMsg::bindParameter", "Allocated data pointer is NULL");
- }
+ p_data = NULL;
}
+ clog << "\tbind parameter = ";
+ tempParameter.displayParameter();
+ clog << endl;
+ i = mListOfParameters.size()-1;
+ bBindParameter = true;
+ }
+ else
+ {
+ throw Error("FunctionSciMsg::bindParameter", "Allocated data pointer is NULL");
}
- }
- else
- {
- throw Error("FunctionSciMsg::bindParameter", "Initialized parameters list pointer is NULL");
}
}
- else
- {
- throw Error("FunctionSciMsg::bindParameter", "Received parameter value pointer is NULL");
- }
-
+
return bBindParameter;
}
@@ -506,87 +424,84 @@ bool FunctionSciMsg::identifyCallbackParameters ( )
// Find parameter name length
//
unsigned long parameterNameLength = 0;
+ char * pTempParameterName = new char [getSpecializedSciMsgDataLength()+1];
while ( (getSpecializedSciMsgDataLength() >= parameterNameLength)
- && ('\0' != *(getSpecializedSciMsgData()+parameterNameLength)) )
+ && ('\0' != *(getSpecializedSciMsgData()+parameterNameLength)) )
{
+ *(pTempParameterName+parameterNameLength) = *(getSpecializedSciMsgData()+parameterNameLength);
parameterNameLength++;
}
+ *(pTempParameterName+parameterNameLength) = '\0';
//clog << dec << "\tparameter " << n+1 << " name length = " << parameterNameLength+1 << endl;
// Copy parameter name from specialized SCI msg data to parameter name attribute
//
- Function_Call_Parameter parameterToFill = { NULL, 0, NULL };
- parameterToFill.p_name = new char [parameterNameLength+1];
- if (NULL != parameterToFill.p_name)
+ FunctionCallParameter parameterToFill;
+ parameterToFill.setName (pTempParameterName);
+ //clog << "\tparameter " << dec << n+1 << " name = " << parameterToFill.getName() << endl;
+
+ if (NULL != pTempParameterName)
{
- for (unsigned int i=0; i<parameterNameLength+1; i++)
- {
- *(parameterToFill.p_name+i) = static_cast<char>(*(getSpecializedSciMsgData()+i));
- }
- //clog << "\tparameter " << dec << n+1 << " name = " << parameterToFill.p_name << endl;
+ delete [] pTempParameterName;
+ pTempParameterName = NULL;
+ }
- // Remove parameter name from specialized SCI msg data
- //
- unsigned long tempDataLength = getSpecializedSciMsgDataLength();
- unsigned char * pTempData = getSpecializedSciMsgData();
- bIdentifyParameters = SciMsg::removeData (parameterNameLength+1, tempDataLength, &pTempData);
- if (0 != bIdentifyParameters)
- {
- bIdentifyParameters &= setSpecializedSciMsgDataLength(tempDataLength);
- bIdentifyParameters &= setSpecializedSciMsgData(pTempData);
- }
+ // Remove parameter name from specialized SCI msg data
+ //
+ unsigned long tempDataLength = getSpecializedSciMsgDataLength();
+ unsigned char * pTempData = getSpecializedSciMsgData();
+ bIdentifyParameters = SciMsg::removeData (parameterNameLength+1, tempDataLength, &pTempData);
+ if (0 != bIdentifyParameters)
+ {
+ bIdentifyParameters &= setSpecializedSciMsgDataLength(tempDataLength);
+ bIdentifyParameters &= setSpecializedSciMsgData(pTempData);
+ }
- // Find parameter value length (coded on 2 bytes)
- //
- uint16_t tempLength = (static_cast<uint8_t>(*(getSpecializedSciMsgData()))<<8) + static_cast<uint8_t>(*(getSpecializedSciMsgData()+1));
- if ( FUNCTION_CALL_PARAM_MAX_SIZE >= tempLength )
- {
- parameterToFill.length = static_cast<unsigned long>(tempLength);
- //clog << dec << "\tparameter " << n+1 << " value length = " << parameterToFill.length << endl;
- }
- else
- {
- throw Error("FunctionSciMsg::identifyCallbackParameters", "Length of parameter value exceeds max size");
- }
+ // Find parameter value length (coded on 2 bytes)
+ //
+ uint16_t tempLength = (static_cast<uint8_t>(*(getSpecializedSciMsgData()))<<8) + static_cast<uint8_t>(*(getSpecializedSciMsgData()+1));
+ if ( FUNCTION_CALL_PARAM_MAX_SIZE >= tempLength )
+ {
+ parameterToFill.setValueLength (static_cast<unsigned long>(tempLength));
+ //clog << dec << "\tparameter " << n+1 << " value length = " << parameterToFill.getValueLength ()<< endl;
+ }
+ else
+ {
+ throw Error("FunctionSciMsg::identifyCallbackParameters", "Length of parameter value exceeds max size");
+ }
- // Find parameter value
- //
- parameterToFill.p_value = new unsigned char [parameterToFill.length];
- if (NULL != parameterToFill.p_value)
- {
- //clog << "\tparameter " << dec << n+1 << " value = ";
- for (unsigned int i=0; i<static_cast<unsigned int>(parameterToFill.length); i++)
- {
- *(parameterToFill.p_value+i) = *(getSpecializedSciMsgData()+2+i); // +2 because parameter value length is coded on 2 bytes
- //clog << *(parameterToFill.p_value+i);
- }
- //clog << endl;
+ // Find parameter value
+ //
+ unsigned char * pTempParameterValue = new unsigned char [parameterToFill.getValueLength()];
+ //clog << "\tparameter " << dec << n+1 << " value = ";
+ for (unsigned int i=0; i<static_cast<unsigned int>(parameterToFill.getValueLength()); i++)
+ {
+ *(pTempParameterValue+i) = *(getSpecializedSciMsgData()+2+i); // +2 because parameter value length is coded on 2 bytes
+ //clog << *(pTempParameterValue+i);
+ }
+ //clog << endl;
+ parameterToFill.setValue (pTempParameterValue);
- // Remove parameter value length and parameter value from specialized SCI msg data
- //
- tempDataLength = getSpecializedSciMsgDataLength();
- pTempData = getSpecializedSciMsgData();
- bIdentifyParameters &= SciMsg::removeData (2+parameterToFill.length, tempDataLength, &pTempData); // +2 because parameter value length is coded on 2 bytes
- if (0 != bIdentifyParameters)
- {
- bIdentifyParameters &= setSpecializedSciMsgDataLength(tempDataLength);
- bIdentifyParameters &= setSpecializedSciMsgData(pTempData);
- }
- pTempData = NULL; // free pointer
- }
- else
- {
- throw Error("FunctionSciMsg::identifyCallbackParameters", "Initialized parameter value pointer is NULL");
- }
-
- // Add parameter to the parameters list of the received function SCI msg
- //
- bIdentifyParameters &= addParameter(parameterToFill);
+ // Remove parameter value length and parameter value from specialized SCI msg data
+ //
+ tempDataLength = getSpecializedSciMsgDataLength();
+ pTempData = getSpecializedSciMsgData();
+ bIdentifyParameters &= SciMsg::removeData (2+parameterToFill.getValueLength(), tempDataLength, &pTempData); // +2 because parameter value length is coded on 2 bytes
+ if (0 != bIdentifyParameters)
+ {
+ bIdentifyParameters &= setSpecializedSciMsgDataLength(tempDataLength);
+ bIdentifyParameters &= setSpecializedSciMsgData(pTempData);
}
- else
+ pTempData = NULL; // free pointer
+ if (NULL != pTempParameterValue)
{
- throw Error("FunctionSciMsg::identifyCallbackParameters", "Initialized parameter name pointer is NULL");
+ delete [] pTempParameterValue;
+ pTempParameterValue = NULL;
}
+
+ // Add parameter to the parameters list of the received function SCI msg
+ //
+ bIdentifyParameters &= addParameter(parameterToFill);
}
}
else
@@ -628,18 +543,18 @@ bool FunctionSciMsg::fillSpecializedSciMsgToSend ( )
// name\0lengthp_value etc. with length coded on 2 bytes
// Number of parameters is sent into the 'Function_Call_Header.param_nb' field
//
- for (unsigned int i=0; i<mpListOfParameters->size(); ++i)
+ for (unsigned int i=0; i<mListOfParameters.size(); ++i)
{
// Dynamic memory allocation for parameter
//
- pData = (unsigned char *)(realloc(pData, dataLength+strlen((*mpListOfParameters)[i]->p_name)+1+2+(*mpListOfParameters)[i]->length));
+ pData = (unsigned char *)(realloc(pData, dataLength+((mListOfParameters)[i].getName().length())+1+2+(mListOfParameters)[i].getValueLength()));
// Parameter name
//
- strcpy ((char*)(pData+dataLength), (*mpListOfParameters)[i]->p_name); // copy parameter name into data
- pData[strlen((*mpListOfParameters)[i]->p_name)] = '\0';
+ mListOfParameters[i].getName().copy ((char*)(pData+dataLength), mListOfParameters[i].getName().length()); // copy parameter name into data
+ pData[mListOfParameters[i].getName().length()]='\0';
clog << "\tparameter " << dec << i+1 << " name = ";
- for (unsigned int j=dataLength; j<dataLength+strlen((*mpListOfParameters)[i]->p_name)+1; j++)
+ for (unsigned int j=dataLength; j<dataLength+mListOfParameters[i].getName().length(); j++)
{
clog << *(pData+j); // display parameter name
}
@@ -648,7 +563,7 @@ bool FunctionSciMsg::fillSpecializedSciMsgToSend ( )
// Parameter value length
//
- uint16_t tempLength = static_cast<uint16_t>((*mpListOfParameters)[i]->length);
+ uint16_t tempLength = static_cast<uint16_t>(mListOfParameters[i].getValueLength());
uint8_t tempLengthHigh=0, tempLengthLow=0;
tempLengthHigh = static_cast<uint8_t>(tempLength >> 8);
tempLengthLow = static_cast<uint8_t>(tempLength);
@@ -661,13 +576,13 @@ bool FunctionSciMsg::fillSpecializedSciMsgToSend ( )
// Parameter value
//
clog << "\tparameter " << dec << i+1 << " value = ";
- for (unsigned int j=0; j<(*mpListOfParameters)[i]->length; j++)
+ for (unsigned int j=0; j<mListOfParameters[i].getValueLength(); j++)
{
- *(pData+dataLength+j) = *((*mpListOfParameters)[i]->p_value+j);
+ *(pData+dataLength+j) = *(mListOfParameters[i].getValue()+j);
clog << *(pData+dataLength+j); // display parameter value
}
clog << endl;
- dataLength += (*mpListOfParameters)[i]->length; // update data length
+ dataLength += mListOfParameters[i].getValueLength(); // update data length
// Increment number of parameters that have been copied into data
//
@@ -740,30 +655,10 @@ void FunctionSciMsg::displaySpecializedSciMsgType ( ) const
void FunctionSciMsg::displayParameter ( unsigned int parameter_iterator ) const
{
clog << "\tparameter " << dec << parameter_iterator+1 << " = ";
- if (parameter_iterator < mpListOfParameters->size())
+ if (parameter_iterator < mListOfParameters.size())
{
- clog << "[";
- if (NULL != (*mpListOfParameters)[parameter_iterator]->p_name)
- {
- clog << (*mpListOfParameters)[parameter_iterator]->p_name;
- }
- else
- {
- clog << "NULL";
- }
- clog << ", " << (*mpListOfParameters)[parameter_iterator]->length << ", ";
- if (NULL != (*mpListOfParameters)[parameter_iterator]->p_value)
- {
- for (unsigned int i=0; i<static_cast<unsigned int>((*mpListOfParameters)[parameter_iterator]->length); i++)
- {
- clog << *((*mpListOfParameters)[parameter_iterator]->p_value+i);
- }
- }
- else
- {
- clog << "NULL";
- }
- clog << "]" << endl;
+ mListOfParameters[parameter_iterator].displayParameter();
+ clog << endl;
}
else
{
@@ -775,12 +670,13 @@ void FunctionSciMsg::displayParameter ( unsigned int parameter_iterator ) const
void FunctionSciMsg::displayListOfParameters ( ) const
{
clog << "\tlist of parameters = " << endl;
- if (!mpListOfParameters->empty())
+ if (!mListOfParameters.empty())
{
- for (unsigned int i=0; i<mpListOfParameters->size(); i++)
+ for (unsigned int i=0; i<mListOfParameters.size(); i++)
{
clog << "\t";
- displayParameter(i);
+ mListOfParameters[i].displayParameter();
+ clog << endl;
}
}
else
@@ -893,7 +789,7 @@ bool FunctionSciMsg::setFunctionName ( const char * name )
//clog << "FunctionSciMsg::setFunctionCallName" << endl;
bool bSetName = false;
- if ( FUNCTION_CALL_ID_MAX_SIZE > strlen(name) ) /* max length of a function id */
+ if ( (NULL != name) && (FUNCTION_CALL_ID_MAX_SIZE > strlen(name)) ) /* max length of a function id */
{
mpFunctionName = new char [strlen(name)];
strcpy (mpFunctionName, name);
@@ -920,28 +816,20 @@ bool FunctionSciMsg::setFunctionName ( const char * name )
}
-ParametersList * FunctionSciMsg::getListOfParameters ( ) const
+const ParametersList & FunctionSciMsg::getListOfParameters ( ) const
{
- return mpListOfParameters;
+ return mListOfParameters;
}
-bool FunctionSciMsg::setListOfParameters ( ParametersList * list_of_parameters )
+bool FunctionSciMsg::setListOfParameters ( const ParametersList & list_of_parameters )
{
//clog << "FunctionSciMsg::setListOfParameters" << endl;
- bool bSetList = false;
- if (NULL != list_of_parameters)
- {
- mpListOfParameters = list_of_parameters;
- bSetList = true;
- }
- else
- {
- throw Error("FunctionSciMsg::setFunctionCallManager", "Received parameters list pointer is NULL");
- }
+ mListOfParameters = list_of_parameters;
+ displayListOfParameters();
- return bSetList;
+ return true;
}
diff --git a/maximus/functioncall/src/FunctionSciMsgTest.cpp b/maximus/functioncall/src/FunctionSciMsgTest.cpp
index eba1a403fb..b119ff3cd8 100644
--- a/maximus/functioncall/src/FunctionSciMsgTest.cpp
+++ b/maximus/functioncall/src/FunctionSciMsgTest.cpp
@@ -2,6 +2,7 @@
#include "FunctionSciMsgTest.h"
#include "SciServer.h"
#include "FunctionCallManager.h"
+#include "FunctionCallParameter.h"
#include <iostream>
using namespace std;
@@ -57,20 +58,20 @@ void FunctionSciMsgTest::addParameterTest (void)
{
// Add parameter 1
//
- Function_Call_Parameter parameter1 = {"parameter1", 3, (unsigned char *)"123"};
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
mpFunctionSciMsg->addParameter(parameter1) );
// Add parameter 2
//
- Function_Call_Parameter parameter2 = {"parameter2", 10, (unsigned char *)"0123456789"};
+ FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
mpFunctionSciMsg->addParameter(parameter2) );
// Add parameter 3
//
- Function_Call_Parameter parameter3 = parameter2;
+ FunctionCallParameter parameter3 = parameter2;
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
mpFunctionSciMsg->addParameter(parameter3) );
@@ -95,40 +96,44 @@ void FunctionSciMsgTest::bindParameterTest (void)
{
// Add parameter 1
//
- Function_Call_Parameter parameter1 = {"parameter1", 3, (unsigned char *)"123"};
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
mpFunctionSciMsg->addParameter(parameter1) );
// Add parameter 2
//
- Function_Call_Parameter parameter2 = {"parameter2", 10, (unsigned char *)"0123456789"};
+ FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
mpFunctionSciMsg->addParameter(parameter2) );
// Add parameter 3
//
- Function_Call_Parameter parameter3 = parameter2;
+ FunctionCallParameter parameter3 = parameter2;
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
mpFunctionSciMsg->addParameter(parameter3) );
+ const string name = "parameter1";
unsigned long dataLength = 0;
- int * pData = NULL;
+ char * pData = NULL;
+ void * pVoidData = (void *)pVoidData;
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::bindParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("bindParameter failed"),
- mpFunctionSciMsg->bindParameter("parameter1", dataLength, (void **)(&pData)) );
-
+ mpFunctionSciMsg->bindParameter(name, dataLength, pVoidData) );
+ pData = static_cast<char*>(pVoidData);
+
// Check results
//
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("bindParameterTest failed: wrong data length"), (3 == dataLength) );
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("bindParameterTest failed: data pointer is NULL"), (NULL != pData) );
- CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("bindParameterTest failed: wrong data"), (0x333231 == *pData) );
// Free memory allocated into 'FunctionSciMsg::bindParameter'
//
- free (pData);
+ pVoidData = NULL;
+ pData = NULL;
+
}
else
{
@@ -150,28 +155,28 @@ void FunctionSciMsgTest::fillSpecializedSciMsgToSendTest (void)
{
// Add parameter 1
//
- Function_Call_Parameter parameter1 = {"parameter1", 3, (unsigned char *)"123"};
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
mpFunctionSciMsg->addParameter(parameter1) );
// Add parameter 2
//
- Function_Call_Parameter parameter2 = {"parameter2", 10, (unsigned char *)"0123456789"};
+ FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
mpFunctionSciMsg->addParameter(parameter2) );
// Add parameter 3
//
- Function_Call_Parameter parameter3 = parameter2;
+ FunctionCallParameter parameter3 = parameter2;
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
mpFunctionSciMsg->addParameter(parameter3) );
clog << "\tFunctionSciMsgTest -> FunctionSciMsg::setFunctionCallName" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("setFunctionName failed"),
- mpFunctionSciMsg->setFunctionName ("function_to_call") );
+ mpFunctionSciMsg->setFunctionName ("function_to_call\0") );
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("fillSpecializedSciMsgToSend failed"),
mpFunctionSciMsg->fillSpecializedSciMsgToSend() );
}
diff --git a/maximus/functioncall/src/IFunctionCallTest.cpp b/maximus/functioncall/src/IFunctionCallTest.cpp
index e99079c1b9..00acf750b5 100644
--- a/maximus/functioncall/src/IFunctionCallTest.cpp
+++ b/maximus/functioncall/src/IFunctionCallTest.cpp
@@ -3,6 +3,7 @@
#include "FunctionCallManager.h"
#include "SciServer.h"
#include "FunctionSciMsg.h"
+#include "FunctionCallParameter.h"
#include <iostream>
using namespace std;
@@ -45,13 +46,13 @@ void IFunctionCallTest::userTest (void)
clog << "IFunctionCallTest -> FunctionCallManager::setFunctionName" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("setFunctionName failed"),
- functionSciMsg->setFunctionName("function_to_call") );
+ functionSciMsg->setFunctionName("function_to_call\0") );
- Function_Call_Parameter parameter = {"parameter", 25, (unsigned char *)"1234567890123456789012345"};
+ FunctionCallParameter parameter ("parameter\0", 25, (unsigned char *)"1234567890123456789012345");
clog << "IFunctionCallTest -> FunctionSciMsg::addParameter" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("addParameter failed"),
functionSciMsg->addParameter (parameter) );
-
+
clog << "IFunctionCallTest -> FunctionCallManager::sendMsg" << endl;
CPPUNIT_ASSERT_MESSAGE ( CPPUNIT_NS::Message("sendMsg failed"),
functionCallManager.sendMsg(functionSciMsg) );
diff --git a/maximus/sci/inc/SciServer.h b/maximus/sci/inc/SciServer.h
index ba4aca72b3..dccce36bff 100644
--- a/maximus/sci/inc/SciServer.h
+++ b/maximus/sci/inc/SciServer.h
@@ -154,7 +154,7 @@ public:
* @param status
*/
bool setStatus ( const Sci_Server_Status new_status ) throw (Error);
-
+
/**
* Get the value of mArraySize
* @return the value of mArraySize
diff --git a/maximus/sci/src/SciServer.cpp b/maximus/sci/src/SciServer.cpp
index 1d1cd51fd3..5d0a6fdbce 100644
--- a/maximus/sci/src/SciServer.cpp
+++ b/maximus/sci/src/SciServer.cpp
@@ -84,9 +84,11 @@ void SciServer::initAttributes ( )
pthread_mutex_init(&mServerMutex, NULL);
// start the server thread
- mStatus = (Sci_Server_Status)pthread_create(&mServerThread, NULL, SciServer::serverThread, this);
- if(mStatus != 0)
+ setStatus ((Sci_Server_Status)pthread_create(&mServerThread, NULL, SciServer::serverThread, this));
+ if(0 != getStatus())
throw new Error(__FUNCTION__, "pthread_create", errno);
+ else
+ setStatus (MAXIMUS_SCI_SERVER_STATUS_RUNNING);
}
@@ -351,6 +353,7 @@ void * SciServer::serverThread ( void * arg )
while(sci_server->getStatus() == MAXIMUS_SCI_SERVER_STATUS_RUNNING)
{
+ //cout << "status running" << endl;
// timeout set to 1sec
timeout.tv_sec = 1;
timeout.tv_usec = 0;
@@ -382,7 +385,7 @@ void * SciServer::serverThread ( void * arg )
header_len = sizeof(struct Sci_Msg_Header);
if((len = read(fd_index, &header, sizeof(struct Sci_Msg_Header))) < header_len)
{
- clog << "\theader read error: len=" << len << ", errno=" << errno << endl;
+ //clog << "\theader read error: len=" << len << ", errno=" << errno << endl;
continue;
}
else
@@ -603,9 +606,9 @@ bool SciServer::setStatus ( const Sci_Server_Status new_status ) throw (Error)
else
{
mStatus = new_status;
- //clog << "\tstatus = ";
- //displayStatus();
- //clog << endl;
+ clog << "\tstatus = ";
+ displayStatus();
+ clog << endl;
bSetStatus = true;
}
@@ -623,6 +626,7 @@ bool SciServer::setStationsList ( StationsList * stations_list )
{
//clog << "SciServer::setStationsList" << endl;
bool bSetList = false;
+ StationsList::iterator it;
if (NULL != stations_list)
{
diff --git a/maximus/system/inc/Station.h b/maximus/system/inc/Station.h
index 4914b88710..6e0f1ee0d2 100644
--- a/maximus/system/inc/Station.h
+++ b/maximus/system/inc/Station.h
@@ -39,7 +39,8 @@ The original location of this file is /home/buret/eclipse/maximus/system/inc/Sta
#define STATION_PIPE_PATH "/tmp"
#define STATION_PIPE_PREFIX "station"
-#define STATION_EXEC_DEFAULT "./station"
+#define STATION_EXEC_DEFAULT "/home/buret/hello_world.elf"
+#define STATION_EXEC_DEFAULT_NAME "hello_world.elf"
#define STATION_WAIT_LOOP_NB 10
#define STATION_WAIT_TIMEOUT_MS 100
@@ -63,7 +64,7 @@ private:
// private attributes
//
- File_Descriptor mInputPipe, mOutputPipe;
+ File_Descriptor mInputPipe, mOutputPipe, mLogPipe;
pid_t mPid;
Station_Status mStationStatus;
StationConfiguration * mpStationConfiguration;
@@ -85,7 +86,7 @@ public:
/**
* Constructor
*/
- Station ( const char * station_exec = STATION_EXEC_DEFAULT );
+ Station ( const char * station_exec = STATION_EXEC_DEFAULT, const char * station_exec_name = STATION_EXEC_DEFAULT_NAME );
/**
* Empty Destructor
@@ -138,6 +139,12 @@ public:
bool setOutputFileDescriptor ( const File_Descriptor output_file_descriptor );
/**
+ * @return bool
+ * @param log_file_descriptor
+ */
+ bool setLogFileDescriptor ( const File_Descriptor log_file_descriptor );
+
+ /**
* @return File_Descriptor
*/
File_Descriptor getInputFileDescriptor ( ) const;
@@ -148,6 +155,11 @@ public:
File_Descriptor getOutputFileDescriptor ( ) const;
/**
+ * @return File_Descriptor
+ */
+ File_Descriptor getLogFileDescriptor ( ) const;
+
+ /**
* @return Station_Status
*/
Station_Status getStationStatus ( ) const;
@@ -180,7 +192,7 @@ private:
/**
* @return bool
*/
- void launchEcosProcess ( const char * station_exec );
+ void launchEcosProcess ( const char * station_exec, const char * station_exec_name );
void initAttributes ( );
diff --git a/maximus/system/src/Station.cpp b/maximus/system/src/Station.cpp
index a440d020b9..f71be92da3 100644
--- a/maximus/system/src/Station.cpp
+++ b/maximus/system/src/Station.cpp
@@ -44,16 +44,17 @@ using namespace std;
//
-Station::Station ( const char * station_exec ):
+Station::Station ( const char * station_exec, const char * station_exec_name ):
mInputPipe(-1),
mOutputPipe(-1),
+mLogPipe(-1),
mPid(0),
mStationStatus(MAXIMUS_STATION_STATUS_NONE),
mpStationConfiguration(NULL)
{
clog << "Station(char*)" << endl;
- //launchEcosProcess(station_exec);
+ launchEcosProcess(station_exec, station_exec_name);
initAttributes();
}
@@ -86,6 +87,8 @@ Station::~Station ( )
close(mInputPipe);
if(mOutputPipe >= 0)
close(mOutputPipe);
+ if(mLogPipe >= 0)
+ close(mLogPipe);
if(mPid > 0)
kill(mPid, SIGTERM);
@@ -136,6 +139,7 @@ bool Station::operator== ( const Station & station ) const
&& (getStationConfiguration() == station.getStationConfiguration())
&& (getInputFileDescriptor() == station.getInputFileDescriptor())
&& (getOutputFileDescriptor() == station.getOutputFileDescriptor())
+ && (getLogFileDescriptor() == station.getLogFileDescriptor())
&& (getStationId() == station.getStationId()) )
{
bOperator = true;
@@ -152,6 +156,7 @@ Station & Station::operator= ( const Station & station )
if ( (!setInputFileDescriptor (station.getInputFileDescriptor()))
|| (!setOutputFileDescriptor (station.getOutputFileDescriptor()))
+ || (!setLogFileDescriptor (station.getLogFileDescriptor()))
|| (!setStationStatus (station.getStationStatus()))
|| (!setStationConfiguration (station.getStationConfiguration())) )
{
@@ -164,7 +169,7 @@ Station & Station::operator= ( const Station & station )
void Station::displayStation ( ) const
{
- clog << dec << "\t[input file descriptor = " << getInputFileDescriptor() << ", output file descriptor = " << getOutputFileDescriptor() << " process id = " << getStationId() << "]" << endl;
+ clog << dec << "\t[input file descriptor = " << getInputFileDescriptor() << ", output file descriptor = " << getOutputFileDescriptor() << ", log file descriptor = " << getLogFileDescriptor() << ", process id = " << getStationId() << "]" << endl;
}
@@ -208,6 +213,17 @@ bool Station::setOutputFileDescriptor ( const File_Descriptor output_file_descri
}
+bool Station::setLogFileDescriptor ( const File_Descriptor log_file_descriptor )
+{
+ //clog << "Station::setLogFileDescriptor" << endl;
+
+ mLogPipe = log_file_descriptor;
+ //displayStation();
+
+ return true;
+}
+
+
File_Descriptor Station::getInputFileDescriptor ( ) const
{
return mInputPipe;
@@ -220,6 +236,12 @@ File_Descriptor Station::getOutputFileDescriptor ( ) const
}
+File_Descriptor Station::getLogFileDescriptor ( ) const
+{
+ return mLogPipe;
+}
+
+
Station_Status Station::getStationStatus ( ) const
{
return mStationStatus;
@@ -268,7 +290,7 @@ StationConfiguration * Station::getStationConfiguration ( ) const
//
-void Station::launchEcosProcess ( const char * station_exec )
+void Station::launchEcosProcess ( const char * station_exec, const char * station_exec_name )
{
clog << "Station::launchEcosProcess" << endl;
@@ -277,14 +299,17 @@ void Station::launchEcosProcess ( const char * station_exec )
throw Error(__FUNCTION__ , "exec", errno);
if((mPid = fork()) == 0)
{
- execlp(STATION_EXEC_DEFAULT, STATION_EXEC_DEFAULT, NULL);
+ //execlp(STATION_EXEC_DEFAULT, STATION_EXEC_DEFAULT, NULL);
+ if (-1 == execl(STATION_EXEC_DEFAULT, STATION_EXEC_DEFAULT_NAME, NULL))
+ throw Error(__FUNCTION__ , "Cannot launch station executable");
exit(1);
}
// loop until pipe creation: max = STATION_WAIT_LOOP_NB * STATION_WAIT_TIMEOUT_MS ms
int loop;
char name_buffer[256];
- sprintf(name_buffer, "%s/%s_%d", STATION_PIPE_PATH, STATION_PIPE_PREFIX, mPid);
+ //sprintf(name_buffer, "%s/%s_in_%d", STATION_PIPE_PATH, STATION_PIPE_PREFIX, mPid);
+ sprintf(name_buffer, "%s/%s_in_1234", STATION_PIPE_PATH, STATION_PIPE_PREFIX);
for(loop = 0; loop < STATION_WAIT_LOOP_NB; loop++)
{
if((mInputPipe = open(name_buffer, O_WRONLY)) >= 0)
@@ -295,9 +320,15 @@ void Station::launchEcosProcess ( const char * station_exec )
throw Error(__FUNCTION__ , "exec", errno);
// open last pipe
- sprintf(name_buffer, "%s/%s_%d", STATION_PIPE_PATH, STATION_PIPE_PREFIX, mPid);
+ //sprintf(name_buffer, "%s/%s_out_%d", STATION_PIPE_PATH, STATION_PIPE_PREFIX, mPid);
+ sprintf(name_buffer, "%s/%s_out_1234", STATION_PIPE_PATH, STATION_PIPE_PREFIX);
if((mOutputPipe = open(name_buffer, O_RDONLY)) < 0)
throw Error(__FUNCTION__ , "exec", errno);
+
+ // open log pipe
+ sprintf(name_buffer, "%s/%s_log_1234", STATION_PIPE_PATH, STATION_PIPE_PREFIX);
+ if((mLogPipe = open(name_buffer, O_RDONLY)) < 0)
+ throw Error(__FUNCTION__ , "exec", errno);
}
diff --git a/maximus/unittest/Makefile b/maximus/unittest/Makefile
new file mode 100644
index 0000000000..31a982b1cd
--- /dev/null
+++ b/maximus/unittest/Makefile
@@ -0,0 +1,11 @@
+BASE = ../..
+
+CPPUNIT_PATH=/opt/cppunit
+HOST_PROGRAMS = unittest
+unittest_SOURCES = main.cpp ../../coreengine/src/CoreEngineTest.cpp ../../networkclock/src/NetworkClockProcessorTest.cpp ../../networkclock/src/NetworkClockEvtListTest.cpp ../../networkclock/src/NetworkClockEvtTest.cpp ../../sci/src/SciServerTest.cpp ../../sci/src/SciMsgTest.cpp ../../system/src/SystemManagerTest.cpp ../../system/src/StationTest.cpp ../../system/src/StationConfigurationTest.cpp ../../functioncall/src/FunctionCallManagerTest.cpp ../../functioncall/src/FunctionSciMsgTest.cpp ../../functioncall/src/IFunctionCallTest.cpp ../../error/src/ErrorTest.cpp ../../phy/src/PhyProcessorTest.cpp ../../system/src/SystemSciMsgTest.cpp
+unittest_MODULES = maximus/error maximus/functioncall maximus/networkclock maximus/phy maximus/sci maximus/system maximus/coreengine
+INCLUDES = maximus/error/inc maximus/coreengine/inc maximus/networkclock/inc maximus/sci/inc maximus/functioncall/inc maximus/phy/inc maximus/system/inc maximus/common/interfaces maximus/common/types
+
+include $(BASE)/common/make/top.mk
+
+HOST_LDFLAGS += -L${CPPUNIT_PATH}/lib -lstdc++ -lcppunit -ldl -lpthread
diff --git a/maximus/unittest/src/main.cpp b/maximus/unittest/src/main.cpp
new file mode 100644
index 0000000000..7abae82786
--- /dev/null
+++ b/maximus/unittest/src/main.cpp
@@ -0,0 +1,69 @@
+
+#include "CoreEngine.h"
+#include "Error.h"
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/TestRunner.h>
+
+#include <iostream> // for 'cout', 'cerr' and 'clog'
+#include <fstream> // for ofstream'
+using namespace std;
+
+
+int main (void)
+{
+ int returnValue = -1;
+
+ // Create a file for logging
+ //
+ ofstream logFile("unittestlog.txt");
+ if (logFile)
+ {
+ clog.rdbuf(logFile.rdbuf());
+ }
+ else
+ {
+ cerr << "Error while opening log file" << endl;
+ clog.rdbuf(cout.rdbuf());
+ }
+
+ cout << "-------------------------------------------------------------------------------------" << endl;
+ cout << "*** Welcome to Fulminata Maximus simulator unitary tests ***" << endl << endl;
+
+ try
+ {
+ cout << "testresult" << endl;
+ CPPUNIT_NS :: TestResult testresult;
+
+ cout << "collectedresults" << endl;
+ CPPUNIT_NS :: TestResultCollector collectedresults;
+ testresult.addListener (&collectedresults);
+
+ cout << "testrunner" << endl;
+ CPPUNIT_NS :: TestRunner testrunner;
+ testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ());
+ testrunner.run (testresult);
+
+ cout << "compileroutputter" << endl;
+ CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr);
+ compileroutputter.write ();
+
+ returnValue = collectedresults.wasSuccessful () ? 0 : 1;
+ }
+ catch ( Error &e )
+ {
+ e.display();
+ }
+
+ cout << endl;
+ cout << "-------------------------------------------------------------------------------------" << endl;
+ cout << "*** END ***" << endl;
+ cout << flush;
+ logFile.close();
+
+ return returnValue;
+}
+