blob: cfceef57a06cc63c3d86ab1d284ca9a6a7b1005b [file] [log] [blame]
Alexander Afanasyev49a18522013-01-18 17:49:04 -08001/* -*- 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 Afanasyev83531a42013-01-19 16:21:54 -080028#include <list>
Alexander Afanasyev49a18522013-01-18 17:49:04 -080029#include <stdint.h>
30#include "scheduler.h"
31
32#include "ccnx-wrapper.h"
Alexander Afanasyev49a18522013-01-18 17:49:04 -080033#include "sync-log.h"
34
Alexander Afanasyev83531a42013-01-19 16:21:54 -080035#include "fetcher.h"
36
Alexander Afanasyev49a18522013-01-18 17:49:04 -080037class FetchManager
38{
39 enum
40 {
41 PRIORITY_NORMAL,
42 PRIORITY_HIGH
43 };
44
45public:
Alexander Afanasyev83531a42013-01-19 16:21:54 -080046 FetchManager (Ccnx::CcnxWrapperPtr ccnx, SyncLogPtr sync, uint32_t parallelFetches = 3);
Alexander Afanasyev49a18522013-01-18 17:49:04 -080047 virtual ~FetchManager ();
48
49 void
Alexander Afanasyeve41e7d22013-01-19 15:13:47 -080050 Enqueue (const Ccnx::Name &deviceName,
51 uint32_t minSeqNo, uint32_t maxSeqNo, int priority=PRIORITY_NORMAL);
52
Alexander Afanasyev83531a42013-01-19 16:21:54 -080053 inline Ccnx::CcnxWrapperPtr
Alexander Afanasyeve41e7d22013-01-19 15:13:47 -080054 GetCcnx ();
55
Alexander Afanasyev83531a42013-01-19 16:21:54 -080056 inline SchedulerPtr
Alexander Afanasyeve41e7d22013-01-19 15:13:47 -080057 GetScheduler ();
Alexander Afanasyev83531a42013-01-19 16:21:54 -080058
Alexander Afanasyev21a166e2013-01-20 16:04:41 -080059 // Fetch Events
60 void
61 DidDataSegmentFetched (Fetcher &fetcher, uint32_t seqno, const Ccnx::Name &basename,
Alexander Afanasyevf278db32013-01-21 14:41:01 -080062 const Ccnx::Name &name, Ccnx::PcoPtr data);
Alexander Afanasyev21a166e2013-01-20 16:04:41 -080063
Alexander Afanasyev83531a42013-01-19 16:21:54 -080064 void
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080065 DidNoDataTimeout (Fetcher &fetcher);
Alexander Afanasyev83531a42013-01-19 16:21:54 -080066
67 void
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080068 DidFetchComplete (Fetcher &fetcher);
Alexander Afanasyev83531a42013-01-19 16:21:54 -080069
70private:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080071 void
72 ScheduleFetches ();
73
74private:
75
Alexander Afanasyev49a18522013-01-18 17:49:04 -080076private:
77 Ccnx::CcnxWrapperPtr m_ccnx;
78 SyncLogPtr m_sync; // to access forwarding hints
Alexander Afanasyeve41e7d22013-01-19 15:13:47 -080079 SchedulerPtr m_scheduler;
Alexander Afanasyev83531a42013-01-19 16:21:54 -080080
81 uint32_t m_maxParallelFetches;
82 uint32_t m_currentParallelFetches;
83 boost::mutex m_parellelFetchMutex;
84
85 // optimized list structure for fetch queue
86 typedef boost::intrusive::member_hook< Fetcher,
87 boost::intrusive::list_member_hook<>, &Fetcher::m_managerListHook> MemberOption;
88 typedef boost::intrusive::list<Fetcher, MemberOption> FetchList;
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080089
Alexander Afanasyev83531a42013-01-19 16:21:54 -080090 FetchList m_fetchList;
Alexander Afanasyev49a18522013-01-18 17:49:04 -080091};
92
Alexander Afanasyev83531a42013-01-19 16:21:54 -080093Ccnx::CcnxWrapperPtr
94FetchManager::GetCcnx ()
95{
96 return m_ccnx;
97}
98
99SchedulerPtr
100FetchManager::GetScheduler ()
101{
102 return m_scheduler;
103}
Alexander Afanasyev49a18522013-01-18 17:49:04 -0800104
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800105typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
Alexander Afanasyev49a18522013-01-18 17:49:04 -0800106namespace Error {
Alexander Afanasyev83531a42013-01-19 16:21:54 -0800107struct FetchManager : virtual boost::exception, virtual std::exception { };
Alexander Afanasyev49a18522013-01-18 17:49:04 -0800108}
109
110typedef boost::shared_ptr<FetchManager> FetchManagerPtr;
111
112
113#endif // FETCHER_H