blob: 1bcaa061e681b2369b91f5ceabf8a924aed28c3d [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 Zhu8339e912013-01-18 18:10:17 -080024 Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback = TimeoutCallback());
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080025 Closure(const Closure &other);
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080026 virtual ~Closure();
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080027 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080028 runDataCallback(const Name &name, const Bytes &content);
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080029 virtual TimeoutCallbackReturnValue
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080030 runTimeoutCallback(const Name &interest);
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080031
Zhenkai Zhu19f81de2013-01-04 22:27:47 -080032 virtual Closure *
33 dup() const;
34
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080035protected:
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080036 TimeoutCallback *m_timeoutCallback;
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080037 DataCallback *m_dataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080038};
39
40} // Ccnx
41
42#endif