blob: 10829048a584e5ce0ec0f77510e9efab02dc34e7 [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
Zhenkai Zhu1ac6f802012-03-06 17:40:27 -080023#ifndef SYNC_APP_DATA_PUBLISH_H
24#define SYNC_APP_DATA_PUBLISH_H
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080025#include <boost/shared_ptr.hpp>
Chaoyi Bian3e99d862012-03-07 17:28:32 -080026#include <boost/unordered_map.hpp>
Chaoyi Bian4194b742012-03-08 17:21:35 -080027#include "sync-seq-no.h"
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080028#include "sync-ccnx-wrapper.h"
29
30/**
31 * \defgroup sync SYNC protocol
32 *
33 * Implementation of SYNC protocol
34 */
35namespace Sync {
36
Chaoyi Bian4194b742012-03-08 17:21:35 -080037struct Seq
38{
39 uint32_t session;
40 uint32_t seq;
41};
42
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080043/**
44 * \ingroup sync
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080045 * @brief publishes application data using incrementing sequence number (for
Chaoyi Bian3e99d862012-03-07 17:28:32 -080046 * each sequence namber and keeps track of most recently published data for
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080047 * each name prefix
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080048 */
49class AppDataPublish
50{
51public:
Chaoyi Bian3e99d862012-03-07 17:28:32 -080052 AppDataPublish(boost::shared_ptr<CcnxWrapper> ccnxHandle)
53 { m_ccnxHandle = ccnxHandle; }
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080054 ~AppDataPublish() {};
55
56 /**
57 * @brief get the name (including sequence number) and the content
58 * (unencoded, just XML stanza) of the most recent published data
59 *
Chaoyi Bian3e99d862012-03-07 17:28:32 -080060 * @param prefix the name prefix to look for
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080061 * @return the pair of name and content
62 */
Chaoyi Bian4194b742012-03-08 17:21:35 -080063 std::string getRecentData(std::string prefix, uint32_t session);
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080064
65 /**
66 * brief get the most recent sequence number for a name prefix
67 */
Chaoyi Bian4194b742012-03-08 17:21:35 -080068 u_int32_t getHighestSeq(std::string prefix, uint32_t session);
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080069
70 /**
71 * @brief publish data for a name prefix, updates the corresponding
72 * sequence number and recent data
73 *
74 * @param name data prefix
75 * @param dataBuffer the data itself
76 * @param freshness the freshness for the data object
77 * @return whether the publish succeeded
78 */
Chaoyi Bian4194b742012-03-08 17:21:35 -080079 bool publishData(std::string name, uint32_t session, std::string dataBuffer, int freshness);
Chaoyi Bian3e99d862012-03-07 17:28:32 -080080
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080081private:
Chaoyi Bian4194b742012-03-08 17:21:35 -080082 boost::unordered_map<std::string, Seq> m_sequenceLog;
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080083 boost::shared_ptr<CcnxWrapper> m_ccnxHandle;
Chaoyi Bian3e99d862012-03-07 17:28:32 -080084 boost::unordered_map<std::string, std::string> m_recentData;
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080085};
86
87} // Sync
88
Zhenkai Zhu1ac6f802012-03-06 17:40:27 -080089#endif // SYNC_APP_DATA_PUBLISH_H