blob: 6a1b8d83b1145abe225144908462f1d70eb718ee [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 Zhuff4fa8a2013-01-28 22:02:40 -080027#include "ccnx-selectors.h"
Zhenkai Zhu1888f742013-01-28 12:47:33 -080028#include "executor.h"
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080029
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080030namespace Ccnx {
31
Alexander Afanasyevf278db32013-01-21 14:41:01 -080032class ParsedContentObject;
33typedef boost::shared_ptr<ParsedContentObject> PcoPtr;
34
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080035class Closure
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080036{
37public:
Zhenkai Zhu1888f742013-01-28 12:47:33 -080038 typedef boost::function<void (Name, PcoPtr pco)> DataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080039
Zhenkai Zhuff4fa8a2013-01-28 22:02:40 -080040 typedef boost::function<void (Name, const Closure &, Selectors)> TimeoutCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080041
Zhenkai Zhu8339e912013-01-18 18:10:17 -080042 Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback = TimeoutCallback());
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080043 virtual ~Closure();
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080044
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080045 virtual void
Zhenkai Zhu1888f742013-01-28 12:47:33 -080046 runDataCallback(Name name, Ccnx::PcoPtr pco);
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080047
Zhenkai Zhuff4fa8a2013-01-28 22:02:40 -080048 virtual void
49 runTimeoutCallback(Name interest, const Closure &closure, Selectors selectors);
Zhenkai Zhu19f81de2013-01-04 22:27:47 -080050
Alexander Afanasyev816251e2013-01-28 16:16:49 -080051 virtual Closure *
52 dup () const { return new Closure (*this); }
53
54public:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080055 TimeoutCallback m_timeoutCallback;
56 DataCallback m_dataCallback;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080057};
58
Alexander Afanasyev816251e2013-01-28 16:16:49 -080059// class ExecutorClosure : public Closure
60// {
61// public:
62// ExecutorClosure(const Closure &closure, ExecutorPtr executor);
63// virtual ~ExecutorClosure();
Zhenkai Zhu1888f742013-01-28 12:47:33 -080064
Alexander Afanasyev816251e2013-01-28 16:16:49 -080065// virtual void
66// runDataCallback(Name name, PcoPtr pco);
Zhenkai Zhu1888f742013-01-28 12:47:33 -080067
Alexander Afanasyev816251e2013-01-28 16:16:49 -080068// // private:
69// // void
70// // execute(Name nae, PcoPtr content);
Zhenkai Zhu1888f742013-01-28 12:47:33 -080071
Alexander Afanasyev816251e2013-01-28 16:16:49 -080072// private:
73// ExecutorPtr m_executor;
74// };
Zhenkai Zhu1888f742013-01-28 12:47:33 -080075
Alexander Afanasyev816251e2013-01-28 16:16:49 -080076// class ExecutorInterestClosure
77// {
78// public:
79// typedef boost::function<void (Name)> InterestCallback;
80// ExecutorInterestClosure(const InterestCallback &callback, ExecutorPtr executor);
81// virtual ~ExecutorInterestClosure() {}
Zhenkai Zhu1888f742013-01-28 12:47:33 -080082
Alexander Afanasyev816251e2013-01-28 16:16:49 -080083// void
84// runInterestCallback(Name interest);
Zhenkai Zhu1888f742013-01-28 12:47:33 -080085
Alexander Afanasyev816251e2013-01-28 16:16:49 -080086// void
87// execute(Name interest);
Zhenkai Zhu1888f742013-01-28 12:47:33 -080088
Alexander Afanasyev816251e2013-01-28 16:16:49 -080089// private:
90// InterestCallback m_callback;
91// ExecutorPtr m_executor;
92// };
Zhenkai Zhu1888f742013-01-28 12:47:33 -080093
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080094} // Ccnx
95
96#endif