blob: d05bcbeefa24a3c1be918f87da58e4c5c5380d2e [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 */
Chaoyi Bian3e99d862012-03-07 17:28:32 -080022
23#include "sync-app-data-publish.h"
24
25using namespace std;
26using namespace boost;
27
28namespace Sync
29{
30
Chaoyi Bian4194b742012-03-08 17:21:35 -080031string AppDataPublish::getRecentData(string prefix, uint32_t session)
Chaoyi Bian3e99d862012-03-07 17:28:32 -080032{
33
34}
35
Chaoyi Bian4194b742012-03-08 17:21:35 -080036uint32_t AppDataPublish::getHighestSeq(string prefix, uint32_t session)
Chaoyi Bian3e99d862012-03-07 17:28:32 -080037{
Chaoyi Bian4194b742012-03-08 17:21:35 -080038 unordered_map<string, Seq>::iterator i = m_sequenceLog.find(prefix);
Chaoyi Bian3e99d862012-03-07 17:28:32 -080039
40 if (i != m_sequenceLog.end())
41 {
Chaoyi Bian4194b742012-03-08 17:21:35 -080042 Seq s = i->second;
43 if (s.session == session)
44 return s.seq;
Chaoyi Bian3e99d862012-03-07 17:28:32 -080045 }
46
Chaoyi Bian4194b742012-03-08 17:21:35 -080047 return 0;
Chaoyi Bian3e99d862012-03-07 17:28:32 -080048}
49
Chaoyi Bian4194b742012-03-08 17:21:35 -080050bool AppDataPublish::publishData(string name, uint32_t session, string dataBuffer, int freshness)
Chaoyi Bian3e99d862012-03-07 17:28:32 -080051{
Chaoyi Bian4194b742012-03-08 17:21:35 -080052 uint32_t seq = getHighestSeq(name, session);
53 if (seq == 0)
54 m_sequenceLog.erase(name);
55
56 seq++;
57 if (seq == 0)
58 seq = 1;
59 Seq s;
60 s.session = session;
61 s.seq = seq;
62 m_sequenceLog[name] = s;
63
Chaoyi Bian3e99d862012-03-07 17:28:32 -080064 string contentName = name;
Chaoyi Bian3e99d862012-03-07 17:28:32 -080065 contentName += seq;
66
Chaoyi Bian3e99d862012-03-07 17:28:32 -080067 m_ccnxHandle->publishData(contentName, dataBuffer, freshness);
68
69 return true;
70}
71
72}