Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Original copyright notice from NFD: |
| 24 | * |
| 25 | * Copyright (c) 2014, Regents of the University of California, |
| 26 | * Arizona Board of Regents, |
| 27 | * Colorado State University, |
| 28 | * University Pierre & Marie Curie, Sorbonne University, |
| 29 | * Washington University in St. Louis, |
| 30 | * Beijing Institute of Technology, |
| 31 | * The University of Memphis |
| 32 | * |
| 33 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 34 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 35 | * |
| 36 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 37 | * of the GNU General Public License as published by the Free Software Foundation, |
| 38 | * either version 3 of the License, or (at your option) any later version. |
| 39 | * |
| 40 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 41 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 42 | * PURPOSE. See the GNU General Public License for more details. |
| 43 | * |
| 44 | * You should have received a copy of the GNU General Public License along with |
| 45 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 46 | */ |
| 47 | |
| 48 | #ifndef NDN_UTIL_NOTIFICATION_STREAM_HPP |
| 49 | #define NDN_UTIL_NOTIFICATION_STREAM_HPP |
| 50 | |
| 51 | #include "../name.hpp" |
| 52 | #include "../face.hpp" |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 53 | #include "../security/v1/key-chain.hpp" |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 54 | |
| 55 | #include "concepts.hpp" |
| 56 | |
| 57 | namespace ndn { |
| 58 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 59 | namespace util { |
| 60 | |
| 61 | /** \brief provides a publisher of Notification Stream |
| 62 | * \sa http://redmine.named-data.net/projects/nfd/wiki/Notification |
| 63 | */ |
| 64 | template<typename Notification> |
| 65 | class NotificationStream : noncopyable |
| 66 | { |
| 67 | public: |
| 68 | BOOST_CONCEPT_ASSERT((WireEncodable<Notification>)); |
| 69 | |
| 70 | NotificationStream(Face& face, const Name& prefix, KeyChain& keyChain) |
| 71 | : m_face(face) |
| 72 | , m_prefix(prefix) |
| 73 | , m_keyChain(keyChain) |
| 74 | , m_sequenceNo(0) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | virtual |
| 79 | ~NotificationStream() |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | postNotification(const Notification& notification) |
| 85 | { |
| 86 | Name dataName = m_prefix; |
| 87 | dataName.appendSequenceNumber(m_sequenceNo); |
| 88 | |
| 89 | shared_ptr<Data> data = make_shared<Data>(dataName); |
| 90 | data->setContent(notification.wireEncode()); |
| 91 | data->setFreshnessPeriod(time::seconds(1)); |
| 92 | |
| 93 | m_keyChain.sign(*data); |
| 94 | m_face.put(*data); |
| 95 | |
| 96 | ++m_sequenceNo; |
| 97 | } |
| 98 | |
| 99 | private: |
| 100 | Face& m_face; |
| 101 | const Name m_prefix; |
| 102 | KeyChain& m_keyChain; |
| 103 | uint64_t m_sequenceNo; |
| 104 | }; |
| 105 | |
| 106 | } // namespace util |
| 107 | } // namespace ndn |
| 108 | |
| 109 | #endif // NDN_UTIL_NOTIFICATION_STREAM_HPP |