Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011-2013 University of California, Los Angeles |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 22 | #include "ndn-content-object.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 24 | #include "ns3/log.h" |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 25 | |
| 26 | #include <boost/foreach.hpp> |
| 27 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 28 | NS_LOG_COMPONENT_DEFINE ("ndn.ContentObject"); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 30 | namespace ns3 { |
| 31 | namespace ndn { |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 33 | NS_OBJECT_ENSURE_REGISTERED (ContentObject); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 34 | NS_OBJECT_ENSURE_REGISTERED (ContentObjectTail); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 36 | ContentObject::ContentObject () |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 37 | : m_signature (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame^] | 41 | ContentObject::ContentObject (const ContentObject &other) |
| 42 | : m_name (Create<Name> (other.GetName ())) |
| 43 | , m_freshness (other->GetFreshness ()) |
| 44 | , m_timestamp (other->GetTimestamp ()) |
| 45 | , m_signature (other->GetSignature ()) |
| 46 | , m_payload (other->GetPayload ()->Copy ()) |
| 47 | , m_wire (0) |
| 48 | { |
| 49 | } |
| 50 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 51 | void |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 52 | ContentObject::SetName (Ptr<Name> name) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 53 | { |
| 54 | m_name = name; |
| 55 | } |
| 56 | |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 57 | void |
| 58 | ContentObject::SetName (const Name &name) |
| 59 | { |
| 60 | m_name = Create<Name> (name); |
| 61 | } |
| 62 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 63 | const Name& |
| 64 | ContentObject::GetName () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 65 | { |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 66 | if (m_name==0) throw ContentObjectException(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 67 | return *m_name; |
| 68 | } |
| 69 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 70 | Ptr<const Name> |
| 71 | ContentObject::GetNamePtr () const |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 72 | { |
| 73 | return m_name; |
| 74 | } |
| 75 | |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 76 | |
| 77 | void |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 78 | ContentObject::SetTimestamp (const Time ×tamp) |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 79 | { |
| 80 | m_timestamp = timestamp; |
| 81 | } |
| 82 | |
| 83 | Time |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 84 | ContentObject::GetTimestamp () const |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 85 | { |
| 86 | return m_timestamp; |
| 87 | } |
| 88 | |
| 89 | void |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 90 | ContentObject::SetFreshness (const Time &freshness) |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 91 | { |
| 92 | m_freshness = freshness; |
| 93 | } |
| 94 | |
| 95 | Time |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 96 | ContentObject::GetFreshness () const |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 97 | { |
| 98 | return m_freshness; |
| 99 | } |
| 100 | |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 101 | void |
| 102 | ContentObject::SetSignature (uint32_t signature) |
| 103 | { |
| 104 | m_signature = signature; |
| 105 | } |
| 106 | |
| 107 | uint32_t |
| 108 | ContentObject::GetSignature () const |
| 109 | { |
| 110 | return m_signature; |
| 111 | } |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 112 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 113 | void |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 114 | ContentObject::Print (std::ostream &os) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 115 | { |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 116 | os << "D: " << GetName (); |
| 117 | // os << "<ContentObject><Name>" << GetName () << "</Name><Content>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 120 | } // namespace ndn |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 121 | } // namespace ns3 |