//---------------------------------------------------------------------------------
// <copyright file="TelemetryEventBase.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>
//   Declarations for TelemetryEventBase, an IEventBase-derived class that includes
//   the option to set various commonly-used telemetry fields.  Events that derive
//   from TelemetryEventBase are not necessarily used for telemetry.
// </summary>
//
// <owner>Mike Cookson</owner>
//---------------------------------------------------------------------------------

#ifndef __EVENTLIB_TELEMETRYEVENTBASE_H__
#define __EVENTLIB_TELEMETRYEVENTBASE_H__

#include "EventBase.h"
#include <boost/shared_ptr.hpp>

namespace LiquidRobotics {
namespace EventLib {

class SHARED_LIB_PUBLIC TelemetryEventBase : public EventBase
{
public:

	typedef LiquidRobotics::EventLib::EventName EventName;
	typedef LiquidRobotics::EventLib::EventType EventType;
	typedef LiquidRobotics::EventLib::IOR IOR;
	typedef std::string string;
	typedef boost::shared_ptr<TelemetryEventBase> Ptr;

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

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

	void ClearGeneratorAddress();
	EventPropertyValue::UInt16 GetGeneratorAddress() const;
	void GetGeneratorAddress(EventPropertyValue::UInt8& boardID, EventPropertyValue::UInt8& taskID) const;
	bool HasGeneratorAddress() const;
	void SetGeneratorAddress(EventPropertyValue::UInt16 boardAddress);
	void SetGeneratorAddress(EventPropertyValue::UInt8 boardID, EventPropertyValue::UInt8 taskID);

	void ClearGenerationTime();
	timeval GetGenerationTime() const;						// timeval's time_t should always be relative to local time
	bool HasGenerationTime() const;
	void SetGenerationTime(const timeval& newValue);		// timeval's time_t should always be relative to local time

	void ClearGenerationLocation();
	void GetGenerationLocation(EventPropertyValue::Int32& latitude, EventPropertyValue::Int32& longitude) const;
	void GetGenerationLocation(EventPropertyValue::DoubleFloat& latitude, EventPropertyValue::DoubleFloat& longitude) const;
	bool HasGenerationLocation() const;
	void SetGenerationLocation(const EventPropertyValue::Int32& latitude, const EventPropertyValue::Int32& longitude);
	void SetGenerationLocation(const EventPropertyValue::DoubleFloat& latitude, const EventPropertyValue::DoubleFloat& longitude);

	//void ClearTargetAddress();
	//EventPropertyValue::UInt16 GetTargetAddress() const;
	//void GetTargetAddress(EventPropertyValue::UInt8& boardID, EventPropertyValue::UInt8& taskID) const;
	//bool HasTargetAddress() const;
	//void SetTargetAddress(EventPropertyValue::UInt16 boardAddress);
	//void SetTargetAddress(EventPropertyValue::UInt8 boardID, EventPropertyValue::UInt8 taskID);

	static EventPropertyValue::Int32 ConvertDoublePosToInt(EventPropertyValue::DoubleFloat dblLoc);
	static EventPropertyValue::DoubleFloat ConvertIntPosToDouble(EventPropertyValue::Int32 intLoc);

	static const PropertyNameType T_BoardIDTag;
	static const PropertyNameType T_TaskIDTag;
	static const PropertyNameType T_LatitudeTag;
	static const PropertyNameType T_LongitudeTag;
	static const PropertyNameType T_GenerationTimeTagSec;
	static const PropertyNameType T_GenerationTimeTagMicroSec;
	static const PropertyNameType T_TargetBoardIDTag;
	static const PropertyNameType T_TargetTaskIDTag;

private:

	void Init();

};

}
}

#endif
