/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2012 University of California, Los Angeles
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
 *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
 *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
 */

#ifndef SYNC_STATE_H
#define SYNC_STATE_H

#include <tinyxml.h>
#include <boost/shared_ptr.hpp>
#include <boost/exception/all.hpp>
#include "sync-diff-state.h"
#include "sync-full-state.h"


/**
 * \defgroup sync SYNC protocol
 *
 * Implementation of SYNC protocol
 */
namespace Sync {

/**
 * \ingroup sync
 * @brief DataBuffer Interface to be used by CcnxWrapper and all other data
 * publish/request/processing related functions
 */
class DataBuffer {
public:
	virtual ~DataBuffer() = 0;
	virtual size_t length() = 0; 
	virtual const unsigned char *buffer() = 0;
	virtual void setBufferAndLength(const unsigned char *buffer, size_t len) =
	0;
};

/**
 * \ingroup sync
 * @brief general Data Buffer class, mainly works for app data
 */
class AppDataBuffer:DataBuffer {
public:
	AppDataBuffer() {m_buffer = NULL; m_len = 0;}
	AppDataBuffer(const unsigned char *buffer, size_t len);
	AppDataBuffer(const DataBuffer *DataBuffer);
	AppDataBuffer &operator=(const DataBuffer *DataBuffer);

	/**
	 * @brief reset the buffer and len
	 */
	virtual void setBufferAndLength(const unsigned char *buffer, size_t len);
	virtual ~AppDataBuffer();
	virtual size_t length() {return m_len;}
	virtual const unsigned char *buffer() { return const_cast<const unsigned
	char *> (m_buffer); }

private:
	unsigned char *m_buffer;
	size_t m_len;
};



/**
 * \ingroup sync
 * @brief decorator class, wrapper for sync data; converts to and from states
 */
class SyncDataBuffer : DataBuffer{
public:
	/**
	 * @brief decorates some object that implements DataBuffer interface
	 * primary usage here is to decorate AppDataBuffer
	 */
	SyncDataBuffer(DataBuffer *dataBuffer) { m_dataBuffer = dataBuffer;}
	virtual ~SyncDataBuffer(){};	
	virtual size_t length() {m_dataBuffer->length();}
	virtual const unsigned char *buffer() {m_dataBuffer->buffer();}
	virtual void setBufferAndLength(const unsigned char *buffer, size_t len)
	{m_dataBuffer->setBufferAndLength(buffer, len); }

	/**
	 * @brief convert from FullState to SyncDataBuffer
	 */
	SyncDataBuffer &operator<<(FullState &fs);

	/**
	 * @brief convert from DiffState to SyncDataBuffer
	 */
	SyncDataBuffer &operator<<(DiffState &ds);

	/**
	 * @brief convert from SyncDataBuffer to FullState, throws
	 * SyncDataBufferConvertException if convert fails
	 */
	SyncDataBuffer &operator>>(FullState &fs);

	/**
	 * @brief convert from SyncDataBuffer to DiffState, throws
	 * SyncDataBufferConvertException if convert fails
	 */
	SyncDataBuffer &operator>>(DiffState &ds);

private:
	boost::shared_ptr<DataBuffer> m_dataBuffer;
};

struct SyncDataBufferConvertException : virtual boost::exception {};

} // Sync

#endif // SYNC_STATE_H
