/*
 * Copyright (c) 2015, University of Kaiserslautern
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors:
 *    Janik Schlemminger
 *    Matthias Jung
 */

#ifndef SCHEDULEDCOMMAND_H_
#define SCHEDULEDCOMMAND_H_

#include <systemc.h>
#include <tlm.h>
#include "../../Command.h"
#include "../../../common/dramExtension.h"
#include "../../../common/Utils.h"

class ScheduledCommand
{
public:

    ScheduledCommand(Command command, sc_time start, sc_time executionTime,
                     const DramExtension &extension) :
        command(command), start(start), executionTime(executionTime),
        end(start + executionTime),
        extension(extension)
    {
    }

    ScheduledCommand(Command command, sc_time start, sc_time executionTime,
                     const tlm::tlm_generic_payload &payload) :
        ScheduledCommand(command, start, executionTime,
                         DramExtension::getExtension(payload))
    {
    }

    ScheduledCommand() :
        command(Command::NOP), start(SC_ZERO_TIME), executionTime(SC_ZERO_TIME),
        end(SC_ZERO_TIME), extension()
    {
    }

    bool isNoCommand() const;
    bool isValidCommand() const;

    const sc_time getStart() const;
    void setStart(sc_time newStart);
    void delayStart(sc_time delay);
    void establishMinDistanceFromStart(sc_time previous, sc_time constraint);

    sc_time getEnd() const;
    Command getCommand() const;
    sc_time getExecutionTime() const;

    Bank getBank() const;
    BankGroup getBankGroup() const;
    Row getRow() const;

    unsigned int getBurstLength() const;
    bool operator ==(const ScheduledCommand &b) const;
    bool commandIsIn(const std::vector<Command> &commandSet) const;

    TimeInterval getIntervalOnDataStrobe() const;

private:
    Command command;
    sc_time start;
    sc_time executionTime;
    sc_time end;
    DramExtension extension;
};

#endif /* SCHEDULEDCOMMAND_H_ */

