//-------------------------------------------------------------------------------------------------
// <copyright file="ServerExecSettings.h" company="LiquidRobotics">
//  Copyright (c) Liquid Robotics Corporation, confidential and proprietary.  All rights reserved. 
// </copyright>
//
// <summary>
// Declarations for ServerExecSettings, a serializable entity class that holds the settings for
// the ServerExec module
// </summary>
//
// <owner>Mike Cookson</owner>
//-------------------------------------------------------------------------------------------------

#ifndef __SERVEREXECSETTINGS_H__
#define __SERVEREXECSETTINGS_H__

#include "EventSettings.h"
#include "EventTransceiver.h"
#include "PayloadAddressableMessageServiceSettings.h"
#include "PayloadManagerClientSettings.h"
#include <string>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/version.hpp>

class ServerExecSettings
{
public:

	typedef LiquidRobotics::EventLib::EventSettings EventSettings;
	typedef LiquidRobotics::EventLib::EventTransceiver::Settings EventTransceiverSettings;
	typedef LiquidRobotics::EventLib::PayloadManagerClientSettings PayloadManagerClientSettings;
	typedef LiquidRobotics::PayloadInterface::PayloadAddressableMessageServiceSettings PayloadAddressableMessageServiceSettings;
	typedef std::string string;

	ServerExecSettings();

	const string& GetServerBaseName()												{ return serverBaseName; }
	void SetServerBaseName(const string& newValue)									{ serverBaseName = newValue; }

	const string& GetServerType()													{ return serverType; }
	void SetServerType(const string& newValue)										{ serverType = newValue; }

	size_t GetMaxCommandSize() const												{ return maxCommandSize; }
	void SetMaxCommandSize(size_t newValue)											{ maxCommandSize = newValue; }

	const EventSettings& GetCommandCompleteEventSettings() const					{ return commandCompleteEvent; }
	void SetCommandCompleteEventSettings(const EventSettings& newValue)				{ commandCompleteEvent = newValue; }

	const EventTransceiverSettings& GetEventTransceiverSettings() const				{ return etSettings; }
	void SetEventTransceiverSettings(const EventTransceiverSettings& newValue)		{ etSettings = newValue; }

	const PayloadAddressableMessageServiceSettings& GetAddressableMessageServiceSettings() const { return pamssSettings; }
	void SetAddressableMessageServiceSettings(const PayloadAddressableMessageServiceSettings& newValue) { pamssSettings = newValue; }

	const EventSettings& GetTransmitRemoteCommandSettings() const					{ return transmitRemoteCommandEvent; }
	void SetTransmitRemoteCommandSetings(const EventSettings& newValue)				{ transmitRemoteCommandEvent = newValue; }

	const string& GetSemaphoreFileName() const										{ return semaphoreFileName; }
	void SetSemaphoreFileName(const string& newValue)								{ semaphoreFileName = newValue; }

	const PayloadManagerClientSettings& GetPMSettings() const						{ return pmSettings; }
	void SetPMSettings(const PayloadManagerClientSettings& newValue)				{ pmSettings = newValue; }

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

private:

	friend class boost::serialization::access;

	template<class Archive>
	void load(Archive & ar, const unsigned int version)
	{
		ar & BOOST_SERIALIZATION_NVP(serverBaseName);					// 1
		ar & BOOST_SERIALIZATION_NVP(serverType);						// 1
		ar & BOOST_SERIALIZATION_NVP(maxCommandSize);					// 1
		ar & BOOST_SERIALIZATION_NVP(commandCompleteEvent);				// 1
		ar & BOOST_SERIALIZATION_NVP(etSettings);						// 1

		if (version >= 2)
		{
			ar & BOOST_SERIALIZATION_NVP(transmitRemoteCommandEvent);		// 2
			ar & BOOST_SERIALIZATION_NVP(semaphoreFileName);				// 2
			ar & BOOST_SERIALIZATION_NVP(pmSettings);						// 2
			ar & BOOST_SERIALIZATION_NVP(pamssSettings);					// 2
		}
	}

	template<class Archive>
	void save(Archive & ar, const unsigned int version) const
	{
		ar & BOOST_SERIALIZATION_NVP(serverBaseName);					// 1
		ar & BOOST_SERIALIZATION_NVP(serverType);						// 1
		ar & BOOST_SERIALIZATION_NVP(maxCommandSize);					// 1
		ar & BOOST_SERIALIZATION_NVP(commandCompleteEvent);				// 1
		ar & BOOST_SERIALIZATION_NVP(etSettings);						// 1
		ar & BOOST_SERIALIZATION_NVP(transmitRemoteCommandEvent);		// 2
		ar & BOOST_SERIALIZATION_NVP(semaphoreFileName);				// 2
		ar & BOOST_SERIALIZATION_NVP(pmSettings);						// 2
		ar & BOOST_SERIALIZATION_NVP(pamssSettings);					// 2
	}

	BOOST_SERIALIZATION_SPLIT_MEMBER()

	const string rootLevel;
	const string className;
	string serverBaseName;
	string serverType;
	size_t maxCommandSize;
	EventSettings commandCompleteEvent;
	EventTransceiverSettings etSettings;
	EventSettings transmitRemoteCommandEvent;
	string semaphoreFileName;
	PayloadManagerClientSettings pmSettings;
	PayloadAddressableMessageServiceSettings pamssSettings;
};

BOOST_CLASS_VERSION(ServerExecSettings, 2)

#endif
