blob: 78f482a9bee1e9c0f91500d38a3a576f4868b28a [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>
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070031#include <ns3/ndn-interest.h>
32#include <ns3/ndn-content-object.h>
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070033
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070034namespace ns3 {
35namespace ndn {
36
Alexander Afanasyev79606062013-07-11 00:57:28 -070037class ApiFacePriv;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070038
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070039/**
40 * \ingroup sync
41 * @brief A handler for NDN; clients of this code do not need to deal
42 * with NDN API directly
43 */
44class ApiFace
Alexander Afanasyev79606062013-07-11 00:57:28 -070045 : public ns3::ndn::Face
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070046{
47public:
Alexander Afanasyev79606062013-07-11 00:57:28 -070048 typedef Callback<void, Ptr<const Name>, Ptr<const Interest> > InterestCallback;
49 typedef Callback<void, Ptr<const Interest>, Ptr<const ContentObject> > DataCallback;
50 typedef Callback<void, Ptr<const Interest> > TimeoutCallback;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070051
52 /**
Alexander Afanasyev79606062013-07-11 00:57:28 -070053 * @brief initialize the handler; a lot of things needs to be done. 1) init
54 * keystore 2) init keylocator 3) start a thread to hold a loop of ccn_run
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070055 *
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070056 */
Alexander Afanasyev79606062013-07-11 00:57:28 -070057 ApiFace (Ptr<Node> node);
58 ~ApiFace ();
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070059
Alexander Afanasyev79606062013-07-11 00:57:28 -070060 /**
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070061 * @brief Shutdown the API face
62 */
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070063 virtual void
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070064 Shutdown ();
65
66 /**
Alexander Afanasyev79606062013-07-11 00:57:28 -070067 * @brief Express Interest
68 *
69 * @param name the Interest name
70 * @param onData the callback function to deal with the returned data
71 * @param onTimeout the callback function to deal with timeouts
72 */
73 void
74 ExpressInterest (Ptr<Interest> interest,
75 DataCallback onData,
76 TimeoutCallback onTimeout); // = MakeNullCallback< void, Ptr<Interest> > ()
77
78 /**
79 * @brief set Interest filter (specify what interest you want to receive)
80 *
81 * @param prefix the prefix of Interest
82 * @param onInterest the callback function to deal with the returned data
83 */
84 void
85 SetInterestFilter (Ptr<const Name> prefix, InterestCallback onInterest);
86
87 /**
88 * @brief clear Interest filter
89 * @param prefix the prefix of Interest
90 */
91 void
92 ClearInterestFilter (Ptr<const Name> prefix);
93
94 /**
95 * @brief Publish data
96 * @param data Data packet to publish
97 */
98 void
99 Put (Ptr<ContentObject> data);
100
101public:
102 virtual bool
103 SendInterest (Ptr<const Interest> interest);
104
105 virtual bool
106 SendData (Ptr<const ContentObject> data);
107
108 virtual std::ostream&
109 Print (std::ostream &os) const;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700110
111private:
Alexander Afanasyev79606062013-07-11 00:57:28 -0700112 ApiFace () : Face (0) {}
113 ApiFace (const ApiFace &) : Face (0) {}
114 ApiFace& operator= (const ApiFace &) { return *this; }
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700115
116private:
Alexander Afanasyev79606062013-07-11 00:57:28 -0700117 ApiFacePriv *m_this;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700118};
119
Alexander Afanasyevf23a7b62013-07-17 13:22:25 -0700120} // ndn
121} // ns3
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700122
123#endif // NDN_API_HANDLER_H