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> |
| 32 | #include <ns3/ndn-content-object.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 | /** |
| 40 | * \ingroup sync |
| 41 | * @brief A handler for NDN; clients of this code do not need to deal |
| 42 | * with NDN API directly |
| 43 | */ |
| 44 | class ApiFace |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 45 | : public ns3::ndn::Face |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 48 | 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 Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 53 | * @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 Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 55 | * |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 56 | */ |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 57 | ApiFace (Ptr<Node> node); |
| 58 | ~ApiFace (); |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 60 | /** |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 61 | * @brief Shutdown the API face |
| 62 | */ |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 63 | virtual void |
Alexander Afanasyev | a4e7428 | 2013-07-11 15:23:20 -0700 | [diff] [blame] | 64 | Shutdown (); |
| 65 | |
| 66 | /** |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 67 | * @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 | |
| 101 | public: |
| 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 Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 110 | |
| 111 | private: |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 112 | ApiFace () : Face (0) {} |
| 113 | ApiFace (const ApiFace &) : Face (0) {} |
| 114 | ApiFace& operator= (const ApiFace &) { return *this; } |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 115 | |
| 116 | private: |
Alexander Afanasyev | 7960606 | 2013-07-11 00:57:28 -0700 | [diff] [blame] | 117 | ApiFacePriv *m_this; |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Alexander Afanasyev | f23a7b6 | 2013-07-17 13:22:25 -0700 | [diff] [blame] | 120 | } // ndn |
| 121 | } // ns3 |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 122 | |
| 123 | #endif // NDN_API_HANDLER_H |