From: g0dil Date: Fri, 25 Sep 2009 15:24:16 +0000 (+0000) Subject: Packets: Better packet registry dump and implement bundledump utility X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=eb83d096ce313989c3588c1cb6663caa513fb370;p=senf.git Packets: Better packet registry dump and implement bundledump utility Packets: Additionally build all bundles as shared libraries git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1446 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Examples/MCSniffer/SConstruct b/Examples/MCSniffer/SConstruct index b7aeeed..2652d43 100644 --- a/Examples/MCSniffer/SConstruct +++ b/Examples/MCSniffer/SConstruct @@ -1,7 +1,7 @@ # -*- python -*- -import sys -sys.path.extend(['senf/site_scons', '../../site_scons']) +import sys, os, os.path +sys.path.append(((_ for _ in (os.path.join(os.path.sep.join(('..' for _ in range(_))),d,'site_scons') for d in ('','senf','Senf') for _ in range(len(os.getcwd().split('/')))) if os.path.exists(_))).next()) import senfutil env = Environment() diff --git a/Examples/MultiMCLoop/SConstruct b/Examples/MultiMCLoop/SConstruct index 372994b..611677d 100644 --- a/Examples/MultiMCLoop/SConstruct +++ b/Examples/MultiMCLoop/SConstruct @@ -1,7 +1,7 @@ # -*- python -*- -import sys -sys.path.extend(['senf/site_scons', '../../site_scons']) +import sys, os, os.path +sys.path.append(((_ for _ in (os.path.join(os.path.sep.join(('..' for _ in range(_))),d,'site_scons') for d in ('','senf','Senf') for _ in range(len(os.getcwd().split('/')))) if os.path.exists(_))).next()) import senfutil env = Environment() diff --git a/Examples/RateStuffer/SConstruct b/Examples/RateStuffer/SConstruct index e19b72f..c4dcb0c 100644 --- a/Examples/RateStuffer/SConstruct +++ b/Examples/RateStuffer/SConstruct @@ -1,7 +1,7 @@ # -*- python -*- -import sys -sys.path.extend(['senf/site_scons', '../../site_scons']) +import sys, os, os.path +sys.path.append(((_ for _ in (os.path.join(os.path.sep.join(('..' for _ in range(_))),d,'site_scons') for d in ('','senf','Senf') for _ in range(len(os.getcwd().split('/')))) if os.path.exists(_))).next()) import senfutil env = Environment() diff --git a/Examples/Sniffer/SConstruct b/Examples/Sniffer/SConstruct index 8751373..6f3a70e 100644 --- a/Examples/Sniffer/SConstruct +++ b/Examples/Sniffer/SConstruct @@ -1,7 +1,7 @@ # -*- python -*- -import sys -sys.path.extend(['senf/site_scons', '../../site_scons']) +import sys, os, os.path +sys.path.append(((_ for _ in (os.path.join(os.path.sep.join(('..' for _ in range(_))),d,'site_scons') for d in ('','senf','Senf') for _ in range(len(os.getcwd().split('/')))) if os.path.exists(_))).next()) import senfutil env = Environment() diff --git a/Examples/TCPClientServer/SConstruct b/Examples/TCPClientServer/SConstruct index 8dfea90..c5fc004 100644 --- a/Examples/TCPClientServer/SConstruct +++ b/Examples/TCPClientServer/SConstruct @@ -1,7 +1,7 @@ # -*- python -*- -import sys -sys.path.extend(['senf/site_scons', '../../site_scons']) +import sys, os, os.path +sys.path.append(((_ for _ in (os.path.join(os.path.sep.join(('..' for _ in range(_))),d,'site_scons') for d in ('','senf','Senf') for _ in range(len(os.getcwd().split('/')))) if os.path.exists(_))).next()) import senfutil env = Environment() diff --git a/Examples/UDPClientServer/SConstruct b/Examples/UDPClientServer/SConstruct index 33efa6c..1dab834 100644 --- a/Examples/UDPClientServer/SConstruct +++ b/Examples/UDPClientServer/SConstruct @@ -1,7 +1,7 @@ # -*- python -*- -import sys -sys.path.extend(['senf/site_scons', '../../site_scons']) +import sys, os, os.path +sys.path.append(((_ for _ in (os.path.join(os.path.sep.join(('..' for _ in range(_))),d,'site_scons') for d in ('','senf','Senf') for _ in range(len(os.getcwd().split('/')))) if os.path.exists(_))).next()) import senfutil env = Environment() diff --git a/SConscript b/SConscript index db03adb..f427690 100644 --- a/SConscript +++ b/SConscript @@ -1,6 +1,9 @@ +# -*- python -*- + Import('env') -env['ALLOBJECTS'] = [] +env.Replace( ALLOBJECTS = [], PACKET_BUNDLES = [] ) +env.SetDefault( ALLBUNDLES = '$LOCALLIBDIR/AllBundles${OBJADDSUFFIX}${OBJSUFFIX}' ) SConscript('senf/SConscript') @@ -14,9 +17,9 @@ conf = env.CreateFile("${LOCALLIBDIR}/${LIBSENF}${LIBADDSUFFIX}.conf", env.Default(conf) env.Install('$CONFINSTALLDIR', conf) -# AllBundles: +### AllBundles: cobject = env.CombinedObject('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', env['PACKET_BUNDLES'], NAME="AllBundles") env.Default(cobject) env.Install('${OBJINSTALLDIR}', cobject) - \ No newline at end of file + diff --git a/senf/Packets/.gitignore b/senf/Packets/.gitignore new file mode 100644 index 0000000..bb4efc0 --- /dev/null +++ b/senf/Packets/.gitignore @@ -0,0 +1 @@ +/bundledump diff --git a/senf/Packets/DefaultBundle/ICMPv6Packet.hh b/senf/Packets/DefaultBundle/ICMPv6Packet.hh index aff2010..1165701 100644 --- a/senf/Packets/DefaultBundle/ICMPv6Packet.hh +++ b/senf/Packets/DefaultBundle/ICMPv6Packet.hh @@ -47,7 +47,7 @@ namespace senf struct ICMPTypes { // ICMP type registry - typedef boost::uint16_t key_t; + typedef boost::uint8_t key_t; }; /** \brief ICMP Packet for IPv6 diff --git a/senf/Packets/DefaultBundle/IPv4Packet.hh b/senf/Packets/DefaultBundle/IPv4Packet.hh index 259a815..0122084 100644 --- a/senf/Packets/DefaultBundle/IPv4Packet.hh +++ b/senf/Packets/DefaultBundle/IPv4Packet.hh @@ -117,7 +117,7 @@ namespace senf { PacketRegistry */ struct IpTypes { - typedef boost::uint16_t key_t; + typedef boost::uint8_t key_t; }; /** \brief IPv4 packet diff --git a/senf/Packets/PacketRegistry.cc b/senf/Packets/PacketRegistry.cc index 366c129..a4fa3dc 100644 --- a/senf/Packets/PacketRegistry.cc +++ b/senf/Packets/PacketRegistry.cc @@ -42,12 +42,22 @@ prefix_ void senf::detail::PacketRegistryImplBase::dump(std::ostream & os) RegistryMap::const_iterator i (registries().begin()); RegistryMap::const_iterator const i_end (registries().end()); for (; i!=i_end; ++i) { - os << i->first << ":\n"; - i->second->v_dump(os); - os << "\n"; + if (! i->second->v_empty()) { + os << i->first << ":\n"; + i->second->v_dump(os); + os << "\n"; + } } } +prefix_ void senf::detail::PacketRegistryImplBase::clear() +{ + RegistryMap::const_iterator i (registries().begin()); + RegistryMap::const_iterator const i_end (registries().end()); + for (; i!=i_end; ++i) + i->second->v_clear(); +} + prefix_ senf::detail::PacketRegistryImplBase::RegistryMap & senf::detail::PacketRegistryImplBase::registries() { diff --git a/senf/Packets/PacketRegistry.ct b/senf/Packets/PacketRegistry.ct index 4d82e36..df12669 100644 --- a/senf/Packets/PacketRegistry.ct +++ b/senf/Packets/PacketRegistry.ct @@ -28,6 +28,8 @@ // Custom includes #include #include +#include +#include #include #define prefix_ @@ -126,12 +128,60 @@ senf::detail::PacketRegistryImpl::lookup(key_t key, bool) } template +prefix_ bool senf::detail::PacketRegistryImpl::v_empty() + const +{ + return registry_.empty(); +} + +template prefix_ void senf::detail::PacketRegistryImpl::v_dump(std::ostream & os) + const { typename PacketMap::const_iterator i (registry_.begin()); typename PacketMap::const_iterator const i_end (registry_.end()); - for (; i != i_end; ++i) - os << i->first << " " << i->second->name() << "\n"; + for (; i != i_end; ++i) { + std::string n (i->second->name()); + senf::detail::DumpKey::dump(i->first, os); + os << ' ' << n.substr(21,n.size()-22) << "\n"; + } +} + +template +prefix_ void senf::detail::PacketRegistryImpl::v_clear() +{ + registry_.clear(); + reverseRegistry_.clear(); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::detail::DumpKey + +template +prefix_ void senf::detail::DumpKey::dump(KeyType const & v, + std::ostream & os) +{ + os << " " << std::setw(16) << std::left << v << std::setw(0) << std::right; +} + +// senf::detail::DumpKey + +template +prefix_ void senf::detail::DumpKey::dump(KeyType const & v, std::ostream & os) +{ + int bytes ((std::numeric_limits::digits+7)/8); + int digs (int(2.4*bytes)+1); + + os << " 0x" << std::setw(2*bytes) << std::setfill('0') << std::hex + << typename senf::detail::CharToInt::type (v) + << " (" << std::setw(digs) << std::setfill(' ') << std::dec + << typename senf::detail::CharToInt::type (v) + << ") ("; + for (int i (bytes-1); i>=0; --i) { + char c ((v>>(8*i))&0xff); + os << ((c>=32 && c<=127) ? c : '.'); + } + os << ')'; } ///////////////////////////////ct.e//////////////////////////////////////// diff --git a/senf/Packets/PacketRegistry.ih b/senf/Packets/PacketRegistry.ih index 24c9851..240773c 100644 --- a/senf/Packets/PacketRegistry.ih +++ b/senf/Packets/PacketRegistry.ih @@ -28,6 +28,7 @@ // Custom includes #include +#include #include #include #include @@ -74,13 +75,16 @@ namespace detail { virtual ~PacketRegistryImplBase(); static void dump(std::ostream & os); + static void clear(); protected: typedef std::map RegistryMap; static RegistryMap & registries(); private: - virtual void v_dump(std::ostream & os) = 0; + virtual bool v_empty() const = 0; + virtual void v_dump(std::ostream & os) const = 0; + virtual void v_clear() = 0; }; /** \brief Internal: Singleton class implementing the packet registry. @@ -131,12 +135,31 @@ namespace detail { protected: private: - virtual void v_dump(std::ostream & os); + virtual bool v_empty() const; + virtual void v_dump(std::ostream & os) const; + virtual void v_clear(); PacketMap registry_; ReversePacketMap reverseRegistry_; }; + template ::is_integer> + struct DumpKey + { + static void dump(KeyType const & v, std::ostream & os); + }; + + template + struct DumpKey + { + static void dump(KeyType const & v, std::ostream & os); + }; + + template struct CharToInt { typedef Type type; }; + template <> struct CharToInt { typedef int type; }; + template <> struct CharToInt { typedef int type; }; + template <> struct CharToInt { typedef unsigned type; }; + }} ///////////////////////////////ih.e//////////////////////////////////////// diff --git a/senf/Packets/PacketRegistry.test.cc b/senf/Packets/PacketRegistry.test.cc index b9244c6..872f490 100644 --- a/senf/Packets/PacketRegistry.test.cc +++ b/senf/Packets/PacketRegistry.test.cc @@ -87,18 +87,17 @@ BOOST_AUTO_UNIT_TEST(packetRegistry_test) senf::dumpPacketRegistries(s); BOOST_CHECK_EQUAL( s.str(), "(anonymous namespace)::BaseTag:\n" - "1 senf::ConcretePacket<(anonymous namespace)::FooPacketType>\n" - "2 senf::ConcretePacket<(anonymous namespace)::BarPacketType>\n" + " 0x00000001 ( 1) (....) (anonymous namespace)::FooPacketType\n" + " 0x00000002 ( 2) (....) (anonymous namespace)::BarPacketType\n" "\n" "(anonymous namespace)::RegTag:\n" - "1 senf::ConcretePacket<(anonymous namespace)::FooPacketType>\n" - "2 senf::ConcretePacket<(anonymous namespace)::BarPacketType>\n" + " 0x00000001 ( 1) (....) (anonymous namespace)::FooPacketType\n" + " 0x00000002 ( 2) (....) (anonymous namespace)::BarPacketType\n" "\n" "(anonymous namespace)::StringTag:\n" - "bar senf::ConcretePacket<(anonymous namespace)::BarPacketType>\n" - "foo senf::ConcretePacket<(anonymous namespace)::FooPacketType>\n" + " bar (anonymous namespace)::BarPacketType\n" + " foo (anonymous namespace)::FooPacketType\n" "\n" ); - } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/senf/Packets/SConscript b/senf/Packets/SConscript index 478d416..7fa90ca 100644 --- a/senf/Packets/SConscript +++ b/senf/Packets/SConscript @@ -5,9 +5,7 @@ import SENFSCons ########################################################################### -env['PACKET_BUNDLES'] = [] - -SENFSCons.AutoRules(env, doc_extra_sources = [ +SENFSCons.AutoRules(env, exclude = [ 'bundledump.cc' ], doc_extra_sources = [ env.Dia2Png("structure.dia"), env.Dia2Png("80221Bundle/TLV.dia"), env.PkgDraw("MPEGDVBBundle/DTCPPacket.hh"), @@ -57,3 +55,5 @@ SENFSCons.AutoRules(env, doc_extra_sources = [ env.PkgDraw("MPEGDVBBundle/TransportPacket.hh"), ]) +env.Default(env.Program('bundledump', [ 'bundledump.cc', '$LOCALLIBDIR/DefaultBundle.o' ], + LIBS = [ '$LIBS', 'dl' ])) diff --git a/senf/Packets/bundledump.cc b/senf/Packets/bundledump.cc new file mode 100644 index 0000000..19ec8d0 --- /dev/null +++ b/senf/Packets/bundledump.cc @@ -0,0 +1,66 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// 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 bundledump non-inline non-template implementation */ + +// Custom includes +#include +#include +#include "Packets.hh" +#include + +//#include "bundledump.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +int main(int argc, char const ** argv) +{ + // Link in logger library ... + (void) senf::log::StreamRegistry::instance(); + for (unsigned i (1); i" - echo - echo "-c Only list C/C++ source files" - echo - echo " are any find commands (which should contain a -print somewhere)" - echo "which are matched for any file fond" - exit 1 -fi - cond="" if [ "$1" = "-c" ]; then shift @@ -36,4 +25,4 @@ find . \ -name ".sconsign*" -o \ -name "semantic.cache" -o \ -name "all_includes.hh" -o \ - -type f $cond \( "$@" \) + -type f $cond \( "$@" -print \)