meta-info.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_META_INFO_HPP
23 #define NDN_META_INFO_HPP
24 
25 #include <math.h>
26 #include "name.hpp"
27 #include "c/data-types.h"
28 #include "lite/meta-info-lite.hpp"
29 
30 namespace ndn {
31 
35 class MetaInfo {
36 public:
37  MetaInfo()
38  : changeCount_(0)
39  {
40  timestampMilliseconds_ = -1;
41  type_ = ndn_ContentType_BLOB;
42  freshnessPeriod_ = -1;
43  }
44 
52  void
53  get(MetaInfoLite& metaInfoLite) const;
54 
59  void
60  set(const MetaInfoLite& metaInfoLite);
61 
66  DEPRECATED_IN_NDN_CPP getTimestampMilliseconds() const
67  {
68  return timestampMilliseconds_;
69  }
70 
71  ndn_ContentType
72  getType() const { return type_; }
73 
75  getFreshnessPeriod() const { return freshnessPeriod_; }
76 
80  int
81  DEPRECATED_IN_NDN_CPP getFreshnessSeconds() const
82  {
83  return freshnessPeriod_ < 0 ? -1 : (int)round(freshnessPeriod_ / 1000.0);
84  }
85 
91  const Name::Component&
92  getFinalBlockId() const { return finalBlockId_; }
93 
97  const Name::Component&
98  DEPRECATED_IN_NDN_CPP getFinalBlockID() const { return getFinalBlockId(); }
99 
103  void
104  DEPRECATED_IN_NDN_CPP setTimestampMilliseconds
105  (MillisecondsSince1970 timestampMilliseconds)
106  {
107  timestampMilliseconds_ = timestampMilliseconds;
108  ++changeCount_;
109  }
110 
111  void
112  setType(ndn_ContentType type)
113  {
114  type_ = type;
115  ++changeCount_;
116  }
117 
118  void
119  setFreshnessPeriod(Milliseconds freshnessPeriod)
120  {
121  freshnessPeriod_ = freshnessPeriod;
122  ++changeCount_;
123  }
124 
128  void
129  DEPRECATED_IN_NDN_CPP setFreshnessSeconds(int freshnessSeconds)
130  {
131  setFreshnessPeriod(freshnessSeconds < 0 ? -1.0 : (double)freshnessSeconds * 1000.0);
132  }
133 
139  void
140  setFinalBlockId(const Name::Component& finalBlockId)
141  {
142  finalBlockId_ = finalBlockId;
143  ++changeCount_;
144  }
145 
149  void
150  DEPRECATED_IN_NDN_CPP setFinalBlockID(const Name::Component& finalBlockId)
151  {
152  finalBlockId_ = finalBlockId;
153  ++changeCount_;
154  }
155 
160  uint64_t
161  getChangeCount() const { return changeCount_; }
162 
163 private:
164  MillisecondsSince1970 timestampMilliseconds_;
165  ndn_ContentType type_;
166  Milliseconds freshnessPeriod_;
167  Name::Component finalBlockId_;
168  uint64_t changeCount_;
169 };
170 
171 }
172 
173 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:111
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
void set(const MetaInfoLite &metaInfoLite)
Clear this meta info, and set the values by copying from metaInfoLite.
Definition: meta-info.cpp:41
A MetaInfoLite holds a type and other info to represent the meta info of a Data packet.
Definition: meta-info-lite.hpp:35
const Name::Component & getFinalBlockId() const
Get the final block ID.
Definition: meta-info.hpp:92
void DEPRECATED_IN_NDN_CPP setTimestampMilliseconds(MillisecondsSince1970 timestampMilliseconds)
Definition: meta-info.hpp:105
A Name::Component holds a read-only name component value.
Definition: name.hpp:45
int DEPRECATED_IN_NDN_CPP getFreshnessSeconds() const
Definition: meta-info.hpp:81
const Name::Component &DEPRECATED_IN_NDN_CPP getFinalBlockID() const
Definition: meta-info.hpp:98
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:116
uint64_t getChangeCount() const
Get the change count, which is incremented each time this object is changed.
Definition: meta-info.hpp:161
MillisecondsSince1970 DEPRECATED_IN_NDN_CPP getTimestampMilliseconds() const
Definition: meta-info.hpp:66
A MetaInfo holds the meta info which is signed inside the data packet.
Definition: meta-info.hpp:35
void DEPRECATED_IN_NDN_CPP setFreshnessSeconds(int freshnessSeconds)
Definition: meta-info.hpp:129
void DEPRECATED_IN_NDN_CPP setFinalBlockID(const Name::Component &finalBlockId)
Definition: meta-info.hpp:150
void setFinalBlockId(const Name::Component &finalBlockId)
Set the final block ID.
Definition: meta-info.hpp:140