Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 1 | #ifndef CCNX_CLOSURE_H |
2 | #define CCNX_CLOSURE_H | ||||
3 | |||||
4 | #include "ccnx-common.h" | ||||
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 5 | #include "ccnx-name.h" |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 6 | |
7 | using namespace std; | ||||
8 | |||||
9 | namespace Ccnx { | ||||
10 | |||||
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 11 | class Closure |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 12 | { |
13 | public: | ||||
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 14 | typedef boost::function<void (const Name &, const Bytes &)> DataCallback; |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 15 | |
16 | typedef enum | ||||
17 | { | ||||
18 | RESULT_OK, | ||||
19 | RESULT_REEXPRESS | ||||
20 | } TimeoutCallbackReturnValue; | ||||
21 | |||||
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 22 | typedef boost::function<TimeoutCallbackReturnValue (const Name &)> TimeoutCallback; |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 23 | |
Zhenkai Zhu | 8339e91 | 2013-01-18 18:10:17 -0800 | [diff] [blame] | 24 | Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback = TimeoutCallback()); |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 25 | Closure(const Closure &other); |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 26 | virtual ~Closure(); |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 27 | virtual void |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 28 | runDataCallback(const Name &name, const Bytes &content); |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 29 | virtual TimeoutCallbackReturnValue |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 30 | runTimeoutCallback(const Name &interest); |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 31 | |
Zhenkai Zhu | 19f81de | 2013-01-04 22:27:47 -0800 | [diff] [blame] | 32 | virtual Closure * |
33 | dup() const; | ||||
34 | |||||
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 35 | protected: |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 36 | TimeoutCallback *m_timeoutCallback; |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 37 | DataCallback *m_dataCallback; |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 38 | }; |
39 | |||||
40 | } // Ccnx | ||||
41 | |||||
42 | #endif |