blob: 85bb9aeaa9bf197d79234ca6c847fe294c63b35b [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
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080025
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"
Zhenkai Zhubc7bfce2012-03-09 14:37:52 -080029#include <utility>
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080030
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080031namespace Sync {
32
Chaoyi Bian4194b742012-03-08 17:21:35 -080033struct Seq
34{
35 uint32_t session;
36 uint32_t seq;
37};
38
Zhenkai Zhu5548e032012-03-12 20:10:15 -070039struct GetSeqException : virtual boost::exception, virtual std::exception { };
40
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080041/**
42 * \ingroup sync
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080043 * @brief publishes application data using incrementing sequence number (for
Chaoyi Bian3e99d862012-03-07 17:28:32 -080044 * each sequence namber and keeps track of most recently published data for
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080045 * each name prefix
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080046 */
47class AppDataPublish
48{
49public:
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080050 AppDataPublish (CcnxWrapperPtr ccnxHandle)
51 : m_ccnxHandle (ccnxHandle)
52 { }
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080053
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080054 /**
55 * @brief get the name (including sequence number) and the content
56 * (unencoded, just XML stanza) of the most recent published data
57 *
58 * @param prefix the name prefix to look for
59 * @param session session
60 * @return the pair of name and content
61 */
62 std::string
63 getRecentData (const std::string &prefix, uint32_t session);
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080064
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080065 /**
66 * @brief get the most recent sequence number for a name prefix
67 * @param prefix the name prefix to look for
68 * @param session session
69 */
70 uint32_t
Zhenkai Zhu1ee93c92012-03-12 20:32:57 -070071 getNextSeq (const std::string &prefix, uint32_t session);
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080072
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080073 /**
74 * @brief publish data for a name prefix, updates the corresponding
75 * sequence number and recent data
76 *
77 * @param name data prefix
78 * @param session session to which data is published
79 * @param dataBuffer the data itself
80 * @param freshness the freshness for the data object
81 * @return whether the publish succeeded
82 */
83 bool publishData (const std::string &name, uint32_t session, const std::string &dataBuffer, int freshness);
Chaoyi Bian3e99d862012-03-07 17:28:32 -080084
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080085private:
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080086 boost::unordered_map<std::string, Seq> m_sequenceLog;
87 CcnxWrapperPtr m_ccnxHandle;
Zhenkai Zhubc7bfce2012-03-09 14:37:52 -080088 boost::unordered_map<std::pair<std::string, uint32_t>, std::string> m_recentData;
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080089};
90
91} // Sync
92
Zhenkai Zhu1ac6f802012-03-06 17:40:27 -080093#endif // SYNC_APP_DATA_PUBLISH_H