summaryrefslogtreecommitdiff
path: root/cesar/maximus/ethernet/src/EtherSciMsg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/ethernet/src/EtherSciMsg.cpp')
-rw-r--r--cesar/maximus/ethernet/src/EtherSciMsg.cpp372
1 files changed, 372 insertions, 0 deletions
diff --git a/cesar/maximus/ethernet/src/EtherSciMsg.cpp b/cesar/maximus/ethernet/src/EtherSciMsg.cpp
new file mode 100644
index 0000000000..7869fb9cd3
--- /dev/null
+++ b/cesar/maximus/ethernet/src/EtherSciMsg.cpp
@@ -0,0 +1,372 @@
+/************************************************************************
+ EtherSciMsg.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/phy/src/EtherSciMsg.cpp
+**************************************************************************/
+
+#include "EtherSciMsg.h"
+#include "IEthernet.h"
+
+#include "Error.h"
+#include "Logger.h"
+
+#include "interface/sniffer/defs.h" // for 'SNIFFER_BEACON' and 'SNIFFER_MME'
+
+#include <iomanip> // for 'setfill()' and 'setw()'
+using namespace std;
+
+
+// Constructors/Destructors
+//
+
+
+EtherSciMsg::EtherSciMsg ( IEthernet * p_ethernet ):
+mSpecializedSciMsgType(ETHERNET_TYPE_NONE),
+mSnifferType(0),
+mFlags(ETHERNET_FLAG_NONE),
+mpEthernet(NULL)
+{
+ logFunction();
+
+ if (NULL == p_ethernet)
+ {
+ throw Error(__PRETTY_FUNCTION__, "Ethernet processor pointer is NULL");
+ }
+
+ mpEthernet = p_ethernet;
+ initAttributes ();
+}
+
+
+void EtherSciMsg::initAttributes ( )
+{
+ logFunction();
+
+ mSpecializedSciMsgHeader.version = ETHERNET_VERSION;
+ mSpecializedSciMsgHeader.type = ETHERNET_TYPE_NONE;
+ mSpecializedSciMsgHeader.sniffer_type = 0x00;
+ mSpecializedSciMsgHeader.flags = ETHERNET_FLAG_NONE;
+ mSpecializedSciMsgHeader.reserved = 0x00000000;
+}
+
+
+EtherSciMsg::~EtherSciMsg ( )
+{
+ logFunction();
+
+ if (NULL != mpEthernet)
+ {
+ mpEthernet = NULL;
+ }
+}
+
+
+//
+// Methods
+//
+
+
+// Other methods
+//
+
+
+// public methods
+//
+
+
+SciMsg * EtherSciMsg::create ( ) const
+{
+ logFunction();
+
+ return new EtherSciMsg (getEthernet());
+}
+
+
+bool EtherSciMsg::dispatchMsg ( )
+{
+ logFunction();
+
+ bool bDispatch = getEthernet()->receiveEther(*this);
+
+ if (!bDispatch)
+ {
+ throw Error(__PRETTY_FUNCTION__, "error while receiving Ether SCI message");
+ }
+
+ return bDispatch;
+}
+
+
+bool EtherSciMsg::identifySpecializedSciMsgHeader ( )
+{
+ logFunction();
+ bool bIdentifyHeader = false;
+
+ if (NULL != SciMsg::getSciMsgData())
+ {
+ // Set specialized SCI msg header size
+ //
+ SciMsg::setSpecializedSciMsgHeaderSize((unsigned long)sizeof(struct Ethernet_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
+ {
+ setSpecializedSciMsgHeader(*((Ethernet_Header*)SciMsg::getSciMsgData()));
+
+ // Set specialized SCI msg attributes from specialized SCI msg header
+ //
+ setSpecializedSciMsgType (static_cast<Ethernet_Type>(getSpecializedSciMsgHeader().type));
+ setSnifferType (static_cast<Ethernet_Sniffer_Type>(getSpecializedSciMsgHeader().sniffer_type));
+ setFlags (static_cast<Ethernet_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;
+}
+
+
+bool EtherSciMsg::checkCompatibility ( ) const
+{
+ logFunction();
+ bool bCheck = false;
+
+ if (ETHERNET_VERSION == getSpecializedSciMsgHeader().version)
+ {
+ bCheck = SciMsg::checkCompatibility();
+ }
+
+ return bCheck;
+}
+
+
+bool EtherSciMsg::checkValidity ( ) const
+{
+ logFunction();
+ bool bCheck = false;
+
+ // Check header values ranges
+ //
+ if ((ETHERNET_TYPE_NB > getSpecializedSciMsgHeader().type)
+ && (ETHERNET_TYPE_NONE < getSpecializedSciMsgHeader().type)
+ && (SNIFFER_MME >= getSpecializedSciMsgHeader().sniffer_type)
+ && (ETHERNET_FLAG_MAX >= getSpecializedSciMsgHeader().flags))
+ {
+ bCheck = SciMsg::checkValidity();
+ }
+
+ return bCheck;
+}
+
+
+void EtherSciMsg::displaySpecializedSciMsgHeader ( ) const
+{
+ logFunction();
+
+ clog << logger(LOG_INFO) << "Ether SCI message 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) << "\tsniffer type = 0x" << setfill('0') << setw(2) << uppercase << hex << static_cast<unsigned short int>(getSpecializedSciMsgHeader().sniffer_type) << endl;
+ clog << logger(LOG_INFO) << "\tflags = 0x" << setfill('0') << setw(2) << uppercase << hex << static_cast<unsigned short int>(getSpecializedSciMsgHeader().flags) << endl;
+ clog << logger(LOG_INFO) << "\treserved = 0x" << setfill('0') << setw(8) << uppercase << hex << getSpecializedSciMsgHeader().reserved << endl;
+}
+
+
+void EtherSciMsg::displaySpecializedSciMsgType ( int log_level ) const
+{
+ logFunction();
+
+ switch (getSpecializedSciMsgHeader().type)
+ {
+ case 0:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_NONE" << endl;
+ break;
+ case 1:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_DATA" << endl;
+ break;
+ case 2:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_MME" << endl;
+ break;
+ case 3:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_DATA_BUFFER_ADD" << endl;
+ break;
+ case 4:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_MME_BUFFER_ADD" << endl;
+ break;
+ case 5:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_INTERFACE_BUFFER_ADD" << endl;
+ break;
+ case 6:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_BUFFER_RELEASED" << endl;
+ break;
+ case 7:
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_SNIFFER" << 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
+//
+
+
+// protected attribute accessor methods
+//
+
+
+void * EtherSciMsg::returnSpecializedSciMsgHeader ( ) const
+{
+ return (void*)&mSpecializedSciMsgHeader;
+}
+
+
+const Ethernet_Header & EtherSciMsg::getSpecializedSciMsgHeader ( ) const
+{
+ return mSpecializedSciMsgHeader;
+}
+
+
+bool EtherSciMsg::setSpecializedSciMsgHeader ( const Ethernet_Header & specialized_sci_msg_header )
+{
+ logFunction();
+
+ mSpecializedSciMsgHeader = specialized_sci_msg_header;
+ displaySpecializedSciMsgHeader();
+
+ return true;
+}
+
+
+IEthernet * EtherSciMsg::getEthernet ( ) const
+{
+ if (NULL == mpEthernet)
+ {
+ throw Error(__PRETTY_FUNCTION__, "Ethernet processor pointer is NULL");
+ }
+
+ return mpEthernet;
+}
+
+
+Ethernet_Type EtherSciMsg::getSpecializedSciMsgType ( ) const
+{
+ return mSpecializedSciMsgType;
+}
+
+
+bool EtherSciMsg::setSpecializedSciMsgType ( const Ethernet_Type type )
+{
+ if ((ETHERNET_TYPE_NB <= type) || (ETHERNET_TYPE_NONE >= type))
+ {
+ errno = EINVAL;
+ throw Error(__PRETTY_FUNCTION__, "Ether SCI message header type is out-of-range", errno);
+ }
+ mSpecializedSciMsgType = type;
+
+ return true;
+}
+
+
+const Ethernet_Sniffer_Type EtherSciMsg::getSnifferType ( ) const
+{
+ if (SNIFFER_MME < mSnifferType)
+ {
+ errno = EINVAL;
+ throw Error(__PRETTY_FUNCTION__, "Ether SCI message header sniffer type is out-of-range", errno);
+ }
+
+ return mSnifferType;
+}
+
+
+bool EtherSciMsg::setSnifferType ( const Ethernet_Sniffer_Type sniffer_type )
+{
+ if (SNIFFER_MME < sniffer_type)
+ {
+ errno = EINVAL;
+ throw Error(__PRETTY_FUNCTION__, "Sniffer type is out-of-range", errno);
+ }
+ mSnifferType = sniffer_type;
+
+ return true;
+}
+
+
+const Ethernet_Flags EtherSciMsg::getFlags ( ) const
+{
+ if (ETHERNET_FLAG_MAX < mFlags)
+ {
+ errno = EINVAL;
+ throw Error(__PRETTY_FUNCTION__, "Ether SCI message header flags are out-of-range", errno);
+ }
+
+ return mFlags;
+}
+
+
+bool EtherSciMsg::setFlags ( const Ethernet_Flags flags )
+{
+ if (ETHERNET_FLAG_MAX < flags)
+ {
+ errno = EINVAL;
+ throw Error(__PRETTY_FUNCTION__, "Ether SCI message header flags are out-of-range", errno);
+ }
+ mFlags = flags;
+
+ return true;
+}
+