blob: 5abcb3e489e567e8c5aacf1f6bee77f2c16566d5 [file] [log] [blame]
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 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: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 */
21
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080022#include "ccnx-closure.h"
23
24namespace Ccnx {
25
Zhenkai Zhu8339e912013-01-18 18:10:17 -080026Closure::Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback)
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080027 : m_timeoutCallback (timeoutCallback)
28 , m_dataCallback (dataCallback)
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080029{
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080030}
31
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080032Closure::~Closure ()
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080033{
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080034}
35
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080036Closure::TimeoutCallbackReturnValue
Zhenkai Zhu1888f742013-01-28 12:47:33 -080037Closure::runTimeoutCallback(Name interest)
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080038{
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080039 if (m_timeoutCallback.empty ())
40 {
41 return RESULT_OK;
42 }
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080043
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080044 return m_timeoutCallback (interest);
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080045}
46
47
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080048void
Zhenkai Zhu1888f742013-01-28 12:47:33 -080049Closure::runDataCallback(Name name, PcoPtr content)
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080050{
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080051 if (!m_dataCallback.empty ())
52 {
53 m_dataCallback (name, content);
54 }
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080055}
56
Zhenkai Zhu1888f742013-01-28 12:47:33 -080057ExecutorClosure::ExecutorClosure(const Closure &closure, ExecutorPtr executor)
58 : Closure(closure)
59 , m_executor(executor)
Zhenkai Zhu19f81de2013-01-04 22:27:47 -080060{
Zhenkai Zhu1888f742013-01-28 12:47:33 -080061}
62
63ExecutorClosure::~ExecutorClosure()
64{
65}
66
67void
68ExecutorClosure::runDataCallback(Name name, PcoPtr content)
69{
70 m_executor->execute(boost::bind(&ExecutorClosure::execute, this, name, content));
71}
72
73void
74ExecutorClosure::execute(Name name, PcoPtr content)
75{
76 Closure::runDataCallback(name, content);
77}
78
79ExecutorInterestClosure::ExecutorInterestClosure(const InterestCallback &callback, ExecutorPtr executor)
80 : m_callback(callback)
81 , m_executor(executor)
82{
83}
84
85void
86ExecutorInterestClosure::runInterestCallback(Name interest)
87{
88 m_executor->execute(boost::bind(&ExecutorInterestClosure::execute, this, interest));
89}
90
91void
92ExecutorInterestClosure::execute(Name interest)
93{
94 if (!m_callback.empty())
95 {
96 m_callback(interest);
97 }
Zhenkai Zhu19f81de2013-01-04 22:27:47 -080098}
99
Zhenkai Zhu974c5a62012-12-28 14:15:30 -0800100} // Ccnx