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