blob: 5dcf25a3d9aa90503803daae9297f3721a43c70c [file] [log] [blame]
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento0f830802018-01-16 23:58:58 -05002/*
3 * Copyright (c) 2014-2018 Regents of the University of California,
Davide Pesaventob5f8bcc2017-02-05 17:58:05 -05004 * 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 Afanasyev4abdbf12014-08-11 12:48:54 -070010 *
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 Afanasyev4abdbf12014-08-11 12:48:54 -070028#ifndef NDN_UTIL_NOTIFICATION_STREAM_HPP
29#define NDN_UTIL_NOTIFICATION_STREAM_HPP
30
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070031#include "concepts.hpp"
Davide Pesavento0f830802018-01-16 23:58:58 -050032#include "../face.hpp"
33#include "../name.hpp"
34#include "../security/v2/key-chain.hpp"
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070035
36namespace ndn {
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070037namespace util {
38
39/** \brief provides a publisher of Notification Stream
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -080040 * \sa https://redmine.named-data.net/projects/nfd/wiki/Notification
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070041 */
42template<typename Notification>
43class NotificationStream : noncopyable
44{
45public:
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 Pesaventob5f8bcc2017-02-05 17:58:05 -050057 ~NotificationStream() = default;
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070058
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 Pesavento0f830802018-01-16 23:58:58 -050067 data->setFreshnessPeriod(1_s);
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070068
69 m_keyChain.sign(*data);
70 m_face.put(*data);
71
72 ++m_sequenceNo;
73 }
74
75private:
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