Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 1 | /* -*- 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 Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 22 | #include "ccnx-closure.h" |
| 23 | |
| 24 | namespace Ccnx { |
| 25 | |
Zhenkai Zhu | 8339e91 | 2013-01-18 18:10:17 -0800 | [diff] [blame] | 26 | Closure::Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback) |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 27 | : m_timeoutCallback (timeoutCallback) |
| 28 | , m_dataCallback (dataCallback) |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 29 | { |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 30 | } |
| 31 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 32 | Closure::~Closure () |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 33 | { |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 36 | Closure::TimeoutCallbackReturnValue |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 37 | Closure::runTimeoutCallback(Name interest) |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 38 | { |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 39 | if (m_timeoutCallback.empty ()) |
| 40 | { |
| 41 | return RESULT_OK; |
| 42 | } |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 43 | |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 44 | return m_timeoutCallback (interest); |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 48 | void |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 49 | Closure::runDataCallback(Name name, PcoPtr content) |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 50 | { |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 51 | if (!m_dataCallback.empty ()) |
| 52 | { |
| 53 | m_dataCallback (name, content); |
| 54 | } |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Alexander Afanasyev | 816251e | 2013-01-28 16:16:49 -0800 | [diff] [blame] | 57 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 58 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 59 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 60 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | 816251e | 2013-01-28 16:16:49 -0800 | [diff] [blame] | 63 | // ExecutorClosure::ExecutorClosure(const Closure &closure, ExecutorPtr executor) |
| 64 | // : Closure(closure.m_dataCallback, closure.m_timeoutCallback) |
| 65 | // , m_executor(executor) |
| 66 | // { |
| 67 | // } |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 68 | |
Alexander Afanasyev | 816251e | 2013-01-28 16:16:49 -0800 | [diff] [blame] | 69 | // ExecutorClosure::~ExecutorClosure() |
| 70 | // { |
| 71 | // } |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | 816251e | 2013-01-28 16:16:49 -0800 | [diff] [blame] | 73 | // void |
| 74 | // ExecutorClosure::runDataCallback(Name name, PcoPtr content) |
| 75 | // { |
| 76 | // m_executor->execute(boost::bind(&Closure::runDataCallback, this, name, content)); |
| 77 | // } |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 78 | |
Alexander Afanasyev | 816251e | 2013-01-28 16:16:49 -0800 | [diff] [blame] | 79 | // // void |
| 80 | // // ExecutorClosure::execute(Name name, PcoPtr content) |
| 81 | // // { |
| 82 | // // Closure::runDataCallback(name, content); |
| 83 | // // } |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 84 | |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | 816251e | 2013-01-28 16:16:49 -0800 | [diff] [blame] | 86 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 87 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 88 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 89 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 90 | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 91 | |
| 92 | |
| 93 | // ExecutorInterestClosure::ExecutorInterestClosure(const InterestCallback &callback, ExecutorPtr executor) |
| 94 | // : m_callback(callback) |
| 95 | // , m_executor(executor) |
| 96 | // { |
| 97 | // } |
| 98 | |
| 99 | // void |
| 100 | // ExecutorInterestClosure::runInterestCallback(Name interest) |
| 101 | // { |
| 102 | // m_executor->execute(boost::bind(&ExecutorInterestClosure::execute, this, interest)); |
| 103 | // } |
| 104 | |
| 105 | // void |
| 106 | // ExecutorInterestClosure::execute(Name interest) |
| 107 | // { |
| 108 | // if (!m_callback.empty()) |
| 109 | // { |
| 110 | // m_callback(interest); |
| 111 | // } |
| 112 | // } |
Zhenkai Zhu | 19f81de | 2013-01-04 22:27:47 -0800 | [diff] [blame] | 113 | |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 114 | } // Ccnx |