From 4b9551fc6a97ed5a3e09fd36bd04146b664645b9 Mon Sep 17 00:00:00 2001 From: g0dil <g0dil@wiback.org> Date: Thu, 19 Jul 2007 14:14:47 +0000 Subject: [PATCH] Packets: Completely restructured #includes, introduced central Packets.hh file Packets: Fix parser-inheritance example Packets: Change PacketRegistry 'Type' argument to be the ConcretePacket instantiation Packets: Updated PacketRegistry documentation Packets/DefaultBundle: Update to use new Packets.hh include --- Packets/DataPacket.hh | 3 + Packets/DefaultBundle/EthernetPacket.cc | 2 +- Packets/DefaultBundle/EthernetPacket.hh | 7 +- Packets/DefaultBundle/EthernetPacket.test.cc | 1 - Packets/DefaultBundle/IpV4Packet.cc | 4 +- Packets/DefaultBundle/IpV4Packet.hh | 9 +- Packets/DefaultBundle/IpV6Extensions.cc | 2 +- Packets/DefaultBundle/IpV6Extensions.hh | 2 + Packets/DefaultBundle/IpV6Extensions.test.cc | 1 - Packets/DefaultBundle/IpV6Packet.cc | 7 +- Packets/DefaultBundle/IpV6Packet.hh | 8 +- Packets/DefaultBundle/UDPPacket.cc | 4 +- Packets/DefaultBundle/UDPPacket.hh | 9 +- Packets/Mainpage.dox | 98 ++++++------ Packets/Packet.cc | 4 +- Packets/Packet.hh | 5 +- Packets/Packet.test.cc | 11 +- Packets/PacketData.cc | 3 +- Packets/PacketData.hh | 4 +- Packets/PacketData.test.cc | 3 +- Packets/PacketImpl.cc | 3 +- Packets/PacketImpl.hh | 3 + Packets/PacketImpl.test.cc | 4 +- Packets/PacketInterpreter.cc | 2 +- Packets/PacketInterpreter.ct | 2 +- Packets/PacketInterpreter.hh | 3 + Packets/PacketInterpreter.test.cc | 4 +- Packets/PacketParser.hh | 9 +- Packets/PacketParser.test.cc | 5 +- Packets/PacketRegistry.cc | 3 +- Packets/PacketRegistry.ct | 5 +- Packets/PacketRegistry.cti | 6 +- Packets/PacketRegistry.hh | 154 ++++++++++++------- Packets/PacketRegistry.ih | 9 +- Packets/PacketRegistry.test.cc | 24 +-- Packets/PacketType.hh | 93 +++++++++-- Packets/PacketTypes.hh | 3 + Packets/Packets.hh | 46 ++++++ Packets/ParseArray.hh | 3 + Packets/ParseArray.test.cc | 5 +- Packets/ParseInt.hh | 3 + Packets/ParseInt.test.cc | 4 +- Packets/ParseList.hh | 3 + Packets/ParseList.test.cc | 2 +- Packets/ParseListB.hh | 3 + Packets/ParseListB.test.cc | 5 +- Packets/ParseListN.hh | 3 + Packets/ParseListN.test.cc | 6 +- Packets/ParseVec.hh | 3 + Packets/ParseVec.test.cc | 4 +- Packets/SConscript | 11 ++ Packets/main.test.cc | 1 + find-sources.sh | 2 + 53 files changed, 410 insertions(+), 213 deletions(-) create mode 100644 Packets/Packets.hh diff --git a/Packets/DataPacket.hh b/Packets/DataPacket.hh index a6d936e58..0d4b6154f 100644 --- a/Packets/DataPacket.hh +++ b/Packets/DataPacket.hh @@ -40,6 +40,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_DataPacket_impl_) +#define HH_DataPacket_impl_ //#include "DataPacket.cci" //#include "DataPacket.ct" //#include "DataPacket.cti" diff --git a/Packets/DefaultBundle/EthernetPacket.cc b/Packets/DefaultBundle/EthernetPacket.cc index 4a50ee29c..99e61bb1f 100644 --- a/Packets/DefaultBundle/EthernetPacket.cc +++ b/Packets/DefaultBundle/EthernetPacket.cc @@ -34,7 +34,7 @@ ///////////////////////////////cc.p//////////////////////////////////////// namespace { - senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::EthVLanPacketType> + senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::EthVLanPacket> registerEthVLanPacket(0x8100); } diff --git a/Packets/DefaultBundle/EthernetPacket.hh b/Packets/DefaultBundle/EthernetPacket.hh index 126748896..ffa1f4bc5 100644 --- a/Packets/DefaultBundle/EthernetPacket.hh +++ b/Packets/DefaultBundle/EthernetPacket.hh @@ -26,10 +26,7 @@ // Custom includes #include <algorithm> #include <boost/array.hpp> -#include "Packets/PacketType.hh" -#include "Packets/ParseInt.hh" -#include "Packets/PacketRegistry.hh" -#include "Packets/PacketParser.hh" +#include "Packets/Packets.hh" //#include "EthernetPacket.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -155,6 +152,8 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#ifndef SENF_PACKETS_DECL_ONLY //#include "EthernetPacket.cci" #include "EthernetPacket.ct" //#include "EthernetPacket.cti" diff --git a/Packets/DefaultBundle/EthernetPacket.test.cc b/Packets/DefaultBundle/EthernetPacket.test.cc index e5698945d..48f5500ff 100644 --- a/Packets/DefaultBundle/EthernetPacket.test.cc +++ b/Packets/DefaultBundle/EthernetPacket.test.cc @@ -27,7 +27,6 @@ // Custom includes #include "EthernetPacket.hh" -#include "Packets/DataPacket.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/DefaultBundle/IpV4Packet.cc b/Packets/DefaultBundle/IpV4Packet.cc index 8daed86a7..42413793b 100644 --- a/Packets/DefaultBundle/IpV4Packet.cc +++ b/Packets/DefaultBundle/IpV4Packet.cc @@ -35,10 +35,10 @@ ///////////////////////////////cc.p//////////////////////////////////////// namespace { - senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::IpV4PacketType> + senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::IpV4Packet> registerIpV4Packet (0x0800); - senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::IpV4PacketType> + senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::IpV4Packet> regsiterIpV4Packet2 (4); // IP-in-IP encapsulation } diff --git a/Packets/DefaultBundle/IpV4Packet.hh b/Packets/DefaultBundle/IpV4Packet.hh index e8879a2e1..4c3d97768 100644 --- a/Packets/DefaultBundle/IpV4Packet.hh +++ b/Packets/DefaultBundle/IpV4Packet.hh @@ -1,4 +1,4 @@ -// $Id: IpV4Packet.hh 307 2007-07-14 21:31:12Z g0dil $ +// $Id$ // // Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) @@ -24,10 +24,7 @@ #define HH_IpV4Packet_ 1 // Custom includes -#include "Packets/PacketType.hh" -#include "Packets/ParseInt.hh" -#include "Packets/PacketRegistry.hh" -#include "Packets/PacketParser.hh" +#include "Packets/Packets.hh" //#include "IpV4Packet.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -106,6 +103,8 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#ifndef SENF_PACKETS_DECL_ONLY //#include IpV4Packet.cci" //#include "IpV4Packet.ct" //#include "IpV4Packet.cti" diff --git a/Packets/DefaultBundle/IpV6Extensions.cc b/Packets/DefaultBundle/IpV6Extensions.cc index cf2d34460..288197ec5 100644 --- a/Packets/DefaultBundle/IpV6Extensions.cc +++ b/Packets/DefaultBundle/IpV6Extensions.cc @@ -31,7 +31,7 @@ ///////////////////////////////cc.p//////////////////////////////////////// namespace { - senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::IpV6ExtensionType_Fragment> + senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::IpV6Extension_Fragment> registerIpV6ExtensionType_Fragment (44); } diff --git a/Packets/DefaultBundle/IpV6Extensions.hh b/Packets/DefaultBundle/IpV6Extensions.hh index 348a1a586..50ace7877 100644 --- a/Packets/DefaultBundle/IpV6Extensions.hh +++ b/Packets/DefaultBundle/IpV6Extensions.hh @@ -82,6 +82,8 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#ifndef SENF_PACKETS_DECL_ONLY //#include "IpV6Extensions.cci" //#include "IpV6Extensions.ct" //#include "IpV6Extensions.cti" diff --git a/Packets/DefaultBundle/IpV6Extensions.test.cc b/Packets/DefaultBundle/IpV6Extensions.test.cc index 0c7ac3168..6c7a09bec 100644 --- a/Packets/DefaultBundle/IpV6Extensions.test.cc +++ b/Packets/DefaultBundle/IpV6Extensions.test.cc @@ -28,7 +28,6 @@ #include "IpV6Extensions.hh" #include "IpV6Packet.hh" #include "UDPPacket.hh" -#include "Packets/DataPacket.hh" #include "Socket/INetAddressing.hh" #include <boost/test/auto_unit_test.hpp> diff --git a/Packets/DefaultBundle/IpV6Packet.cc b/Packets/DefaultBundle/IpV6Packet.cc index 899e21a77..7a72d0fcf 100644 --- a/Packets/DefaultBundle/IpV6Packet.cc +++ b/Packets/DefaultBundle/IpV6Packet.cc @@ -26,7 +26,6 @@ // Custom includes #include "EthernetPacket.hh" -#include "Packets/DataPacket.hh" #include "Socket/INetAddressing.hh" //#include "IpV6Packet.mpp" @@ -34,13 +33,13 @@ ///////////////////////////////cc.p//////////////////////////////////////// namespace { - senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::IpV6PacketType> + senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::IpV6Packet> registerIpV6Packet (0x86dd); - senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::IpV6PacketType> + senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::IpV6Packet> registerIpV6Packet2 (41); // IP6-in-IP(6) encapsulation - senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::DataPacketType> + senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::DataPacket> registerNoNextHeader (59); } diff --git a/Packets/DefaultBundle/IpV6Packet.hh b/Packets/DefaultBundle/IpV6Packet.hh index 0f1aafbf9..b332a9846 100644 --- a/Packets/DefaultBundle/IpV6Packet.hh +++ b/Packets/DefaultBundle/IpV6Packet.hh @@ -25,11 +25,7 @@ #define HH_IpV6Packet_ 1 // Custom includes -#include "Packets/PacketType.hh" -#include "Packets/ParseInt.hh" -#include "Packets/PacketRegistry.hh" -#include "Packets/PacketParser.hh" -#include "Packets/ParseArray.hh" +#include "Packets/Packets.hh" #include "IpV4Packet.hh" //#include "IpV6Packet.mpp" @@ -95,6 +91,8 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#ifndef SENF_PACKETS_DECL_ONLY //#include "IpV6Packet.cci" //#include "IpV6Packet.ct" //#include "IpV6Packet.cti" diff --git a/Packets/DefaultBundle/UDPPacket.cc b/Packets/DefaultBundle/UDPPacket.cc index 3c8247ca6..4b6fe1e9c 100644 --- a/Packets/DefaultBundle/UDPPacket.cc +++ b/Packets/DefaultBundle/UDPPacket.cc @@ -27,13 +27,13 @@ #include "IpV4Packet.hh" // Custom includes -#include "Packets/DataPacket.hh" +#include "Packets/Packets.hh" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// namespace { - senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::UDPPacketType> + senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::UDPPacket> registerUDPPacket (17); } diff --git a/Packets/DefaultBundle/UDPPacket.hh b/Packets/DefaultBundle/UDPPacket.hh index 26485486f..bc3ab1d6d 100644 --- a/Packets/DefaultBundle/UDPPacket.hh +++ b/Packets/DefaultBundle/UDPPacket.hh @@ -1,4 +1,4 @@ -// $Id: UDPPacket.hh 308 2007-07-14 22:31:20Z g0dil $ +// $Id$ // // Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) @@ -24,10 +24,7 @@ #define HH_UDPPacket_ 1 // Custom includes -#include "Packets/PacketType.hh" -#include "Packets/ParseInt.hh" -#include "Packets/PacketRegistry.hh" -#include "Packets/PacketParser.hh" +#include "Packets/Packets.hh" //#include "UDPPacket.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -75,6 +72,8 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#ifndef SENF_PACKETS_DECL_ONLY //#include UDPPacket.cci" //#include "UDPPacket.ct" //#include "UDPPacket.cti" diff --git a/Packets/Mainpage.dox b/Packets/Mainpage.dox index d1437a746..f62651fd3 100644 --- a/Packets/Mainpage.dox +++ b/Packets/Mainpage.dox @@ -15,18 +15,30 @@ packet parsing and creation. \section intro Introduction + + Whenever using the library, you will probably need to \c \#include it's header: + + \code + #include "Packets/Packets.hh" + \endcode + + \warning Never include any other Packets library header directly, always include \c + Packets/Packets.hh. + + Additionally you will have to include the header files for the packet types you use, e.g. \c + Packets/DefaultBundle/EthernetPacket.hh etc. Most every use of the packet library starts with some concrete packet typedef. Some fundamental - packet typedefs are provided by \ref protocolbundle_default. The first example will build a - complex packet: This will be an Ethernet packet containing an IPv4 UDP packet. We begin by - building the raw packet skeleton: + packet types are provided by \ref protocolbundle_default. Building on those packet types, this + example will build a complex packet: This will be an Ethernet packet containing an IPv4 UDP + packet. We begin by building the raw packet skeleton: \code - senf::EthernetPacket eth (senf::EthernetPacket::create()); - senf::IpV4Packet ip (senf::IpV4Packet::createAfter(ethernet)); - senf::UDPPacket udp (senf::UDPPacket::createAfter(ip)); - senf::DataPacket payload (senf::DataPacket::createAfter(udp, - std::string("Hello, world!"))); + senf::EthernetPacket eth (senf::EthernetPacket::create()); + senf::IpV4Packet ip (senf::IpV4Packet ::createAfter(ethernet)); + senf::UDPPacket udp (senf::UDPPacket ::createAfter(ip)); + senf::DataPacket payload (senf::DataPacket ::createAfter(udp, + std::string("Hello, world!"))); \endcode These commands create what is called an interpreter chain. This chain consists of four @@ -42,15 +54,15 @@ empty. We need to set those protocol fields: \code - udp->source() = 2000u; - udp->destination() = 2001u; - ip->ttl() = 255u; - ip->source() = senf::INet4Address("192.168.0.1"); // (*) - ip->destination() = senf::INet4Address("192.168.0.2"); // (*) - eth->source() = senf::MACAddress("00:11:22:33:44:55"); - eth->destination() = senf::MACAddress("00:11:22:33:44:66"); + udp->source() = 2000u; + udp->destination() = 2001u; + ip->ttl() = 255u; + ip->source() = senf::INet4Address("192.168.0.1"); // (*) + ip->destination() = senf::INet4Address("192.168.0.2"); // (*) + eth->source() = senf::MACAddress("00:11:22:33:44:55"); + eth->destination() = senf::MACAddress("00:11:22:33:44:66"); - eth.finalize(); // (*) + eth.finalize(); // (*) \endcode As seen above, packet fields are accessed using the <tt>-></tt> operator whereas other packet @@ -60,26 +72,26 @@ checksums etc). Now the packet is ready. We may now send it out using a packet socket \code - senf::PacketSocketHandle sock ("eth0"); - sock.write(eth.data()); + senf::PacketSocketHandle sock ("eth0"); + sock.write(eth.data()); \endcode The packet library also provides lot's of facilities to navigate the packet chain: \code - eth.next() == ip; // true - eth.next().is<IpV4Packet>(); // true - eth.next().next() == udp; // true - eth.next().is<UDPPacket>(); // false - eth.next<UDPPacket>() == udp; // true - - udp.next<UDPPacket>(); // throws InvalidPacketChainException - udp.next<UDPPacket>(senf::nothrow); // a senf::Packet testing as false - udp.findNext<UDPPacket()> == udp; // true - udp.first<IpV4Packet>() == ip; // true - - udp.prev() == ip; // true - udp.prev<EthernetPacket>() == eth // true + eth.next() == ip; // true + eth.next().is<IpV4Packet>(); // true + eth.next().next() == udp; // true + eth.next().is<UDPPacket>(); // false + eth.next<UDPPacket>() == udp; // true + + udp.next<UDPPacket>(); // throws InvalidPacketChainException + udp.next<UDPPacket>(senf::nothrow); // a senf::Packet testing as false + udp.findNext<UDPPacket()> == udp; // true + udp.first<IpV4Packet>() == ip; // true + + udp.prev() == ip; // true + udp.prev<EthernetPacket>() == eth // true \endcode ... and so on. It is therefore not necessary to stash away a reference for every interpreter (as @@ -89,23 +101,23 @@ from a packet socket handle: \code - senf::PacketSocketHandle sock ("eth0"); - senf::EthernetPacket packet (senf::EthernetPacket::create(senf::Packet::noinit)); - sock.read(packet.data(),0u); + senf::PacketSocketHandle sock ("eth0"); + senf::EthernetPacket packet (senf::EthernetPacket::create(senf::Packet::noinit)); + sock.read(packet.data(),0u); \endcode This first creates an uninitialized Ethernet packet and then reads into this packet. We can now parse this packet. Let's find out, whether this is a UDP packet destined to port 2001: \code - try { - senf::UDPPacket udp (packet.findNext<UDPPacket>(senf::nothrow)); - if (udp && udp->destination() == 2001u) { - // Voila ... - } - } catch (senf::TruncatedPacketException const &) { - std::cerr << "Ooops !! Broken packet received ...\n" - } + try { + senf::UDPPacket udp (packet.findNext<UDPPacket>(senf::nothrow)); + if (udp && udp->destination() == 2001u) { + // Voila ... + } + } catch (senf::TruncatedPacketException const &) { + std::cerr << "Ooops !! Broken packet received ...\n" + } \endcode TruncatedPacketException is thrown by <tt>udp->destination()</tt> if that field cannot be @@ -131,4 +143,4 @@ // LocalWords: udp endcode li senf EthernetPacket eth IpV createAfter ip std // LocalWords: ethernet UDPPacket DataPacket ttl INet MACAddress nothrow prev // LocalWords: PacketSocketHandle InvalidPacketChainException findNext noinit -// LocalWords: tt TruncatedPacketException const cerr Ooops +// LocalWords: tt TruncatedPacketException const cerr Ooops hh diff --git a/Packets/Packet.cc b/Packets/Packet.cc index 02cc5ec2d..1522add3c 100644 --- a/Packets/Packet.cc +++ b/Packets/Packet.cc @@ -21,12 +21,10 @@ /** \file \brief Packet non-inline non-template implementation */ -#include "PacketInterpreter.hh" -#include "Packet.hh" //#include "Packet.ih" // Custom includes -#include "DataPacket.hh" +#include "Packets.hh" //#include "Packet.mpp" #define prefix_ diff --git a/Packets/Packet.hh b/Packets/Packet.hh index c2c8b923d..fabd6a455 100644 --- a/Packets/Packet.hh +++ b/Packets/Packet.hh @@ -580,6 +580,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_Packet_i_) +#define HH_Packet_i_ #include "Packet.cci" #include "Packet.ct" #include "Packet.cti" @@ -604,4 +607,4 @@ namespace senf { // LocalWords: PacketTypeBase TruncatedPacketException http www org Institut // LocalWords: Fraunhofer fuer offene Kommunikationssysteme FOKUS SatCom Bund // LocalWords: Kompetenzzentrum Satelitenkommunikation berlios de hh -// LocalWords: addtogroup Structors PacketType dil +// LocalWords: addtogroup Structors PacketType dil PacketType's diff --git a/Packets/Packet.test.cc b/Packets/Packet.test.cc index 509039e06..a33ccd4fa 100644 --- a/Packets/Packet.test.cc +++ b/Packets/Packet.test.cc @@ -26,12 +26,7 @@ // Custom includes #include <sstream> -#include "PacketType.hh" -#include "PacketRegistry.hh" -#include "Packet.hh" -#include "ParseInt.hh" -#include "PacketParser.hh" -#include "DataPacket.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> @@ -105,8 +100,8 @@ namespace { typedef BarPacketType::packet BarPacket; namespace reg { - senf::PacketRegistry<RegTag>::RegistrationProxy<FooPacketType> registerFoo(1u); - senf::PacketRegistry<RegTag>::RegistrationProxy<BarPacketType> registerBar(2u); + senf::PacketRegistry<RegTag>::RegistrationProxy<FooPacket> registerFoo(1u); + senf::PacketRegistry<RegTag>::RegistrationProxy<BarPacket> registerBar(2u); } } diff --git a/Packets/PacketData.cc b/Packets/PacketData.cc index 8751951ae..7e50a002b 100644 --- a/Packets/PacketData.cc +++ b/Packets/PacketData.cc @@ -21,11 +21,10 @@ /** \file \brief PacketData non-inline non-template implementation */ -#include "PacketData.hh" //#include "PacketData.ih" // Custom includes -#include "PacketImpl.hh" +#include "Packets.hh" //#include "PacketData.mpp" #define prefix_ diff --git a/Packets/PacketData.hh b/Packets/PacketData.hh index fee2c00a1..8d94d9c68 100644 --- a/Packets/PacketData.hh +++ b/Packets/PacketData.hh @@ -186,8 +186,8 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(HH_PacketData_DeclOnly) &&!defined(HH_PacketData_def) -#define HH_PacketData_def +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketData_i_) +#define HH_PacketData_i_ #include "PacketData.cci" //#include "PacketData.ct" #include "PacketData.cti" diff --git a/Packets/PacketData.test.cc b/Packets/PacketData.test.cc index e9e3f3a05..91c544724 100644 --- a/Packets/PacketData.test.cc +++ b/Packets/PacketData.test.cc @@ -25,8 +25,7 @@ //#include "PacketData.test.ih" // Custom includes -#include "PacketData.hh" -#include "PacketType.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/PacketImpl.cc b/Packets/PacketImpl.cc index e4db0665e..8dfd75e10 100644 --- a/Packets/PacketImpl.cc +++ b/Packets/PacketImpl.cc @@ -21,12 +21,11 @@ /** \file \brief PacketImpl non-inline non-template implementation */ -#include "PacketImpl.hh" //#include "PacketImpl.ih" // Custom includes #include <iterator> -#include "PacketInterpreter.hh" +#include "Packets.hh" //#include "PacketImpl.mpp" #define prefix_ diff --git a/Packets/PacketImpl.hh b/Packets/PacketImpl.hh index 39ccd470f..516d272d2 100644 --- a/Packets/PacketImpl.hh +++ b/Packets/PacketImpl.hh @@ -114,6 +114,9 @@ namespace detail { }} ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketImpl_i_) +#define HH_PacketImpl_i_ #include "PacketImpl.cci" //#include "PacketImpl.ct" #include "PacketImpl.cti" diff --git a/Packets/PacketImpl.test.cc b/Packets/PacketImpl.test.cc index 83e5373c9..e4e5bcbae 100644 --- a/Packets/PacketImpl.test.cc +++ b/Packets/PacketImpl.test.cc @@ -25,9 +25,7 @@ //#include "PacketImpl.test.ih" // Custom includes -#include "PacketImpl.hh" -#include "PacketInterpreter.hh" -#include "PacketType.hh" +#include "Packets.hh" #include "main.test.hh" #include <boost/test/auto_unit_test.hpp> diff --git a/Packets/PacketInterpreter.cc b/Packets/PacketInterpreter.cc index 7cd389a3b..a9ca16394 100644 --- a/Packets/PacketInterpreter.cc +++ b/Packets/PacketInterpreter.cc @@ -21,10 +21,10 @@ /** \file \brief PacketInterpreter non-inline non-template implementation */ -#include "PacketInterpreter.hh" //#include "PacketInterpreter.ih" // Custom includes +#include "Packets.hh" //#include "PacketInterpreter.mpp" #define prefix_ diff --git a/Packets/PacketInterpreter.ct b/Packets/PacketInterpreter.ct index b2f455b2b..a8d0095a5 100644 --- a/Packets/PacketInterpreter.ct +++ b/Packets/PacketInterpreter.ct @@ -194,7 +194,7 @@ prefix_ void senf::PacketInterpreter<PacketType>::v_dump(std::ostream & os) template <class PacketType> prefix_ senf::TypeIdValue senf::PacketInterpreter<PacketType>::v_type() { - return typeIdValue<PacketType>(); + return typeIdValue< ConcretePacket<PacketType> >(); } template <class PacketType> diff --git a/Packets/PacketInterpreter.hh b/Packets/PacketInterpreter.hh index aed5c56d1..878de5b71 100644 --- a/Packets/PacketInterpreter.hh +++ b/Packets/PacketInterpreter.hh @@ -352,6 +352,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketInterpreter_i_) +#define HH_PacketInterpreter_i_ #include "PacketInterpreter.cci" #include "PacketInterpreter.ct" #include "PacketInterpreter.cti" diff --git a/Packets/PacketInterpreter.test.cc b/Packets/PacketInterpreter.test.cc index c26dc07fc..242869975 100644 --- a/Packets/PacketInterpreter.test.cc +++ b/Packets/PacketInterpreter.test.cc @@ -25,9 +25,7 @@ //#include "PacketInterpreter.test.ih" // Custom includes -#include "PacketImpl.hh" -#include "PacketInterpreter.hh" -#include "PacketType.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/PacketParser.hh b/Packets/PacketParser.hh index 6c40b2f1f..b96395520 100644 --- a/Packets/PacketParser.hh +++ b/Packets/PacketParser.hh @@ -74,9 +74,7 @@ #include <boost/optional.hpp> #include "Utils/SafeBool.hh" #include "PacketTypes.hh" -#define HH_PacketData_DeclOnly #include "PacketData.hh" -#undef HH_PacketData_DeclOnly #include "PacketParser.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -459,7 +457,7 @@ namespace senf { \code struct ExtendedParser : public BaseParser { - SENF_PACKET_PARSER_NO_INIT(ExtendedParser); + ExtendedParser(data_iterator i, state_type s) : BaseParser(i,s) {} SENF_PACKET_PARSER_DEFINE_FIELDS_OFFSET(senf::bytes(BaseParser(*this)), ( ... fields ... ) ); @@ -499,7 +497,7 @@ namespace senf { \code struct ExtendedParser : public BaseParser { - SENF_PACKET_PARSER_NO_INIT(ExtendedParser); + ExtendedParser(data_iterator i, state_type s) : BaseParser(i,s) {} SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS_OFFSET(BaseParser::fixed_bytes, ( ... fields ... ) ); @@ -582,6 +580,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketParser_i_) +#define HH_PacketParser_i_ #include "PacketParser.cci" #include "PacketParser.ct" #include "PacketParser.cti" diff --git a/Packets/PacketParser.test.cc b/Packets/PacketParser.test.cc index 5db0e606a..23b1be9e1 100644 --- a/Packets/PacketParser.test.cc +++ b/Packets/PacketParser.test.cc @@ -25,10 +25,7 @@ //#include "PacketParser.test.ih" // Custom includes -#include "PacketParser.hh" -#include "PacketInterpreter.hh" -#include "PacketType.hh" -#include "ParseInt.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/PacketRegistry.cc b/Packets/PacketRegistry.cc index 09a6af831..c11913160 100644 --- a/Packets/PacketRegistry.cc +++ b/Packets/PacketRegistry.cc @@ -21,10 +21,9 @@ /** \file \brief PacketRegistry non-inline non-template implementation */ -#include "PacketRegistry.hh" -#include "PacketRegistry.ih" // Custom includes +#include "Packets.hh" //#include "PacketRegistry.mpp" #define prefix_ diff --git a/Packets/PacketRegistry.ct b/Packets/PacketRegistry.ct index ca5a144ba..214702340 100644 --- a/Packets/PacketRegistry.ct +++ b/Packets/PacketRegistry.ct @@ -20,7 +20,8 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// Definition of non-inline template funPacketRegistry.ons +/** \file + \brief PacketRegistry non-inline template implementation */ #include "PacketRegistry.ih" @@ -34,7 +35,7 @@ template <class PacketType> prefix_ senf::PacketInterpreterBase::factory_t senf::detail::PkReg_EntryImpl<PacketType>::factory() const { - return PacketInterpreter<PacketType>::factory(); + return PacketType::factory(); } template <class KeyType> diff --git a/Packets/PacketRegistry.cti b/Packets/PacketRegistry.cti index 41a912711..099880128 100644 --- a/Packets/PacketRegistry.cti +++ b/Packets/PacketRegistry.cti @@ -20,7 +20,8 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// Definition of inline template funPacketRegistry.ons +/** \file + \brief PacketRegistry inline template implementation */ #include "PacketRegistry.ih" @@ -65,7 +66,8 @@ prefix_ typename Tag::key_t senf::PacketRegistry<Tag>::key(Packet packet) } template <class Tag> -prefix_ typename Tag::key_t senf::PacketRegistry<Tag>::key(Packet packet, NoThrow_t) +prefix_ typename boost::optional<typename Tag::key_t> +senf::PacketRegistry<Tag>::key(Packet packet, NoThrow_t) { return registry().key(packet.typeId(),true); } diff --git a/Packets/PacketRegistry.hh b/Packets/PacketRegistry.hh index e27f10660..ef1fa2617 100644 --- a/Packets/PacketRegistry.hh +++ b/Packets/PacketRegistry.hh @@ -20,6 +20,8 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/** \file + \brief PacketRegistry public header */ #ifndef HH_PacketRegistryImpl_ #define HH_PacketRegistryImpl_ 1 @@ -29,7 +31,6 @@ #include <boost/utility.hpp> // for boost::noncopyable #include <boost/optional.hpp> #include "Utils/Exception.hh" -#include "PacketInterpreter.hh" #include "Packet.hh" //#include "PacketRegistry.mpp" @@ -37,66 +38,77 @@ namespace senf { + /** \brief Registry entry + + Value returned by a registry lookup + */ struct PkReg_Entry : public intrusive_refcount { virtual ~PkReg_Entry(); - virtual PacketInterpreterBase::factory_t factory() const = 0; + virtual Packet::factory_t factory() const = 0; + ///< Get factory of the registered packet type }; namespace detail { template <class Key> class PacketRegistryImpl; } /** \brief Packet registration facility - The PacketRegistry provides a generic facility to associate an - arbitrary key with Packets. Example keys are Ethertype or IP - protocols. + The PacketRegistry provides a generic facility to associate an arbitrary key with + Packets. Example keys are Ethertype or IP protocols. Every PacketRegistry is identified by a type tag: \code - struct SomeTag { - typedef some_key_type key_t; - }; + struct SomeTag { + typedef some_key_type key_t; + }; \endcode - The key type can be an arbitrary value type. The PacketRegistry - for this Tag can then be accessed using - <code>PacketRegistry<SomeTag>::</code>. + The key type can be an arbitrary value type. The PacketRegistry for this Tag can then be + accessed using <code>senf::PacketRegistry<SomeTag>::</code>. - The PacketRegistry class has only static members and provides - access to the packet registry. It allows to register Packet - classes and to create new Packets given a key. Methods are - also provided to find the key of a Packet type. + The PacketRegistry class has only static members and provides access to the packet + registry. It allows two-way lookup either by key or by packet type. \code - PacketRegistry<SomeTag>::registerPacket<SomePacket>(key_of_somePacket); - p = PacketRegistry<SomeTag>::create(some_key,begin,end); - SomeTag::key_t key = PacketRegistry<SomeTag>::key<SomePacket>(); + senf::Packet::factory_t factory (senf::PacketRegistry<SomeTag>::lookup(some_key).factory()); + SomeTag::key_t key = PacketRegistry<SomeTag>::key<SomePacket>(); \endcode - Normally, packet classes are registered statically and not - procedurally. To this end, the RegistrationProxy is provided: + Packets can be registered either dynamically or statically. Dynamic: \code - PacketRegistry<SomeTag>::RegistrationProxy<SomePacket> - registerSomePacket (key_of_somePacket); + // dynamic registration + senf::PacketRegistry<SomeTag>::registerPacket<SomePacket>(key_of_somePacket); + + // static registration. 'registerSomePacket' is an arbitrary symbol name + senf::PacketRegistry<SomeTag>::RegistrationProxy<SomePacket> + registerSomePacket (key_of_somePacket); \endcode - This global variable declaration will register \c SomePacket - with the \c SomeTag registry under the key \c - key_of_somePacket. The variable \c registerSomePacket is a - dummy. It's only function is to force the call of it's - constructor during global construction time. - - The PacketRegistry's purpose is mostly to assist in - implementing the v_nextInterpreter() member of packet - facades. This is further supported by the PacketRegistryMixin - class. - - \todo Add parameterless create() method + + This global variable declaration will register \a SomePacket with the \a SomeTag registry + under the key \a key_of_somePacket. The variable \a registerSomePacket is a dummy. It's only + function is to force the call of it's constructor during global construction time. This + static registration only works when the symbol is included into the final binary. To force + this inclusion, you should not put packet registrations into a library but into an object + file. + + \ingroup packet_module */ template <class Tag> class PacketRegistry { public: /** \brief Statically register a packet type in a PacketRegistry + + To use this class, define a global symbol in the following way: + \code + namespace { + senf::PacketRegistry<Tag>::RegistrationProxy<PacketType> + registerPacketType (key); + } + \endcode Here \a Tag is the type tag of the registry to register the packet in, \a + PacketType is the packet to register (this is the ConcretePacket of that packet) and \a + key is the key of type \c Tag::key_t under which the packet is to be registered. \a + registerPacketType is an arbitrary name for the global symbol. */ template <class PacketType> struct RegistrationProxy @@ -106,49 +118,74 @@ namespace senf { /** \brief Register new packet type - Register \c PacketType in the packet registry \c Tag - under the given \c key. + Register \a PacketType in the packet registry \a Tag under the given \a key. - \par Preconditions: - The given \c key must be unique and not be assigned to - any other packet class in this registry. - The Packet must not already be registered in the registry. + \par Preconditions: The given \a key must be unique and not be assigned to any other + packet class in this registry. The Packet must not already be registered in the + registry. - \param PacketType packet to register - \param key key of the packet + \param PacketType ConcretePacket instantiation of packet to register + \param key The key of the packet */ template <class PacketType> static void registerPacket(typename Tag::key_t key); - /** \brief Find key of a packet + /** \brief Find key of a packet type - Return the key of \c PacketType as registered in the \c - Tag registry + Return the key of \a PacketType as registered in the \a Tag registry \param PacketType packet of which the key is requested \returns key of the packet - \throws PacketTypeNotRegistered if the packet type is not - found in the registry. + \throws PacketTypeNotRegistered if the packet type is not found in the registry. */ template <class PacketType> static typename Tag::key_t key(); + /** \brief Find key of a packet type + + Return the key of \a PacketType as registered in the \a Tag registry + + \param PacketType packet of which the key is requested + \returns key of the packet wrapped in a <a + href="http://www.boost.org/libs/optional/doc/optional.html">boost::optional</a> or + an unbound optional, if the key is not found. + */ template <class PacketType> static typename boost::optional<typename Tag::key_t> key(NoThrow_t); + /** \brief Find key of a packet + + Return the key of \a packet, an arbitrary packet, as registered in the \a Tag registry. + + \param packet The packet of which the key is requested + \returns key of the packet + \throws PacketTypeNotRegistered if the packet type is not found in the registry. + */ static typename Tag::key_t key(Packet packet); - static typename Tag::key_t key(Packet packet, NoThrow_t); - /** \brief Lookup a packet by it's key + /** \brief Find key of a packet + + Return the key of \a packet, an arbitrary packet, as registered in the \a Tag registry. - Returns the packet registration registered under \a key in the \a Tag registry + \param packet The +packet of which the key is requested + \returns key of the packet wrapped in a <a + href="http://www.boost.org/libs/optional/doc/optional.html">boost::optional</a> or + an unbound optional, if the key is not found. + */ + static typename boost::optional<typename Tag::key_t> key(Packet packet, NoThrow_t); - \param key Key of the packet registered - \returns Registration entry of the packet - \throws PacketTypeNotRegistered if the packet type is not found in the registry + /** \brief Lookup a packet by it's key + + \throws PacketTypeNotRegistered if the \a key is not found in the registry + \return Packet entry for given \a key */ static PkReg_Entry const & lookup(typename Tag::key_t key); + /** \brief Lookup a packet by it's key + \return Pointer to packet entry for given \a key or 0, if the key is not found in the + registry. + */ static PkReg_Entry const * lookup(typename Tag::key_t key, NoThrow_t); private: @@ -162,6 +199,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketRegistryImpl_i_) +#define HH_PacketRegistryImpl_i_ //#include "PacketRegistry.cci" #include "PacketRegistry.ct" #include "PacketRegistry.cti" @@ -177,3 +217,11 @@ namespace senf { // compile-command: "scons -u test" // comment-column: 40 // End: + +// LocalWords: PacketRegistry hh dil Fraunhofer Institut fuer offene FOKUS de +// LocalWords: Kommunikationssysteme Kompetenzzentrum Satelitenkommunikation +// LocalWords: SatCom Bund stefan bund fokus fraunhofer Ethertype IP struct +// LocalWords: SomeTag endcode senf SomePacket registerPacket ingroup param +// LocalWords: registerSomePacket RegistrationProxy namespace PacketType key +// LocalWords: registerPacketType ConcretePacket PacketTypeNotRegistered href +// LocalWords: http www org html diff --git a/Packets/PacketRegistry.ih b/Packets/PacketRegistry.ih index 94b9169d9..404336251 100644 --- a/Packets/PacketRegistry.ih +++ b/Packets/PacketRegistry.ih @@ -20,6 +20,9 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/** \file + \brief PacketRegistry internal header */ + #ifndef IH_PacketRegistryImpl_ #define IH_PacketRegistryImpl_ 1 @@ -31,14 +34,16 @@ namespace senf { namespace detail { - + + ///\internal template <class PacketType> struct PkReg_EntryImpl : public PkReg_Entry { - virtual PacketInterpreterBase::factory_t factory() const; + virtual Packet::factory_t factory() const; }; + ///\internal template <class KeyType> class PacketRegistryImpl : private boost::noncopyable diff --git a/Packets/PacketRegistry.test.cc b/Packets/PacketRegistry.test.cc index 70618f28e..07523d93b 100644 --- a/Packets/PacketRegistry.test.cc +++ b/Packets/PacketRegistry.test.cc @@ -27,9 +27,7 @@ // Custom includes #include <string> -#include "PacketRegistry.hh" -#include "PacketType.hh" -#include "ParseInt.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> @@ -50,30 +48,32 @@ namespace { }; struct FooPacketType : public PacketTypeBase {}; + typedef senf::ConcretePacket<FooPacketType> FooPacket; struct BarPacketType : public PacketTypeBase {}; + typedef senf::ConcretePacket<BarPacketType> BarPacket; struct OtherPacketType : public PacketTypeBase {}; + typedef senf::ConcretePacket<OtherPacketType> OtherPacket; namespace reg { - PacketRegistry<StringTag>::RegistrationProxy<FooPacketType> registerFoo ("foo"); - PacketRegistry<StringTag>::RegistrationProxy<BarPacketType> registerBar ("bar"); + PacketRegistry<StringTag>::RegistrationProxy<FooPacket> registerFoo ("foo"); + PacketRegistry<StringTag>::RegistrationProxy<BarPacket> registerBar ("bar"); } } BOOST_AUTO_UNIT_TEST(packetRegistry_test) { - PacketRegistry<BaseTag>::registerPacket<FooPacketType>(1u); - PacketRegistry<BaseTag>::registerPacket<BarPacketType>(2u); + PacketRegistry<BaseTag>::registerPacket<FooPacket>(1u); + PacketRegistry<BaseTag>::registerPacket<BarPacket>(2u); - BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<FooPacketType>(), 1u ); - BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<BarPacketType>(), 2u ); - BOOST_CHECK_THROW( PacketRegistry<BaseTag>::key<OtherPacketType>(), + BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<FooPacket>(), 1u ); + BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<BarPacket>(), 2u ); + BOOST_CHECK_THROW( PacketRegistry<BaseTag>::key<OtherPacket>(), PacketTypeNotRegisteredException ); - BOOST_CHECK_EQUAL( PacketRegistry<StringTag>::key<FooPacketType>(), "foo" ); + BOOST_CHECK_EQUAL( PacketRegistry<StringTag>::key<FooPacket>(), "foo" ); BOOST_CHECK( ! PacketRegistry<StringTag>::lookup("blub", senf::nothrow) ); BOOST_CHECK( PacketRegistry<BaseTag>::lookup(1u, senf::nothrow) ); - } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Packets/PacketType.hh b/Packets/PacketType.hh index 8e46eecf8..03af113c6 100644 --- a/Packets/PacketType.hh +++ b/Packets/PacketType.hh @@ -36,7 +36,7 @@ namespace senf { - /** \brief Helper baseclass implementing the PacketType interface + /** \brief Helper base-class implementing the PacketType interface This helper class maybe used when building a new PacketType. It provides a complete default implementations of this interface. To define a new PacketType, derive from this class and @@ -88,7 +88,7 @@ namespace senf { static void finalize(packet p) { - // optionally complete the packet by generating autogenerated information + // optionally complete the packet by generating auto-generated information // (like checksums) } @@ -101,6 +101,8 @@ namespace senf { You may leave out any one of the members (you should however always define the \c interpreter typedef member) + + \ingroup packet_module */ struct PacketTypeBase { @@ -124,7 +126,7 @@ namespace senf { ///< Parser to parser packet fields /**< This typedef has to be set to the parser of the packet - The default is a VoidPacketParser which does not parser + The default is a VoidPacketParser which does not parse any field. */ static size_type initSize(); @@ -136,7 +138,7 @@ namespace senf { static size_type initHeadSize(); ///< Get size of new (empty) packet header /**< This function gives the index within a newly created, - empty packet where a subpacket is to be placed. + empty packet where a sub-packet is to be placed. The default implementation returns initSize(). @@ -152,7 +154,7 @@ namespace senf { packet. The new packet will have a size of at least initSize() but the size may well be larger. It is also possible for the packet to already have further - subpackets. + sub-packets. The default implementation does nothing. */ @@ -203,8 +205,8 @@ namespace senf { static void dump(packet p, std::ostream & os); ///< Dump packet data in readable form /**< The dump() function writes out a complete - representation of the packet. This is used formost for - debugging purposes. + representation of the packet. This is used for most for + debugging purposes. The default implementation does nothing. */ }; @@ -213,13 +215,28 @@ namespace senf { /** \brief Mixin to provide standard implementations for nextPacketRange and nextPacketType This mixin class simplifies the definition of simple packets with fixed-size headers and/or - trailers. For this type of Packet, this mixin provides the nextPacketRange() and - nextPacketType() members: + trailers. For this type of Packet, this mixin provides the nextPacketRange() member. If you + additionally provide the optional \a Registry argument, PacketTypeMixin provides a simple + implementation of nextPacketType. When using the PacketTypeMixin, the implementation of a + packet is simplified to: \code + // Here 'SomeRegistryTag' is optional struct SimplePacketType : public senf::PacketTypeBase - pyblic senf:PacketTypeMixin<SimplePacketType, SomeRegistryTag> + public senf:PacketTypeMixin<SimplePacketType, SomeRegistryTag> { + typedef senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag> mixin; + typedef senf::ConcretePacket<SimplePacketType> packet; + typedef SomePacketParser parser; + + using mixin::nextPacketRange; + // Only if the optional 'Registry' argument is provided + using mixin::nextPacketType; + // Only if using the default implementation + using mixin::initSize; + // Only if using the default implementation + using mixin::init; + static interpreter::size_type initSize() { // This member is optional. If it is not defined, 'senf::init_size<parser>::value' @@ -238,6 +255,12 @@ namespace senf { return header_size; } + static void init(packet p) + { + // This member is optional. The default implementation calls the parsers init() + // member. + } + static registry_key_t nextPacketKey(packet p) { // Return the key in the registry under which the next packet @@ -245,8 +268,46 @@ namespace senf { // passed to the PacketTypeMixin template. return i.fields().typeField(); } + + static void finalize(packet p) + { + // optionally complete the packet by generating auto-generated information + // (like checksums) + } + + static void dump(packet p, std::ostream & os) + { + // Write out a readable representation of the packet for debug purposes + } }; \endcode + + Most of the members are optional, which reduces the implementation of a fixed-sized header + packet with no trailer and a simple next-packet header to + + \code + struct SimplePacketType + : public senf::PacketTypeBase + public senf:PacketTypeMixin<SimplePacketType, SomeRegistryTag> + { + typedef senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag> mixin; + typedef senf::ConcretePacket<SimplePacketType> packet; + typedef SomePacketParser parser; + + using mixin::nextPacketRange; + using mixin::nextPacketType; + using mixin::initSize; + using mixin::init; + + static registry_key_t nextPacketKey(packet p) + { return i.fields().typeField(); } + }; + \endcode + + If needed, you may additionally add a \c finalize() member. You also should add a \c dump() + member to help debugging but both members are optional. + + \ingroup packet_module */ template <class Self, class Registry=void> class PacketTypeMixin @@ -272,6 +333,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketType_i_) +#define HH_PacketType_i_ #include "PacketType.cci" //#include "PacketType.ct" #include "PacketType.cti" @@ -287,3 +351,12 @@ namespace senf { // compile-command: "scons -u test" // comment-column: 40 // End: + +// LocalWords: Fraunhofer Institut fuer offene Kommunikationssysteme FOKUS de +// LocalWords: Kompetenzzentrum Satelitenkommunikation SatCom Bund berlios dil +// LocalWords: PacketType struct SomePacketType senf PacketTypeBase initSize +// LocalWords: ConcretePacket init initHeadSize nextPacketRange NextPacket os +// LocalWords: nextPacketType std ostream endcode ingroup VoidPacketParser Ok +// LocalWords: tt li OtherPacketType Mixin mixin SimplePacketType typeField +// LocalWords: PacketTypeMixin SomeRegistryTag SomePacketParser nextPacketKey +// LocalWords: hh diff --git a/Packets/PacketTypes.hh b/Packets/PacketTypes.hh index 980c18330..68fa4712e 100644 --- a/Packets/PacketTypes.hh +++ b/Packets/PacketTypes.hh @@ -72,6 +72,9 @@ namespace test { }}}} ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketTypes_i_) +#define HH_PacketTypes_i_ //#include "PacketTypes.cci" //#include "PacketTypes.ct" //#include "PacketTypes.cti" diff --git a/Packets/Packets.hh b/Packets/Packets.hh new file mode 100644 index 000000000..9178325a4 --- /dev/null +++ b/Packets/Packets.hh @@ -0,0 +1,46 @@ +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <g0dil@berlios.de> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Packets public header */ + +#ifndef HH_Packets_ +#define HH_Packets_ 1 + +#define SENF_PACKETS_DECL_ONLY + +#include "all_includes.hh" + +#undef SENF_PACKETS_DECL_ONLY + +#include "all_includes.hh" + +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Packets/ParseArray.hh b/Packets/ParseArray.hh index 1e98a71d5..f0669b3e2 100644 --- a/Packets/ParseArray.hh +++ b/Packets/ParseArray.hh @@ -62,6 +62,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseArray_i_) +#define HH_ParseArray_i_ //#include "ParseArray.cci" //#include "ParseArray.ct" #include "ParseArray.cti" diff --git a/Packets/ParseArray.test.cc b/Packets/ParseArray.test.cc index 8dc19ae1d..44b406d6b 100644 --- a/Packets/ParseArray.test.cc +++ b/Packets/ParseArray.test.cc @@ -26,10 +26,7 @@ //#include "ParseArray.test.ih" // Custom includes -#include "PacketInterpreter.hh" -#include "ParseArray.hh" -#include "ParseInt.hh" -#include "PacketType.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/ParseInt.hh b/Packets/ParseInt.hh index 86a373069..865fd5620 100644 --- a/Packets/ParseInt.hh +++ b/Packets/ParseInt.hh @@ -259,6 +259,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseInt_i_) +#define HH_ParseInt_i_ //#include "ParseInt.cci" //#include "ParseInt.ct" //#include "ParseInt.cti" diff --git a/Packets/ParseInt.test.cc b/Packets/ParseInt.test.cc index deee2fdf6..e240e377f 100644 --- a/Packets/ParseInt.test.cc +++ b/Packets/ParseInt.test.cc @@ -26,9 +26,7 @@ //#include "ParseInt.test.ih" // Custom includes -#include "ParseInt.hh" -#include "PacketInterpreter.hh" -#include "PacketType.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/ParseList.hh b/Packets/ParseList.hh index 4927be2be..945f72e80 100644 --- a/Packets/ParseList.hh +++ b/Packets/ParseList.hh @@ -316,6 +316,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseList_i_) +#define HH_ParseList_i_ //#include "ParseList.cci" #include "ParseList.ct" #include "ParseList.cti" diff --git a/Packets/ParseList.test.cc b/Packets/ParseList.test.cc index 0bd0ab46a..1145af6c6 100644 --- a/Packets/ParseList.test.cc +++ b/Packets/ParseList.test.cc @@ -25,7 +25,7 @@ //#include "ParseList.test.ih" // Custom includes -#include "ParseList.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/ParseListB.hh b/Packets/ParseListB.hh index 7a53c0ab3..72b5159e1 100644 --- a/Packets/ParseListB.hh +++ b/Packets/ParseListB.hh @@ -65,6 +65,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseListB_i_) +#define HH_ParseListB_i_ //#include "ParseListB.cci" //#include "ParseListB.ct" #include "ParseListB.cti" diff --git a/Packets/ParseListB.test.cc b/Packets/ParseListB.test.cc index cd433edb2..764ab645f 100644 --- a/Packets/ParseListB.test.cc +++ b/Packets/ParseListB.test.cc @@ -25,10 +25,7 @@ //#include "ParseListB.test.ih" // Custom includes -#include "ParseListB.hh" -#include "ParseVec.hh" -#include "PacketType.hh" -#include "ParseInt.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/ParseListN.hh b/Packets/ParseListN.hh index e3f816bc1..8dc224349 100644 --- a/Packets/ParseListN.hh +++ b/Packets/ParseListN.hh @@ -43,6 +43,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseListN_i_) +#define HH_ParseListN_i_ //#include "ParseListN.cci" #include "ParseListN.ct" #include "ParseListN.cti" diff --git a/Packets/ParseListN.test.cc b/Packets/ParseListN.test.cc index 84f2ff167..3800a0d90 100644 --- a/Packets/ParseListN.test.cc +++ b/Packets/ParseListN.test.cc @@ -25,11 +25,7 @@ //#include "ParseListN.test.ih" // Custom includes -#include "ParseListN.hh" -#include "ParseVec.hh" -#include "ParseInt.hh" -#include "PacketType.hh" -#include "Packet.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/ParseVec.hh b/Packets/ParseVec.hh index 21239e8be..157b061bf 100644 --- a/Packets/ParseVec.hh +++ b/Packets/ParseVec.hh @@ -198,6 +198,9 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseVec_i_) +#define HH_ParseVec_i_ //#include "ParseVec.cci" #include "ParseVec.ct" #include "ParseVec.cti" diff --git a/Packets/ParseVec.test.cc b/Packets/ParseVec.test.cc index 35079a76c..078626c2d 100644 --- a/Packets/ParseVec.test.cc +++ b/Packets/ParseVec.test.cc @@ -26,9 +26,7 @@ //#include "ParseVec.test.ih" // Custom includes -#include "ParseVec.hh" -#include "ParseInt.hh" -#include "PacketType.hh" +#include "Packets.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> diff --git a/Packets/SConscript b/Packets/SConscript index 27f0650e3..153a67c9c 100644 --- a/Packets/SConscript +++ b/Packets/SConscript @@ -5,10 +5,21 @@ import SENFSCons, glob ########################################################################### +def makeAllIncludesHH(target = None, source = None, env = None): + file(target[0].abspath,"w").write("".join([ '#include "%s"\n' % f + for f in env['SOURCE_HEADERS']])) +makeAllIncludesHH = env.Action(makeAllIncludesHH, varlist=['SOURCE_HEADERS']) + +########################################################################### + sources = SENFSCons.GlobSources() SENFSCons.StandardTargets(env) +env.Command('all_includes.hh', 'SConscript', makeAllIncludesHH, + SOURCE_HEADERS = [ f for f in glob.glob("*.hh") + if 'defined(SENF_PACKETS_DECL_ONLY)' in file(f).read() ]) + SENFSCons.Lib(env, library = 'Packets', sources = sources, diff --git a/Packets/main.test.cc b/Packets/main.test.cc index b759387fb..c2972fdad 100644 --- a/Packets/main.test.cc +++ b/Packets/main.test.cc @@ -29,6 +29,7 @@ #define BOOST_AUTO_TEST_MAIN #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> +#include "Packets.hh" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// diff --git a/find-sources.sh b/find-sources.sh index b28c390cc..9cb24ecbe 100755 --- a/find-sources.sh +++ b/find-sources.sh @@ -17,6 +17,8 @@ if [ "$1" = "-c" ]; then cond='( -name *.h -o -name *.hh -o -name *.ih -o -name *.c -o -name *.cc -o -name *.cci -o -name *.ct -o -name *.cti )' fi +set -f + find . \ -name .svn -prune -o \ -name doc -prune -o \ -- GitLab