//------------------------------------------------------------------------------
// <copyright file="AddressedPacketEvent.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 AddressedPacketEvent, the front end for a CORBA event that
//  contains messages or status information with a target and/or source event.
// </summary>
//
// <owner>Mike Cookson</owner>
//------------------------------------------------------------------------------

#ifndef __PayloadInterfaceLib_AddressedPacketEvent_H__
#define __PayloadInterfaceLib_AddressedPacketEvent_H__

#include "TelemetryEventBase.h"
#include "LqrSMACAddressableMessageServiceBase.h"

namespace LiquidRobotics {
namespace PayloadInterface {

typedef LiquidRobotics::EventLib::TelemetryEventBase AddressedPacketEventBase;

class SHARED_LIB_PUBLIC AddressedPacketEvent
: public AddressedPacketEventBase
{
public:

	typedef LiquidRobotics::SMACFramework::AddressableMessageServiceBase AMSB;
	typedef LiquidRobotics::SMACFramework::ByteArray ByteArray;
	typedef LiquidRobotics::EventLib::EventSettings EventSettings;

	enum NotifyType
	{
		NT_ENCRYPTED = AMSB::NT_ENCRYPTED,			// encrypted data received
		NT_ENQUEUED = AMSB::NT_ENQUEUED,			// message has been enqueued and intermediary
		NT_PRIMARY = AMSB::NT_PRIMARY,				// primary/command message received
		NT_SECONDARY = AMSB::NT_SECONDARY,			// secondary/acknowledge message received
		NT_TRANSMITTED = AMSB::NT_TRANSMITTED,		// intermediary has been transmitted
		NT_MAX
	};

	typedef std::string string;
	static string ToString(NotifyType notify);

	AddressedPacketEvent(IObjectBroker& _broker, NotifyType notifyType = NT_PRIMARY);
	AddressedPacketEvent(const EventSettings& _eventSettings, IObjectBroker& _broker, NotifyType notifyType = NT_PRIMARY);
	AddressedPacketEvent(const EventName& _eventName, const EventType& _eventType, IObjectBroker& _broker, NotifyType notifyType = NT_PRIMARY);
	AddressedPacketEvent(const EventName& _eventName, const EventType& _eventType, const IOR& _senderIOR, IObjectBroker& _broker, NotifyType notifyType = NT_PRIMARY);
	AddressedPacketEvent(const AddressedPacketEvent& other);

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

	void ClearSourceAddress();
	PropertyValueType::UInt16 GetSourceAddress() const;
	void GetSourceAddress(PropertyValueType::UInt8& boardID, PropertyValueType::UInt8& taskID) const;
	bool HasSourceAddress() const;
	void SetSourceAddress(PropertyValueType::UInt16 boardAddress);
	void SetSourceAddress(PropertyValueType::UInt8 boardID, PropertyValueType::UInt8 taskID);

	void ClearDestAddress();
	PropertyValueType::UInt16 GetDestAddress() const;
	void GetDestAddress(PropertyValueType::UInt8& boardID, PropertyValueType::UInt8& taskID) const;
	bool HasDestAddress() const;
	void SetDestAddress(PropertyValueType::UInt16 boardAddress);
	void SetDestAddress(PropertyValueType::UInt8 boardID, PropertyValueType::UInt8 taskID);

	NotifyType GetNotify() const;
	void SetNotify(NotifyType notifyType);

	void ClearMessage();
	AMSB::ByteArrayPtr GetMessage() const;
	bool HasMessage() const;
	void SetMessage(const ByteArray& msg);

	void ClearTransactionID();
	PropertyValueType::UInt16 GetTransactionID() const;
	bool HasTransactionID() const;
	void SetTransactionID(PropertyValueType::UInt16 transID);

private:

	static const PropertyNameType sourceAddressTag;
	static const PropertyNameType destAddressTag;
	static const PropertyNameType notifyTag;
	static const PropertyNameType messageTag;
	static const PropertyNameType transactionIDTag;
};

}
}

#endif
