#include "packers_i.hh" // Include the header definition for // the implementation class #include "Buffer.h" // Provide Support for Buffer Class #include // Provide Support for IO handling /////////////////////////////////////// //Function: Packers_i Constructor //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Description: This constructor is // responsible for initialising the // server object upon initial load. // // This routine places the object // into a safe state and allocates // the appropriate memory /////////////////////////////////////// Packers_i::Packers_i() : m_aByteStream(2000), m_aString(CORBA::string_alloc(2000)) // Allocate storage space for 2000 // characters for the internal // string data member and // allocate 2000 bytes to the // byte stream { m_aShort = 0; // m_aLong = 0; // m_aUnsignedShort = 0; // m_aUnsignedLong = 0; //---> Assigning "safe" values to the m_aFloat = 0; // Packers class m_aDouble = 0; // m_aCharacter = 0; // m_aBoolean = 0; // m_bFloat = 0; // m_bDouble = 0; // m_bShort = 0; // m_bLong = 0; // } /////////////////////////////////////// //Function: Packers_i Destructor //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Description: This destructor is // responsible for de-allocating any // memory which was assigned to the // class during its lifetime or // construction. /////////////////////////////////////// Packers_i::~Packers_i() { CORBA::string_free(m_aString); // Deallocate memory that was assigned } /////////////////////////////////////// //Function: aShort //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Short //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aShort(CORBA::Short aShort, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_aShort = aShort; } /////////////////////////////////////// //Function: aShort //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Short //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // process. /////////////////////////////////////// CORBA::Short Packers_i::aShort(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_aShort; } /////////////////////////////////////// //Function: aLong //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Long //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aLong(CORBA::Long aLong, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_aLong = aLong; } /////////////////////////////////////// //Function: aLong //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Long //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::Long Packers_i::aLong(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_aLong; } /////////////////////////////////////// //Function: bShort //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Short //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::bShort(CORBA::Short bShort, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_bShort = bShort; } /////////////////////////////////////// //Function: bShort //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Short //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // process. /////////////////////////////////////// CORBA::Short Packers_i::bShort(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_bShort; } /////////////////////////////////////// //Function: bLong //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Long //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::bLong(CORBA::Long bLong, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_bLong = bLong; } /////////////////////////////////////// //Function: bLong //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Long //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::Long Packers_i::bLong(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_bLong; } /////////////////////////////////////// //Function: aUnsignedShort //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::UShort //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aUnsignedShort(CORBA::UShort aUnsignedShort, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_aUnsignedShort = aUnsignedShort; } /////////////////////////////////////// //Function: aUnsignedShort //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::UShort //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::UShort Packers_i::aUnsignedShort(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_aUnsignedShort; } /////////////////////////////////////// //Function: aUnsignedLong //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::ULong //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aUnsignedLong(CORBA::ULong aUnsignedLong, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_aUnsignedLong = aUnsignedLong; } /////////////////////////////////////// //Function: aUnsignedLong //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::ULong //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::ULong Packers_i::aUnsignedLong(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_aUnsignedLong; } /////////////////////////////////////// //Function: aFloat //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Float //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aFloat(CORBA::Float aFloat, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_aFloat = aFloat; } /////////////////////////////////////// //Function: aFloat //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Float //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::Float Packers_i::aFloat(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_aFloat; } /////////////////////////////////////// //Function: aDouble //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Double //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aDouble(CORBA::Double aDouble, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_aDouble = aDouble; } /////////////////////////////////////// //Function: aDouble //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Double //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::Double Packers_i::aDouble(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_aDouble; } /////////////////////////////////////// //Function: bFloat //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Float //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::bFloat(CORBA::Float bFloat, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_bFloat = bFloat; } /////////////////////////////////////// //Function: bFloat //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Float //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::Float Packers_i::bFloat(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_bFloat; } /////////////////////////////////////// //Function: bDouble //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Double //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::bDouble(CORBA::Double bDouble, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_bDouble = bDouble; } /////////////////////////////////////// //Function: bDouble //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Double //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::Double Packers_i::bDouble(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_bDouble; } /////////////////////////////////////// //Function: aCharacter //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Char //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aCharacter(CORBA::Char aCharacter, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_aCharacter = aCharacter; } /////////////////////////////////////// //Function: aCharacter //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Char //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::Char Packers_i::aCharacter(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_aCharacter; } /////////////////////////////////////// //Function: aBoolean //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: CORBA::Boolean //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aBoolean(CORBA::Boolean aBoolean, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_aBoolean = aBoolean; } /////////////////////////////////////// //Function: aBoolean //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: CORBA::Boolean //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// CORBA::Boolean Packers_i::aBoolean(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_aBoolean; } /////////////////////////////////////// //Function: aString //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: const char *String //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aString(const char *aString, CORBA::Environment &IT_env) throw (CORBA::SystemException) { CORBA::string_free(m_aString); m_aString = CORBA::string_alloc(strlen(aString)+1); strcpy(m_aString,aString); } /////////////////////////////////////// //Function: aString //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: char * //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// char *Packers_i::aString(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return m_aString; } /////////////////////////////////////// //Function: aByteStream //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: const byteStream& //Return Type: (void) //Description: This member function // is responsible for taking a // parameter in and assigning that // data to the internal data member // without validation. /////////////////////////////////////// void Packers_i::aByteStream(const byteStream& aByteStream, CORBA::Environment &IT_env) throw (CORBA::SystemException) { m_aByteStream = aByteStream; } /////////////////////////////////////// //Function: aByteStream //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: byteStream * //Description: This member function // is responsible for taking the // internal data member and // returning it back to the calling // procedure. /////////////////////////////////////// byteStream *Packers_i::aByteStream(CORBA::Environment &IT_env) throw (CORBA::SystemException) { return &m_aByteStream; } /////////////////////////////////////// //Function: saveObject (octet) //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Inputs: (none) //Return Type: (void) //Description: This member function // is responsible for taking all the // data members located in the class // and packing them into a // byteStream which the client // then requests at a later date /////////////////////////////////////// void Packers_i::saveObject(CORBA::Environment &IT_env) throw (CORBA::SystemException) { int counted = 0; // Used to hold the length // of the binary bit stream CORBA::string aBuffer; // Temporary string created to // hold all the data after it has // been marshalled and is // awaiting transfer into the // bytestream Buffer buff; // Temporary buffer created to // hold all the data while it is // being packed buff.pack(m_aShort); // Pack the internal short data // member into the buffer buff.pack(m_aLong); // Pack the internal long data // member into the buffer buff.pack(m_aUnsignedShort); // Pack the internal unsigned short // data member into the buffer buff.pack(m_aUnsignedLong); // Pack the internal unsigned long // data member into the buffer buff.pack(m_aFloat); // Pack the internal float data // member into the buffer buff.pack(m_aDouble); // Pack the internal double data // member into the buffer buff.pack(m_aCharacter); // Pack the internal character data // member into the buffer buff.pack(m_aBoolean); // Pack the internal boolean data // member into the buffer buff.packNonMappedString(m_aString); // Pack the internal string data // member into the buffer buff.pack(m_bFloat); // Pack the internal float data // member into the buffer buff.pack(m_bDouble); // Pack the internal double data // member into the buffer buff.pack(m_bShort); // Pack the internal short data // member into the buffer buff.pack(m_bLong); // Pack the internal long data // member into the buffer counted = buff.calculateSize(); // Calculate the total length of // the binary bit stream held in // the buffer try { aBuffer = CORBA::string_alloc(counted+1); // Try and allocate memory space for the buffer to hold the character // representation of the buffer class } catch(...) // Catch any errors that might // occur as a result of allocating // memory { cout << "Error allocating memory in the function string_alloc" << endl; } buff.constructBuffer(aBuffer); // Construct a string // representation of the "buff" // class and place the character // representation into the aBuffer try { m_aByteStream.length(counted); // Inform the byteStream of how // much data we are going to // store within it } catch(...) // Catch any errors that might // occur as a result of trying to // set the length of the // byteStream { cout << "Error allocating a length to the byteStream" << endl; } for (int counter=0;counter