Zhenkai Zhu | bed7895 | 2012-03-06 11:06:08 -0800 | [diff] [blame] | 1 | /* -*- 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> |
| 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
Zhenkai Zhu | 1ac6f80 | 2012-03-06 17:40:27 -0800 | [diff] [blame] | 23 | #ifndef SYNC_APP_SOCKET_H |
| 24 | #define SYNC_APP_SOCKET_H |
Chaoyi Bian | 11f294f | 2012-03-08 14:28:06 -0800 | [diff] [blame^] | 25 | |
| 26 | #include "sync-logic.h" |
| 27 | #include "sync-app-data-fetch.h" |
| 28 | #include "sync-app-data-publish.h" |
Zhenkai Zhu | bed7895 | 2012-03-06 11:06:08 -0800 | [diff] [blame] | 29 | #include <boost/function.hpp> |
| 30 | |
| 31 | namespace Sync { |
| 32 | |
| 33 | /** |
| 34 | * \ingroup sync |
| 35 | * @brief A simple interface to interact with client code |
| 36 | */ |
| 37 | class SyncAppSocket |
| 38 | { |
| 39 | public: |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 40 | /** |
| 41 | * @brief the constructor for SyncAppSocket; the parameter syncPrefix |
| 42 | * should be passed to the constructor of m_syncAppWrapper; the other |
| 43 | * parameter should be passed to the constructor of m_fetcher; furthermore, |
| 44 | * the fetch function of m_fetcher should be a second paramter passed to |
| 45 | * the constructor of m_syncAppWrapper, so that m_syncAppWrapper can tell |
| 46 | * m_fetcher to fetch the actual app data after it learns the names |
| 47 | * |
| 48 | * @param syncPrefix the name prefix for Sync Interest |
| 49 | * @param dataCallback the callback to process data |
| 50 | */ |
Chaoyi Bian | 11f294f | 2012-03-08 14:28:06 -0800 | [diff] [blame^] | 51 | SyncAppSocket(std::string syncPrefix, boost::function<void (std::string)> |
| 52 | dataCallback); |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 53 | |
Zhenkai Zhu | bed7895 | 2012-03-06 11:06:08 -0800 | [diff] [blame] | 54 | ~SyncAppSocket(); |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 55 | |
| 56 | /** |
Chaoyi Bian | 11f294f | 2012-03-08 14:28:06 -0800 | [diff] [blame^] | 57 | * @brief publish data from local client and tell SyncLogic to update |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 58 | * the sync tree by adding the local names |
Chaoyi Bian | 11f294f | 2012-03-08 14:28:06 -0800 | [diff] [blame^] | 59 | * |
Zhenkai Zhu | 46b26a1 | 2012-03-06 13:51:16 -0800 | [diff] [blame] | 60 | * @param prefix the name prefix for the data |
| 61 | * @param dataBuffer the data itself |
| 62 | * @param freshness the freshness time for the data (in seconds) |
| 63 | */ |
Chaoyi Bian | 11f294f | 2012-03-08 14:28:06 -0800 | [diff] [blame^] | 64 | bool publish(std::string prefix, std::string dataBuffer, int freshness); |
| 65 | |
Zhenkai Zhu | bed7895 | 2012-03-06 11:06:08 -0800 | [diff] [blame] | 66 | private: |
Chaoyi Bian | 11f294f | 2012-03-08 14:28:06 -0800 | [diff] [blame^] | 67 | AppDataFetch *m_fetcher; |
| 68 | AppDataPublish *m_publisher; |
| 69 | SyncLogic *m_syncLogic; |
| 70 | boost::shared_ptr<CcnxWrapper> m_ccnxHandle; |
Zhenkai Zhu | bed7895 | 2012-03-06 11:06:08 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // Sync |
| 74 | |
Zhenkai Zhu | 1ac6f80 | 2012-03-06 17:40:27 -0800 | [diff] [blame] | 75 | #endif // SYNC_APP_SOCKET_H |