NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
notification-stream.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_CORE_NOTIFICATION_STREAM_HPP
27 #define NFD_CORE_NOTIFICATION_STREAM_HPP
28 
29 #include "common.hpp"
30 
31 #include <ndn-cxx/encoding/encoding-buffer.hpp>
32 #include <ndn-cxx/security/key-chain.hpp>
33 
34 namespace nfd {
35 
39 template <class FaceBase>
40 class NotificationStream : noncopyable
41 {
42 public:
43  NotificationStream(FaceBase& face, const Name& prefix, ndn::KeyChain& keyChain)
44  : m_face(face)
45  , m_prefix(prefix)
46  , m_keyChain(keyChain)
47  , m_sequenceNo(0)
48  {
49  }
50 
51  virtual
53  {
54  }
55 
56  template<typename T> void
57  postNotification(const T& notification)
58  {
59  Name dataName = m_prefix;
60  dataName.appendSequenceNumber(m_sequenceNo);
61 
62  shared_ptr<Data> data = make_shared<Data>(dataName);
63  data->setContent(notification.wireEncode());
64  data->setFreshnessPeriod(time::seconds(1));
65 
66  m_keyChain.sign(*data);
67  m_face.put(*data);
68 
69  ++m_sequenceNo;
70  }
71 
72 private:
73  FaceBase& m_face;
74  const Name m_prefix;
75  ndn::KeyChain& m_keyChain;
76  uint64_t m_sequenceNo;
77 };
78 
79 } // namespace nfd
80 
81 #endif // NFD_CORE_NOTIFICATION_STREAM_HPP
provides a publisher of Notification Stream
NotificationStream(FaceBase &face, const Name &prefix, ndn::KeyChain &keyChain)
void postNotification(const T &notification)