/******************************************************************* * * DESCRIPTION: Class MessageBag * * AUTHOR: Alejandro Troccoli * Revised By: Qi (Jacky) Liu * * EMAIL: mailto://atroccol@dc.uba.ar * mailto://liuqi@sce.carleton.ca * * DATE: 19/02/2001 * Revision Date: Sept, 2005 *******************************************************************/ #ifndef __MESSAGEBAG_H #define __MESSAGEBAG_H #include #include #include #include "VTime.hh" #include "JackyDebugStream.h" //for jacky-revision /** forward declarations **/ class BasicPortMessage; /*Revision Note: *We will create a subclass of this class MessageBag. This subtype is for *Node Coordinator use only. It is called "NCMessageBag". The differences *between this MessageBag and the NCMessageBag are listed as follows: *1. Since we cannot assume any synchronization between the node coordinators * on different machines, the NCMessageBag may contain msgs that have different * sendTime. Thus, the add(const BasicPortMessage*) function in this class is * made virtual to be overridden in class NCMessageBag. *2. The "msgtime" in class NCMessageBag should reflect the MIN time stamp among * all msgs in the bag rather than just the common time stamp of the msgs in the * bag. *3. Extra functions will be added in class NCMessageBag to remove msgs that have * greater time stamps than the specified time. The removal should only happen * on those msgs that were sent from a specific node coordinator, which caused * the rollback on the receiving node coordinator that has the NCMessageBag. * This is for the rollback mechanism. Specifically, the rollbackCheck() function * in the node coordinator will remove these msgs to restore the content of the * NCMessageBag to a previous state. *All other ParallelProcessors, including the flat coordinators and simualtors will *still use the MessageBag that is defined in class ParallelProcessor. The node *coordinator will define its own NCMessageBag. * *Note: *1. The previously private data members in this class have been declared as protected * to facilitate the inheritance of the class. *2. The destructor of this class is made virtual as well to allow proper cleanup of the * resources. */ class MessageBag { public: typedef list MessageList; protected: typedef map< string, MessageList , less< string > > MessagesOnPort; MessagesOnPort msgs; int count; VTime msgtime; public: MessageBag(); //Default Constructor virtual ~MessageBag(); virtual MessageBag &add( const BasicPortMessage* ); bool portHasMsgs( const string& portName ) const; const MessageList& msgsOnPort( const string& portName ) const; int size() const {return count;} MessageBag& eraseAll(); const VTime& time() const {return msgtime;} struct iterator { iterator(); iterator( const MessagesOnPort::const_iterator &begin, const MessagesOnPort::const_iterator &end, const MessageList* currentList); iterator( const MessagesOnPort::const_iterator &begin, const MessagesOnPort::const_iterator &end ); iterator &operator ++(int) ; const BasicPortMessage *operator *() const; bool operator ==( const iterator &it ) const; iterator &operator=( const iterator &it ); MessagesOnPort::const_iterator msgsxport, msgsEnd; const MessageList *currentList; MessageList::const_iterator msgs; }; iterator begin() const; iterator end() const; #ifdef JACKY_DEBUG //================================================= //Jacky: this function prints out the whole MessageBag friend ostream& operator<<(ostream&, const MessageBag&); #endif //end JACKY_DEBUG ============================================= }; // MessageBag /** Inline Functions **/ inline MessageBag::iterator::iterator() : currentList(NULL) {} #endif //__MESSAGEBAG_H