blob: 77b9160d8cb5118342518c422643a443e00a59c4 [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
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080031string
32AppDataPublish::getRecentData (const string &prefix, uint32_t session)
Chaoyi Bian3e99d862012-03-07 17:28:32 -080033{
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080034 return "";
Chaoyi Bian3e99d862012-03-07 17:28:32 -080035}
36
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080037uint32_t
38AppDataPublish::getHighestSeq (const string &prefix, uint32_t session)
Chaoyi Bian3e99d862012-03-07 17:28:32 -080039{
Chaoyi Bian4194b742012-03-08 17:21:35 -080040 unordered_map<string, Seq>::iterator i = m_sequenceLog.find(prefix);
Chaoyi Bian3e99d862012-03-07 17:28:32 -080041
42 if (i != m_sequenceLog.end())
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080043 {
44 Seq s = i->second;
45 if (s.session == session)
46 return s.seq;
47 }
Chaoyi Bian3e99d862012-03-07 17:28:32 -080048
Chaoyi Bian4194b742012-03-08 17:21:35 -080049 return 0;
Chaoyi Bian3e99d862012-03-07 17:28:32 -080050}
51
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080052bool
53AppDataPublish::publishData (const string &name, uint32_t session, const string &dataBuffer, int freshness)
Chaoyi Bian3e99d862012-03-07 17:28:32 -080054{
Chaoyi Bian4194b742012-03-08 17:21:35 -080055 uint32_t seq = getHighestSeq(name, session);
56 if (seq == 0)
57 m_sequenceLog.erase(name);
58
59 seq++;
60 if (seq == 0)
61 seq = 1;
62 Seq s;
63 s.session = session;
64 s.seq = seq;
65 m_sequenceLog[name] = s;
66
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080067 ostringstream contentNameWithSeqno;
68 contentNameWithSeqno << name << "/" << seq;
Chaoyi Bian3e99d862012-03-07 17:28:32 -080069
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080070 m_ccnxHandle->publishData (contentNameWithSeqno.str (), dataBuffer, freshness);
Chaoyi Bian3e99d862012-03-07 17:28:32 -080071
72 return true;
73}
74
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080075}