Zhenkai Zhu | 11a0ad4 | 2012-03-05 22:28:33 -0800 | [diff] [blame] | 1 | /* -*- 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 Zhu | 1ac6f80 | 2012-03-06 17:40:27 -0800 | [diff] [blame] | 23 | #ifndef SYNC_APP_DATA_PUBLISH_H |
| 24 | #define SYNC_APP_DATA_PUBLISH_H |
Zhenkai Zhu | 11a0ad4 | 2012-03-05 22:28:33 -0800 | [diff] [blame] | 25 | #include <boost/shared_ptr.hpp> |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 26 | #include <boost/unordered_map.hpp> |
Zhenkai Zhu | 11a0ad4 | 2012-03-05 22:28:33 -0800 | [diff] [blame] | 27 | #include "sync-ccnx-wrapper.h" |
| 28 | |
| 29 | /** |
| 30 | * \defgroup sync SYNC protocol |
| 31 | * |
| 32 | * Implementation of SYNC protocol |
| 33 | */ |
| 34 | namespace Sync { |
| 35 | |
| 36 | /** |
| 37 | * \ingroup sync |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 38 | * @brief publishes application data using incrementing sequence number (for |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 39 | * each sequence namber and keeps track of most recently published data for |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 40 | * each name prefix |
Zhenkai Zhu | 11a0ad4 | 2012-03-05 22:28:33 -0800 | [diff] [blame] | 41 | */ |
| 42 | class AppDataPublish |
| 43 | { |
| 44 | public: |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 45 | AppDataPublish(boost::shared_ptr<CcnxWrapper> ccnxHandle) |
| 46 | { m_ccnxHandle = ccnxHandle; } |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 47 | ~AppDataPublish() {}; |
| 48 | |
| 49 | /** |
| 50 | * @brief get the name (including sequence number) and the content |
| 51 | * (unencoded, just XML stanza) of the most recent published data |
| 52 | * |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 53 | * @param prefix the name prefix to look for |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 54 | * @return the pair of name and content |
| 55 | */ |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 56 | std::pair<std::string, std::string> getRecentData(std::string prefix); |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * brief get the most recent sequence number for a name prefix |
| 60 | */ |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 61 | u_int32_t getHighestSeq(std::string prefix); |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * @brief publish data for a name prefix, updates the corresponding |
| 65 | * sequence number and recent data |
| 66 | * |
| 67 | * @param name data prefix |
| 68 | * @param dataBuffer the data itself |
| 69 | * @param freshness the freshness for the data object |
| 70 | * @return whether the publish succeeded |
| 71 | */ |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 72 | bool publishData(std::string name, std::string dataBuffer, int freshness); |
| 73 | |
Zhenkai Zhu | 11a0ad4 | 2012-03-05 22:28:33 -0800 | [diff] [blame] | 74 | private: |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 75 | boost::unordered_map<std::string, uint32_t> m_sequenceLog; |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 76 | boost::shared_ptr<CcnxWrapper> m_ccnxHandle; |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 77 | boost::unordered_map<std::string, std::string> m_recentData; |
Zhenkai Zhu | 11a0ad4 | 2012-03-05 22:28:33 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // Sync |
| 81 | |
Zhenkai Zhu | 1ac6f80 | 2012-03-06 17:40:27 -0800 | [diff] [blame] | 82 | #endif // SYNC_APP_DATA_PUBLISH_H |