blob: 6fe589c11ae54daadcd163ae6fd83f48516b324c [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_LOGIC_H
#define SYNC_LOGIC_H
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include "sync-ccnx-wrapper.h"
#include "sync-interest-table.h"
#include "sync-diff-state.h"
#include "sync-full-state.h"
#include "sync-app.h"
namespace Sync {
/**
* \ingroup sync
* @brief A wrapper for SyncApp, which handles ccnx related things (process
* interests and data)
*/
class SyncLogic
{
public:
/**
* @brief constructor for this class;
* @param syncPrefix the name prefix to use for the Sync Interest
* @param fetch the fetch function, which will be called to actually fetch
* the app data when new remote names are learned
*/
SyncLogic(std::string syncPrefix, boost::function<void (std::string,
uint32_t, uint32_t)> fetch, boost::shared_ptr<CcnxWrapper> ccnxHandle);
~SyncLogic();
/**
* a wrapper for the same func in SyncApp
*/
void addLocalNames(std::string prefix, uint32_t seq);
/**
* @brief respond to the Sync Interest; a lot of logic needs to go in here
* @param interest the Sync Interest in string format
*/
void respondSyncInterest(std::string interest);
/**
* @brief process the fetched sync data
* @param dataBuffer the sync data
*/
void processSyncData(std::string dataBuffer);
private:
void sendSyncInterest();
private:
boost::shared_ptr<CcnxWrapper> m_ccnxHandle;
//boost::shared_ptr<SyncApp> m_syncApp;
boost::function<void (std::string, uint32_t, uint32_t)> m_fetch;
SyncInterestTable m_syncInterestTable;
std::string m_syncPrefix;
};
} // Sync
#endif // SYNC_APP_WRAPPER_H