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 | 0ccc9ec | 2013-01-04 19:24:09 -0800 | [diff] [blame] | 24 | Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback = TimeoutCallback()); |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 25 | Closure(const Closure &other); |
| 26 | int getRetry() {return m_retry;} |
| 27 | void decRetry() { m_retry--;} |
| 28 | virtual ~Closure(); |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 29 | virtual void |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 30 | runDataCallback(const Name &name, const Bytes &content); |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 31 | virtual TimeoutCallbackReturnValue |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 32 | runTimeoutCallback(const Name &interest); |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 33 | |
Zhenkai Zhu | 19f81de | 2013-01-04 22:27:47 -0800 | [diff] [blame^] | 34 | virtual Closure * |
| 35 | dup() const; |
| 36 | |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 37 | protected: |
| 38 | int m_retry; |
| 39 | TimeoutCallback *m_timeoutCallback; |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 40 | DataCallback *m_dataCallback; |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | } // Ccnx |
| 44 | |
| 45 | #endif |