#include "packers.hh" // Include the header definition for // the common interface declaration // for the distributed class #include "Buffer.h" // Provide Support for Buffer Class #include // Provide Support for IO handling /////////////////////////////////////// //Function: main //Author: Dean Thompson //Created: 3rd August 1996 //Last Modified: 4th October 1996 //Description: This routine is // responsible for conducting the // test by doing the following: // // * Creating two objects // * Binding to two servers // * Setting the data up into the // objects // * Passing the data between the // the objects 10,000 times // * Print the contents out to the // screen // // * (Standard Implementation) /////////////////////////////////////// int main() { Packers_var aPackerVar,bPackerVar; // CORBA variables designed to // manage pointers to objects // which are "bound" to a server dataTransfer aTransBuffer; // Declare the transfer buffer used // to pass data between the server // and client objects dataTransfer *tempBuff; // Declare a pointer to the transfer // buffer to allow the server to put // data into it via the memory // pointer aTransBuffer.aString = CORBA::string_alloc(80); // Allocate memory for the character // array aPackerVar = Packers::_bind(); // Make contact with one server bPackerVar = Packers::_bind(":ObjectStore2","firefly.sd.monash.edu.au"); // Make contact with a second server // located on "firefly.sd" aTransBuffer.aLong = -2100000000; // Set the local "long" variable aTransBuffer.bLong = -2100000000; aTransBuffer.aUnsignedLong = 4200000000; // Set the local "unsigned long" // variable aTransBuffer.aUnsignedShort = 65535; // Set the local "unsigned short" // variable aTransBuffer.aFloat = -65545.57; // Set the local "float" variable aTransBuffer.bFloat = -65545.57; aTransBuffer.aDouble = 6000; // Set the local "double" variable aTransBuffer.bDouble = 6000; aTransBuffer.aCharacter = 'M'; // Set the local "character" // variable aTransBuffer.aBoolean = 1; // Set the local "boolean" variable strcpy(aTransBuffer.aString," Data Transfer Test for Communications Data........."); // Set the local "character array" variable for (int i=0;i<10000;i++) // Setting up the looping construct // for 10,000 iterations { try // Make all the CORBA calls with // the safety of a "try" block to // "catch" any errors { cout << "Iteration #" << i+1 << "." << endl; // Report the number of the // iteration we are currently on aTransBuffer.aShort = i+1; // Set the local "short" variable to // the current iteration aTransBuffer.bShort = i+1; aPackerVar->defaultSaveStruct(aTransBuffer); // Send the data structure to the // remote object to have it's data // loaded aPackerVar->defaultLoadStruct(tempBuff); // Request the data structure back // from the first object in a // structure format bPackerVar->defaultSaveStruct(aTransBuffer); // Transmit the same data to the // second object in a structure // format // To make sure that the data was sent to the second object correctly // the client request all that data to be sent back and displayed to the // screen cout << "Reconstructed short: " << bPackerVar->aShort() << "." << endl; // Display the value of the remote object's short cout << "Reconstructed long: " << bPackerVar->aLong() << "." << endl; // Display the value of the remote object's long cout << "Reconstructed unsigned short: " << bPackerVar->aUnsignedShort() << "." << endl; // Display the value of the remote object's unsigned short cout << "Reconstructed unsigned long: " << bPackerVar->aUnsignedLong() << "." << endl; // Display the value of the remote object's unsigned long cout << "Reconstructed float: " << bPackerVar->aFloat() << "." << endl; // Display the value of the remote object's float cout << "Reconstructed double: " << bPackerVar->aDouble() << "." << endl; // Display the value of the remote object's double cout << "Reconstructed character: " << (char) bPackerVar->aCharacter() << "." << endl; // Display the value of the remote object's character cout << "Reconstructed boolean: " << (int) bPackerVar->aBoolean() << "." << endl; // Display the value of the remote object's boolean bPackerVar->aFloat(); bPackerVar->aFloat(); cout << "Reconstructed string: " << bPackerVar->aString() << "." << endl; // Display the value of the remote object's string after it was // return from the inital object cout << "Reconstructed short: " << bPackerVar->bShort() << "." << endl; // Display the value of the remote object's short cout << "Reconstructed long: " << bPackerVar->bLong() << "." << endl; // Display the value of the remote object's long cout << "Reconstructed float: " << bPackerVar->bFloat() << "." << endl; // Display the value of the remote object's float cout << "Reconstructed double: " << bPackerVar->bDouble() << "." << endl; // Display the value of the remote object's double cout << endl; } catch(CORBA::SystemException &se) // catch any CORBA::SystemException { cout << "Error" << &se << endl; // Display the data about the // associated error return 1; } } return 0; }