blob: 274103595d80d83a3b7ec4c3f36b7fc4ec8b82d5 [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());
45
46 m_face->sign(*data);
47 m_face->put(*data);
48
49 ++m_sequenceNo;
50}
51
52inline
53NotificationStream::~NotificationStream()
54{
55}
56
57} // namespace nfd
58
59
60#endif // NFD_MGMT_NOTIFICATION_STREAM_HPP