Message.hh revision 7002
16157Snate@binkert.org
26157Snate@binkert.org/*
36157Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
46157Snate@binkert.org * All rights reserved.
56157Snate@binkert.org *
66157Snate@binkert.org * Redistribution and use in source and binary forms, with or without
76157Snate@binkert.org * modification, are permitted provided that the following conditions are
86157Snate@binkert.org * met: redistributions of source code must retain the above copyright
96157Snate@binkert.org * notice, this list of conditions and the following disclaimer;
106157Snate@binkert.org * redistributions in binary form must reproduce the above copyright
116157Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
126157Snate@binkert.org * documentation and/or other materials provided with the distribution;
136157Snate@binkert.org * neither the name of the copyright holders nor the names of its
146157Snate@binkert.org * contributors may be used to endorse or promote products derived from
156157Snate@binkert.org * this software without specific prior written permission.
166157Snate@binkert.org *
176157Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186157Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196157Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206157Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216157Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226157Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236157Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246157Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256157Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266157Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276157Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286157Snate@binkert.org */
296157Snate@binkert.org
306157Snate@binkert.org/*
316157Snate@binkert.org * $Id$
326157Snate@binkert.org */
336157Snate@binkert.org
346157Snate@binkert.org#ifndef MESSAGE_H
356157Snate@binkert.org#define MESSAGE_H
366157Snate@binkert.org
376157Snate@binkert.org#include <iostream>
386157Snate@binkert.org
396157Snate@binkert.org#include "mem/ruby/common/Global.hh"
406168Snate@binkert.org#include "mem/gems_common/RefCnt.hh"
416168Snate@binkert.org#include "mem/gems_common/RefCountable.hh"
426168Snate@binkert.org#include "mem/ruby/eventqueue/RubyEventQueue.hh"
436157Snate@binkert.org
446157Snate@binkert.orgclass Message;
456157Snate@binkert.orgtypedef RefCnt<Message> MsgPtr;
466157Snate@binkert.org
476157Snate@binkert.orgclass Message : public RefCountable {
486157Snate@binkert.orgpublic:
496157Snate@binkert.org  // Constructors
506157Snate@binkert.org  Message() : RefCountable() { m_time = g_eventQueue_ptr->getTime();  m_LastEnqueueTime = g_eventQueue_ptr->getTime(); m_DelayedCycles = 0;}
516157Snate@binkert.org
526157Snate@binkert.org  // Destructor
536157Snate@binkert.org  virtual ~Message() { }
546157Snate@binkert.org
556157Snate@binkert.org  // Public Methods
566157Snate@binkert.org  virtual Message* clone() const = 0;
576157Snate@binkert.org  virtual void destroy() = 0;
586157Snate@binkert.org  virtual void print(std::ostream& out) const = 0;
596157Snate@binkert.org
606157Snate@binkert.org  void setDelayedCycles(const int& cycles) { m_DelayedCycles = cycles; }
616157Snate@binkert.org  const int& getDelayedCycles() const {return m_DelayedCycles;}
626157Snate@binkert.org  int& getDelayedCycles() {return m_DelayedCycles;}
636157Snate@binkert.org  void setLastEnqueueTime(const Time& time) { m_LastEnqueueTime = time; }
646157Snate@binkert.org  const Time& getLastEnqueueTime() const {return m_LastEnqueueTime;}
656157Snate@binkert.org  Time& getLastEnqueueTime() {return m_LastEnqueueTime;}
666157Snate@binkert.org
676157Snate@binkert.org  const Time& getTime() const { return m_time; }
686157Snate@binkert.org  void setTime(const Time& new_time) { m_time = new_time; }
696157Snate@binkert.orgprivate:
706157Snate@binkert.org  // Private Methods
716157Snate@binkert.org
726157Snate@binkert.org  // Data Members (m_ prefix)
736157Snate@binkert.org  Time m_time;
746157Snate@binkert.org  Time m_LastEnqueueTime; // my last enqueue time
756157Snate@binkert.org  int m_DelayedCycles; // my delayed cycles
766157Snate@binkert.org
776157Snate@binkert.org};
786157Snate@binkert.org
796157Snate@binkert.org// Output operator declaration
806157Snate@binkert.orgstd::ostream& operator<<(std::ostream& out, const Message& obj);
816157Snate@binkert.org
826157Snate@binkert.org// ******************* Definitions *******************
836157Snate@binkert.org
846157Snate@binkert.org// Output operator definition
856157Snate@binkert.orgextern inline
866157Snate@binkert.orgstd::ostream& operator<<(std::ostream& out, const Message& obj)
876157Snate@binkert.org{
886157Snate@binkert.org  obj.print(out);
896157Snate@binkert.org  out << std::flush;
906157Snate@binkert.org  return out;
916157Snate@binkert.org}
926157Snate@binkert.org
936157Snate@binkert.org#endif //MESSAGE_H
946157Snate@binkert.org