Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

vpr::sim::Message Class Reference

Container class used to transmit messages between simulated network nodes. More...

#include <Message.h>

Collaboration diagram for vpr::sim::Message:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::vector< vpr::Uint8MessageDataType
typedef boost::shared_ptr<
std::vector< vpr::Uint8 > > 
MessageDataPtr

Public Methods

 Message (const void *msg, const vpr::Uint32 msg_size)
 Creates a new message by copying the given buffer into freshly allocated memory. More...

 Message (MessageDataPtr msgData)
 Creates message by copying shared pointer to data buffer. More...

 Message (const Message &msg)
 Copy constructor that makes a copy of the given source object. More...

 ~Message ()
 Releases the memory allocated for the contained message body. More...

void setStartOnWireTime (const vpr::Interval &time)
const vpr::IntervalwhenStartOnWire () const
void setFullyOnWireTime (const vpr::Interval &time)
const vpr::IntervalwhenFullyOnWire () const
void setArrivesFullyTime (const vpr::Interval &time)
const vpr::IntervalwhenArrivesFully () const
void * getBody () const
MessageDataPtr getMessageData ()
vpr::Uint32 getSize () const
vpr::Uint32 resize (const vpr::Uint32 bytes_read)
 Determines if this message needs to be resized after a read. More...

void setPath (NetworkGraph::VertexListPtr path, const vpr::SocketImplSIM *source, vpr::SocketImplSIM *dest)
 Assigns the path that this message will follow. More...

const NetworkGraph::VertexListPtrgetPath () const
 Returns a constant reference to the path that this message will follow. More...

const vpr::SocketImplSIMgetSourceSocket () const
vpr::SocketImplSIMgetDestinationSocket () const
const NetworkGraph::net_vertex_tgetNextHop () const
 Retrieves the next hop (network graph vertex) in the path of this message and returns it to the caller via the by-reference parameter. More...

void incNextHop (bool &end_of_path)
 Increment the pointer to the next hop in this message's path as it moves towards its destination. More...


Detailed Description

Container class used to transmit messages between simulated network nodes.

Copying these objects is an expensive operation, and hence, it should be done as infrequently as possible. Passing by reference may require access synchronization, however.

Definition at line 73 of file Message.h.


Member Typedef Documentation

typedef std::vector<vpr::Uint8> vpr::sim::Message::MessageDataType
 

Definition at line 76 of file Message.h.

typedef boost::shared_ptr<std::vector<vpr::Uint8> > vpr::sim::Message::MessageDataPtr
 

Definition at line 77 of file Message.h.


Constructor & Destructor Documentation

vpr::sim::Message::Message const void *    msg,
const vpr::Uint32    msg_size
[inline]
 

Creates a new message by copying the given buffer into freshly allocated memory.

Definition at line 83 of file Message.h.

00084       : mSrcSock(NULL), mDestSock(NULL)
00085    {
00086       vpr::Uint8* start = (vpr::Uint8*) msg;
00087       mMsg = MessageDataPtr( new MessageDataType(start, start+msg_size));
00088       //mMsg = malloc(msg_size);
00089       //memcpy(mMsg, msg, msg_size);
00090    }

vpr::sim::Message::Message MessageDataPtr    msgData [inline]
 

Creates message by copying shared pointer to data buffer.

Definition at line 93 of file Message.h.

00094       : mSrcSock(NULL), mDestSock(NULL)
00095    {
00096       mMsg = msgData;
00097    }

vpr::sim::Message::Message const Message &    msg
 

Copy constructor that makes a copy of the given source object.

That is, now new memory is allocated for this object's copy of the message body, instead we just make a copy of the shared_ptr to the message body and share it with the other message

Definition at line 54 of file Message.cpp.

References vprASSERT.

00055    : mStartOnWire(msg.mStartOnWire),
00056      mFullyOnWire(msg.mFullyOnWire), mArrivesFully(msg.mArrivesFully),
00057      mMsgPath(msg.mMsgPath), mNextHop(msg.mNextHop), mSrcSock(msg.mSrcSock),
00058      mDestSock(msg.mDestSock)
00059 {
00060    vprASSERT(false && "In copy constructor");
00061    mMsg = msg.mMsg;     // Just copy the shared pointer.  VERY cheap
00062 
00063    /*
00064    if ( (msg.mMsg.get() != NULL) && (!msg.mMsg->empty()) )
00065    {
00066       // Yikes, this could get expensive!
00067       // XXX: Find out if this is REALLY needed
00068       mMsg = MessageDataPtr( new MessageDataType(msg.mMsg->begin(), msg.mMsg->end()));
00069       //mMsg = malloc(msg.mMsgSize);
00070       //memcpy(mMsg, msg.mMsg, msg.mMsgSize);
00071    }
00072    */
00073 }

vpr::sim::Message::~Message   [inline]
 

Releases the memory allocated for the contained message body.

Definition at line 110 of file Message.h.

00111    {
00112       // Releases automatically based on shared_ptr semantics
00113    }


Member Function Documentation

void vpr::sim::Message::setStartOnWireTime const vpr::Interval   time [inline]
 

Definition at line 115 of file Message.h.

00116    {
00117       mStartOnWire = time;
00118    }

const vpr::Interval& vpr::sim::Message::whenStartOnWire   const [inline]
 

Definition at line 120 of file Message.h.

00121    {
00122       return mStartOnWire;
00123    }

void vpr::sim::Message::setFullyOnWireTime const vpr::Interval   time [inline]
 

Definition at line 125 of file Message.h.

00126    {
00127       mFullyOnWire = time;
00128    }

const vpr::Interval& vpr::sim::Message::whenFullyOnWire   const [inline]
 

Definition at line 130 of file Message.h.

00131    {
00132       return mFullyOnWire;
00133    }

void vpr::sim::Message::setArrivesFullyTime const vpr::Interval   time [inline]
 

Definition at line 135 of file Message.h.

00136    {
00137       mArrivesFully = time;
00138    }

const vpr::Interval& vpr::sim::Message::whenArrivesFully   const [inline]
 

Definition at line 140 of file Message.h.

00141    {
00142       return mArrivesFully;
00143    }

void* vpr::sim::Message::getBody   const [inline]
 

Definition at line 145 of file Message.h.

00146    {
00147       return (void*)&((*mMsg)[0]);
00148    }

MessageDataPtr vpr::sim::Message::getMessageData   [inline]
 

Definition at line 151 of file Message.h.

00152    {
00153       return mMsg;
00154    }

vpr::Uint32 vpr::sim::Message::getSize   const [inline]
 

Definition at line 156 of file Message.h.

Referenced by resize.

00157    {
00158       return mMsg->size();
00159    }

vpr::Uint32 vpr::sim::Message::resize const vpr::Uint32    bytes_read
 

Determines if this message needs to be resized after a read.

If the given number of bytes read from the message is less than the actual size, this message is resized to contain only the remaining unread bytes.

Precondition:
This message has had some bytes read.
Postcondition:
The message is resized based on <bytes_read>, and the new size of this message is returned to the caller.
Parameters:
bytes_read  The number of bytes read from this message so far.
Returns:
0 is returned if the message was not resized. This indicates that all the bytes were read.
A value greater than 0 is returned if this message has been resized.

Definition at line 75 of file Message.cpp.

References getSize, and vprASSERT.

00076 {
00077    vpr::Uint32 resize_amount;
00078 
00079    resize_amount = getSize() - bytes_read;
00080 
00081    // Only resize the message if 0 < bytes_read < mMessageSize.
00082    if ( resize_amount > 0 && resize_amount != getSize() ) {
00083 
00084       mMsg->erase(mMsg->begin(), mMsg->begin()+bytes_read);
00085       vprASSERT(resize_amount == mMsg->size());    // Must be this size
00086 
00087       /*
00088       char* data;
00089       vpr::Uint32 i;
00090 
00091       data = (char*) mMsg;
00092 
00093       // If there is still stuff left in the buffer, move it over.
00094       for ( i = 0; i < resize_amount; i++ ) {
00095          data[i] = data[bytes_read + i];
00096       }
00097 
00098       data[i]  = '\0';
00099       mMsgSize = resize_amount;
00100       */
00101    }
00102 
00103    return resize_amount;
00104 }

void vpr::sim::Message::setPath NetworkGraph::VertexListPtr    path,
const vpr::SocketImplSIM   source,
vpr::SocketImplSIM   dest
[inline]
 

Assigns the path that this message will follow.

The pointer to the next hop in the path is set to the beginning of the path, and any previous path information is lost.

Postcondition:
A new path is assigned for this message, and the pointer to the next hop is set to the beginning of the given path.

Definition at line 188 of file Message.h.

References vprASSERT.

00190    {
00191       mMsgPath  = path;
00192       mNextHop  = mMsgPath->begin();
00193       mSrcSock  = source;
00194       mDestSock = dest;
00195 
00196       vprASSERT(mNextHop != mMsgPath->end() && "Path must have at least one value");
00197    }

const NetworkGraph::VertexListPtr& vpr::sim::Message::getPath   const [inline]
 

Returns a constant reference to the path that this message will follow.

Definition at line 202 of file Message.h.

00203    {
00204       return mMsgPath;
00205    }

const vpr::SocketImplSIM* vpr::sim::Message::getSourceSocket   const [inline]
 

Definition at line 207 of file Message.h.

00208    {
00209       return mSrcSock;
00210    }

vpr::SocketImplSIM* vpr::sim::Message::getDestinationSocket   const [inline]
 

Definition at line 212 of file Message.h.

00213    {
00214       return mDestSock;
00215    }

const NetworkGraph::net_vertex_t& vpr::sim::Message::getNextHop   const [inline]
 

Retrieves the next hop (network graph vertex) in the path of this message and returns it to the caller via the by-reference parameter.

Definition at line 221 of file Message.h.

References vprASSERT.

00222    {
00223       vprASSERT(mMsgPath->end() != mNextHop && "Requesting hop past end of path");
00224       return *mNextHop;
00225    }

void vpr::sim::Message::incNextHop bool &    end_of_path [inline]
 

Increment the pointer to the next hop in this message's path as it moves towards its destination.

Definition at line 231 of file Message.h.

00232    {
00233       ++mNextHop;
00234       end_of_path = (mMsgPath->end() == mNextHop);
00235    }


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:47:20 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002