//------------------------------------------------------------------------------
// <copyright file="SBDPacketEvent.h" company="LiquidRobotics">
//
// Copyright (c) 2014 Liquid Robotics, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// This software is associated with a release.  Liquid Robotics makes no
// representation that the design, interfaces or component distribution will
// remain unchanged in future releases.
//
// </copyright>
//
// <summary>
//   Declaration of the SBDPacketEvent class, which carries packet data being
//   sent from the SMC or received into the SMC.
// </summary>
//
// <owner>Mike Cookson</owner>
//------------------------------------------------------------------------------

#ifndef __EVENTLIB_SBDPACKETEVENT_H__
#define	__EVENTLIB_SBDPACKETEVENT_H__

#include "TelemetryEventBase.h"

namespace LiquidRobotics {
namespace EventLib {

class SHARED_LIB_PUBLIC SBDPacketEvent : public TelemetryEventBase
{
public:

	typedef TelemetryEventBase Base;
	typedef LiquidRobotics::SMACFramework::ByteArray ByteArray;

	SBDPacketEvent(IObjectBroker& _broker);
	SBDPacketEvent(const EventSettings& _eventSettings, IObjectBroker& _broker);
	SBDPacketEvent(const EventName& _eventName, const EventType& _eventType, IObjectBroker& _broker);
	SBDPacketEvent(const EventName& _eventName, const EventType& _eventType, const IOR& _senderIOR, IObjectBroker& _broker);
	SBDPacketEvent(const SBDPacketEvent& other);

	virtual ostream& Describe(ostream& stm) const;
	virtual IEventBase::Ptr Duplicate() const;

    bool HasPacketData() const;
	void GetPacketData(ByteArray& content) const;
	void SetPacketData(const ByteArray& content);

    enum PacketDirection
    {
        RECEIVED_FROM_COMM_CHANNEL,
        SENDING_TO_COMM_CHANNEL,
        DIRECTION_NOT_SPECIFIED
    };

    PacketDirection GetPacketDirection() const;
    void SetPacketDirection(PacketDirection newValue);

    bool HasPacketSerialNumber() const;
    uint32_t GetPacketSerialNumber() const;
    void SetPacketSerialNumber(uint32_t newValue);

    bool HasPriority() const;
    uint16_t GetPriority() const;
    void SetPriority(uint16_t newValue);

    bool HasReferenceID() const;
    uint16_t GetReferenceID() const;
    void SetReferenceID(uint16_t newValue);

    bool HasTransactionID() const;
    uint32_t GetTransactionID() const;
    void SetTransactionID(uint32_t newValue);

    bool HasTimeToLive() const;
    uint32_t GetTimeToLive() const;
    void SetTimeToLive(uint32_t newValue);

    enum QueuePosition
    {
        QUEUE_END = 0,                  // put the message at the end of the queue (FIFO)
        QUEUE_FRONT = 1,                // put the message at the start of the queue (LIFO)
        QUEUE_LATEST_AT_FRONT = 2       // put the message at the start of the queue (LIFO), but move it to the end if another message arrives (FIFO)
    };

    bool HasQueueStrategy() const;
    QueuePosition GetQueueStrategy() const;
    void SetQueueStrategy(QueuePosition newValue);

    enum Disposition
    {
        DISP_SUCCESS = 0,                // message was sent successfully
        DISP_TOO_LONG = 1,               // message could not be sent because it was too long
        DISP_TIMEOUT = 2,                // message took longer than time to live
        DISP_ZERO_LENGTH = 3             // message is zero length
    };

    bool HasDisposition() const;
    Disposition GetDisposition() const;
    void SetDisposition(Disposition newValue);

private:

	static const PropertyNameType DataTag;
	static const PropertyNameType PriorityTag;
	static const PropertyNameType DirectionTag;
	static const PropertyNameType PSNTag;
	static const PropertyNameType TransactionIDTag;
	static const PropertyNameType TimeToLiveTag;
	static const PropertyNameType QueueStrategyTag;
    static const PropertyNameType DispositionTag;
    static const PropertyNameType ReferenceIDTag;
};

}
}

#endif	/* __EVENTLIB_SBDPACKETEVENT_H__ */

