//-------------------------------------------------------------------------------------------------
// <copyright file="LWSetTraceOptionsInternalCmd.cpp" company="LiquidRobotics">
//  Copyright (c) Liquid Robotics Corporation, confidential and proprietary.  All rights reserved. 
// </copyright>
//
// <summary>
//	Implementation of LWSetTraceOptionsInternalCmd, a delegate class that sets trace
//  options for a lua instance.
// </summary>
//
// <owner>Mike Cookson</owner>
//-------------------------------------------------------------------------------------------------

#include "LWController.h"
#include "LWSetTraceOptionsInternalCmd.h"
#include "LqrSMACLogger.h"

using namespace std;
using namespace LiquidRobotics::SMACFramework;

namespace LiquidRobotics {
namespace LuaWrapper {

LWSetTraceOptionsInternalCmd::LWSetTraceOptionsInternalCmd(TCon& _ctrl, const string& _cmd, const string& _instanceName, const int _traceOpts)
: LWConcreteCmd(_ctrl)
, ctrl(_ctrl)
, cmd(_cmd)
, instanceName(_instanceName)
, traceOpts(_traceOpts)
{
}

LWSetTraceOptionsInternalCmd::~LWSetTraceOptionsInternalCmd()
{
}

void LWSetTraceOptionsInternalCmd::Execute()
{
	typedef boost::shared_ptr<LuaInstance> LuaInstancePtr;

	try
	{
		SignalStarted();
		ctrl.SetTraceOptionsInternal(instanceName, traceOpts);
		SetException(TEx::NoException, "");
	}
	catch(exception& ex)
	{
		const int exNum = TEx::ExceptionToNumber(ex);

		stringstream msg;
		msg << "caught exception " << typeid(ex).name() << " '" << ex.what() << "'";

		SetException(exNum, msg.str());
	}
	catch(...)
	{
		TEx::NotReady exc("");
		const int exNum = TEx::ExceptionToNumber(exc);

		SetException(exNum, "caught unknown exception");
	}
}

// get the output of the command
string LWSetTraceOptionsInternalCmd::GetResult()
{
	DoThrow();
	return "OK";
}


}
}
