Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 26 | #include <ns3/ptr.h> |
| 27 | #include <ns3/node.h> |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 28 | #include <ns3/callback.h> |
| 29 | #include <ns3/ndn-face.h> |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 30 | #include <ns3/ndn-name.h> |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 31 | #include <ns3/ndn-interest.h> |
Alexander Afanasyev | 6eba36f | 2013-08-07 17:42:54 -0700 | [diff] [blame] | 32 | #include <ns3/ndn-data.h> |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 34 | namespace ns3 { |
| 35 | namespace ndn { |
| 36 | |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 37 | class ApiFacePriv; |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 38 | |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 39 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 40 | * @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 Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 50 | */ |
| 51 | class ApiFace |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 52 | : public ns3::ndn::Face |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 53 | { |
| 54 | public: |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 55 | typedef Callback<void, Ptr<const Name>, Ptr<const Interest> > InterestCallback; |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 56 | typedef Callback<void, Ptr<const Interest>, Ptr<const Data> > DataCallback; |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 57 | typedef Callback<void, Ptr<const Interest> > TimeoutCallback; |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 60 | * @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 Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 62 | * |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 63 | */ |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 64 | ApiFace (Ptr<Node> node); |
| 65 | ~ApiFace (); |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 66 | |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 67 | /** |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 68 | * @brief Shutdown the API face |
| 69 | */ |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 70 | virtual void |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 71 | Shutdown (); |
| 72 | |
| 73 | /** |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 74 | * @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 Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 106 | Put (Ptr<Data> data); |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 107 | |
| 108 | public: |
| 109 | virtual bool |
| 110 | SendInterest (Ptr<const Interest> interest); |
| 111 | |
| 112 | virtual bool |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 113 | SendData (Ptr<const Data> data); |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 114 | |
| 115 | virtual std::ostream& |
| 116 | Print (std::ostream &os) const; |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 117 | |
| 118 | private: |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 119 | ApiFace () : Face (0) {} |
| 120 | ApiFace (const ApiFace &) : Face (0) {} |
| 121 | ApiFace& operator= (const ApiFace &) { return *this; } |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 122 | |
| 123 | private: |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 124 | ApiFacePriv *m_this; |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
Alexander Afanasyev | f23a7b6 | 2013-07-17 13:22:25 -0700 | [diff] [blame] | 127 | } // ndn |
| 128 | } // ns3 |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 129 | |
| 130 | #endif // NDN_API_HANDLER_H |