blob: 9741f6b733b3e29fd42c49b0045f1a432ca3df04 [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 Zhu1888f742013-01-28 12:47:33 -080027#include "executor.h"
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080028
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080029namespace Ccnx {
30
Alexander Afanasyevf278db32013-01-21 14:41:01 -080031class ParsedContentObject;
32typedef boost::shared_ptr<ParsedContentObject> PcoPtr;
33
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080034class Closure
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080035{
36public:
Zhenkai Zhu1888f742013-01-28 12:47:33 -080037 typedef boost::function<void (Name, PcoPtr pco)> DataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080038
39 typedef enum
40 {
41 RESULT_OK,
42 RESULT_REEXPRESS
43 } TimeoutCallbackReturnValue;
44
Zhenkai Zhu1888f742013-01-28 12:47:33 -080045 typedef boost::function<TimeoutCallbackReturnValue (Name )> TimeoutCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080046
Zhenkai Zhu8339e912013-01-18 18:10:17 -080047 Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback = TimeoutCallback());
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080048 virtual ~Closure();
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080049
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080050 virtual void
Zhenkai Zhu1888f742013-01-28 12:47:33 -080051 runDataCallback(Name name, Ccnx::PcoPtr pco);
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080052
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080053 virtual TimeoutCallbackReturnValue
Zhenkai Zhu1888f742013-01-28 12:47:33 -080054 runTimeoutCallback(Name interest);
Zhenkai Zhu19f81de2013-01-04 22:27:47 -080055
Alexander Afanasyev816251e2013-01-28 16:16:49 -080056 virtual Closure *
57 dup () const { return new Closure (*this); }
58
59public:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080060 TimeoutCallback m_timeoutCallback;
61 DataCallback m_dataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080062};
63
Alexander Afanasyev816251e2013-01-28 16:16:49 -080064// class ExecutorClosure : public Closure
65// {
66// public:
67// ExecutorClosure(const Closure &closure, ExecutorPtr executor);
68// virtual ~ExecutorClosure();
Zhenkai Zhu1888f742013-01-28 12:47:33 -080069
Alexander Afanasyev816251e2013-01-28 16:16:49 -080070// virtual void
71// runDataCallback(Name name, PcoPtr pco);
Zhenkai Zhu1888f742013-01-28 12:47:33 -080072
Alexander Afanasyev816251e2013-01-28 16:16:49 -080073// // private:
74// // void
75// // execute(Name nae, PcoPtr content);
Zhenkai Zhu1888f742013-01-28 12:47:33 -080076
Alexander Afanasyev816251e2013-01-28 16:16:49 -080077// private:
78// ExecutorPtr m_executor;
79// };
Zhenkai Zhu1888f742013-01-28 12:47:33 -080080
Alexander Afanasyev816251e2013-01-28 16:16:49 -080081// class ExecutorInterestClosure
82// {
83// public:
84// typedef boost::function<void (Name)> InterestCallback;
85// ExecutorInterestClosure(const InterestCallback &callback, ExecutorPtr executor);
86// virtual ~ExecutorInterestClosure() {}
Zhenkai Zhu1888f742013-01-28 12:47:33 -080087
Alexander Afanasyev816251e2013-01-28 16:16:49 -080088// void
89// runInterestCallback(Name interest);
Zhenkai Zhu1888f742013-01-28 12:47:33 -080090
Alexander Afanasyev816251e2013-01-28 16:16:49 -080091// void
92// execute(Name interest);
Zhenkai Zhu1888f742013-01-28 12:47:33 -080093
Alexander Afanasyev816251e2013-01-28 16:16:49 -080094// private:
95// InterestCallback m_callback;
96// ExecutorPtr m_executor;
97// };
Zhenkai Zhu1888f742013-01-28 12:47:33 -080098
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080099} // Ccnx
100
101#endif