blob: 39fbc16ad081f8fa1a5231053f1f6bd7d103d4bc [file] [log] [blame]
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 */
21
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080022#ifndef CCNX_CLOSURE_H
23#define CCNX_CLOSURE_H
24
25#include "ccnx-common.h"
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080026#include "ccnx-name.h"
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080027
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080028namespace Ccnx {
29
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080030class Closure
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080031{
32public:
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080033 typedef boost::function<void (const Name &, const Bytes &)> DataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080034
35 typedef enum
36 {
37 RESULT_OK,
38 RESULT_REEXPRESS
39 } TimeoutCallbackReturnValue;
40
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080041 typedef boost::function<TimeoutCallbackReturnValue (const Name &)> TimeoutCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080042
Zhenkai Zhu8339e912013-01-18 18:10:17 -080043 Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback = TimeoutCallback());
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080044 virtual ~Closure();
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080045
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080046 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080047 runDataCallback(const Name &name, const Bytes &content);
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080048
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080049 virtual TimeoutCallbackReturnValue
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080050 runTimeoutCallback(const Name &interest);
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080051
Zhenkai Zhu19f81de2013-01-04 22:27:47 -080052 virtual Closure *
53 dup() const;
54
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080055protected:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080056 TimeoutCallback m_timeoutCallback;
57 DataCallback m_dataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080058};
59
60} // Ccnx
61
62#endif