blob: e4b6133b262eb6fc024914b949c10602f84c95c6 [file] [log] [blame]
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012 University of California, Los Angeles
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
* 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
* Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
#ifndef SYNC_LEAF_H
#define SYNC_LEAF_H
#include <boost/function.hpp>
namespace Sync {
/**
* \ingroup sync
* @brief A simple interface to interact with client code
*/
class SyncAppSocket
{
public:
/**
* @brief the constructor for SyncAppSocket; the parameter syncPrefix
* should be passed to the constructor of m_syncAppWrapper; the other
* parameter should be passed to the constructor of m_fetcher; furthermore,
* the fetch function of m_fetcher should be a second paramter passed to
* the constructor of m_syncAppWrapper, so that m_syncAppWrapper can tell
* m_fetcher to fetch the actual app data after it learns the names
*
* @param syncPrefix the name prefix for Sync Interest
* @param dataCallback the callback to process data
*/
SyncAppSocket(std::string syncPrefix, boost::function<void
(boost::shared_ptr<DataBuffer>)> dataCallback);
~SyncAppSocket();
/**
* @brief publish data from local client and tell SyncAppWrapper to update
* the sync tree by adding the local names
*
* @param prefix the name prefix for the data
* @param dataBuffer the data itself
* @param freshness the freshness time for the data (in seconds)
*/
bool publish(std::string prefix, boost::shared_ptr<DataBuffer>
dataBuffer, int freshness);
private:
boost::shared_ptr<AppDataFetch> m_fetcher;
boost::shared_ptr<AppDataPublish> m_publisher;
boost::shared_ptr<SyncAppWrapper> m_syncAppWrapper;
};
} // Sync
#endif // SYNC_LEAF_H