blob: 06c3b5a634dccece3730c30b53129c91219a403f [file] [log] [blame]
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehman5144f822014-07-23 15:12:56 -07003 * 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
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Vince Lehman5144f822014-07-23 15:12:56 -070024 */
25
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_MGMT_NOTIFICATION_STREAM_HPP
27#define NFD_DAEMON_MGMT_NOTIFICATION_STREAM_HPP
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060028
29#include "mgmt/app-face.hpp"
30
31namespace nfd {
32
33class NotificationStream
34{
35public:
Vince Lehman5144f822014-07-23 15:12:56 -070036 NotificationStream(shared_ptr<AppFace> face, const Name& prefix, ndn::KeyChain& keyChain);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060037
38 ~NotificationStream();
39
40 template <typename T> void
41 postNotification(const T& notification);
42
43private:
44 shared_ptr<AppFace> m_face;
45 const Name m_prefix;
46 uint64_t m_sequenceNo;
Vince Lehman5144f822014-07-23 15:12:56 -070047 ndn::KeyChain& m_keyChain;
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060048};
49
50inline
Vince Lehman5144f822014-07-23 15:12:56 -070051NotificationStream::NotificationStream(shared_ptr<AppFace> face,
52 const Name& prefix,
53 ndn::KeyChain& keyChain)
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060054 : m_face(face)
55 , m_prefix(prefix)
56 , m_sequenceNo(0)
Vince Lehman5144f822014-07-23 15:12:56 -070057 , m_keyChain(keyChain)
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060058{
59}
60
61template <typename T>
62inline void
63NotificationStream::postNotification(const T& notification)
64{
65 Name dataName(m_prefix);
66 dataName.appendSegment(m_sequenceNo);
67 shared_ptr<Data> data(make_shared<Data>(dataName));
68 data->setContent(notification.wireEncode());
Alexander Afanasyev82afa1a2014-03-20 16:56:56 -070069 data->setFreshnessPeriod(time::seconds(1));
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060070
Vince Lehman5144f822014-07-23 15:12:56 -070071 m_keyChain.sign(*data);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060072 m_face->put(*data);
73
74 ++m_sequenceNo;
75}
76
77inline
78NotificationStream::~NotificationStream()
79{
80}
81
82} // namespace nfd
83
84
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070085#endif // NFD_DAEMON_MGMT_NOTIFICATION_STREAM_HPP