blob: 2031532899ac4254f50f144de5c2f45395e22c14 [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_APP_DATA_PUBLISH_H
#define SYNC_APP_DATA_PUBLISH_H
#include <boost/shared_ptr.hpp>
#include "sync-ccnx-wrapper.h"
/**
* \defgroup sync SYNC protocol
*
* Implementation of SYNC protocol
*/
namespace Sync {
/**
* \ingroup sync
* @brief publishes application data using incrementing sequence number (for
* each sequence namber and keeps track of most recently published data for
* each name prefix
*/
class AppDataPublish
{
public:
AppDataPublish();
~AppDataPublish() {};
/**
* @brief get the name (including sequence number) and the content
* (unencoded, just XML stanza) of the most recent published data
*
* @param prefix the name prefix to look for
* @return the pair of name and content
*/
std::pair<std::string, boost::shared_ptr<const DataBuffer> >
getRecentData(std::string prefix);
/**
* brief get the most recent sequence number for a name prefix
*/
long getHighestSeq(std:string prefix);
/**
* @brief publish data for a name prefix, updates the corresponding
* sequence number and recent data
*
* @param name data prefix
* @param dataBuffer the data itself
* @param freshness the freshness for the data object
* @return whether the publish succeeded
*/
bool publishData(std::string name, boost::shared_ptr<DataBufer> dataBuffer,
int freshness);
private:
boost::unordered_map<string, long> m_sequenceLog;
boost::shared_ptr<CcnxWrapper> m_ccnxHandle;
std::pair<std::string, boost::shared_ptr<DataBuffer> > m_recentData;
};
} // Sync
#endif // SYNC_APP_DATA_PUBLISH_H