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