blob: 848a6d0e534ac6269f9929913eafba24300c4aa1 [file] [log] [blame]
Zhenkai Zhubed78952012-03-06 11:06:08 -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>
Chaoyi Bian3e1eb162012-04-03 16:59:32 -070019 * Chaoyi Bian <bcy@pku.edu.cn>
Zhenkai Zhubed78952012-03-06 11:06:08 -080020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
Chaoyi Bian11f294f2012-03-08 14:28:06 -080022
23#include "sync-app-socket.h"
24
25using namespace std;
26using namespace boost;
27
28namespace Sync
29{
30
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080031SyncAppSocket::SyncAppSocket (const string &syncPrefix, CcnxWrapper::DataCallback dataCallback)
Zhenkai Zhuce66e212012-03-12 22:27:19 -070032 : m_appHandle (new CcnxWrapper())
33 , m_fetcher (m_appHandle, dataCallback)
34 , m_publisher (m_appHandle)
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080035 , m_syncLogic (syncPrefix,
Alexander Afanasyev750d1872012-03-12 15:33:56 -070036 bind (&AppDataFetch::onUpdate, m_fetcher, _1, _2, _3),
Zhenkai Zhuce66e212012-03-12 22:27:19 -070037 bind (&AppDataFetch::onRemove, m_fetcher, _1))
Chaoyi Bian11f294f2012-03-08 14:28:06 -080038{
Chaoyi Bian11f294f2012-03-08 14:28:06 -080039}
40
41SyncAppSocket::~SyncAppSocket()
42{
Chaoyi Bian11f294f2012-03-08 14:28:06 -080043}
44
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080045bool SyncAppSocket::publish (const string &prefix, uint32_t session, const string &dataBuffer, int freshness)
Chaoyi Bian11f294f2012-03-08 14:28:06 -080046{
Alexander Afanasyev1b449c42012-03-13 20:24:07 -070047 uint32_t sequence = m_publisher.publishData (prefix, session, dataBuffer, freshness);
48 m_syncLogic.addLocalNames (prefix, session, sequence);
Chaoyi Bian11f294f2012-03-08 14:28:06 -080049}
50
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080051}