Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012-2013 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #ifndef FETCH_MANAGER_H |
| 23 | #define FETCH_MANAGER_H |
| 24 | |
| 25 | #include <boost/exception/all.hpp> |
| 26 | #include <boost/shared_ptr.hpp> |
| 27 | #include <string> |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame^] | 28 | #include <list> |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 29 | #include <stdint.h> |
| 30 | #include "scheduler.h" |
| 31 | |
| 32 | #include "ccnx-wrapper.h" |
| 33 | #include "ccnx-tunnel.h" |
| 34 | #include "sync-log.h" |
| 35 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame^] | 36 | #include "fetcher.h" |
| 37 | |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 38 | class FetchManager |
| 39 | { |
| 40 | enum |
| 41 | { |
| 42 | PRIORITY_NORMAL, |
| 43 | PRIORITY_HIGH |
| 44 | }; |
| 45 | |
| 46 | public: |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame^] | 47 | FetchManager (Ccnx::CcnxWrapperPtr ccnx, SyncLogPtr sync, uint32_t parallelFetches = 3); |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 48 | virtual ~FetchManager (); |
| 49 | |
| 50 | void |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 51 | Enqueue (const Ccnx::Name &deviceName, |
| 52 | uint32_t minSeqNo, uint32_t maxSeqNo, int priority=PRIORITY_NORMAL); |
| 53 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame^] | 54 | inline Ccnx::CcnxWrapperPtr |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 55 | GetCcnx (); |
| 56 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame^] | 57 | inline SchedulerPtr |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 58 | GetScheduler (); |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame^] | 59 | |
| 60 | private: |
| 61 | void |
| 62 | ScheduleFetches (); |
| 63 | |
| 64 | // Events called from Fetcher |
| 65 | void |
| 66 | NoDataTimeout (Fetcher &fetcher); |
| 67 | |
| 68 | void |
| 69 | FetchComplete (Fetcher &fetcher); |
| 70 | |
| 71 | private: |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | Ccnx::CcnxWrapperPtr m_ccnx; |
| 75 | SyncLogPtr m_sync; // to access forwarding hints |
Alexander Afanasyev | e41e7d2 | 2013-01-19 15:13:47 -0800 | [diff] [blame] | 76 | SchedulerPtr m_scheduler; |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame^] | 77 | |
| 78 | uint32_t m_maxParallelFetches; |
| 79 | uint32_t m_currentParallelFetches; |
| 80 | boost::mutex m_parellelFetchMutex; |
| 81 | |
| 82 | // optimized list structure for fetch queue |
| 83 | typedef boost::intrusive::member_hook< Fetcher, |
| 84 | boost::intrusive::list_member_hook<>, &Fetcher::m_managerListHook> MemberOption; |
| 85 | typedef boost::intrusive::list<Fetcher, MemberOption> FetchList; |
| 86 | |
| 87 | FetchList m_fetchList; |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame^] | 90 | Ccnx::CcnxWrapperPtr |
| 91 | FetchManager::GetCcnx () |
| 92 | { |
| 93 | return m_ccnx; |
| 94 | } |
| 95 | |
| 96 | SchedulerPtr |
| 97 | FetchManager::GetScheduler () |
| 98 | { |
| 99 | return m_scheduler; |
| 100 | } |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 101 | |
| 102 | typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str; |
| 103 | namespace Error { |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame^] | 104 | struct FetchManager : virtual boost::exception, virtual std::exception { }; |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | typedef boost::shared_ptr<FetchManager> FetchManagerPtr; |
| 108 | |
| 109 | |
| 110 | #endif // FETCHER_H |