blob: f006d114f13e0856040c212e980e442f907ec074 [file] [log] [blame]
Zhenkai Zhu974c5a62012-12-28 14:15:30 -08001#ifndef CCNX_CLOSURE_H
2#define CCNX_CLOSURE_H
3
4#include "ccnx-common.h"
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -08005#include "ccnx-name.h"
Zhenkai Zhu974c5a62012-12-28 14:15:30 -08006
7using namespace std;
8
9namespace Ccnx {
10
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080011class Closure
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080012{
13public:
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080014 typedef boost::function<void (const Name &, const Bytes &)> DataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080015
16 typedef enum
17 {
18 RESULT_OK,
19 RESULT_REEXPRESS
20 } TimeoutCallbackReturnValue;
21
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080022 typedef boost::function<TimeoutCallbackReturnValue (const Name &)> TimeoutCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080023
Zhenkai Zhu0ccc9ec2013-01-04 19:24:09 -080024 Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback = TimeoutCallback());
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080025 Closure(const Closure &other);
26 int getRetry() {return m_retry;}
27 void decRetry() { m_retry--;}
28 virtual ~Closure();
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080029 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080030 runDataCallback(const Name &name, const Bytes &content);
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080031 virtual TimeoutCallbackReturnValue
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080032 runTimeoutCallback(const Name &interest);
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080033
Zhenkai Zhu19f81de2013-01-04 22:27:47 -080034 virtual Closure *
35 dup() const;
36
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080037protected:
38 int m_retry;
39 TimeoutCallback *m_timeoutCallback;
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080040 DataCallback *m_dataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080041};
42
43} // Ccnx
44
45#endif