blob: 780ea948c1c765411e32a062f2bf1cb571ac538f [file] [log] [blame]
Steve DiBenedettofbb40a82014-03-11 19:40:15 -06001/* -*- 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
11namespace nfd {
12
13class NotificationStream
14{
15public:
16 NotificationStream(shared_ptr<AppFace> face, const Name& prefix);
17
18 ~NotificationStream();
19
20 template <typename T> void
21 postNotification(const T& notification);
22
23private:
24 shared_ptr<AppFace> m_face;
25 const Name m_prefix;
26 uint64_t m_sequenceNo;
27};
28
29inline
30NotificationStream::NotificationStream(shared_ptr<AppFace> face, const Name& prefix)
31 : m_face(face)
32 , m_prefix(prefix)
33 , m_sequenceNo(0)
34{
35}
36
37template <typename T>
38inline void
39NotificationStream::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 Afanasyev82afa1a2014-03-20 16:56:56 -070045 data->setFreshnessPeriod(time::seconds(1));
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060046
47 m_face->sign(*data);
48 m_face->put(*data);
49
50 ++m_sequenceNo;
51}
52
53inline
54NotificationStream::~NotificationStream()
55{
56}
57
58} // namespace nfd
59
60
61#endif // NFD_MGMT_NOTIFICATION_STREAM_HPP