blob: 5b24f661b32b860e496eaa4232eb14e7495ce5ef [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)
6 : m_retry(retry), m_timeoutCallback(NULL)
7{
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)
13{
14 Closure(other.m_retry, *(other.m_dataCallback), *(other.m_timeoutCallback));
15}
16
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080017Closure::~Closure ()
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080018{
19 delete m_dataCallback;
20 delete m_timeoutCallback;
21 m_dataCallback = NULL;
22 m_timeoutCallback = NULL;
23}
24
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080025Closure::TimeoutCallbackReturnValue
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080026Closure::runTimeoutCallback(const string &interest)
27{
28 if ((*m_timeoutCallback).empty())
29 {
30 return RESULT_OK;
31 }
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080032
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080033 return (*m_timeoutCallback)(interest);
34}
35
36
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080037void
38Closure::runDataCallback(const string &name, const Bytes &content)
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080039{
40 if (m_dataCallback != NULL) {
41 (*m_dataCallback)(name, content);
42 }
43}
44
45} // Ccnx