//----------------------------------------------------------------------------------
// <copyright file="LqrSMACStdOutLoggerSettings.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 StdOutLoggerSettings class, a serializable entity that holds the
//   configuration settings for an instance of StdOutLogger
// </summary>
//
// <owner>Mike Cookson</owner>
//----------------------------------------------------------------------------------

#ifndef __StdOutLoggerSettings_H__
#define __StdOutLoggerSettings_H__

#include <iostream>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/shared_ptr.hpp>
#include "LqrSMACLogger.h"

namespace LiquidRobotics {
namespace SMACFramework {

class SHARED_LIB_PUBLIC StdOutLoggerSettings
{
public:

	typedef Logger::LogType LogType;
	typedef std::string string;

	StdOutLoggerSettings();
	StdOutLoggerSettings(LogType _lt, const string& _procName, bool _isFileDes, int _fd, const string& _fileName, const string& _pipeName);

	virtual ~StdOutLoggerSettings();

	StdOutLoggerSettings& operator=(const StdOutLoggerSettings& right);
	bool operator==(const StdOutLoggerSettings& right) const;

	string ToString() const;

	LogType GetLogLevel() const;
	void SetLogLevel(LogType newValue);

	const string& GetProcessName() const;
	void SetProcessName(const string& newValue);

	bool IsFileDescriptorBased() const;
	bool IsPipeBased() const;

	int GetFileDescriptor() const;
	void SetFileDescriptor(int newValue);

	const string& GetFileName() const;
	void SetFileName(const string& newValue);

	const string& GetPipeName() const;
	void SetPipeName(const string& newValue);

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

private:

	friend class boost::serialization::access;

	template<class Archive>
	void save(Archive& ar, const unsigned int version) const
	{
		string logLevelStr;

		Logger::ToString(logLevel, logLevelStr);
		ar & boost::serialization::make_nvp("logLevel", logLevelStr);

		ar & BOOST_SERIALIZATION_NVP(processName);
		ar & BOOST_SERIALIZATION_NVP(isFileDes);
		ar & BOOST_SERIALIZATION_NVP(fileDes);
		ar & BOOST_SERIALIZATION_NVP(fileName);
		ar & BOOST_SERIALIZATION_NVP(pipeName);
	}

	template<class Archive>
	void load(Archive& ar, const int version)
	{
		string logLevelStr;

		ar & boost::serialization::make_nvp("logLevel", logLevelStr);
		Logger::FromString(logLevelStr, logLevel);

		ar & BOOST_SERIALIZATION_NVP(processName);
		ar & BOOST_SERIALIZATION_NVP(isFileDes);
		ar & BOOST_SERIALIZATION_NVP(fileDes);
		ar & BOOST_SERIALIZATION_NVP(fileName);
		ar & BOOST_SERIALIZATION_NVP(pipeName);
	}

	BOOST_SERIALIZATION_SPLIT_MEMBER()

	LogType logLevel;
	string processName;
	bool isFileDes;
	int fileDes;
	string fileName;
	string pipeName;
};

SHARED_LIB_PUBLIC std::ostream& operator<<(std::ostream& out, const StdOutLoggerSettings& settings);

}
}

#endif /* SERIALPORTSETTINGS_H_ */
