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 
29 struct ndn_MetaInfo;
30 
31 namespace ndn {
32 
36 class MetaInfo {
37 public:
38  MetaInfo()
39  : changeCount_(0)
40  {
41  timestampMilliseconds_ = -1;
42  type_ = ndn_ContentType_BLOB;
43  freshnessPeriod_ = -1;
44  }
45 
51  void
52  get(struct ndn_MetaInfo& metaInfoStruct) const;
53 
58  void
59  set(const struct ndn_MetaInfo& metaInfoStruct);
60 
65  DEPRECATED_IN_NDN_CPP getTimestampMilliseconds() const
66  {
67  return timestampMilliseconds_;
68  }
69 
70  ndn_ContentType
71  getType() const { return type_; }
72 
74  getFreshnessPeriod() const { return freshnessPeriod_; }
75 
79  int
80  DEPRECATED_IN_NDN_CPP getFreshnessSeconds() const
81  {
82  return freshnessPeriod_ < 0 ? -1 : (int)round(freshnessPeriod_ / 1000.0);
83  }
84 
90  const Name::Component&
91  getFinalBlockId() const { return finalBlockId_; }
92 
96  const Name::Component&
97  DEPRECATED_IN_NDN_CPP getFinalBlockID() const { return getFinalBlockId(); }
98 
102  void
103  DEPRECATED_IN_NDN_CPP setTimestampMilliseconds
105  {
106  timestampMilliseconds_ = timestampMilliseconds;
107  ++changeCount_;
108  }
109 
110  void
111  setType(ndn_ContentType type)
112  {
113  type_ = type;
114  ++changeCount_;
115  }
116 
117  void
118  setFreshnessPeriod(Milliseconds freshnessPeriod)
119  {
120  freshnessPeriod_ = freshnessPeriod;
121  ++changeCount_;
122  }
123 
127  void
128  DEPRECATED_IN_NDN_CPP setFreshnessSeconds(int freshnessSeconds)
129  {
130  setFreshnessPeriod(freshnessSeconds < 0 ? -1.0 : (double)freshnessSeconds * 1000.0);
131  }
132 
138  void
140  {
141  finalBlockId_ = finalBlockId;
142  ++changeCount_;
143  }
144 
148  void
149  DEPRECATED_IN_NDN_CPP setFinalBlockID(const Name::Component& finalBlockId)
150  {
151  finalBlockId_ = finalBlockId;
152  ++changeCount_;
153  }
154 
159  uint64_t
160  getChangeCount() const { return changeCount_; }
161 
162 private:
163  MillisecondsSince1970 timestampMilliseconds_;
164  ndn_ContentType type_;
165  Milliseconds freshnessPeriod_;
166  Name::Component finalBlockId_;
167  uint64_t changeCount_;
168 };
169 
170 }
171 
172 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:111
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
ndn_MillisecondsSince1970 timestampMilliseconds
milliseconds since 1/1/1970.
Definition: data-types.h:80
const Name::Component & getFinalBlockId() const
Get the final block ID.
Definition: meta-info.hpp:91
ndn_ContentType type
default is ndn_ContentType_DATA.
Definition: data-types.h:81
void DEPRECATED_IN_NDN_CPP setTimestampMilliseconds(MillisecondsSince1970 timestampMilliseconds)
Definition: meta-info.hpp:104
A Name::Component holds a read-only name component value.
Definition: name.hpp:47
int DEPRECATED_IN_NDN_CPP getFreshnessSeconds() const
Definition: meta-info.hpp:80
void set(const struct ndn_MetaInfo &metaInfoStruct)
Clear this meta info, and set the values by copying from the ndn_MetaInfo struct. ...
Definition: meta-info.cpp:39
struct ndn_NameComponent finalBlockId
has a pointer to a pre-allocated buffer.
Definition: data-types.h:83
An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
Definition: data-types.h:79
const Name::Component &DEPRECATED_IN_NDN_CPP getFinalBlockID() const
Definition: meta-info.hpp:97
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:160
MillisecondsSince1970 DEPRECATED_IN_NDN_CPP getTimestampMilliseconds() const
Definition: meta-info.hpp:65
A MetaInfo holds the meta info which is signed inside the data packet.
Definition: meta-info.hpp:36
ndn_Milliseconds freshnessPeriod
-1 for none
Definition: data-types.h:82
void DEPRECATED_IN_NDN_CPP setFreshnessSeconds(int freshnessSeconds)
Definition: meta-info.hpp:128
void DEPRECATED_IN_NDN_CPP setFinalBlockID(const Name::Component &finalBlockId)
Definition: meta-info.hpp:149
void setFinalBlockId(const Name::Component &finalBlockId)
Set the final block ID.
Definition: meta-info.hpp:139