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" |
| 5 | |
| 6 | using namespace std; |
| 7 | |
| 8 | namespace Ccnx { |
| 9 | |
| 10 | class Closure |
| 11 | { |
| 12 | public: |
| 13 | typedef boost::function<void (const string &, const Bytes &)> DataCallback; |
| 14 | |
| 15 | typedef enum |
| 16 | { |
| 17 | RESULT_OK, |
| 18 | RESULT_REEXPRESS |
| 19 | } TimeoutCallbackReturnValue; |
| 20 | |
| 21 | typedef boost::function<TimeoutCallbackReturnValue (const string &)> TimeoutCallback; |
| 22 | |
| 23 | Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback); |
| 24 | Closure(const Closure &other); |
| 25 | int getRetry() {return m_retry;} |
| 26 | void decRetry() { m_retry--;} |
| 27 | virtual ~Closure(); |
| 28 | virtual void |
| 29 | runDataCallback(const string &name, const Bytes &content); |
| 30 | virtual TimeoutCallbackReturnValue |
| 31 | runTimeoutCallback(const string &interest); |
| 32 | |
| 33 | protected: |
| 34 | int m_retry; |
| 35 | TimeoutCallback *m_timeoutCallback; |
| 36 | DataCallback *m_dataCallback; |
| 37 | }; |
| 38 | |
| 39 | } // Ccnx |
| 40 | |
| 41 | #endif |