blob: 8c589bbf9655d74f599fb690cc75592d41d0536e [file] [log] [blame]
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -07001/* -*- 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
20 * Chaoyi Bian <bcy@pku.edu.cn>
21 */
22
23#ifndef NDN_API_FACE_H
24#define NDN_API_FACE_H
25
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070026#include <ns3/ptr.h>
27#include <ns3/node.h>
Alexander Afanasyev79606062013-07-11 00:57:28 -070028#include <ns3/callback.h>
29#include <ns3/ndn-face.h>
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070030#include <ns3/ndn-name.h>
31
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070032namespace ns3 {
33namespace ndn {
34
Alexander Afanasyev79606062013-07-11 00:57:28 -070035class ApiFacePriv;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070036
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070037/**
38 * \ingroup sync
39 * @brief A handler for NDN; clients of this code do not need to deal
40 * with NDN API directly
41 */
42class ApiFace
Alexander Afanasyev79606062013-07-11 00:57:28 -070043 : public ns3::ndn::Face
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070044{
45public:
Alexander Afanasyev79606062013-07-11 00:57:28 -070046 typedef Callback<void, Ptr<const Name>, Ptr<const Interest> > InterestCallback;
47 typedef Callback<void, Ptr<const Interest>, Ptr<const ContentObject> > DataCallback;
48 typedef Callback<void, Ptr<const Interest> > TimeoutCallback;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070049
50 /**
Alexander Afanasyev79606062013-07-11 00:57:28 -070051 * @brief initialize the handler; a lot of things needs to be done. 1) init
52 * keystore 2) init keylocator 3) start a thread to hold a loop of ccn_run
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070053 *
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070054 */
Alexander Afanasyev79606062013-07-11 00:57:28 -070055 ApiFace (Ptr<Node> node);
56 ~ApiFace ();
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070057
Alexander Afanasyev79606062013-07-11 00:57:28 -070058 /**
59 * @brief Express Interest
60 *
61 * @param name the Interest name
62 * @param onData the callback function to deal with the returned data
63 * @param onTimeout the callback function to deal with timeouts
64 */
65 void
66 ExpressInterest (Ptr<Interest> interest,
67 DataCallback onData,
68 TimeoutCallback onTimeout); // = MakeNullCallback< void, Ptr<Interest> > ()
69
70 /**
71 * @brief set Interest filter (specify what interest you want to receive)
72 *
73 * @param prefix the prefix of Interest
74 * @param onInterest the callback function to deal with the returned data
75 */
76 void
77 SetInterestFilter (Ptr<const Name> prefix, InterestCallback onInterest);
78
79 /**
80 * @brief clear Interest filter
81 * @param prefix the prefix of Interest
82 */
83 void
84 ClearInterestFilter (Ptr<const Name> prefix);
85
86 /**
87 * @brief Publish data
88 * @param data Data packet to publish
89 */
90 void
91 Put (Ptr<ContentObject> data);
92
93public:
94 virtual bool
95 SendInterest (Ptr<const Interest> interest);
96
97 virtual bool
98 SendData (Ptr<const ContentObject> data);
99
100 virtual std::ostream&
101 Print (std::ostream &os) const;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700102
103private:
Alexander Afanasyev79606062013-07-11 00:57:28 -0700104 ApiFace () : Face (0) {}
105 ApiFace (const ApiFace &) : Face (0) {}
106 ApiFace& operator= (const ApiFace &) { return *this; }
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700107
108private:
Alexander Afanasyev79606062013-07-11 00:57:28 -0700109 ApiFacePriv *m_this;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700110};
111
112}
113}
114
115#endif // NDN_API_HANDLER_H