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) |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 6 | : m_retry(retry), m_timeoutCallback(NULL), m_dataCallback(NULL) |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 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) |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 13 | :m_retry(other.m_retry), m_timeoutCallback(NULL), m_dataCallback(NULL) |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 14 | { |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 15 | m_timeoutCallback = new TimeoutCallback(*(other.m_timeoutCallback)); |
| 16 | m_dataCallback = new DataCallback(*(other.m_dataCallback)); |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 17 | } |
| 18 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 19 | Closure::~Closure () |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 20 | { |
| 21 | delete m_dataCallback; |
| 22 | delete m_timeoutCallback; |
| 23 | m_dataCallback = NULL; |
| 24 | m_timeoutCallback = NULL; |
| 25 | } |
| 26 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 27 | Closure::TimeoutCallbackReturnValue |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 28 | Closure::runTimeoutCallback(const Name &interest) |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 29 | { |
| 30 | if ((*m_timeoutCallback).empty()) |
| 31 | { |
| 32 | return RESULT_OK; |
| 33 | } |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 34 | |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 35 | return (*m_timeoutCallback)(interest); |
| 36 | } |
| 37 | |
| 38 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 39 | void |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 40 | Closure::runDataCallback(const Name &name, const Bytes &content) |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 41 | { |
| 42 | if (m_dataCallback != NULL) { |
| 43 | (*m_dataCallback)(name, content); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | } // Ccnx |