blob: a2c8b7d5576f088383fb59e15dbe6f67c7033bb2 [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
24 Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback);
25 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
34protected:
35 int m_retry;
36 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