blob: 160540e9876eb3bb111242ea53a55135c8d379df [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 /**
Alexander Afanasyeva4e74282013-07-11 15:23:20 -070059 * @brief Shutdown the API face
60 */
61 void
62 Shutdown ();
63
64 /**
Alexander Afanasyev79606062013-07-11 00:57:28 -070065 * @brief Express Interest
66 *
67 * @param name the Interest name
68 * @param onData the callback function to deal with the returned data
69 * @param onTimeout the callback function to deal with timeouts
70 */
71 void
72 ExpressInterest (Ptr<Interest> interest,
73 DataCallback onData,
74 TimeoutCallback onTimeout); // = MakeNullCallback< void, Ptr<Interest> > ()
75
76 /**
77 * @brief set Interest filter (specify what interest you want to receive)
78 *
79 * @param prefix the prefix of Interest
80 * @param onInterest the callback function to deal with the returned data
81 */
82 void
83 SetInterestFilter (Ptr<const Name> prefix, InterestCallback onInterest);
84
85 /**
86 * @brief clear Interest filter
87 * @param prefix the prefix of Interest
88 */
89 void
90 ClearInterestFilter (Ptr<const Name> prefix);
91
92 /**
93 * @brief Publish data
94 * @param data Data packet to publish
95 */
96 void
97 Put (Ptr<ContentObject> data);
98
99public:
100 virtual bool
101 SendInterest (Ptr<const Interest> interest);
102
103 virtual bool
104 SendData (Ptr<const ContentObject> data);
105
106 virtual std::ostream&
107 Print (std::ostream &os) const;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700108
109private:
Alexander Afanasyev79606062013-07-11 00:57:28 -0700110 ApiFace () : Face (0) {}
111 ApiFace (const ApiFace &) : Face (0) {}
112 ApiFace& operator= (const ApiFace &) { return *this; }
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700113
114private:
Alexander Afanasyev79606062013-07-11 00:57:28 -0700115 ApiFacePriv *m_this;
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700116};
117
118}
119}
120
121#endif // NDN_API_HANDLER_H