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 | */ |
Chaoyi Bian | 3e99d86 | 2012-03-07 17:28:32 -0800 | [diff] [blame] | 22 | |
| 23 | #include "sync-app-data-publish.h" |
| 24 | |
| 25 | using namespace std; |
| 26 | using namespace boost; |
| 27 | |
| 28 | namespace Sync |
| 29 | { |
| 30 | |
| 31 | pair<string, string> AppDataPublish::getRecentData(string prefix) |
| 32 | { |
| 33 | |
| 34 | } |
| 35 | |
| 36 | uint32_t AppDataPublish::getHighestSeq(string prefix) |
| 37 | { |
| 38 | unordered_map<string, uint32_t>::iterator i = m_sequenceLog.find(prefix); |
| 39 | |
| 40 | if (i != m_sequenceLog.end()) |
| 41 | { |
| 42 | return i->second; |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | m_sequenceLog[prefix] = 0; |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | } |
| 51 | |
| 52 | bool AppDataPublish::publishData(string name, string dataBuffer, int freshness) |
| 53 | { |
| 54 | uint32_t seq = getHighestSeq(name) + 1; |
| 55 | string contentName = name; |
| 56 | |
| 57 | contentName += seq; |
| 58 | |
| 59 | m_sequenceLog[contentName] = seq; |
| 60 | m_recentData[contentName] = dataBuffer; |
| 61 | |
| 62 | m_ccnxHandle->publishData(contentName, dataBuffer, freshness); |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | } |