summaryrefslogtreecommitdiff
path: root/cesar/maximus/system/src/SystemSciMsg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/system/src/SystemSciMsg.cpp')
-rw-r--r--cesar/maximus/system/src/SystemSciMsg.cpp285
1 files changed, 285 insertions, 0 deletions
diff --git a/cesar/maximus/system/src/SystemSciMsg.cpp b/cesar/maximus/system/src/SystemSciMsg.cpp
new file mode 100644
index 0000000000..048924b8da
--- /dev/null
+++ b/cesar/maximus/system/src/SystemSciMsg.cpp
@@ -0,0 +1,285 @@
+/************************************************************************
+ SystemSciMsg.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/system/src/SystemSciMsg.cpp
+**************************************************************************/
+
+#include "SystemSciMsg.h"
+
+#include "ISystem.h"
+
+#include "Error.h"
+#include "Logger.h"
+
+#include <iomanip> // for 'setfill()' and 'setw()'
+#include <netinet/in.h> // for 'ntohl()' and 'ntohs()'
+#include <iostream> // for 'cout', 'cerr' and 'clog'
+using namespace std;
+
+
+// Constructors/Destructors
+//
+
+
+SystemSciMsg::SystemSciMsg ( ISystem * p_system_manager ):
+mSpecializedSciMsgType(SYSTEM_TYPE_NONE),
+mpSystemManager(NULL)
+{
+ logFunction();
+
+ initAttributes ();
+ if (NULL != p_system_manager)
+ {
+ mpSystemManager = p_system_manager;
+ }
+ else
+ {
+ errno = EINVAL;
+ throw Error(__PRETTY_FUNCTION__, "System manager pointer is NULL", errno);
+ }
+}
+
+
+void SystemSciMsg::initAttributes ( )
+{
+ logFunction();
+
+ mSpecializedSciMsgHeader.version = 0x00;
+ mSpecializedSciMsgHeader.type = 0x00;
+ mSpecializedSciMsgHeader.flags = 0x0000;
+}
+
+
+SystemSciMsg::~SystemSciMsg ( )
+{
+ logFunction();
+
+ if (NULL != mpSystemManager)
+ {
+ mpSystemManager = NULL;
+ }
+}
+
+
+//
+// Methods
+//
+
+
+// Other methods
+//
+
+
+// public methods
+//
+
+
+SciMsg * SystemSciMsg::create ( ) const
+{
+ logFunction();
+
+ return new SystemSciMsg (mpSystemManager);
+}
+
+
+bool SystemSciMsg::dispatchMsg ( )
+{
+ logFunction();
+ bool bDispatch = false;
+
+ if (NULL != mpSystemManager)
+ {
+ if ( SYSTEM_TYPE_IDLE == getSpecializedSciMsgType() )
+ {
+ bDispatch = mpSystemManager->receiveIdleMsg(*this);
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "type is not SYSTEM_TYPE_IDLE!" << endl;
+ }
+ }
+ else
+ {
+ throw Error(__PRETTY_FUNCTION__, "System 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 SystemSciMsg::identifySpecializedSciMsgHeader ( )
+{
+ logFunction();
+ bool bIdentifyHeader = false;
+
+ if (NULL != SciMsg::getSciMsgData())
+ {
+ // Set specialized SCI msg header size
+ //
+ SciMsg::setSpecializedSciMsgHeaderSize(static_cast<unsigned long>(sizeof(struct System_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 = *((System_Header*)SciMsg::getSciMsgData());
+ mSpecializedSciMsgHeader.flags = ntohs(getSpecializedSciMsgHeader().flags);
+
+ bIdentifyHeader = setSpecializedSciMsgType (static_cast<System_Type>(getSpecializedSciMsgHeader().type));
+
+ displaySpecializedSciMsgHeader();
+ }
+ else
+ {
+ errno = ENODATA;
+ throw Error(__PRETTY_FUNCTION__, "Not enough data to get the system 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 SystemSciMsg::checkCompatibility ( ) const
+{
+ logFunction();
+ bool bCheck = false;
+
+ if (SYSTEM_VERSION == getSpecializedSciMsgHeader().version)
+ {
+ bCheck = SciMsg::checkCompatibility();
+ }
+
+ return bCheck;
+}
+
+
+void SystemSciMsg::displaySpecializedSciMsgHeader ( ) const
+{
+ logFunction();
+
+ clog << logger(LOG_INFO) << "system SCI msg header = " << endl;
+ clog << logger(LOG_INFO) << "\tversion = 0x" << setfill('0') << setw(2) << uppercase << hex << static_cast<unsigned short int>(getSpecializedSciMsgHeader().version) << endl;
+ displaySpecializedSciMsgType(LOG_INFO);
+ clog << logger(LOG_INFO) << "\tflags = 0x" << setfill('0') << setw(4) << uppercase << hex << getSpecializedSciMsgHeader().flags << dec << endl;
+}
+
+
+void SystemSciMsg::displaySpecializedSciMsgType ( int log_level ) const
+{
+ logFunction();
+
+ switch (getSpecializedSciMsgType())
+ {
+ case 0:
+ clog << logger(log_level) << "\ttype = SYSTEM_TYPE_NONE" << endl;
+ break;
+ case 1:
+ clog << logger(log_level) << "\ttype = SYSTEM_TYPE_IDLE" << endl;
+ break;
+ case 2:
+ clog << logger(log_level) << "\ttype = SYSTEM_TYPE_STATION_NAME" << endl;
+ break;
+ default:
+ clog << logger(log_level) << "\ttype = unknown!" << endl;
+ break;
+ }
+}
+
+
+// private methods
+//
+
+
+// protected methods
+//
+
+
+// Accessor methods
+//
+
+
+// public attribute accessor methods
+//
+
+
+// private attribute accessor methods
+//
+
+
+System_Type SystemSciMsg::getSpecializedSciMsgType ( ) const
+{
+ return mSpecializedSciMsgType;
+}
+
+
+bool SystemSciMsg::setSpecializedSciMsgType ( const System_Type type )
+{
+ mSpecializedSciMsgType = type;
+
+ return true;
+}
+
+
+void * SystemSciMsg::returnSpecializedSciMsgHeader ( ) const
+{
+ return (void*)&mSpecializedSciMsgHeader;
+}
+
+
+const System_Header & SystemSciMsg::getSpecializedSciMsgHeader ( ) const
+{
+ return mSpecializedSciMsgHeader;
+}
+
+
+bool SystemSciMsg::setSpecializedSciMsgHeader ( const System_Header & specialized_sci_msg_header )
+{
+ logFunction();
+ bool bSetHeader = false;
+
+ mSpecializedSciMsgHeader = specialized_sci_msg_header;
+
+ bSetHeader = setSpecializedSciMsgType (static_cast<System_Type>(getSpecializedSciMsgHeader().type));
+
+ displaySpecializedSciMsgHeader();
+
+ return bSetHeader;
+}
+
+
+// protected attribute accessor methods
+//
+