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  otherTypeCode_ = -1;
43  freshnessPeriod_ = -1;
44  }
45 
53  void
54  get(MetaInfoLite& metaInfoLite) const;
55 
60  void
61  set(const MetaInfoLite& metaInfoLite);
62 
67  DEPRECATED_IN_NDN_CPP getTimestampMilliseconds() const
68  {
69  return timestampMilliseconds_;
70  }
71 
77  ndn_ContentType
78  getType() const { return type_; }
79 
86  int
87  getOtherTypeCode() const { return otherTypeCode_; }
88 
90  getFreshnessPeriod() const { return freshnessPeriod_; }
91 
95  int
96  DEPRECATED_IN_NDN_CPP getFreshnessSeconds() const
97  {
98  return freshnessPeriod_ < 0 ? -1 : (int)round(freshnessPeriod_ / 1000.0);
99  }
100 
106  const Name::Component&
107  getFinalBlockId() const { return finalBlockId_; }
108 
112  const Name::Component&
113  DEPRECATED_IN_NDN_CPP getFinalBlockID() const { return getFinalBlockId(); }
114 
118  void
119  DEPRECATED_IN_NDN_CPP setTimestampMilliseconds
120  (MillisecondsSince1970 timestampMilliseconds)
121  {
122  timestampMilliseconds_ = timestampMilliseconds;
123  ++changeCount_;
124  }
125 
132  void
133  setType(ndn_ContentType type)
134  {
135  type_ = type;
136  ++changeCount_;
137  }
138 
146  void
147  setOtherTypeCode(int otherTypeCode);
148 
149  void
150  setFreshnessPeriod(Milliseconds freshnessPeriod)
151  {
152  freshnessPeriod_ = freshnessPeriod;
153  ++changeCount_;
154  }
155 
159  void
160  DEPRECATED_IN_NDN_CPP setFreshnessSeconds(int freshnessSeconds)
161  {
162  setFreshnessPeriod(freshnessSeconds < 0 ? -1.0 : (double)freshnessSeconds * 1000.0);
163  }
164 
170  void
171  setFinalBlockId(const Name::Component& finalBlockId)
172  {
173  finalBlockId_ = finalBlockId;
174  ++changeCount_;
175  }
176 
180  void
181  DEPRECATED_IN_NDN_CPP setFinalBlockID(const Name::Component& finalBlockId)
182  {
183  finalBlockId_ = finalBlockId;
184  ++changeCount_;
185  }
186 
191  uint64_t
192  getChangeCount() const { return changeCount_; }
193 
194 private:
195  MillisecondsSince1970 timestampMilliseconds_;
196  ndn_ContentType type_;
197  int otherTypeCode_;
198  Milliseconds freshnessPeriod_;
199  Name::Component finalBlockId_;
200  uint64_t changeCount_;
201 };
202 
203 }
204 
205 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:112
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
void set(const MetaInfoLite &metaInfoLite)
Clear this meta info, and set the values by copying from metaInfoLite.
Definition: meta-info.cpp:43
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:107
ndn_ContentType getType() const
Get the content type.
Definition: meta-info.hpp:78
void DEPRECATED_IN_NDN_CPP setTimestampMilliseconds(MillisecondsSince1970 timestampMilliseconds)
Definition: meta-info.hpp:120
void setType(ndn_ContentType type)
Set the content type.
Definition: meta-info.hpp:133
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:96
void setOtherTypeCode(int otherTypeCode)
Set the packet's content type code to use when the content type enum is ndn_ContentType_OTHER_CODE.
Definition: meta-info.cpp:56
const Name::Component &DEPRECATED_IN_NDN_CPP getFinalBlockID() const
Definition: meta-info.hpp:113
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:117
uint64_t getChangeCount() const
Get the change count, which is incremented each time this object is changed.
Definition: meta-info.hpp:192
int getOtherTypeCode() const
Get the content type code from the packet which is other than a recognized ContentType enum value...
Definition: meta-info.hpp:87
MillisecondsSince1970 DEPRECATED_IN_NDN_CPP getTimestampMilliseconds() const
Definition: meta-info.hpp:67
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:160
void DEPRECATED_IN_NDN_CPP setFinalBlockID(const Name::Component &finalBlockId)
Definition: meta-info.hpp:181
void setFinalBlockId(const Name::Component &finalBlockId)
Set the final block ID.
Definition: meta-info.hpp:171