Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | #ifndef NFD_MGMT_NOTIFICATION_STREAM_HPP |
| 7 | #define NFD_MGMT_NOTIFICATION_STREAM_HPP |
| 8 | |
| 9 | #include "mgmt/app-face.hpp" |
| 10 | |
| 11 | namespace nfd { |
| 12 | |
| 13 | class NotificationStream |
| 14 | { |
| 15 | public: |
| 16 | NotificationStream(shared_ptr<AppFace> face, const Name& prefix); |
| 17 | |
| 18 | ~NotificationStream(); |
| 19 | |
| 20 | template <typename T> void |
| 21 | postNotification(const T& notification); |
| 22 | |
| 23 | private: |
| 24 | shared_ptr<AppFace> m_face; |
| 25 | const Name m_prefix; |
| 26 | uint64_t m_sequenceNo; |
| 27 | }; |
| 28 | |
| 29 | inline |
| 30 | NotificationStream::NotificationStream(shared_ptr<AppFace> face, const Name& prefix) |
| 31 | : m_face(face) |
| 32 | , m_prefix(prefix) |
| 33 | , m_sequenceNo(0) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | template <typename T> |
| 38 | inline void |
| 39 | NotificationStream::postNotification(const T& notification) |
| 40 | { |
| 41 | Name dataName(m_prefix); |
| 42 | dataName.appendSegment(m_sequenceNo); |
| 43 | shared_ptr<Data> data(make_shared<Data>(dataName)); |
| 44 | data->setContent(notification.wireEncode()); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 45 | data->setFreshnessPeriod(time::seconds(1)); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 46 | |
| 47 | m_face->sign(*data); |
| 48 | m_face->put(*data); |
| 49 | |
| 50 | ++m_sequenceNo; |
| 51 | } |
| 52 | |
| 53 | inline |
| 54 | NotificationStream::~NotificationStream() |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | } // namespace nfd |
| 59 | |
| 60 | |
| 61 | #endif // NFD_MGMT_NOTIFICATION_STREAM_HPP |