blob: a4c378c9b82d4cfc2d3d3e68960d5fbcafbeb41c [file] [log] [blame]
Zhenkai Zhu974c5a62012-12-28 14:15:30 -08001#include "ccnx-closure.h"
2
3namespace Ccnx {
4
5Closure::Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback)
Zhenkai Zhu9f2ef6f2013-01-04 21:46:08 -08006 : m_retry(retry), m_timeoutCallback(NULL), m_dataCallback(NULL)
Zhenkai Zhu974c5a62012-12-28 14:15:30 -08007{
8 m_timeoutCallback = new TimeoutCallback (timeoutCallback);
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -08009 m_dataCallback = new DataCallback (dataCallback);
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080010}
11
12Closure::Closure(const Closure &other)
Zhenkai Zhu9f2ef6f2013-01-04 21:46:08 -080013 :m_retry(other.m_retry), m_timeoutCallback(NULL), m_dataCallback(NULL)
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080014{
Zhenkai Zhu9f2ef6f2013-01-04 21:46:08 -080015 m_timeoutCallback = new TimeoutCallback(*(other.m_timeoutCallback));
16 m_dataCallback = new DataCallback(*(other.m_dataCallback));
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080017}
18
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080019Closure::~Closure ()
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080020{
21 delete m_dataCallback;
22 delete m_timeoutCallback;
23 m_dataCallback = NULL;
24 m_timeoutCallback = NULL;
25}
26
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080027Closure::TimeoutCallbackReturnValue
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080028Closure::runTimeoutCallback(const Name &interest)
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080029{
30 if ((*m_timeoutCallback).empty())
31 {
32 return RESULT_OK;
33 }
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080034
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080035 return (*m_timeoutCallback)(interest);
36}
37
38
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080039void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080040Closure::runDataCallback(const Name &name, const Bytes &content)
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080041{
42 if (m_dataCallback != NULL) {
43 (*m_dataCallback)(name, content);
44 }
45}
46
47} // Ccnx