blob: fda34d15c6f0b0b93bbeb19ff5af43bb870922f6 [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>
Alexander Afanasyev6eba36f2013-08-07 17:42:54 -070032#include <ns3/ndn-data.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/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070040 * @ingroup ndn
41 * @defgroup ndn-cxx NDN.cxx API
42 */
43
44/**
45 * @ingroup ndn-face
46 * @ingroup ndn-cxx
47 * @brief An application NDN face, providing richer API interface, compared to ndn::AppFace
48 *
49 * @see ndn::AppFace
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070050 */
51class ApiFace
Alexander Afanasyev79606062013-07-11 00:57:28 -070052 : public ns3::ndn::Face
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070053{
54public:
Alexander Afanasyev79606062013-07-11 00:57:28 -070055 typedef Callback<void, Ptr<const Name>, Ptr<const Interest> > InterestCallback;
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070056 typedef Callback<void, Ptr<const Interest>, Ptr<const Data> > DataCallback;
Alexander Afanasyev79606062013-07-11 00:57:28 -070057 typedef Callback<void, Ptr<const Interest> > TimeoutCallback;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070058
59 /**
Alexander Afanasyev79606062013-07-11 00:57:28 -070060 * @brief initialize the handler; a lot of things needs to be done. 1) init
61 * keystore 2) init keylocator 3) start a thread to hold a loop of ccn_run
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070062 *
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070063 */
Alexander Afanasyev79606062013-07-11 00:57:28 -070064 ApiFace (Ptr<Node> node);
65 ~ApiFace ();
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070066
Alexander Afanasyev79606062013-07-11 00:57:28 -070067 /**
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070068 * @brief Shutdown the API face
69 */
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070070 virtual void
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070071 Shutdown ();
72
73 /**
Alexander Afanasyev79606062013-07-11 00:57:28 -070074 * @brief Express Interest
75 *
76 * @param name the Interest name
77 * @param onData the callback function to deal with the returned data
78 * @param onTimeout the callback function to deal with timeouts
79 */
80 void
81 ExpressInterest (Ptr<Interest> interest,
82 DataCallback onData,
83 TimeoutCallback onTimeout); // = MakeNullCallback< void, Ptr<Interest> > ()
84
85 /**
86 * @brief set Interest filter (specify what interest you want to receive)
87 *
88 * @param prefix the prefix of Interest
89 * @param onInterest the callback function to deal with the returned data
90 */
91 void
92 SetInterestFilter (Ptr<const Name> prefix, InterestCallback onInterest);
93
94 /**
95 * @brief clear Interest filter
96 * @param prefix the prefix of Interest
97 */
98 void
99 ClearInterestFilter (Ptr<const Name> prefix);
100
101 /**
102 * @brief Publish data
103 * @param data Data packet to publish
104 */
105 void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700106 Put (Ptr<Data> data);
Alexander Afanasyev79606062013-07-11 00:57:28 -0700107
108public:
109 virtual bool
110 SendInterest (Ptr<const Interest> interest);
111
112 virtual bool
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700113 SendData (Ptr<const Data> data);
Alexander Afanasyev79606062013-07-11 00:57:28 -0700114
115 virtual std::ostream&
116 Print (std::ostream &os) const;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700117
118private:
Alexander Afanasyev79606062013-07-11 00:57:28 -0700119 ApiFace () : Face (0) {}
120 ApiFace (const ApiFace &) : Face (0) {}
121 ApiFace& operator= (const ApiFace &) { return *this; }
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700122
123private:
Alexander Afanasyev79606062013-07-11 00:57:28 -0700124 ApiFacePriv *m_this;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700125};
126
Alexander Afanasyevf23a7b62013-07-17 13:22:25 -0700127} // ndn
128} // ns3
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700129
130#endif // NDN_API_HANDLER_H