Packet.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 "Packet.ih"
18 
19 // Custom includes
20 #include "Packets.hh"
21 
22 //#include "Packet.mpp"
23 #define prefix_
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
26 #ifdef SENF_DEBUG
27 std::int32_t senf::Packet::pktCount_ = 0;
28 #endif
29 
30 prefix_ std::int32_t const & senf::Packet::pktCount()
31 {
32 #ifdef SENF_DEBUG
33  return pktCount_;
34 #else
35  static std::int32_t noCount (-1);
36  return noCount;
37 #endif
38 }
39 
41  const
42 {
43  factory_t factory (ptr()->nextPacketType());
44  return parseNextAs(factory ? factory : DataPacket::factory(), range);
45 }
46 
48  const
49 {
50  Packet p (*this);
51  Packet n (p.next(nothrow));
52  while (n) {
53  p = n;
54  n = p.next(nothrow);
55  }
56  return p;
57 }
58 
59 prefix_ void senf::Packet::dump(std::ostream & os, DumpPacketAnnotations_t dumpAnnotationsSwitch)
60  const
61 {
62  last(); // Make sure the packet is complete
63  ptr()->dump(os, dumpAnnotationsSwitch);
64 }
65 
66 prefix_ void senf::Packet::memDebug(std::ostream & os)
67  const
68 {
69  ptr()->impl().memDebug(os);
70  os << " handle @" << ptr().get() << std::endl;
71  PacketInterpreterBase * p (first().ptr().get());
72  p->memDebug(os);
73 }
74 
75 prefix_ std::ostream & senf::operator<<(std::ostream & os, Packet const & packet)
76 {
77  os << "Packet<" << packet.typeId().prettyName() << ">:" << packet.id();
78  return os;
79 }
80 
81 
82 //-/////////////////////////////////////////////////////////////////////////////////////////////////
83 #undef prefix_
84 //#include "Packet.mpp"
85 
86 
87 // Local Variables:
88 // mode: c++
89 // fill-column: 100
90 // c-file-style: "senf"
91 // indent-tabs-mode: nil
92 // ispell-local-dictionary: "american"
93 // compile-command: "scons -u test"
94 // comment-column: 40
95 // End:
DumpPacketAnnotations_t
std::string prettyName() const
static std::int32_t const & pktCount()
Definition: Packet.cc:30
std::ostream & operator<<(std::ostream &os, Packet const &packet)
Definition: Packet.cc:75
Packets public header.
Internal: Base packet interpreter class.
Packet last() const
Return last packet in chain.
#define prefix_
Definition: Packet.cc:23
Main Packet class.
Definition: Packet.hh:131
Packet next() const
Get next packet in chain.
void memDebug(std::ostream &os) const
Definition: Packet.cc:66
OtherPacket parseNextAs() const
Interpret payload of this as OtherPacket.
senf::detail::packet::smart_pointer< PacketInterpreterBase >::ptr_t ptr
nothrow
PacketInterpreterBase::ptr getNext(PacketInterpreterBase::optional_range const &range) const
Definition: Packet.cc:40
void dump(std::ostream &os, DumpPacketAnnotations_t dumpAnnotationsSwitch=dumpAnnotations) const
Write out a printable packet representation.
Definition: Packet.cc:59
unsigned long id() const
Unique packet id.
PacketInterpreterBase::ptr const & ptr() const
Packet first() const
Return first packet in chain.
boost::optional< range > optional_range
TypeIdValue typeId() const
Get type of this packet.
static factory_t factory()
Return factory for packets of specific type.
PacketInterpreterBase::factory_t factory_t
Packet factory type (see below)
Definition: Packet.hh:144
Packet getLast() const
Definition: Packet.cc:47
void memDebug(std::ostream &os)
factory_t factory() const
Return factory instance of this packet.