blob: 01358c454f833077d02b1ab7d1eeb4f3f9091f8d [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"
5
6using namespace std;
7
8namespace Ccnx {
9
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080010class Closure
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080011{
12public:
13 typedef boost::function<void (const string &, const Bytes &)> DataCallback;
14
15 typedef enum
16 {
17 RESULT_OK,
18 RESULT_REEXPRESS
19 } TimeoutCallbackReturnValue;
20
21 typedef boost::function<TimeoutCallbackReturnValue (const string &)> TimeoutCallback;
22
23 Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback);
24 Closure(const Closure &other);
25 int getRetry() {return m_retry;}
26 void decRetry() { m_retry--;}
27 virtual ~Closure();
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080028 virtual void
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080029 runDataCallback(const string &name, const Bytes &content);
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080030 virtual TimeoutCallbackReturnValue
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080031 runTimeoutCallback(const string &interest);
32
33protected:
34 int m_retry;
35 TimeoutCallback *m_timeoutCallback;
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080036 DataCallback *m_dataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080037};
38
39} // Ccnx
40
41#endif