//-----------------------------------------------------------------------------------
// <copyright file="SensorCommandBase.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>
//   Declarations/implementation of SensorCommandBase abstract template class, which
//	 defines the operations that command objects used by the controller.  The template
//	 parameter is the type of command ID class used by the controller (command ID's
//   are used to track commands.)
// </summary>
//
// <owner>Mike Cookson</owner>
//-----------------------------------------------------------------------------------

#ifndef __EventLib_SensorCommandBase_h__
#define __EventLib_SensorCommandBase_h__

#include <string>
#include <boost/shared_ptr.hpp>
#include <LqrSMACCmdOutputFormatter.h>

namespace LiquidRobotics {
namespace EventLib {

template<class TCmdID>
class SensorCommandBase
{
public:

	typedef std::string string;
	typedef SensorCommandBase<TCmdID> SensorCommandBaseT;
	typedef boost::shared_ptr<SensorCommandBaseT> Ptr;
	typedef LiquidRobotics::SMACFramework::CmdOutputFormatter CmdOutputFormatter;

	// each command implements a static Parse method that evaluates parameters and
	// returns a pointer to the base class (SensorCommandBase) or NULL if the
	// parameters don't match; if the parameters do match, but are somehow invalid,
	// a one of the Exception workspace exceptions should be thrown

	// placeholder for destructor if needed
	virtual ~SensorCommandBase() { }

	// this method is called to abort the action
	virtual void Abort(const string& reasonCode) = 0;

	// this method is called after queuing it to evaluate once the action starts;
	// exceptions should be thrown to indicate problems
	virtual void ActionStart() = 0;

	// this method called to wait for completion; exceptions should be thrown to
	// indicate problems
	virtual bool ActionWait(string& result) = 0;

	// this method is called by the background thread to execute the command
	virtual void Execute() = 0;

	// this retrieves the completion parameters for the command
	virtual const TCmdID& GetCompletionParams() const = 0;

	// returns the output formatter used to format responses
	virtual CmdOutputFormatter::Ptr GetOutputFormatter() = 0;

	// get the output of the command
	virtual string GetResult() = 0;

	// returns true if the command is of a type that will block until complete
	// or false if it can return asynchronously
	virtual bool IsBlocking() const = 0;

	// sets the completion parameters for the command
	virtual void SetCompletionParams(const TCmdID& newValue) = 0;

	// sets the output formatter
	virtual void SetOutputFormatter(CmdOutputFormatter::Ptr _formatter) = 0;

	// this method is called to indicate that action has started
	virtual void SignalStarted() = 0;

	// this method is called to indicate that action is complete
	virtual void SignalComplete() = 0;

	// this method returns the state of the success flag
	virtual bool GetSuccessFlag() const = 0;

	// this method sets or clear the underlying success flag
	virtual void SetSuccessFlag(bool newState) = 0;
};

}
}

#endif
