Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 1 | #include "ccnx-closure.h" |
| 2 | |
| 3 | namespace Ccnx { |
| 4 | |
| 5 | Closure::Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback) |
| 6 | : m_retry(retry), m_timeoutCallback(NULL) |
| 7 | { |
| 8 | m_timeoutCallback = new TimeoutCallback (timeoutCallback); |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 9 | m_dataCallback = new DataCallback (dataCallback); |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | Closure::Closure(const Closure &other) |
| 13 | { |
| 14 | Closure(other.m_retry, *(other.m_dataCallback), *(other.m_timeoutCallback)); |
| 15 | } |
| 16 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 17 | Closure::~Closure () |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 18 | { |
| 19 | delete m_dataCallback; |
| 20 | delete m_timeoutCallback; |
| 21 | m_dataCallback = NULL; |
| 22 | m_timeoutCallback = NULL; |
| 23 | } |
| 24 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 25 | Closure::TimeoutCallbackReturnValue |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 26 | Closure::runTimeoutCallback(const string &interest) |
| 27 | { |
| 28 | if ((*m_timeoutCallback).empty()) |
| 29 | { |
| 30 | return RESULT_OK; |
| 31 | } |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 32 | |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 33 | return (*m_timeoutCallback)(interest); |
| 34 | } |
| 35 | |
| 36 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 37 | void |
| 38 | Closure::runDataCallback(const string &name, const Bytes &content) |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 39 | { |
| 40 | if (m_dataCallback != NULL) { |
| 41 | (*m_dataCallback)(name, content); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | } // Ccnx |