blob: 1c7887e036221e6d13b79da051dfb8b585246f37 [file] [log] [blame]
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventob5f8bcc2017-02-05 17:58:05 -05003 * 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 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
31#include "../name.hpp"
32#include "../face.hpp"
Alexander Afanasyev80782e02017-01-04 13:16:54 -080033#include "../security/v2/key-chain.hpp"
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070034
35#include "concepts.hpp"
36
37namespace ndn {
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070038namespace util {
39
40/** \brief provides a publisher of Notification Stream
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -080041 * \sa https://redmine.named-data.net/projects/nfd/wiki/Notification
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070042 */
43template<typename Notification>
44class NotificationStream : noncopyable
45{
46public:
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 Pesaventob5f8bcc2017-02-05 17:58:05 -050058 ~NotificationStream() = default;
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070059
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
76private:
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