//---------------------------------------------------------------------------------------
// <copyright file="PayloadAddressableMessageServiceSettings.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 PayloadAddressableMessageServiceSettings, a serializable entity
//   that holds the configuration settings for PayloadAddressableMessageService
// </summary>
//
// <owner>Mike Cookson</owner>
//---------------------------------------------------------------------------------------

#ifndef __PAYLOADINTERFACELIB_PayloadAddressableMessageServiceSettings_H__
#define __PAYLOADINTERFACELIB_PayloadAddressableMessageServiceSettings_H__

#include <ostream>
#include <set>
#include <string>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/set.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/version.hpp>
#include <boost/serialization/split_member.hpp>
#include "LqrSMACSharedLib.h"
#include "EventSettings.h"

namespace LiquidRobotics {
namespace PayloadInterface {

class SHARED_LIB_PUBLIC PayloadAddressableMessageServiceSettings
{
public:

	typedef LiquidRobotics::EventLib::EventSettings EventSettings;
	typedef std::string string;
	typedef std::pair<string,string> StringPair;
	typedef std::set<StringPair> StringPairSet;
	typedef std::set<string> StringSet;

	PayloadAddressableMessageServiceSettings();
	virtual ~PayloadAddressableMessageServiceSettings();

	const EventSettings& GetTransmitSettings() const;
	bool IsMessageAddressable(const EventSettings& eventIDs) const;

	void Load(const string& fileName);
	void Save(const string& fileName);

	std::ostream& ToStream(std::ostream& stm) const;

private:

	friend class boost::serialization::access;

	template<class Archive>
	void save(Archive & ar, const unsigned int version) const
	{
		ar & BOOST_SERIALIZATION_NVP(enableReceiveNameFilter);
		ar & BOOST_SERIALIZATION_NVP(enableReceiveTypeFilter);
		ar & BOOST_SERIALIZATION_NVP(receiveNames);
		ar & BOOST_SERIALIZATION_NVP(receiveTypes);
		ar & BOOST_SERIALIZATION_NVP(transmitSettings);
	}

	template<class Archive>
    void load(Archive & ar, const unsigned int version)
	{
		ar & BOOST_SERIALIZATION_NVP(enableReceiveNameFilter);
		ar & BOOST_SERIALIZATION_NVP(enableReceiveTypeFilter);
		ar & BOOST_SERIALIZATION_NVP(receiveNames);
		ar & BOOST_SERIALIZATION_NVP(receiveTypes);
		ar & BOOST_SERIALIZATION_NVP(transmitSettings);
	}

	BOOST_SERIALIZATION_SPLIT_MEMBER()

	bool enableReceiveNameFilter;
	bool enableReceiveTypeFilter;
	StringSet receiveNames;
	StringPairSet receiveTypes;
	EventSettings transmitSettings;
};

SHARED_LIB_PUBLIC std::ostream& operator<<(std::ostream& stm, const PayloadAddressableMessageServiceSettings& settings);

}
}

BOOST_CLASS_VERSION(LiquidRobotics::PayloadInterface::PayloadAddressableMessageServiceSettings, 1)

#endif
