//------------------------------------------------------------------------------
// <copyright file="ProxySC_TransactionInfo.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 ProxySC transaction info class, which holds transaction
//  information (i.e. commands being executed)
// </summary>
//
// <owner>Mike Cookson</owner>
//------------------------------------------------------------------------------

#include "ProxySC.h"
#include "LqrSMACTempFile.h"

using namespace std;
using namespace LiquidRobotics::SMACFramework;

namespace LiquidRobotics {
namespace PayloadInterface {

ProxySC::TransactionInfo::TransactionInfo(bool _fileOriented, string _transID, unsigned _destID, StorageController::FileIDType _fileID, bool _retFile, long _transNumber)
: fileOriented(_fileOriented)
, transID(_transID)
, transNumber(_transNumber)
, destID(_destID)
, fileID(_fileID)
, retFile(_retFile)
, resultNum(0)
{
	if (fileOriented || retFile)
		tempFile.reset(new TempFile);
}

ProxySC::TransactionInfo::TransactionInfo(const TransactionInfo& other)
: fileOriented(other.fileOriented)
, transID(other.transID)
, transNumber(other.transNumber)
, destID(other.destID)
, fileID(other.fileID)
, retFile(other.retFile)
, tempFile(other.tempFile)
{
}

bool ProxySC::TransactionInfo::FileOriented() const						{ return fileOriented; }
void ProxySC::TransactionInfo::GetContent(ByteArray& result)			{ tempFile->GetContent(result); }
const string& ProxySC::TransactionInfo::TransID() const					{ return transID; }
long ProxySC::TransactionInfo::TransNumber() const						{ return transNumber; }
unsigned ProxySC::TransactionInfo::DestID() const						{ return destID; }
StorageController::FileIDType ProxySC::TransactionInfo::FileID() const	{ return fileID; }
void ProxySC::TransactionInfo::Write(const ByteArray& data)				{ tempFile->Write(data); }
unsigned ProxySC::TransactionInfo::ResultNum(unsigned offset)			{ return (resultNum += offset); }
bool ProxySC::TransactionInfo::ReturnFile() const						{ return retFile; }


}
}
