Source

COS 520 Lamport 2 / Message.cpp

Full commit
#include <cstdlib>
#include <iostream>

using namespace std;

#include "Message.hpp"

Message::Message(type::process_id to, type::process_id from, type::time time, type::requestID ID, vote::type v) {
  this->to = to;
  this->from = from;
  this->requestTime = time;
  this->requestID = ID;
  TTA = MaximumTTA;
}

void Message::display() const
{
  cout << "Message (request ID: " << getRequestID() << "): \n";
  cout << "\tTo: " << getTo() << "\tFrom: " << getFrom() << "\n";
  cout << "\tRequest timestamp: " << getRequestTime() << "\n";
  cout << "\tVote: " << getVote() << "\tTTA: " << getTTA() << "\n";
  cout << "\n";
}

type::process_id Message::getTo() const {
  return to;
}

type::process_id Message::getFrom() const {
  return from;
}

type::time Message::getRequestTime() const {
  return requestTime;
}

type::time Message::getTTA() const {
  return TTA;
}

type::requestID Message::getRequestID() const {
  return requestID;
}

Message::vote::type Message::getVote() const {
  return messageVote;
}

void Message::tick() const {
    --TTA;
}

bool Message::hasArrived() const
{
    return (TTA <= 0);
}

bool operator<(const Message &LHS, const Message &RHS)
{
    return LHS.requestID < RHS.requestID;
}