blob: 87b82fcc5d8cc966ce98c47697c0a88fcc9db5f9 [file] [log] [blame]
Zhenkai Zhu8d935c82012-03-06 10:44:12 -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>
Alexander Afanasyevc1030192012-03-08 22:21:28 -080020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080021 */
22
Chaoyi Bian11f294f2012-03-08 14:28:06 -080023#ifndef SYNC_LOGIC_H
24#define SYNC_LOGIC_H
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080025#include <boost/shared_ptr.hpp>
26#include <boost/function.hpp>
27#include "sync-ccnx-wrapper.h"
28#include "sync-interest-table.h"
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080029#include "sync-diff-state.h"
30#include "sync-full-state.h"
Chaoyi Bian4194b742012-03-08 17:21:35 -080031#include "sync-std-name-info.h"
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080032
Alexander Afanasyevc1030192012-03-08 22:21:28 -080033#include "sync-diff-state-container.h"
34
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080035namespace Sync {
36
37/**
38 * \ingroup sync
Zhenkai Zhuaae81522012-03-06 11:05:44 -080039 * @brief A wrapper for SyncApp, which handles ccnx related things (process
40 * interests and data)
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080041 */
Chaoyi Bian11f294f2012-03-08 14:28:06 -080042class SyncLogic
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080043{
44public:
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -080045 typedef boost::function<void (const std::string &, uint32_t, uint32_t)> LogicCallback;
46
Alexander Afanasyevc1030192012-03-08 22:21:28 -080047 /**
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080048 * @brief Constructor
Alexander Afanasyevc1030192012-03-08 22:21:28 -080049 * @param syncPrefix the name prefix to use for the Sync Interest
50 * @param fetch the fetch function, which will be called to actually fetch
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080051 * @param ccnxHandle ccnx handle
Alexander Afanasyevc1030192012-03-08 22:21:28 -080052 * the app data when new remote names are learned
53 */
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080054 SyncLogic (const std::string &syncPrefix, LogicCallback fetch, CcnxWrapperPtr ccnxHandle);
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080055
Alexander Afanasyevc1030192012-03-08 22:21:28 -080056 ~SyncLogic ();
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -080057
Alexander Afanasyevc1030192012-03-08 22:21:28 -080058 /**
59 * a wrapper for the same func in SyncApp
60 */
61 void addLocalNames (const std::string &prefix, uint32_t session, uint32_t seq);
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080062
Alexander Afanasyevc1030192012-03-08 22:21:28 -080063 /**
64 * @brief respond to the Sync Interest; a lot of logic needs to go in here
65 * @param interest the Sync Interest in string format
66 */
67 void respondSyncInterest (const std::string &interest);
Zhenkai Zhu46b26a12012-03-06 13:51:16 -080068
Alexander Afanasyevc1030192012-03-08 22:21:28 -080069 /**
70 * @brief process the fetched sync data
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080071 * @param name name ???
Alexander Afanasyevc1030192012-03-08 22:21:28 -080072 * @param dataBuffer the sync data
73 */
74 void processSyncData (const std::string &name, const std::string &dataBuffer);
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080075
76private:
Alexander Afanasyevc1030192012-03-08 22:21:28 -080077 void sendSyncInterest ();
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080078
79private:
Alexander Afanasyevc1030192012-03-08 22:21:28 -080080 FullState m_state;
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -080081 DiffStateContainer m_log;
Alexander Afanasyevc1030192012-03-08 22:21:28 -080082 SyncInterestTable m_syncInterestTable;
83
84 std::string m_syncPrefix;
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080085 LogicCallback m_fetch;
Alexander Afanasyevc1030192012-03-08 22:21:28 -080086 CcnxWrapperPtr m_ccnxHandle;
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -080087
88 static const int m_syncResponseFreshness = 2;
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080089};
90
91
92} // Sync
93
Zhenkai Zhu1ac6f802012-03-06 17:40:27 -080094#endif // SYNC_APP_WRAPPER_H