summaryrefslogtreecommitdiff
path: root/cesar/maximus/functioncall
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/functioncall')
-rw-r--r--cesar/maximus/functioncall/Module5
-rw-r--r--cesar/maximus/functioncall/inc/FunctionCallManager.h147
-rw-r--r--cesar/maximus/functioncall/inc/FunctionCallManagerTest.h43
-rw-r--r--cesar/maximus/functioncall/inc/FunctionCallParameter.h167
-rw-r--r--cesar/maximus/functioncall/inc/FunctionCallParameterTest.h40
-rw-r--r--cesar/maximus/functioncall/inc/FunctionSciMsg.h332
-rw-r--r--cesar/maximus/functioncall/inc/FunctionSciMsgTest.h44
-rw-r--r--cesar/maximus/functioncall/inc/IFunctionCall.h116
-rw-r--r--cesar/maximus/functioncall/inc/IFunctionCallTest.h34
-rw-r--r--cesar/maximus/functioncall/src/FunctionCallManager.cpp316
-rw-r--r--cesar/maximus/functioncall/src/FunctionCallManagerTest.cpp128
-rw-r--r--cesar/maximus/functioncall/src/FunctionCallParameter.cpp277
-rw-r--r--cesar/maximus/functioncall/src/FunctionCallParameterTest.cpp162
-rw-r--r--cesar/maximus/functioncall/src/FunctionSciMsg.cpp865
-rw-r--r--cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp206
-rw-r--r--cesar/maximus/functioncall/src/IFunctionCallTest.cpp89
16 files changed, 2971 insertions, 0 deletions
diff --git a/cesar/maximus/functioncall/Module b/cesar/maximus/functioncall/Module
new file mode 100644
index 0000000000..061de8e25d
--- /dev/null
+++ b/cesar/maximus/functioncall/Module
@@ -0,0 +1,5 @@
+SOURCES := FunctionCallManager.cpp FunctionSciMsg.cpp FunctionCallParameter.cpp
+ifdef UNITTEST
+SOURCES += FunctionCallManagerTest.cpp FunctionSciMsgTest.cpp IFunctionCallTest.cpp FunctionCallParameterTest.cpp
+endif
+HOST_INCLUDES += maximus/functioncall/inc
diff --git a/cesar/maximus/functioncall/inc/FunctionCallManager.h b/cesar/maximus/functioncall/inc/FunctionCallManager.h
new file mode 100644
index 0000000000..b7027285b6
--- /dev/null
+++ b/cesar/maximus/functioncall/inc/FunctionCallManager.h
@@ -0,0 +1,147 @@
+/************************************************************************
+ FunctionCallManager.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/FunctionCallManager.h
+**************************************************************************/
+
+#ifndef FUNCTIONCALLMANAGER_H
+#define FUNCTIONCALLMANAGER_H
+
+#include "IFunctionCall.h"
+
+#include "networkclock_types.h"
+
+class FunctionSciMsg;
+class ISci;
+
+
+/**
+ * class FunctionCallManager
+ */
+
+class FunctionCallManager : public IFunctionCall
+{
+
+public:
+
+ // public attributes
+ //
+
+private:
+
+ // private attributes
+ //
+ CallbacksList mListOfCallbacks;
+ ISci * mpSciServer;
+
+protected:
+
+ // protected attributes
+ //
+
+public:
+
+ // Constructors/Destructors
+ //
+
+ /**
+ * Constructor
+ */
+ FunctionCallManager ( ISci * p_sci_server );
+
+ /**
+ * Empty Destructor
+ */
+ virtual ~FunctionCallManager ( );
+
+ // public methods
+ //
+
+ /**
+ * @return FunctionSciMsg *
+ */
+ FunctionSciMsg * createMsg ( );
+
+ /**
+ * @return bool
+ * @param msg_id
+ * @param callback_address
+ */
+ bool registerCallback ( Function_Call_Msg_Id msg_id, const CallbackFunction & callback_address );
+
+ /**
+ * @return bool
+ * @param p_function_sci_msg
+ */
+ bool sendMsg ( FunctionSciMsg * p_function_sci_msg_to_send );
+
+ /**
+ * @return bool
+ * @param function_sci_msg
+ */
+ bool sendMsg ( FunctionSciMsg & function_sci_msg_to_send );
+
+ /**
+ * @return bool
+ * @param function_sci_msg
+ */
+ bool receiveMsg ( const FunctionSciMsg & function_sci_msg );
+
+ // public attribute accessor methods
+ //
+
+ // private attribute accessor methods
+ //
+
+ /**
+ * @return pointer to mListOfCallbacks
+ */
+ CallbacksList * getListOfCallbacks ( );
+
+ // protected attribute accessor methods
+ //
+
+private:
+
+ // private methods
+ //
+
+ void initAttributes ( );
+
+ bool registerFunctionSciMsg ( );
+
+ void displayListOfCallbacks ( ) const;
+
+protected:
+
+ // protected methods
+ //
+
+};
+
+
+#endif // FUNCTIONCALLMANAGER_H
diff --git a/cesar/maximus/functioncall/inc/FunctionCallManagerTest.h b/cesar/maximus/functioncall/inc/FunctionCallManagerTest.h
new file mode 100644
index 0000000000..944b32d857
--- /dev/null
+++ b/cesar/maximus/functioncall/inc/FunctionCallManagerTest.h
@@ -0,0 +1,43 @@
+
+#ifndef FUNCTIONCALLMANAGERTEST_H
+#define FUNCTIONCALLMANAGERTEST_H
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class FunctionCallManager;
+class SciServer;
+class FunctionSciMsg;
+
+void userFunction1 ( const FunctionSciMsg & function_sci_msg );
+void userFunction2 ( const FunctionSciMsg & function_sci_msg );
+void userFunction3 ( const FunctionSciMsg & function_sci_msg );
+
+
+class FunctionCallManagerTest : public CPPUNIT_NS::TestFixture
+{
+
+ CPPUNIT_TEST_SUITE (FunctionCallManagerTest);
+ CPPUNIT_TEST (registerCallbackTest);
+ CPPUNIT_TEST (receiveMsgTest);
+ CPPUNIT_TEST_SUITE_END ();
+
+public:
+
+ void setUp (void);
+ void tearDown (void);
+
+protected:
+
+ void registerCallbackTest (void);
+ void receiveMsgTest (void);
+
+private:
+
+ FunctionCallManager * mpFunctionCallManager;
+ SciServer * mpSciServer;
+
+};
+
+
+#endif // FUNCTIONCALLMANAGERTEST_H
diff --git a/cesar/maximus/functioncall/inc/FunctionCallParameter.h b/cesar/maximus/functioncall/inc/FunctionCallParameter.h
new file mode 100644
index 0000000000..f96b5c75b0
--- /dev/null
+++ b/cesar/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/cesar/maximus/functioncall/inc/FunctionCallParameterTest.h b/cesar/maximus/functioncall/inc/FunctionCallParameterTest.h
new file mode 100644
index 0000000000..147d6e8fb3
--- /dev/null
+++ b/cesar/maximus/functioncall/inc/FunctionCallParameterTest.h
@@ -0,0 +1,40 @@
+
+#ifndef FUNCTIONCALLPARAMETERTEST_H
+#define FUNCTIONCALLPARAMETERTEST_H
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class FunctionCallParameter;
+
+
+class FunctionCallParameterTest : public CPPUNIT_NS::TestFixture
+{
+
+ CPPUNIT_TEST_SUITE (FunctionCallParameterTest);
+ CPPUNIT_TEST (setNameTest);
+ CPPUNIT_TEST (setValueTest);
+ CPPUNIT_TEST (setValueLengthTest);
+ CPPUNIT_TEST (constructorsTest);
+ CPPUNIT_TEST_SUITE_END ();
+
+public:
+
+ void setUp (void);
+ void tearDown (void);
+
+protected:
+
+ void setNameTest (void);
+ void setValueTest (void);
+ void setValueLengthTest (void);
+ void constructorsTest (void);
+
+private:
+
+ FunctionCallParameter * mpFunctionCallParameter;
+
+};
+
+
+#endif // FUNCTIONCALLPARAMETERTEST_H
diff --git a/cesar/maximus/functioncall/inc/FunctionSciMsg.h b/cesar/maximus/functioncall/inc/FunctionSciMsg.h
new file mode 100644
index 0000000000..85c900945b
--- /dev/null
+++ b/cesar/maximus/functioncall/inc/FunctionSciMsg.h
@@ -0,0 +1,332 @@
+/************************************************************************
+ FunctionSciMsg.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/FunctionSciMsg.h
+**************************************************************************/
+
+#ifndef FUNCTIONSCIMSG_H
+#define FUNCTIONSCIMSG_H
+
+#include "SciMsg.h"
+
+#include "functioncall_types.h"
+#include "sci_types.h"
+
+#include <vector>
+#include <string>
+#include <ostream>
+
+class IFunctionCall;
+class FunctionCallParameter;
+
+typedef std::vector<FunctionCallParameter> ParametersList;
+
+
+/**
+ * class FunctionSciMsg
+ */
+
+class FunctionSciMsg : public SciMsg
+{
+
+public:
+
+ // public attributes
+ //
+
+private:
+
+ // private attributes
+ //
+
+ // Get from specialized SCI message header
+ //
+ Function_Call_Type mSpecializedSciMsgType;
+ static Function_Call_Msg_Id mSpecializedSciMsgId; // to send to station
+ Function_Call_Parameters_Number mSpecializedSciMsgParametersNumber;
+ Function_Call_Flags mSpecializedSciMsgFlags;
+
+ // Specialized SCI msg header
+ //
+ Function_Call_Header mSpecializedSciMsgHeader;
+
+ // Unique string identifier for function call
+ //
+ std::string mFunctionName;
+
+ // Function parameters
+ //
+ ParametersList mListOfParameters;
+
+ IFunctionCall * mpFunctionCallManager;
+
+protected:
+
+ // protected attributes
+ //
+
+public:
+
+ // Constructors/Destructors
+ //
+
+ /**
+ * Constructor
+ */
+ FunctionSciMsg ( IFunctionCall * p_function_call_manager );
+
+ /**
+ * Copy Constructors
+ */
+ FunctionSciMsg ( const FunctionSciMsg & function_sci_msg );
+
+ /**
+ * Empty Destructor
+ */
+ virtual ~FunctionSciMsg ( );
+
+ // public methods
+ //
+
+ /**
+ * @return SciMsg *
+ */
+ SciMsg * create ( ) const;
+
+ /**
+ * return bool
+ */
+ bool dispatchMsg ( );
+
+ /**
+ * @return bool
+ */
+ bool identifySpecializedSciMsgHeader ( );
+
+ /**
+ * @return bool
+ */
+ bool checkCompatibility ( ) const;
+
+ /**
+ * @return bool
+ * @param function_argument_to_add
+ */
+ bool addParameter ( const FunctionCallParameter & function_argument_to_add );
+
+ /**
+ * @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
+ */
+ bool bindParameter ( const std::string name_of_parameter_to_get, unsigned long & data_length, unsigned char * p_data ) const;
+
+ /**
+ * @return bool
+ */
+ bool identifyFunctionName ( );
+
+ /**
+ * @return bool
+ */
+ bool identifyParameters ( );
+
+ /**
+ * @return bool
+ */
+ bool fillSpecializedSciMsgToSend ( );
+
+ void displaySpecializedSciMsgHeader ( ) const;
+
+ /**
+ * Display the specialized SCI message type.
+ */
+ void displaySpecializedSciMsgType ( int log_level ) const;
+
+ // public attribute accessor methods
+ //
+
+ // private attribute accessor methods
+ //
+
+ /**
+ * Get the value of mSpecializedSciMsgType
+ * @return the value of mSpecializedSciMsgType
+ */
+ Function_Call_Type getSpecializedSciMsgType ( ) const;
+
+ /**
+ * Set the value of mSpecializedSciMsgType
+ * @return bool
+ * @param type the new value of mSpecializedSciMsgType
+ */
+ bool setSpecializedSciMsgType ( const Function_Call_Type type );
+
+ /**
+ * Get the value of mSpecializedSciMsgHeader.msg_id
+ * @return the value of mSpecializedSciMsgHeader.msg_id
+ */
+ Function_Call_Msg_Id getMsgId ( ) const;
+
+ /**
+ * Set the value of mSpecializedSciMsgHeader.msg_id
+ * @return bool
+ */
+ bool setMsgId ( const Function_Call_Msg_Id msg_id );
+
+ /**
+ * Get the value of mSpecializedSciMsgId
+ * @return the value of mSpecializedSciMsgId
+ */
+ Function_Call_Msg_Id getSpecializedSciMsgId ( ) const;
+
+ /**
+ * Increment the value of mSpecializedSciMsgId
+ * @return bool
+ */
+ bool incrementSpecializedSciMsgId ( );
+
+ /**
+ * Get the value of mSpecializedSciMsgParametersNumber
+ * @return the value of mSpecializedSciMsgParametersNumber
+ */
+ Function_Call_Parameters_Number getSpecializedSciMsgParametersNumber ( ) const;
+
+ /**
+ * Set the value of mSpecializedSciMsgParametersNumber
+ * @return bool
+ * @param number_of_parameters the new value of mSpecializedSciMsgParametersNumber
+ */
+ bool setSpecializedSciMsgParametersNumber ( const Function_Call_Parameters_Number number_of_parameters );
+
+ /**
+ * Get the value of mSpecializedSciMsgFlags
+ * @return the value of mSpecializedSciMsgFlags
+ */
+ Function_Call_Flags getSpecializedSciMsgFlags ( ) const;
+
+ /**
+ * Set the value of mSpecializedSciMsgFlags
+ * @return bool
+ * @param flags the new value of mSpecializedSciMsgFlags
+ */
+ bool setSpecializedSciMsgFlags ( const Function_Call_Flags flags );
+
+ /**
+ * Set the value of mSpecializedSciMsgHeader.reserved
+ * @return bool
+ */
+ bool setReserved ( const uint16_t reserved );
+
+ /**
+ * Get the value of mSpecializedSciMsgHeader
+ * @return the value of mSpecializedSciMsgHeader into a void pointer
+ */
+ void * returnSpecializedSciMsgHeader ( ) const;
+
+ /**
+ * @return mSpecializedSciMsgHeader
+ */
+ const Function_Call_Header & getSpecializedSciMsgHeader ( ) const;
+
+ /**
+ * @return bool
+ * @param specialized_sci_msg_header the new value of mSpecializedSciMsgHeader
+ */
+ bool setSpecializedSciMsgHeader ( const Function_Call_Header & specialized_sci_msg_header );
+
+ /**
+ * Get the value of mFunctionName
+ * @return the value of mFunctionName
+ */
+ std::string getFunctionName ( ) const;
+
+ /**
+ * Set the value of mFunctionName
+ * @return bool
+ * @param name the new value of mFunctionName
+ */
+ bool setFunctionName ( const std::string name );
+
+ /**
+ * Get the value of mListOfParameters
+ * @return the value of mListOfParameters
+ */
+ const ParametersList & getListOfParameters ( ) const;
+
+ /**
+ * Set the value of mListOfParameters
+ * @return bool
+ * @param list_of_parameters the new value of mListOfParameters
+ */
+ bool setListOfParameters ( const ParametersList & list_of_parameters );
+
+ /**
+ * Get the value of mpFunctionCallManager
+ * @return mpFunctionCallManager
+ */
+ IFunctionCall * getFunctionCallManager () const;
+
+ /**
+ * Set the value of mpFunctionCallManager
+ * @return bool
+ * @param p_function_call_manager the new value of mpFunctionCallManager
+ */
+ bool setFunctionCallManager ( IFunctionCall * p_function_call_manager );
+
+ // protected attribute accessor methods
+ //
+
+private:
+
+ // private methods
+ //
+
+ void initAttributes ( );
+
+ void displayFunctionName ( ) const;
+
+ void displayParameter ( unsigned int parameter_iterator ) const;
+
+ void displayListOfParameters ( ) const;
+
+protected:
+
+ // protected methods
+ //
+
+};
+
+
+#endif // FUNCTIONSCIMSG_H
diff --git a/cesar/maximus/functioncall/inc/FunctionSciMsgTest.h b/cesar/maximus/functioncall/inc/FunctionSciMsgTest.h
new file mode 100644
index 0000000000..98fb97e785
--- /dev/null
+++ b/cesar/maximus/functioncall/inc/FunctionSciMsgTest.h
@@ -0,0 +1,44 @@
+
+#ifndef FUNCTIONSCIMSGTEST_H
+#define FUNCTIONSCIMSGTEST_H
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class FunctionSciMsg;
+class FunctionCallManager;
+class SciServer;
+
+
+class FunctionSciMsgTest : public CPPUNIT_NS::TestFixture
+{
+
+ CPPUNIT_TEST_SUITE (FunctionSciMsgTest);
+ CPPUNIT_TEST (addParameterTest);
+ CPPUNIT_TEST (bindParameterTest);
+ CPPUNIT_TEST (fillSpecializedSciMsgToSendTest);
+ CPPUNIT_TEST (setSpecializedSciMsgFlagsTest);
+ CPPUNIT_TEST_SUITE_END ();
+
+public:
+
+ void setUp (void);
+ void tearDown (void);
+
+protected:
+
+ void addParameterTest (void);
+ void bindParameterTest (void);
+ void fillSpecializedSciMsgToSendTest (void);
+ void setSpecializedSciMsgFlagsTest (void);
+
+private:
+
+ FunctionSciMsg * mpFunctionSciMsg;
+ FunctionCallManager * mpFunctionCallManager;
+ SciServer * mpSciServer;
+
+};
+
+
+#endif // FUNCTIONSCIMSGTEST_H
diff --git a/cesar/maximus/functioncall/inc/IFunctionCall.h b/cesar/maximus/functioncall/inc/IFunctionCall.h
new file mode 100644
index 0000000000..091c8391a1
--- /dev/null
+++ b/cesar/maximus/functioncall/inc/IFunctionCall.h
@@ -0,0 +1,116 @@
+/************************************************************************
+ IFunctionCall.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/common/interfaces/IFunctionCall.h
+**************************************************************************/
+
+#ifndef IFUNCTIONCALL_H
+#define IFUNCTIONCALL_H
+
+#include "functioncall_types.h"
+
+#include <boost/function.hpp> // for 'CallbackFunction'
+#include <map>
+
+class FunctionSciMsg;
+
+typedef boost::function <void (const FunctionSciMsg &)> CallbackFunction;
+
+struct compareMsgId
+{
+ bool operator( ) ( Function_Call_Msg_Id msg_id1, Function_Call_Msg_Id msg_id2 ) const
+ {
+ return msg_id1 < msg_id2;
+ }
+};
+typedef std::multimap<Function_Call_Msg_Id, CallbackFunction, compareMsgId> CallbacksList;
+
+
+/**
+ * class IFunctionCall
+ */
+
+class IFunctionCall
+{
+
+public:
+
+ // Constructors/Destructors
+ //
+
+ /**
+ * Empty Constructor
+ */
+ IFunctionCall ( ) { }
+
+ /**
+ * Empty Destructor
+ */
+ virtual ~IFunctionCall ( ) { }
+
+ // public methods
+ //
+
+ /**
+ * @return FunctionSciMsg *
+ */
+ virtual FunctionSciMsg * createMsg ( ) = 0;
+
+ /**
+ * @return bool
+ * @param function_sci_msg
+ * @param callback_address
+ */
+ virtual bool registerCallback ( Function_Call_Msg_Id msg_id, const CallbackFunction & callback_address ) = 0;
+
+ /**
+ * @return bool
+ * @param function_sci_msg
+ */
+ virtual bool sendMsg ( FunctionSciMsg * p_function_sci_msg_to_send ) = 0;
+
+ /**
+ * @return bool
+ * @param function_sci_msg
+ */
+ virtual bool sendMsg ( FunctionSciMsg & function_sci_msg_to_send ) = 0;
+
+ /**
+ * @return bool
+ * @param function_sci_msg
+ */
+ virtual bool receiveMsg ( const FunctionSciMsg & function_sci_msg ) = 0;
+
+ /**
+ * @return pointer to mListOfCallbacks
+ */
+ virtual CallbacksList * getListOfCallbacks ( ) = 0;
+
+};
+
+
+#endif // IFUNCTIONCALL_H
diff --git a/cesar/maximus/functioncall/inc/IFunctionCallTest.h b/cesar/maximus/functioncall/inc/IFunctionCallTest.h
new file mode 100644
index 0000000000..68fd2edca9
--- /dev/null
+++ b/cesar/maximus/functioncall/inc/IFunctionCallTest.h
@@ -0,0 +1,34 @@
+
+#ifndef IFUNCTIONCALLTEST_H
+#define IFUNCTIONCALLTEST_H
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class FunctionSciMsg;
+
+void userFunction ( const FunctionSciMsg & function_sci_msg );
+
+
+class IFunctionCallTest : public CPPUNIT_NS::TestFixture
+{
+
+ CPPUNIT_TEST_SUITE (IFunctionCallTest);
+ CPPUNIT_TEST (userTest);
+ CPPUNIT_TEST_SUITE_END ();
+
+public:
+
+ void setUp (void);
+ void tearDown (void);
+
+protected:
+
+ void userTest (void);
+
+private:
+
+};
+
+
+#endif // IFUNCTIONCALLTEST_H
diff --git a/cesar/maximus/functioncall/src/FunctionCallManager.cpp b/cesar/maximus/functioncall/src/FunctionCallManager.cpp
new file mode 100644
index 0000000000..15c74da849
--- /dev/null
+++ b/cesar/maximus/functioncall/src/FunctionCallManager.cpp
@@ -0,0 +1,316 @@
+/************************************************************************
+ FunctionCallManager.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/FunctionCallManager.cpp
+**************************************************************************/
+
+#include "FunctionCallManager.h"
+
+#include "FunctionSciMsg.h"
+#include "ISci.h"
+
+#include "Error.h"
+#include "Logger.h"
+
+#include <netinet/in.h> // for 'htonl()' and 'htons()'
+#include <iomanip> // for 'setfill()' and 'setw()'
+#include <iostream> // for 'cout', 'cerr' and 'clog'
+using namespace std;
+
+
+// Constructors/Destructors
+//
+
+
+FunctionCallManager::FunctionCallManager ( ISci * p_sci_server ):
+mpSciServer(NULL)
+{
+ logFunction();
+
+ initAttributes();
+ if (NULL != p_sci_server)
+ {
+ mpSciServer = p_sci_server;
+ registerFunctionSciMsg();
+ }
+ else
+ {
+ errno = EINVAL;
+ throw Error(__PRETTY_FUNCTION__, "SCI server pointer is NULL", errno);
+ }
+}
+
+
+void FunctionCallManager::initAttributes ( )
+{
+ logFunction();
+}
+
+
+FunctionCallManager::~FunctionCallManager ( )
+{
+ logFunction();
+
+ if (!mListOfCallbacks.empty())
+ {
+ mListOfCallbacks.clear();
+ }
+ if (NULL != mpSciServer)
+ {
+ mpSciServer = NULL;
+ }
+}
+
+
+//
+// Methods
+//
+
+
+// Other methods
+//
+
+
+// public methods
+//
+
+
+// Called by user to create a message to send
+//
+FunctionSciMsg * FunctionCallManager::createMsg ( )
+{
+ logFunction();
+
+ return new FunctionSciMsg(this);
+}
+
+
+// Called by user before a message is sent
+//
+bool FunctionCallManager::registerCallback ( Function_Call_Msg_Id msg_id, const CallbackFunction & callback_address )
+{
+ logFunction();
+ bool bRegister = false;
+
+ if (NULL != callback_address)
+ {
+ mListOfCallbacks.insert(CallbacksList::value_type(msg_id, callback_address));
+ bRegister = true;
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "callback address is NULL!" << endl;
+ }
+
+ return bRegister;
+}
+
+
+// Called by user to send a configured message
+//
+bool FunctionCallManager::sendMsg ( FunctionSciMsg * p_function_sci_msg_to_send )
+{
+ logFunction();
+ bool bSend = false;
+
+ if (NULL != p_function_sci_msg_to_send)
+ {
+ bSend = sendMsg(*p_function_sci_msg_to_send);
+ }
+ else
+ {
+ errno = EINVAL;
+ throw Error(__PRETTY_FUNCTION__, "Function SCI message pointer is NULL", errno);
+ }
+
+ return bSend;
+}
+
+
+// Called by user to send a configured message
+//
+bool FunctionCallManager::sendMsg ( FunctionSciMsg & function_sci_msg_to_send )
+{
+ logFunction();
+ bool bSend = false;
+
+ clog << logger(LOG_COM) << "sending function call SCI message..." << endl;
+ displayListOfCallbacks();
+
+ // Fill specialized SCI msg attributes
+ // Fill specialized SCI msg data length and specialized SCI msg data
+ //
+ bSend = function_sci_msg_to_send.fillSpecializedSciMsgToSend();
+
+ // Fill specialized SCI msg header
+ //
+ struct Function_Call_Header functionSciMsgHeader = { FUNCTION_CALL_VERSION,
+ static_cast<uint8_t>(function_sci_msg_to_send.getSpecializedSciMsgType()),
+ function_sci_msg_to_send.getSpecializedSciMsgId(),
+ static_cast<uint8_t>(function_sci_msg_to_send.getSpecializedSciMsgParametersNumber()),
+ 0x00, // flags
+ 0x0000 }; // reserved
+
+ // Set specialized SCI msg header
+ //
+ bSend &= function_sci_msg_to_send.setSpecializedSciMsgHeader(functionSciMsgHeader);
+
+ // As specialized SCI msg header will be sent on an output pipe, 'hton' functions have to be called
+ //
+ function_sci_msg_to_send.setMsgId(htons(function_sci_msg_to_send.getSpecializedSciMsgHeader().msg_id));
+ function_sci_msg_to_send.setReserved(htons(function_sci_msg_to_send.getSpecializedSciMsgHeader().reserved));
+
+ // Fill specialized SCI msg attributes:
+ // - header size
+ //
+ bSend &= function_sci_msg_to_send.setSpecializedSciMsgHeaderSize(sizeof(struct Function_Call_Header));
+
+ // Fill SCI msg attributes:
+ // - type
+ //
+ bSend &= function_sci_msg_to_send.setSciMsgType(SCI_MSG_TYPE_FUNCTION_CALL);
+
+ if (bSend)
+ {
+ if (NULL != mpSciServer)
+ {
+ bSend = mpSciServer->fillSciMsg(function_sci_msg_to_send);
+ bSend &= mpSciServer->sendSciMsg(function_sci_msg_to_send);
+ }
+ else
+ {
+ throw Error(__PRETTY_FUNCTION__, "SCI server pointer is NULL");
+ }
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "function SCI message cannot be sent because it is not correctly filled in!" << endl;
+ }
+
+ return bSend;
+}
+
+
+// Called by FunctionSciMsg when receiving a message
+//
+bool FunctionCallManager::receiveMsg ( const FunctionSciMsg & function_sci_msg )
+{
+ logFunction();
+ bool bReceive = false;
+
+ displayListOfCallbacks();
+ if (!mListOfCallbacks.empty())
+ {
+ for (CallbacksList::const_iterator it = mListOfCallbacks.begin(); it != mListOfCallbacks.end(); ++it)
+ {
+ if (function_sci_msg.getSpecializedSciMsgHeader().msg_id == it->first)
+ {
+ clog << logger(LOG_INFO) << "=> callback" << endl;
+ (it->second) (function_sci_msg);
+ bReceive = true;
+ }
+ }
+ }
+ if (bReceive)
+ {
+ mListOfCallbacks.erase(function_sci_msg.getSpecializedSciMsgHeader().msg_id);
+ }
+ else
+ {
+ clog << logger(LOG_INFO) << "=> no callback!" << endl;
+ }
+
+ return bReceive;
+}
+
+
+CallbacksList * FunctionCallManager::getListOfCallbacks ( )
+{
+ return &mListOfCallbacks;
+}
+
+
+// private methods
+//
+
+
+bool FunctionCallManager::registerFunctionSciMsg ( )
+{
+ logFunction();
+ bool bRegister = false;
+
+ if (NULL != mpSciServer)
+ {
+ bRegister = mpSciServer->registerSpecializedSciMsg(SCI_MSG_TYPE_FUNCTION_CALL, new FunctionSciMsg(this));
+ }
+ else
+ {
+ throw Error(__PRETTY_FUNCTION__, "SCI server pointer is NULL");
+ }
+
+ return bRegister;
+}
+
+
+void FunctionCallManager::displayListOfCallbacks ( ) const
+{
+ logFunction();
+ clog << logger(LOG_INFO) << "list of callbacks = " << endl;
+
+ if (!mListOfCallbacks.empty())
+ {
+ for (CallbacksList::const_iterator it = mListOfCallbacks.begin(); it != mListOfCallbacks.end(); ++it)
+ {
+ clog << logger(LOG_INFO) << "\t[msg id = 0x" << setfill('0') << setw(4) << uppercase << hex << it->first << ", callback address = " << &(it->second) << "]" << dec << endl;
+ }
+ }
+ else
+ {
+ clog << logger(LOG_INFO) << "\tempty!" << endl;
+ }
+}
+
+
+// protected methods
+//
+
+
+// Accessor methods
+//
+
+
+// public attribute accessor methods
+//
+
+
+// private attribute accessor methods
+//
+
+
+// protected attribute accessor methods
+//
+
diff --git a/cesar/maximus/functioncall/src/FunctionCallManagerTest.cpp b/cesar/maximus/functioncall/src/FunctionCallManagerTest.cpp
new file mode 100644
index 0000000000..e37d0f209d
--- /dev/null
+++ b/cesar/maximus/functioncall/src/FunctionCallManagerTest.cpp
@@ -0,0 +1,128 @@
+
+#include "FunctionCallManagerTest.h"
+
+#include "FunctionCallManager.h"
+#include "SciServer.h"
+#include "FunctionSciMsg.h"
+
+#include "Error.h"
+#include "Logger.h"
+
+#include <iostream>
+using namespace std;
+
+CPPUNIT_TEST_SUITE_REGISTRATION (FunctionCallManagerTest);
+
+
+void FunctionCallManagerTest::setUp (void)
+{
+ logTest();
+
+ try
+ {
+ mpSciServer = new SciServer();
+ mpFunctionCallManager = new FunctionCallManager(mpSciServer);
+ }
+ catch (Error &e)
+ {
+ e.display();
+ }
+}
+
+
+void FunctionCallManagerTest::tearDown (void)
+{
+ logTest();
+
+ try
+ {
+ if (NULL != mpFunctionCallManager)
+ {
+ delete (mpFunctionCallManager);
+ mpFunctionCallManager = NULL;
+ }
+ if (NULL != mpSciServer)
+ {
+ delete (mpSciServer);
+ mpSciServer = NULL;
+ }
+ }
+ catch (Error &e)
+ {
+ e.display();
+ }
+}
+
+
+void FunctionCallManagerTest::registerCallbackTest (void)
+{
+ logTest();
+
+ try
+ {
+ if (NULL != mpFunctionCallManager)
+ {
+ CPPUNIT_ASSERT_MESSAGE ( "registerCallback failed",
+ mpFunctionCallManager->registerCallback(1, &userFunction1) );
+
+ CPPUNIT_ASSERT_MESSAGE ( "registerCallback failed",
+ mpFunctionCallManager->registerCallback(2, &userFunction2) );
+ }
+ }
+ catch (Error &e)
+ {
+ e.display();
+ }
+}
+
+
+void FunctionCallManagerTest::receiveMsgTest (void)
+{
+ logTest();
+
+ try
+ {
+ if (NULL != mpFunctionCallManager)
+ {
+ FunctionSciMsg functionSciMsg(mpFunctionCallManager);
+
+ CPPUNIT_ASSERT_MESSAGE ( "registerCallback failed",
+ mpFunctionCallManager->registerCallback(functionSciMsg.getSpecializedSciMsgHeader().msg_id, &userFunction1) );
+
+ CPPUNIT_ASSERT_MESSAGE ( "registerCallback failed",
+ mpFunctionCallManager->registerCallback(2, &userFunction2) );
+
+ CPPUNIT_ASSERT_MESSAGE ( "registerCallback failed",
+ mpFunctionCallManager->registerCallback(3, &userFunction3) );
+
+ CPPUNIT_ASSERT_MESSAGE ( "setFunctionName failed",
+ functionSciMsg.setFunctionName ("userFunction1") );
+
+ CPPUNIT_ASSERT_MESSAGE ( "receiveMsg failed",
+ mpFunctionCallManager->receiveMsg (functionSciMsg) );
+ }
+ }
+ catch (Error &e)
+ {
+ e.display();
+ }
+}
+
+
+void userFunction1 ( const FunctionSciMsg & function_sci_msg )
+{
+ logTest();
+}
+
+
+void userFunction2 ( const FunctionSciMsg & function_sci_msg )
+{
+ logTest();
+}
+
+
+void userFunction3 ( const FunctionSciMsg & function_sci_msg )
+{
+ logTest();
+}
+
diff --git a/cesar/maximus/functioncall/src/FunctionCallParameter.cpp b/cesar/maximus/functioncall/src/FunctionCallParameter.cpp
new file mode 100644
index 0000000000..640c6fd19b
--- /dev/null
+++ b/cesar/maximus/functioncall/src/FunctionCallParameter.cpp
@@ -0,0 +1,277 @@
+/************************************************************************
+ 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 "Logger.h"
+
+#include <sstream> // for 'ostringstream'
+#include <iomanip> // for 'setfill()' and 'setw()'
+#include <iostream> // for 'cout', 'cerr' and 'clog'
+using namespace std;
+
+
+// Constructors/Destructors
+//
+
+
+FunctionCallParameter::FunctionCallParameter ( ):
+mName("none"),
+mValueLength(0),
+mpValue(NULL)
+{
+ logFunction();
+
+ initAttributes ();
+}
+
+
+FunctionCallParameter::FunctionCallParameter ( const FunctionCallParameter & parameter ):
+mName("none"),
+mValueLength(0),
+mpValue(NULL)
+{
+ logFunction();
+
+ 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)
+{
+ logFunction();
+
+ setName (name);
+ setValueLength (value_length);
+ setValue (p_value);
+
+ initAttributes ();
+}
+
+
+void FunctionCallParameter::initAttributes ( )
+{
+ logFunction();
+}
+
+FunctionCallParameter::~FunctionCallParameter ( )
+{
+ logFunction();
+
+ mName.clear();
+ if (NULL != mpValue)
+ {
+ delete [] mpValue;
+ mpValue = NULL;
+ }
+}
+
+
+//
+// Methods
+//
+
+
+// Other methods
+//
+
+
+// public methods
+//
+
+
+bool FunctionCallParameter::operator== ( const FunctionCallParameter & parameter ) const
+{
+ logFunction();
+ bool bOperator = false;
+
+ if ( (0 == getName().compare(parameter.getName()))
+ && (getValueLength() == parameter.getValueLength())
+ && (0 == memcmp(getValue(), parameter.getValue(), parameter.getValueLength())) )
+ {
+ bOperator = true;
+ }
+
+ return bOperator;
+}
+
+
+FunctionCallParameter & FunctionCallParameter::operator= ( const FunctionCallParameter & parameter )
+{
+ logFunction();
+
+ setName (parameter.getName());
+ setValueLength (parameter.getValueLength());
+ setValue (parameter.getValue());
+
+ return *this;
+}
+
+
+void FunctionCallParameter::displayParameter ( ) const
+{
+ logFunction();
+
+ ostringstream oss;
+ oss << "\t[name = " << getName() << ", value length = " << dec << getValueLength() << ", value = ";
+ if (NULL != getValue())
+ {
+ oss << "0x";
+ for (unsigned int i=0; i<static_cast<unsigned int>(getValueLength()); i++)
+ {
+ if ('\0' != *(getValue()+i))
+ {
+ oss << setfill('0') << setw(2) << uppercase << hex << static_cast<unsigned short int>(*(getValue()+i));
+ }
+ else
+ {
+ oss << "00";
+ }
+ }
+ }
+ else
+ {
+ oss << "NULL!";
+ }
+ oss << "]" << dec << endl;
+ oss.flush();
+ clog << logger(LOG_COM) << oss.str();
+}
+
+
+// protected methods
+//
+
+
+// Accessor methods
+//
+
+
+// public attribute accessor methods
+//
+
+
+// private attribute accessor methods
+//
+
+
+string FunctionCallParameter::getName ( ) const
+{
+ return mName;
+}
+
+
+bool FunctionCallParameter::setName ( const string name )
+{
+ logFunction();
+
+ mName.clear();
+ mName.assign(name);
+
+ return true;
+}
+
+
+bool FunctionCallParameter::setName ( const char * p_name )
+{
+ logFunction();
+
+ if (NULL != p_name)
+ {
+ mName.clear();
+ mName.assign(p_name);
+ }
+
+ return true;
+}
+
+
+unsigned long FunctionCallParameter::getValueLength ( ) const
+{
+ return mValueLength;
+}
+
+
+bool FunctionCallParameter::setValueLength ( const unsigned long value_length )
+{
+ mValueLength = value_length;
+
+ return true;
+}
+
+
+unsigned char * FunctionCallParameter::getValue ( ) const
+{
+ return mpValue;
+}
+
+
+bool FunctionCallParameter::setValue ( const unsigned char * p_value )
+{
+ logFunction();
+ bool bSetValue = false;
+
+ // Free memory
+ //
+ if (NULL != mpValue)
+ {
+ delete [] mpValue;
+ mpValue = NULL;
+ }
+
+ if (NULL != p_value)
+ {
+ // Allocate memory
+ //
+ mpValue = new unsigned char [getValueLength()];
+
+ // Copy value
+ //
+ memcpy(mpValue, p_value, getValueLength());
+
+ bSetValue = true;
+ }
+
+ return bSetValue;
+}
+
+
+// protected attribute accessor methods
+//
+
diff --git a/cesar/maximus/functioncall/src/FunctionCallParameterTest.cpp b/cesar/maximus/functioncall/src/FunctionCallParameterTest.cpp
new file mode 100644
index 0000000000..6d139b73e9
--- /dev/null
+++ b/cesar/maximus/functioncall/src/FunctionCallParameterTest.cpp
@@ -0,0 +1,162 @@
+
+#include "FunctionCallParameterTest.h"
+
+#include "FunctionCallParameter.h"
+
+#include "Error.h"
+#include "Logger.h"
+
+#include <iostream>
+using namespace std;
+
+CPPUNIT_TEST_SUITE_REGISTRATION (FunctionCallParameterTest);
+
+
+void FunctionCallParameterTest::setUp (void)
+{
+ logTest();
+
+ mpFunctionCallParameter = new FunctionCallParameter();
+}
+
+
+void FunctionCallParameterTest::tearDown (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionCallParameter)
+ {
+ delete (mpFunctionCallParameter);
+ mpFunctionCallParameter = NULL;
+ }
+}
+
+
+void FunctionCallParameterTest::setNameTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionCallParameter)
+ {
+ try
+ {
+ string name1("name1");
+ mpFunctionCallParameter->setName(name1);
+
+ mpFunctionCallParameter->displayParameter();
+ CPPUNIT_ASSERT_MESSAGE ( "setName failed",
+ 0 == name1.compare(mpFunctionCallParameter->getName()) );
+
+ char name2 [] = "name2";
+ mpFunctionCallParameter->setName(name2);
+
+ mpFunctionCallParameter->displayParameter();
+ CPPUNIT_ASSERT_MESSAGE ( "setName failed",
+ (mpFunctionCallParameter->getName().length() == strlen(name2))
+ && (0 == memcmp(name2, mpFunctionCallParameter->getName().c_str(), strlen(name2)+1)) );
+ }
+ catch (Error &e)
+ {
+ e.display();
+ CPPUNIT_FAIL ( "Catch exception" );
+ }
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Function call parameter pointer is NULL" );
+ }
+}
+
+
+void FunctionCallParameterTest::setValueTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionCallParameter)
+ {
+ try
+ {
+ const unsigned long length = 10;
+ unsigned char value [length+1] = "1234567890";
+ mpFunctionCallParameter->setValueLength(length);
+ mpFunctionCallParameter->setValue(value);
+
+ mpFunctionCallParameter->displayParameter();
+ CPPUNIT_ASSERT_MESSAGE ( "setValue failed",
+ 0 == memcmp(value, mpFunctionCallParameter->getValue(), length) );
+ }
+ catch (Error &e)
+ {
+ e.display();
+ CPPUNIT_FAIL ( "Catch exception" );
+ }
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Function call parameter pointer is NULL" );
+ }
+}
+
+
+void FunctionCallParameterTest::setValueLengthTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionCallParameter)
+ {
+ try
+ {
+ const unsigned long length = 10;
+ mpFunctionCallParameter->setValueLength(length);
+
+ mpFunctionCallParameter->displayParameter();
+ CPPUNIT_ASSERT_MESSAGE ( "setValueLength failed",
+ length == mpFunctionCallParameter->getValueLength() );
+ }
+ catch (Error &e)
+ {
+ e.display();
+ CPPUNIT_FAIL ( "Catch exception" );
+ }
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Function call parameter pointer is NULL" );
+ }
+}
+
+
+void FunctionCallParameterTest::constructorsTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionCallParameter)
+ {
+ try
+ {
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"abc");
+ FunctionCallParameter parameter2(parameter1);
+ FunctionCallParameter parameter3 = parameter2;
+
+ parameter1.displayParameter();
+ parameter2.displayParameter();
+ parameter3.displayParameter();
+ CPPUNIT_ASSERT_MESSAGE ( "constructors failed",
+ (0 == parameter1.getName().compare("parameter1"))
+ && (3 == parameter1.getValueLength())
+ && (0 == memcmp(parameter1.getValue(), "abc", 3))
+ && (parameter1 == parameter2)
+ && (parameter2 == parameter3) );
+ }
+ catch (Error &e)
+ {
+ e.display();
+ CPPUNIT_FAIL ( "Catch exception" );
+ }
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Function call parameter pointer is NULL" );
+ }
+}
+
diff --git a/cesar/maximus/functioncall/src/FunctionSciMsg.cpp b/cesar/maximus/functioncall/src/FunctionSciMsg.cpp
new file mode 100644
index 0000000000..7e1c63dbd7
--- /dev/null
+++ b/cesar/maximus/functioncall/src/FunctionSciMsg.cpp
@@ -0,0 +1,865 @@
+/************************************************************************
+ FunctionSciMsg.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/FunctionSciMsg.cpp
+**************************************************************************/
+
+#include "FunctionSciMsg.h"
+
+#include "IFunctionCall.h"
+#include "FunctionCallParameter.h"
+
+#include "Error.h"
+#include "Logger.h"
+
+#include <netinet/in.h> // for 'htonl()' and 'htons()'
+#include <cstring> // for 'strcpy()' and 'strcmp()'
+#include <iomanip> // for 'setfill()' and 'setw()'
+#include <iostream> // for 'cout', 'cerr' and 'clog'
+using namespace std;
+
+
+// Constructors/Destructors
+//
+
+
+Function_Call_Msg_Id FunctionSciMsg::mSpecializedSciMsgId = 0;
+
+
+FunctionSciMsg::FunctionSciMsg ( IFunctionCall * p_function_call_manager ):
+mSpecializedSciMsgType(FUNCTION_CALL_TYPE_NONE),
+mSpecializedSciMsgParametersNumber(0),
+mSpecializedSciMsgFlags(FUNCTION_CALL_FLAG_NONE),
+mpFunctionCallManager(NULL)
+{
+ logFunction();
+
+ if (NULL != p_function_call_manager)
+ {
+ mpFunctionCallManager = p_function_call_manager;
+ }
+ else
+ {
+ errno = EINVAL;
+ throw Error(__PRETTY_FUNCTION__, "Function call manager pointer is NULL", errno);
+ }
+
+ initAttributes ();
+}
+
+
+void FunctionSciMsg::initAttributes ( )
+{
+ logFunction();
+
+ mSpecializedSciMsgHeader.version = 0x00;
+ mSpecializedSciMsgHeader.type = 0x00;
+ mSpecializedSciMsgHeader.msg_id = 0x0000;
+ mSpecializedSciMsgHeader.param_nb = 0x00;
+ mSpecializedSciMsgHeader.flags = 0x00;
+ mSpecializedSciMsgHeader.reserved = 0x0000;
+}
+
+
+FunctionSciMsg::FunctionSciMsg ( const FunctionSciMsg & function_sci_msg ) : SciMsg ( )
+{
+ logFunction();
+
+ setSpecializedSciMsgType (function_sci_msg.getSpecializedSciMsgType());
+ setSpecializedSciMsgParametersNumber (function_sci_msg.getSpecializedSciMsgParametersNumber());
+ setSpecializedSciMsgHeader (function_sci_msg.getSpecializedSciMsgHeader());
+ setFunctionName (function_sci_msg.getFunctionName());
+ setListOfParameters (function_sci_msg.getListOfParameters());
+ setFunctionCallManager (function_sci_msg.getFunctionCallManager());
+}
+
+
+FunctionSciMsg::~FunctionSciMsg ( )
+{
+ logFunction();
+
+ if (!mListOfParameters.empty())
+ {
+ mListOfParameters.clear();
+ }
+ if (NULL != mpFunctionCallManager)
+ {
+ mpFunctionCallManager = NULL;
+ }
+}
+
+
+//
+// Methods
+//
+
+
+// Other methods
+//
+
+
+// public methods
+//
+
+
+SciMsg * FunctionSciMsg::create ( ) const
+{
+ logFunction();
+
+ return new FunctionSciMsg(getFunctionCallManager());
+}
+
+
+bool FunctionSciMsg::dispatchMsg ( )
+{
+ logFunction();
+ bool bDispatch = false;
+
+ if (NULL != getFunctionCallManager())
+ {
+ bDispatch = identifyFunctionName();
+ bDispatch &= identifyParameters();
+
+ if ( FUNCTION_CALL_TYPE_RSP == getSpecializedSciMsgType() )
+ {
+ bDispatch &= getFunctionCallManager()->receiveMsg(*this);
+ }
+ }
+ else
+ {
+ throw Error(__PRETTY_FUNCTION__, "Function call manager pointer is NULL");
+ }
+
+ return bDispatch;
+}
+
+
+// When receiving a SCI msg, specialized SCI msg header has to be extracted from received SCI msg data
+//
+bool FunctionSciMsg::identifySpecializedSciMsgHeader ( )
+{
+ logFunction();
+ bool bIdentifyHeader = false;
+
+ if (NULL != SciMsg::getSciMsgData())
+ {
+ // Set specialized SCI msg header size
+ //
+ SciMsg::setSpecializedSciMsgHeaderSize((unsigned long)sizeof(struct Function_Call_Header));
+
+ // Get specialized SCI message header contents
+ //
+ if (SciMsg::getSciMsgDataLength() >= SciMsg::getSpecializedSciMsgHeaderSize()) // check that there are enough data to get the specialized SCI message header
+ {
+ mSpecializedSciMsgHeader = *((Function_Call_Header*)SciMsg::getSciMsgData());
+ mSpecializedSciMsgHeader.msg_id = ntohs(getSpecializedSciMsgHeader().msg_id);
+ mSpecializedSciMsgHeader.reserved = ntohs(getSpecializedSciMsgHeader().reserved);
+
+ // Set specialized SCI msg attributes from specialized SCI msg header
+ //
+ setSpecializedSciMsgType (static_cast<Function_Call_Type>(getSpecializedSciMsgHeader().type));
+ setSpecializedSciMsgParametersNumber (static_cast<Function_Call_Parameters_Number>(getSpecializedSciMsgHeader().param_nb));
+ setSpecializedSciMsgFlags (static_cast<Function_Call_Flags>(getSpecializedSciMsgHeader().flags));
+ displaySpecializedSciMsgHeader();
+ bIdentifyHeader = true;
+ }
+ else
+ {
+ errno = ENODATA;
+ throw Error(__PRETTY_FUNCTION__, "Not enough data to get the specialized SCI message header", errno);
+ }
+ }
+ else
+ {
+ throw Error(__PRETTY_FUNCTION__, "SCI message data pointer is NULL");
+ }
+
+ return bIdentifyHeader;
+}
+
+
+// Check specialized SCI msg compatibility (check specialized SCI msg version)
+//
+bool FunctionSciMsg::checkCompatibility ( ) const
+{
+ logFunction();
+ bool bCheck = false;
+
+ if (FUNCTION_CALL_VERSION == getSpecializedSciMsgHeader().version)
+ {
+ bCheck = SciMsg::checkCompatibility();
+ }
+
+ return bCheck;
+}
+
+
+// Called by user to configure a message to send
+//
+bool FunctionSciMsg::addParameter ( const FunctionCallParameter & function_argument_to_add )
+{
+ logFunction();
+ bool bAddParameter = false;
+
+ if ( FUNCTION_CALL_PARAM_MAX_SIZE >= function_argument_to_add.getValueLength())
+ {
+ mListOfParameters.push_back(function_argument_to_add);
+ bAddParameter = true;
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "add_param: length of parameter value exceeds max size!" << endl;
+ }
+
+ return bAddParameter;
+}
+
+
+// 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
+{
+ logFunction();
+ bool bBindParameter = false;
+
+ 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;
+}
+
+
+// Called when a function SCI msg is received
+//
+bool FunctionSciMsg::identifyFunctionName ( )
+{
+ logFunction();
+ bool bName = false;
+
+ if (NULL != getSpecializedSciMsgData())
+ {
+ // Find function name length
+ //
+ unsigned long functionNameLength = 0;
+ while ( (getSpecializedSciMsgDataLength() >= functionNameLength)
+ && ('\0' != *(getSpecializedSciMsgData()+functionNameLength)) )
+ {
+ if (FUNCTION_CALL_ID_MAX_SIZE > functionNameLength) /* max length of a function id */
+ {
+ functionNameLength++;
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "length of function call name exceeds max size!" << endl;
+ }
+ }
+
+ // Copy function name from specialized SCI msg data to function name attribute
+ //
+ mFunctionName.assign((char*)getSpecializedSciMsgData(), functionNameLength);
+
+ // Remove function name from specialized SCI msg data
+ //
+ unsigned long tempDataLength = getSpecializedSciMsgDataLength();
+ unsigned char * pTempData = new unsigned char [tempDataLength];
+ memcpy(pTempData, getSpecializedSciMsgData(), tempDataLength);
+ bName = SciMsg::removeData (functionNameLength+1, tempDataLength, &pTempData);
+ if (0 != bName)
+ {
+ bName &= setSpecializedSciMsgDataLength(tempDataLength);
+ bName &= setSpecializedSciMsgData(pTempData);
+ }
+
+ // Free pointer
+ //
+ if (NULL != pTempData)
+ {
+ delete [] pTempData;
+ pTempData = NULL;
+ }
+ }
+ else
+ {
+ if (!getFunctionName().empty()) // function name has already been set
+ {
+ bName = true;
+ }
+ }
+ displayFunctionName();
+
+ return bName;
+}
+
+
+// Called when a function SCI msg is received
+//
+bool FunctionSciMsg::identifyParameters ( )
+{
+ logFunction();
+ bool bParam = false;
+
+ if ( NULL != getSpecializedSciMsgData() )
+ {
+ // For each parameter
+ //
+ for (unsigned int n=0; n<getSpecializedSciMsgParametersNumber(); n++)
+ {
+ // Find parameter name length
+ //
+ unsigned long parameterNameLength = 0;
+ while ( (getSpecializedSciMsgDataLength() >= parameterNameLength)
+ && ('\0' != *(getSpecializedSciMsgData()+parameterNameLength)) )
+ {
+ parameterNameLength++;
+ }
+
+ // Copy parameter name from specialized SCI msg data to parameter name attribute
+ //
+ string tempParameterName;
+ tempParameterName.assign((char*)getSpecializedSciMsgData(), parameterNameLength);
+ FunctionCallParameter parameterToFill;
+ parameterToFill.setName(tempParameterName);
+
+ // Remove parameter name from specialized SCI msg data
+ //
+ unsigned long tempDataLength = getSpecializedSciMsgDataLength();
+ unsigned char * pTempData = new unsigned char [tempDataLength];
+ memcpy(pTempData, getSpecializedSciMsgData(), tempDataLength);
+ bParam = SciMsg::removeData (parameterNameLength+1, tempDataLength, &pTempData);
+ if (0 != bParam)
+ {
+ bParam &= setSpecializedSciMsgDataLength(tempDataLength);
+ bParam &= setSpecializedSciMsgData(pTempData);
+ }
+ if (NULL != pTempData)
+ {
+ delete [] pTempData;
+ pTempData = NULL;
+ }
+
+ // Find parameter value length (coded on 2 bytes)
+ //
+ uint16_t tempLength = (static_cast<uint8_t>(*(getSpecializedSciMsgData()))<<8) + static_cast<uint8_t>(*(getSpecializedSciMsgData()+1));
+ if ( FUNCTION_CALL_PARAM_MAX_SIZE >= tempLength )
+ {
+ parameterToFill.setValueLength (static_cast<unsigned long>(tempLength));
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "length of parameter value exceeds max size!" << endl;
+ }
+
+ // Find parameter value
+ //
+ unsigned char * pTempParameterValue = new unsigned char [parameterToFill.getValueLength()];
+ memcpy(pTempParameterValue, getSpecializedSciMsgData()+2, parameterToFill.getValueLength()); // +2 because parameter value length is coded on 2 bytes
+ parameterToFill.setValue(pTempParameterValue);
+
+ // Remove parameter value length and parameter value from specialized SCI msg data
+ //
+ tempDataLength = getSpecializedSciMsgDataLength();
+ pTempData = new unsigned char [tempDataLength];
+ memcpy(pTempData, getSpecializedSciMsgData(), tempDataLength);
+ bParam &= SciMsg::removeData (2+parameterToFill.getValueLength(), tempDataLength, &pTempData); // +2 because parameter value length is coded on 2 bytes
+ if (0 != bParam)
+ {
+ bParam &= setSpecializedSciMsgDataLength(tempDataLength);
+ bParam &= setSpecializedSciMsgData(pTempData);
+ }
+ if (NULL != pTempData)
+ {
+ delete [] pTempData;
+ pTempData = NULL;
+ }
+ if (NULL != pTempParameterValue)
+ {
+ delete [] pTempParameterValue;
+ pTempParameterValue = NULL;
+ }
+
+ // Add parameter to the parameters list of the received function SCI msg
+ //
+ bParam &= addParameter(parameterToFill);
+ }
+ }
+ displayListOfParameters();
+
+ return bParam;
+}
+
+
+// Called when a function SCI msg is sent
+// Fill specialized SCI msg attributes
+// Fill specialized SCI msg data length and specialized SCI msg data
+//
+bool FunctionSciMsg::fillSpecializedSciMsgToSend ( )
+{
+ logFunction();
+ bool bFill = false;
+
+ Function_Call_Parameters_Number numberOfParameters = 0;
+ unsigned long dataLength = 0;
+ unsigned char * pData = NULL;
+
+ displayFunctionName();
+ displayListOfParameters();
+
+ // Function name is sent into the SCI msg data, before parameters
+ //
+ if (!getFunctionName().empty())
+ {
+ pData = (unsigned char *)(malloc(getFunctionName().size()+1)); // memory allocation for function name
+ getFunctionName().copy ((char*)(pData), getFunctionName().size()); // copy function name into data
+ pData[getFunctionName().size()] = '\0';
+ dataLength += static_cast<unsigned long>(getFunctionName().size()+1); // update data length
+
+ // Parameters are defined as 'FunctionCallParameter'
+ // They will be sent into the function SCI msg into specialized SCI msg data
+ // 'FunctionCallParameter' fields are sent according to the following format:
+ // 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<mListOfParameters.size(); ++i)
+ {
+ // Dynamic memory allocation for parameter
+ //
+ pData = (unsigned char *)(realloc(pData, dataLength+((mListOfParameters)[i].getName().length())+1+2+(mListOfParameters)[i].getValueLength()));
+
+ // Parameter name
+ //
+ mListOfParameters[i].getName().copy ((char*)(pData+dataLength), mListOfParameters[i].getName().size()); // copy parameter name into data
+ *(pData+dataLength+mListOfParameters[i].getName().size()) = '\0';
+ dataLength += static_cast<unsigned long>(mListOfParameters[i].getName().size()+1); // update data length
+
+ // Parameter value 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);
+ *(pData+dataLength) = static_cast<unsigned char>(tempLengthHigh);
+ *(pData+dataLength+1) = static_cast<unsigned char>(tempLengthLow);
+ dataLength += 2; // update data length
+
+ // Parameter value
+ //
+ if (0 != (mListOfParameters[i].getValueLength()))
+ {
+ for (unsigned int j=0; j<mListOfParameters[i].getValueLength(); j++)
+ {
+ *(pData+dataLength+j) = *(mListOfParameters[i].getValue()+j);
+ }
+ }
+ dataLength += mListOfParameters[i].getValueLength(); // update data length
+
+ // Increment number of parameters that have been copied into data
+ //
+ numberOfParameters++;
+ }
+ }
+
+ // Fill specialized SCI msg type,
+ // specialized SCI msg number of parameters,
+ // specialized SCI msg data length,
+ // and specialized SCI msg data
+ //
+ if (NULL != pData)
+ {
+ bFill = setSpecializedSciMsgType(FUNCTION_CALL_TYPE_REQ);
+ bFill &= setSpecializedSciMsgParametersNumber(numberOfParameters);
+ bFill &= setSpecializedSciMsgDataLength(dataLength);
+ bFill &= setSpecializedSciMsgData(pData);
+
+ // Free temporary allocated memory
+ //
+ free(pData);
+ pData = NULL;
+ }
+
+ return bFill;
+}
+
+
+void FunctionSciMsg::displaySpecializedSciMsgHeader ( ) const
+{
+ logFunction();
+
+ clog << logger(LOG_INFO) << "function SCI msg header = " << endl;
+ clog << logger(LOG_INFO) << "\tversion = 0x" << setfill('0') << setw(2) << uppercase << hex << static_cast<unsigned short int>(mSpecializedSciMsgHeader.version) << endl;
+ displaySpecializedSciMsgType(LOG_INFO);
+ clog << logger(LOG_INFO) << "\tmsg id = 0x" << setfill('0') << setw(4) << uppercase << hex << mSpecializedSciMsgHeader.msg_id << endl;
+ clog << logger(LOG_INFO) << "\tparam nb = " << dec << static_cast<unsigned short int>(mSpecializedSciMsgHeader.param_nb) \
+ << " (0x" << setw(2) << uppercase << hex << static_cast<unsigned short int>(mSpecializedSciMsgHeader.param_nb) << ")" << endl;
+ clog << logger(LOG_INFO) << "\tflags = 0x" << setfill('0') << setw(2) << uppercase << hex << static_cast<unsigned short int>(mSpecializedSciMsgHeader.flags) << endl;
+ clog << logger(LOG_INFO) << "\treserved = 0x" << setfill('0') << setw(4) << uppercase << hex << mSpecializedSciMsgHeader.reserved << dec << endl;
+}
+
+
+void FunctionSciMsg::displaySpecializedSciMsgType ( int log_level ) const
+{
+ switch (getSpecializedSciMsgType())
+ {
+ case 0:
+ clog << logger(log_level) << "\ttype = FUNCTION_CALL_TYPE_NONE" << endl;
+ break;
+ case 1:
+ clog << logger(log_level) << "\ttype = FUNCTION_CALL_TYPE_REQ" << endl;
+ break;
+ case 2:
+ clog << logger(log_level) << "\ttype = FUNCTION_CALL_TYPE_RSP" << endl;
+ break;
+ default:
+ clog << logger(log_level) << "\ttype = unknown!" << endl;
+ break;
+ }
+}
+
+
+// private methods
+//
+
+
+void FunctionSciMsg::displayFunctionName ( ) const
+{
+ logFunction();
+
+ if (!getFunctionName().empty())
+ {
+ clog << logger(LOG_COM) << "function name = " << getFunctionName() << endl;
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "function name = empty!" << endl;
+ }
+}
+
+
+void FunctionSciMsg::displayParameter ( unsigned int parameter_iterator ) const
+{
+ logFunction();
+
+ clog << logger(LOG_INFO) << "parameter " << dec << parameter_iterator+1 << " = " << endl;
+ if (parameter_iterator < mListOfParameters.size())
+ {
+ mListOfParameters[parameter_iterator].displayParameter();
+ }
+ else
+ {
+ clog << logger(LOG_INFO) << "\tdoes not exist!" << endl;
+ }
+}
+
+
+void FunctionSciMsg::displayListOfParameters ( ) const
+{
+ logFunction();
+ clog << logger(LOG_COM) << "list of parameters = " << endl;
+
+ if (!mListOfParameters.empty())
+ {
+ for (unsigned int i=0; i<mListOfParameters.size(); i++)
+ {
+ mListOfParameters[i].displayParameter();
+ }
+ }
+ else
+ {
+ clog << logger(LOG_COM) << "\tempty!" << endl;
+ }
+}
+
+
+// protected methods
+//
+
+
+// Accessor methods
+//
+
+
+// public attribute accessor methods
+//
+
+
+// private attribute accessor methods
+//
+
+
+Function_Call_Type FunctionSciMsg::getSpecializedSciMsgType ( ) const
+{
+ return mSpecializedSciMsgType;
+}
+
+
+bool FunctionSciMsg::setSpecializedSciMsgType ( const Function_Call_Type type )
+{
+ mSpecializedSciMsgType = type;
+
+ return true;
+}
+
+
+Function_Call_Msg_Id FunctionSciMsg::getMsgId ( ) const
+{
+ return getSpecializedSciMsgHeader().msg_id;
+}
+
+
+bool FunctionSciMsg::setMsgId ( const Function_Call_Msg_Id msg_id )
+{
+ mSpecializedSciMsgHeader.msg_id = msg_id;
+
+ return true;
+}
+
+
+Function_Call_Msg_Id FunctionSciMsg::getSpecializedSciMsgId ( ) const
+{
+ return mSpecializedSciMsgId;
+}
+
+
+bool FunctionSciMsg::incrementSpecializedSciMsgId ( )
+{
+ mSpecializedSciMsgId++;
+
+ return true;
+}
+
+
+Function_Call_Parameters_Number FunctionSciMsg::getSpecializedSciMsgParametersNumber ( ) const
+{
+ return mSpecializedSciMsgParametersNumber;
+}
+
+
+bool FunctionSciMsg::setSpecializedSciMsgParametersNumber ( const Function_Call_Parameters_Number number_of_parameters )
+{
+ logFunction();
+ bool bNb = false;
+
+ if ( FUNCTION_CALL_PARAM_MAX_NB >= number_of_parameters ) /* max number of parameter in a function call */
+ {
+ mSpecializedSciMsgParametersNumber = number_of_parameters;
+ bNb = true;
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "number of parameters exceeds max number!" << endl;
+ }
+
+ return bNb;
+}
+
+
+Function_Call_Flags FunctionSciMsg::getSpecializedSciMsgFlags ( ) const
+{
+ return mSpecializedSciMsgFlags;
+}
+
+
+bool FunctionSciMsg::setSpecializedSciMsgFlags ( const Function_Call_Flags flags )
+{
+ logFunction();
+ bool bFlags = false;
+
+ if ( FUNCTION_CALL_FLAG_MAX < flags )
+ {
+ clog << logger(LOG_ERROR) << "function SCI message header flags is out-of-range!" << endl;
+ }
+ else if (FUNCTION_CALL_FLAG_FAILED == flags & FUNCTION_CALL_FLAG_FAILED)
+ {
+ clog << logger(LOG_ERROR) << "function SCI message header flags is set to FAILED!" << endl;
+ mSpecializedSciMsgFlags = flags;
+ }
+ else
+ {
+ mSpecializedSciMsgFlags = flags;
+ bFlags = true;
+ }
+
+ return bFlags;
+}
+
+
+bool FunctionSciMsg::setReserved ( const uint16_t reserved )
+{
+ mSpecializedSciMsgHeader.reserved = reserved;
+
+ return true;
+}
+
+
+void * FunctionSciMsg::returnSpecializedSciMsgHeader ( ) const
+{
+ return (void*)&mSpecializedSciMsgHeader;
+}
+
+
+const Function_Call_Header & FunctionSciMsg::getSpecializedSciMsgHeader ( ) const
+{
+ return mSpecializedSciMsgHeader;
+}
+
+
+bool FunctionSciMsg::setSpecializedSciMsgHeader ( const Function_Call_Header & specialized_sci_msg_header )
+{
+ logFunction();
+ bool bSetHeader = false;
+
+ mSpecializedSciMsgHeader = specialized_sci_msg_header;
+
+ // Set specialized SCI msg attributes from specialized SCI msg header
+ //
+ bSetHeader = setSpecializedSciMsgType (static_cast<Function_Call_Type>(getSpecializedSciMsgHeader().type));
+ bSetHeader &= setSpecializedSciMsgParametersNumber (static_cast<Function_Call_Parameters_Number>(getSpecializedSciMsgHeader().param_nb));
+
+ displaySpecializedSciMsgHeader();
+
+ return bSetHeader;
+}
+
+
+string FunctionSciMsg::getFunctionName ( ) const
+{
+ return mFunctionName;
+}
+
+
+// Called by user to configure a SCI message to send
+//
+bool FunctionSciMsg::setFunctionName ( const string name )
+{
+ logFunction();
+ bool bName = false;
+
+ if ( FUNCTION_CALL_ID_MAX_SIZE > name.size() ) /* max length of a function id */
+ {
+ mFunctionName = name;
+ bName = true;
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "function name exceeds max length!" << endl;
+ }
+
+ return bName;
+}
+
+
+const ParametersList & FunctionSciMsg::getListOfParameters ( ) const
+{
+ return mListOfParameters;
+}
+
+
+bool FunctionSciMsg::setListOfParameters ( const ParametersList & list_of_parameters )
+{
+ if (!mListOfParameters.empty())
+ {
+ mListOfParameters.clear();
+ }
+ mListOfParameters = ParametersList(list_of_parameters);
+
+ return true;
+}
+
+
+IFunctionCall * FunctionSciMsg::getFunctionCallManager ( ) const
+{
+ return mpFunctionCallManager;
+}
+
+
+bool FunctionSciMsg::setFunctionCallManager ( IFunctionCall * p_function_call_manager )
+{
+ logFunction();
+
+ if (NULL != p_function_call_manager)
+ {
+ mpFunctionCallManager = p_function_call_manager;
+ }
+ else
+ {
+ clog << logger(LOG_WARNING) << "function call manager pointer is NULL!" << endl;
+ mpFunctionCallManager = NULL;
+ }
+
+ return true;
+}
+
+
+// protected attribute accessor methods
+//
+
diff --git a/cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp b/cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp
new file mode 100644
index 0000000000..440a271c67
--- /dev/null
+++ b/cesar/maximus/functioncall/src/FunctionSciMsgTest.cpp
@@ -0,0 +1,206 @@
+
+#include "FunctionSciMsgTest.h"
+
+#include "FunctionSciMsg.h"
+#include "SciServer.h"
+#include "FunctionCallManager.h"
+#include "FunctionCallParameter.h"
+
+#include "Error.h"
+#include "Logger.h"
+
+#include <iostream>
+using namespace std;
+
+CPPUNIT_TEST_SUITE_REGISTRATION (FunctionSciMsgTest);
+
+
+void FunctionSciMsgTest::setUp (void)
+{
+ logTest();
+
+ mpSciServer = new SciServer();
+ mpFunctionCallManager = new FunctionCallManager (mpSciServer);
+ mpFunctionSciMsg = new FunctionSciMsg (mpFunctionCallManager);
+}
+
+
+void FunctionSciMsgTest::tearDown (void)
+{
+ logTest();
+
+ if (NULL != mpSciServer)
+ {
+ delete (mpSciServer);
+ mpSciServer = NULL;
+ }
+ if (NULL != mpFunctionCallManager)
+ {
+ delete (mpFunctionCallManager);
+ mpFunctionCallManager = NULL;
+ }
+ if (NULL != mpFunctionSciMsg)
+ {
+ delete mpFunctionSciMsg;
+ mpFunctionSciMsg = NULL;
+ }
+}
+
+
+void FunctionSciMsgTest::addParameterTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionSciMsg)
+ {
+ // Add parameter 1
+ //
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter1) );
+
+ // Add parameter 2
+ //
+ FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter2) );
+
+ // Add parameter 3
+ //
+ FunctionCallParameter parameter3 = parameter2;
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter3) );
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
+ }
+}
+
+
+void FunctionSciMsgTest::bindParameterTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionSciMsg)
+ {
+ // Add parameter 1
+ //
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter1) );
+
+ // Add parameter 2
+ //
+ FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter2) );
+
+ // Add parameter 3
+ //
+ FunctionCallParameter parameter3 = parameter2;
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter3) );
+
+ const string name = "parameter1";
+ unsigned long dataLength = FUNCTION_CALL_PARAM_MAX_SIZE;
+ unsigned char * pData = new unsigned char [FUNCTION_CALL_PARAM_MAX_SIZE];
+
+ CPPUNIT_ASSERT_MESSAGE ( "bindParameter failed",
+ mpFunctionSciMsg->bindParameter(name, dataLength, pData) );
+
+ // Check results
+ //
+ CPPUNIT_ASSERT_MESSAGE ( "bindParameterTest failed: wrong data length", 3 == dataLength) ;
+
+ CPPUNIT_ASSERT_MESSAGE ( "bindParameterTest failed: data pointer is NULL", NULL != pData) ;
+
+ pData[dataLength] = '\0';
+
+ CPPUNIT_ASSERT_MESSAGE ( "bindParameterTest failed: wrong data", !strcmp("123", (char*)pData)) ;
+
+ // Free memory allocated for 'FunctionSciMsg::bindParameter'
+ //
+ if (NULL != pData)
+ {
+ delete [] pData;
+ pData = NULL;
+ }
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
+ }
+}
+
+
+void FunctionSciMsgTest::fillSpecializedSciMsgToSendTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionSciMsg)
+ {
+ // Add parameter 1
+ //
+ FunctionCallParameter parameter1 ("parameter1", 3, (unsigned char *)"123");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter1) );
+
+ // Add parameter 2
+ //
+ FunctionCallParameter parameter2 ("parameter2", 10, (unsigned char *)"0123456789");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter2) );
+
+ // Add parameter 3
+ //
+ FunctionCallParameter parameter3 = parameter2;
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ mpFunctionSciMsg->addParameter(parameter3) );
+
+ CPPUNIT_ASSERT_MESSAGE ( "setFunctionName failed",
+ mpFunctionSciMsg->setFunctionName ("function_to_call") );
+
+ CPPUNIT_ASSERT_MESSAGE ( "fillSpecializedSciMsgToSend failed",
+ mpFunctionSciMsg->fillSpecializedSciMsgToSend() );
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
+ }
+}
+
+
+void FunctionSciMsgTest::setSpecializedSciMsgFlagsTest (void)
+{
+ logTest();
+
+ if (NULL != mpFunctionSciMsg)
+ {
+ mpFunctionSciMsg->setSpecializedSciMsgFlags(FUNCTION_CALL_FLAG_MAX + 1);
+ CPPUNIT_ASSERT_MESSAGE ( "setSpecializedSciMsgFlags failed",
+ FUNCTION_CALL_FLAG_NONE == mpFunctionSciMsg->getSpecializedSciMsgFlags() );
+
+ mpFunctionSciMsg->setSpecializedSciMsgFlags(FUNCTION_CALL_FLAG_FAILED);
+ CPPUNIT_ASSERT_MESSAGE ( "setSpecializedSciMsgFlags failed",
+ FUNCTION_CALL_FLAG_FAILED == mpFunctionSciMsg->getSpecializedSciMsgFlags() );
+
+ mpFunctionSciMsg->setSpecializedSciMsgFlags(FUNCTION_CALL_FLAG_NONE);
+ CPPUNIT_ASSERT_MESSAGE ( "setSpecializedSciMsgFlags failed",
+ FUNCTION_CALL_FLAG_NONE == mpFunctionSciMsg->getSpecializedSciMsgFlags() );
+ }
+ else
+ {
+ CPPUNIT_FAIL ( "Initialized FunctionSciMsg pointer is NULL" );
+ }
+}
+
diff --git a/cesar/maximus/functioncall/src/IFunctionCallTest.cpp b/cesar/maximus/functioncall/src/IFunctionCallTest.cpp
new file mode 100644
index 0000000000..5f60e7b435
--- /dev/null
+++ b/cesar/maximus/functioncall/src/IFunctionCallTest.cpp
@@ -0,0 +1,89 @@
+
+#include "IFunctionCallTest.h"
+
+#include "IFunctionCall.h"
+#include "FunctionCallManager.h"
+#include "SciServer.h"
+#include "FunctionSciMsg.h"
+#include "FunctionCallParameter.h"
+#include "SystemManager.h"
+#include "PhyProcessor.h"
+#include "NetworkClockProcessor.h"
+#include "EthernetProcessor.h"
+
+#include "Error.h"
+#include "Logger.h"
+
+#include <iostream>
+using namespace std;
+
+CPPUNIT_TEST_SUITE_REGISTRATION (IFunctionCallTest);
+
+
+void IFunctionCallTest::setUp (void)
+{
+ logTest();
+}
+
+
+void IFunctionCallTest::tearDown (void)
+{
+ logTest();
+}
+
+
+void IFunctionCallTest::userTest (void)
+{
+ logTest();
+
+ try
+ {
+ SciServer sciServer;
+ FunctionCallManager functionCallManager(&sciServer);
+ FunctionSciMsg * pFunctionSciMsg = functionCallManager.createMsg();
+
+ CPPUNIT_ASSERT_MESSAGE ( "createMsg failed", (NULL != pFunctionSciMsg) );
+
+ CPPUNIT_ASSERT_MESSAGE ( "registerCallback failed",
+ functionCallManager.registerCallback(pFunctionSciMsg->getSpecializedSciMsgId(), &userFunction) );
+
+ CPPUNIT_ASSERT_MESSAGE ( "setFunctionName failed",
+ pFunctionSciMsg->setFunctionName("function_to_call") );
+
+ FunctionCallParameter parameter ("parameter", 25, (unsigned char *)"1234567890123456789012345");
+
+ CPPUNIT_ASSERT_MESSAGE ( "addParameter failed",
+ pFunctionSciMsg->addParameter (parameter) );
+
+ SystemManager systemManager(&sciServer);
+ FunctionCallManager functionCall(&sciServer);
+ PhyProcessor phy(&sciServer);
+ EthernetProcessor ethernet(&sciServer);
+ NetworkClockProcessor networkClock(&sciServer, &systemManager, &functionCall, &phy, &ethernet);
+ systemManager.setNetworkClock(&networkClock);
+ Sci_Msg_Station_Id stationId = 0;
+ stationId = systemManager.createStation(systemManager.getDefaultStationExecutable());
+ pFunctionSciMsg->setSciMsgStationId(stationId);
+ systemManager.updateStationStatus ( stationId, MAXIMUS_STATION_STATUS_IDLE );
+
+ CPPUNIT_ASSERT_MESSAGE ( "sendMsg failed",
+ functionCallManager.sendMsg(pFunctionSciMsg) );
+
+ if (NULL != pFunctionSciMsg)
+ {
+ delete pFunctionSciMsg;
+ pFunctionSciMsg = NULL;
+ }
+ }
+ catch ( Error &e )
+ {
+ e.display();
+ }
+}
+
+
+void userFunction ( const FunctionSciMsg & function_sci_msg )
+{
+ logTest();
+}
+