blob: 9a89b4ccc5211a549a4cfbb90d84fcad27603af9 [file] [log] [blame]
Junxiao Shi15b12e72014-08-09 19:56:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NFD_CORE_NOTIFICATION_STREAM_HPP
27#define NFD_CORE_NOTIFICATION_STREAM_HPP
28
29#include "common.hpp"
30
31#include <ndn-cxx/encoding/encoding-buffer.hpp>
32#include <ndn-cxx/security/key-chain.hpp>
33
34namespace nfd {
35
36/** \brief provides a publisher of Notification Stream
37 * \sa http://redmine.named-data.net/projects/nfd/wiki/Notification
38 */
39template <class FaceBase>
40class NotificationStream : noncopyable
41{
42public:
43 NotificationStream(FaceBase& face, const Name& prefix, ndn::KeyChain& keyChain)
44 : m_face(face)
45 , m_prefix(prefix)
46 , m_keyChain(keyChain)
47 , m_sequenceNo(0)
48 {
49 }
50
51 virtual
52 ~NotificationStream()
53 {
54 }
55
56 template<typename T> void
57 postNotification(const T& notification)
58 {
59 Name dataName = m_prefix;
60 dataName.appendSequenceNumber(m_sequenceNo);
61
62 shared_ptr<Data> data = make_shared<Data>(dataName);
63 data->setContent(notification.wireEncode());
64 data->setFreshnessPeriod(time::seconds(1));
65
66 m_keyChain.sign(*data);
67 m_face.put(*data);
68
69 ++m_sequenceNo;
70 }
71
72private:
73 FaceBase& m_face;
74 const Name m_prefix;
75 ndn::KeyChain& m_keyChain;
76 uint64_t m_sequenceNo;
77};
78
79} // namespace nfd
80
81#endif // NFD_CORE_NOTIFICATION_STREAM_HPP