blob: 269b3795106ace3ca917b96450696e1c1563d055 [file] [log] [blame]
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
20 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#ifndef SYNC_STATE_H
24#define SYNC_STATE_H
25
26#include <tinyxml.h>
27#include <boost/shared_ptr.hpp>
28#include "sync-diff-state.h"
29#include "sync-full-state.h"
30
31
32/**
33 * \defgroup sync SYNC protocol
34 *
35 * Implementation of SYNC protocol
36 */
37namespace Sync {
38
39/**
40 * \ingroup sync
Zhenkai Zhudfab1d02012-03-05 23:42:30 -080041 * @brief DataBuffer Interface
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080042 */
43class DataBuffer {
Zhenkai Zhudfab1d02012-03-05 23:42:30 -080044public:
45 virtual ~DataBuffer() = 0;
46 virtual size_t length() = 0;
47 virtual const unsigned char *buffer() = 0;
48 virtual void setBufferAndLength(const unsigned char *buffer, size_t len) =
49 0;
50};
51
52/**
53 * \ingroup sync
54 * @brief general Data Buffer class, mainly works for app data
55 */
56class AppDataBuffer:DataBuffer {
57public:
58 AppDataBuffer() {m_buffer = NULL; m_len = 0;}
59 AppDataBuffer(const unsigned char *buffer, size_t len);
60 AppDataBuffer(const DataBuffer *DataBuffer);
61 AppDataBuffer &operator=(const DataBuffer *DataBuffer);
62 virtual void setBufferAndLength(const unsigned char *buffer, size_t len);
63 virtual ~DataBuffer();
64 virtual size_t length() {return len;}
65 virtual const unsigned char *buffer() { return const_cast<const unsigned char *> (buffer); }
66
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080067private:
68 unsigned char *m_buffer;
69 size_t m_len;
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080070};
71
72
73
Zhenkai Zhudfab1d02012-03-05 23:42:30 -080074/**
75 * \ingroup sync
76 * @brief decorator class, wrapper for sync data; converts to and from states
77 */
78class SyncDataBuffer : DataBuffer{
79public:
80 SyncDataBuffer(DataBuffer *dataBuffer) { m_dataBuffer = dataBuffer;}
81 virtual ~SyncDataBuffer(){};
82 virtual size_t length() {m_dataBuffer->length();}
83 virtual const unsigned char *buffer() {m_dataBuffer->buffer();}
84 virtual void setBufferAndLength(const unsigned char *buffer, size_t len)
85 {m_dataBuffer->setBufferAndLength(buffer, len); }
86
87 SyncDataBuffer &operator<<(FullState &fs);
88 SyncDataBuffer &operator<<(DiffState &ds);
89
90 FullState &operator>>(FullState &fs);
91 DiffState &operator>>(DiffState &ds);
92
93private:
94 boost::shared_ptr<DataBuffer> m_dataBuffer;
95};
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080096
97} // Sync
98
99#endif // SYNC_STATE_H