102 lines
2.6 KiB
C++
102 lines
2.6 KiB
C++
// Copyright (c) 2011-2024 Squall Line Software, LLC
|
|
// Distributed under the terms of the MIT License
|
|
// See accompanying LICENSE.txt file or
|
|
// http://www.opensource.org/licenses/mit-license.php
|
|
|
|
#ifndef DISORDER_PDU_PDU_HPP
|
|
#define DISORDER_PDU_PDU_HPP
|
|
|
|
#include <disorder/dso_api.hpp>
|
|
|
|
#include <disorder/pdu/record/header.hpp>
|
|
|
|
#include <disorder/time/time_point.hpp>
|
|
|
|
namespace disorder
|
|
{
|
|
|
|
namespace pdu
|
|
{
|
|
|
|
/**
|
|
* PDU serves as the abstract base class for all Protocol Data Units (PDUs).
|
|
*/
|
|
struct DISORDER_DSO_PUBLIC PDU: public record::Record
|
|
{
|
|
/// header that appears at the beginning of all PDUs
|
|
record::Header header;
|
|
|
|
/**
|
|
* Prepares the PDU for sending by filling out various fields in the header
|
|
* and any automatic fields within the PDU itself such as event id fields.
|
|
*
|
|
* This method is automatically called by the system when PDU::send or
|
|
* Exercise::send is called, so disorder users will probably not need to
|
|
* invoke this method directly.
|
|
*/
|
|
virtual void finalize_for_sending();
|
|
|
|
/**
|
|
* Instructs this PDU to finalize its header fields and send itself using
|
|
* all the transports that have been registered with disorder::Exercise.
|
|
*/
|
|
void send();
|
|
|
|
/**
|
|
* Traverses all the fields that makeup this PDU including the header
|
|
* portion.
|
|
*
|
|
* @param visitor visitor that operates on the traversed fields
|
|
*/
|
|
void accept(field::Visitor& visitor) override;
|
|
|
|
/**
|
|
* Traverses the fields that makeup this PDU without the header portion.
|
|
*
|
|
* @param visitor visitor that operates on the traversed fields
|
|
*/
|
|
virtual void accept_without_header(field::Visitor& visitor) = 0;
|
|
|
|
/**
|
|
* This method returns the time at which this PDU was received.
|
|
*
|
|
* Obviously, this method only returns something reasonable for PDUs that
|
|
* have been received from other simulation applications.
|
|
*
|
|
* @return time at which this PDU was received
|
|
*/
|
|
const time::TimePoint& received_at() const
|
|
{
|
|
return received_at_;
|
|
}
|
|
|
|
/**
|
|
* This method sets the time at which this PDU was received.
|
|
*
|
|
* @param time time at which this PDU was received
|
|
*/
|
|
void received_at(const time::TimePoint& time)
|
|
{
|
|
received_at_ = time;
|
|
}
|
|
|
|
protected:
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param type type of this PDU
|
|
* @param family protocol family of this PDU
|
|
*/
|
|
PDU(siso::DISPDUType type, siso::DISProtocolFamily family);
|
|
|
|
private:
|
|
/// local reference and simulation times at which this PDU was received.
|
|
/// This field is only valid for received PDUs and is zeroed otherwise.
|
|
time::TimePoint received_at_;
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif |