PacketInterpreter.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 //#include "PacketInterpreter.ih"
18 
19 // Custom includes
20 #include "Packets.hh"
21 
22 //#include "PacketInterpreter.mpp"
23 #define prefix_
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 // senf::PacketInterpreterBase
28 
29 // structors and default members
30 
32 {
34  ptr pi (appendClone(p.p,begin(),p.p->begin()));
35  for (ptr i (next()); i; i = i->next())
36  i->appendClone(p.p,begin(),p.p->begin());
37  pi->impl().assignAnnotations( impl());
38  return pi;
39 }
40 
41 // Interpreter chain access
42 
44 {
45  if (next())
47 
49  if (!r)
51 
52  ptr rv (packet->appendClone(&impl(), *r));
53  rv->data().resize(packet->data().size());
54  std::copy(packet->data().begin(), packet->data().end(), rv->data().begin());
55 
56  for (ptr p (packet->next()) ; p ; p = p->next())
57  p->appendClone(&impl(), packet->data().begin(), rv->data().begin());
58 
59  return rv;
60 }
61 
63 {
64  if (next())
66 }
67 
68 // Access to the abstract interface
69 
70 prefix_ void senf::PacketInterpreterBase::dump(std::ostream & os, DumpPacketAnnotations_t dumpAnnotationsSwitch)
71 {
72  try {
73  if (dumpAnnotationsSwitch == dumpAnnotations &&
74  detail::AnnotationRegistry::instance().begin() != detail::AnnotationRegistry::instance().end()) {
75  os << "Annotations:\n";
76  impl().dumpAnnotations(os);
77  }
78  v_dump(os);
79  for (ptr i (next()); i; i = i->next())
80  i->v_dump(os);
81  }
82  catch (senf::Exception & e) {
83  os << "[Exception: " << e.message() << "]\n";
84  }
85 }
86 
88 {
89  os << " interpreter @" << this << " refcount=" << refcount() << std::endl;
90  PacketInterpreterBase * n (next().get());
91  if (n)
92  n->memDebug(os);
93 }
94 
96 {
97  v_finalize();
98 }
99 
101 {
102  for (ptr i (other); i.get() != this && i.get(); i = i->prev())
103  i->finalizeThis();
104  finalizeThis();
105 }
106 
107 // reference/memory management
108 
109 prefix_ void senf::PacketInterpreterBase::add_ref()
110 {
111  if (impl_ && !refcount())
112  impl_->add_ref();
114 }
115 
116 prefix_ void senf::PacketInterpreterBase::release()
117 {
118  SENF_ASSERT(impl_, "Internal failure: release of lone PacketInterpreter");
121  if (! is_linked())
122  releaseImpl(); // This commits suicide !
123  // If this is the last handle referencing the Packet, this call will commit suicide
124  impl->release();
125  }
126 }
127 
128 //-/////////////////////////////////////////////////////////////////////////////////////////////////
129 // senf::PacketInterpreterBase::Factory
130 
132 {}
133 
134 //-/////////////////////////////////////////////////////////////////////////////////////////////////
135 #undef prefix_
136 //#include "PacketInterpreter.mpp"
137 
138 
139 // Local Variables:
140 // mode: c++
141 // fill-column: 100
142 // c-file-style: "senf"
143 // indent-tabs-mode: nil
144 // ispell-local-dictionary: "american"
145 // compile-command: "scons -u test"
146 // comment-column: 40
147 // End:
void truncateInterpreters(PacketInterpreterBase *p)
#define prefix_
Internal: Keep PacketImpl instance alive.
Definition: PacketImpl.hh:203
void dump(std::ostream &os, DumpPacketAnnotations_t dumpAnnotationsSwitch)
void copy(ListParser< ListPolicy > const &listParser, OutputIterator result)
Definition: algorithms.hh:58
DumpPacketAnnotations_t
detail::PacketImpl & impl() const
PacketInterpreterBase * nextP()
void dumpAnnotations(std::ostream &os)
Definition: PacketImpl.cc:270
detail::PacketImpl * impl_
Need to make this protected so we can change it in the derived class.
Definition: PacketData.hh:155
iterator begin() const
Return iterator to beginning.
Packets public header.
Internal: Base packet interpreter class.
iterator end() const
Return iterator to end.
Invalid packet chain operation.
Internal: Packet data storage.
Definition: PacketImpl.hh:112
senf::detail::packet::smart_pointer< PacketInterpreterBase >::ptr_t ptr
ptr appendClone(detail::PacketImpl *impl, iterator base, iterator new_base)
#define SENF_ASSERT(x, comment)
boost::optional< range > optional_range
std::string message() const
void memDebug(std::ostream &os)
refcount_t refcount() const
optional_range nextPacketRange()