//-------------------------------------------------------------------------------------------------
// <copyright file="SETestCommand.cpp" company="LiquidRobotics">
//  Copyright (c) Liquid Robotics Corporation, confidential and proprietary.  All rights reserved. 
// </copyright>
//
// <summary>
//	 Example TEST command
// </summary>
//
// <owner>Mike Cookson</owner>
//-------------------------------------------------------------------------------------------------

#include "SETestCommand.h"
#include "LqrSMACCmdLineParser.h"

using namespace std;
using namespace LiquidRobotics::SMACFramework;

namespace LiquidRobotics {
namespace SensorExample {

SETestCommand::SETestCommand(TCon& _ctrl, const StringArray& _args, Logger& _logger)
: Base(_ctrl)
, ctrl(_ctrl)
, logger(_logger)
, sem(0)
, args(_args.begin(), _args.end())
{
}

SETestCommand::~SETestCommand()
{
}

// this method is called by the background thread to execute the command
void SETestCommand::Execute()
{
	SignalStarted();

	sleep(3);

	if (formatter)
	{
		formatter->AppendOutput("Here is output 1");
		formatter->AppendOutput("Here is output 2");
		formatter->AppendOutput("Here is output 3");
	}

	SetException(TEx::NoException, "");
}

// parse the command
SETestCommand::CmdPtr SETestCommand::Parse(const string& arg1, const string& arg2, TCon& ctrl, const CmdLineParser& parser, ParsingContext& context, Logger& logger)
{
	CmdPtr result;
	const StringArray& tokens = parser.GetTokens();

	if (tokens.size() >= 2)
	{
		if (boost::iequals(tokens[0], arg1) && boost::iequals(tokens[1], arg2))
		{
			if (tokens.size() > 2)
				throw invalid_argument("Too many arguments");

			result.reset(new SETestCommand(ctrl, tokens, logger));
		}
	}

	return result;
}


}
}
