Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_MGMT_NOTIFICATION_STREAM_HPP |
| 27 | #define NFD_DAEMON_MGMT_NOTIFICATION_STREAM_HPP |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 28 | |
| 29 | #include "mgmt/app-face.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | |
| 33 | class NotificationStream |
| 34 | { |
| 35 | public: |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 36 | NotificationStream(shared_ptr<AppFace> face, const Name& prefix, ndn::KeyChain& keyChain); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 37 | |
| 38 | ~NotificationStream(); |
| 39 | |
| 40 | template <typename T> void |
| 41 | postNotification(const T& notification); |
| 42 | |
| 43 | private: |
| 44 | shared_ptr<AppFace> m_face; |
| 45 | const Name m_prefix; |
| 46 | uint64_t m_sequenceNo; |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 47 | ndn::KeyChain& m_keyChain; |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | inline |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 51 | NotificationStream::NotificationStream(shared_ptr<AppFace> face, |
| 52 | const Name& prefix, |
| 53 | ndn::KeyChain& keyChain) |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 54 | : m_face(face) |
| 55 | , m_prefix(prefix) |
| 56 | , m_sequenceNo(0) |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 57 | , m_keyChain(keyChain) |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 58 | { |
| 59 | } |
| 60 | |
| 61 | template <typename T> |
| 62 | inline void |
| 63 | NotificationStream::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 Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 69 | data->setFreshnessPeriod(time::seconds(1)); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 70 | |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 71 | m_keyChain.sign(*data); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 72 | m_face->put(*data); |
| 73 | |
| 74 | ++m_sequenceNo; |
| 75 | } |
| 76 | |
| 77 | inline |
| 78 | NotificationStream::~NotificationStream() |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | } // namespace nfd |
| 83 | |
| 84 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 85 | #endif // NFD_DAEMON_MGMT_NOTIFICATION_STREAM_HPP |