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

#include "PayloadInterfaceSettings.h"
#include "LqrSMACLoadSaveBoostXml.h"

using namespace std;
using namespace LiquidRobotics::SMACFramework;
using namespace LiquidRobotics::SMACFramework::BooleanParser;

static const char rootLevel[] = { "rootlevel" };
static const char className[] = { "PayloadInterfaceSettings" };

namespace LiquidRobotics {
namespace PayloadInterface {

PayloadInterfaceSettings::PayloadInterfaceSettings()
: sv3Enabled(false)
, serverName("PayloadInterface")
, serverKind("")
{
}

PayloadInterfaceSettings::~PayloadInterfaceSettings()
{
}

const PayloadInterfaceSettings::StdOutLoggerSettings& PayloadInterfaceSettings::GetLoggerSettings() const
{
	return loggerSettings;
}

void PayloadInterfaceSettings::SetLoggerSettings(const StdOutLoggerSettings& newValue)
{
	loggerSettings = newValue;
}

void PayloadInterfaceSettings::SetPortSettings(const SerialPortSettings& newValue)
{
	serialPortSettings = newValue;
}

void PayloadInterfaceSettings::SetSCSettings(const StorageController::Config& newValue)
{
	scSettings = newValue;
}

void PayloadInterfaceSettings::SetControllerSettings(const PayloadInterfaceController_Config& newValue)
{
	picSettings = newValue;
}


const string& PayloadInterfaceSettings::GetServerName() const
{
	return serverName;
}

void PayloadInterfaceSettings::SetServerName(const string& newValue)
{
	serverName = newValue;
}

const string& PayloadInterfaceSettings::GetServerKind() const
{
	return serverKind;
}

void PayloadInterfaceSettings::SetServerKind(const string& newValue)
{
	serverKind = newValue;
}

void PayloadInterfaceSettings::Load(const string& fileName)
{
	LoadBoostXml(fileName, *this);
}

void PayloadInterfaceSettings::Save(const string& fileName)
{
	SaveBoostXml(fileName, *this);
}

ostream& operator<<(ostream& stm, const PayloadInterfaceSettings& settings)
{
	stm << "sv3Enabled = " << BooleanToString(settings.GetSV3Enabled())
		<< " serialPortSettings = { " << settings.GetPortSettings() << " }"
		<< " sv3NetInterfaceSettings = { " << settings.GetSV3NetInterfaceSettings() << " }"
	    << " scSettings = { " << settings.GetSCSettings() << " }"
	    << " picSettings = { " << settings.GetControllerSettings() << " }"
	    << " serverName = '" << settings.GetServerName() << "'"
	    << " serverKind = '" << settings.GetServerKind() << "'";

	return stm;
}

}
}
