Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | b5f8bcc | 2017-02-05 17:58:05 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017 Regents of the University of California, |
| 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 | |
| 31 | #include "../name.hpp" |
| 32 | #include "../face.hpp" |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 33 | #include "../security/v1/key-chain.hpp" |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 34 | |
| 35 | #include "concepts.hpp" |
| 36 | |
| 37 | namespace ndn { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 38 | namespace util { |
| 39 | |
| 40 | /** \brief provides a publisher of Notification Stream |
| 41 | * \sa http://redmine.named-data.net/projects/nfd/wiki/Notification |
| 42 | */ |
| 43 | template<typename Notification> |
| 44 | class NotificationStream : noncopyable |
| 45 | { |
| 46 | public: |
| 47 | BOOST_CONCEPT_ASSERT((WireEncodable<Notification>)); |
| 48 | |
| 49 | NotificationStream(Face& face, const Name& prefix, KeyChain& keyChain) |
| 50 | : m_face(face) |
| 51 | , m_prefix(prefix) |
| 52 | , m_keyChain(keyChain) |
| 53 | , m_sequenceNo(0) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | virtual |
Davide Pesavento | b5f8bcc | 2017-02-05 17:58:05 -0500 | [diff] [blame^] | 58 | ~NotificationStream() = default; |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 59 | |
| 60 | void |
| 61 | postNotification(const Notification& notification) |
| 62 | { |
| 63 | Name dataName = m_prefix; |
| 64 | dataName.appendSequenceNumber(m_sequenceNo); |
| 65 | |
| 66 | shared_ptr<Data> data = make_shared<Data>(dataName); |
| 67 | data->setContent(notification.wireEncode()); |
| 68 | data->setFreshnessPeriod(time::seconds(1)); |
| 69 | |
| 70 | m_keyChain.sign(*data); |
| 71 | m_face.put(*data); |
| 72 | |
| 73 | ++m_sequenceNo; |
| 74 | } |
| 75 | |
| 76 | private: |
| 77 | Face& m_face; |
| 78 | const Name m_prefix; |
| 79 | KeyChain& m_keyChain; |
| 80 | uint64_t m_sequenceNo; |
| 81 | }; |
| 82 | |
| 83 | } // namespace util |
| 84 | } // namespace ndn |
| 85 | |
| 86 | #endif // NDN_UTIL_NOTIFICATION_STREAM_HPP |