X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacket.cci;h=001f69c4db60bb67c5765f85323ffb44e657588d;hb=92f8630b75f3ef50e73c48cde58645dcd1534e27;hp=5a299df9dc9d318fdf8e23fe62ed23f350592ece;hpb=ac6a813d9d99f7add4e13aff7a4bcd314d5604a6;p=senf.git diff --git a/Packets/Packet.cci b/Packets/Packet.cci index 5a299df..001f69c 100644 --- a/Packets/Packet.cci +++ b/Packets/Packet.cci @@ -1,9 +1,9 @@ // $Id$ // -// Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Copyright (C) 2007 +// 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 @@ -20,169 +20,174 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// Definition of inline non-template functions - -#include "Packet.ih" +/** \file + \brief Packet inline non-template implementation */ // Custom includes +#include "../Utils/senfassert.hh" #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// -prefix_ senf::impl::PacketImpl::PacketImpl() - : data_(), interpreters_(), refcount_(1) -{ - SATCOM_PKF_REFC_MSG("] PacketImpl::PacketImpl (" << this << "): refcount_ = 1\n"); -} +/////////////////////////////////////////////////////////////////////////// +// senf::Packet + +// protected members -prefix_ senf::impl::PacketImpl::PacketImpl(unsigned size, Packet::byte initValue) - : data_(size,initValue), interpreters_(), refcount_(1) +prefix_ senf::Packet::Packet(PacketInterpreterBase::ptr packet) + : packet_(packet) +{} + +prefix_ senf::PacketInterpreterBase::ptr senf::Packet::ptr() + const { - SATCOM_PKF_REFC_MSG("] PacketImpl::PacketImpl (" << this << "): refcount_ = 1\n"); + SENF_ASSERT(packet_); + return packet_; } -prefix_ senf::impl::PacketImpl::~PacketImpl() +// public structors + +prefix_ senf::Packet::Packet() +{} + +// public members + +prefix_ senf::Packet senf::Packet::clone() + const { - BOOST_ASSERT( !refcount_ ); - SATCOM_PKF_REFC_MSG("] PacketImpl::~PacketImpl (" << this << ")\n"); + return Packet(ptr()->clone()); } -// PacketImpl::add_ref and PacketImpl::release are only called from -// intrusive_ptr_add_ref and intrusive_ptr_release -prefix_ void senf::impl::PacketImpl::add_ref() -{ - ++refcount_; - SATCOM_PKF_REFC_MSG("] PacketImpl::add_ref (" << this << "): refcount_ = " << refcount_ << "\n"); +// Interpreter chain access + +prefix_ senf::Packet senf::Packet::next(NoThrow_t) + const +{ + PacketInterpreterBase::ptr p (ptr()->next()); + return !p && ptr()->nextPacketRange() ? checkNext() : Packet(p); } -prefix_ bool senf::impl::PacketImpl::release() -{ - BOOST_ASSERT( refcount_ > 0 ); - --refcount_; - SATCOM_PKF_REFC_MSG("] PacketImpl::release (" << this << "): refcount_ = " << refcount_ << "\n"); - return ! refcount_; +prefix_ senf::Packet senf::Packet::next() + const +{ + Packet p (next(nothrow)); + if (!p) throw InvalidPacketChainException(); + return p; } -prefix_ void senf::impl::PacketImpl::truncateInterpreters(Packet const * p) +prefix_ senf::Packet senf::Packet::prev(NoThrow_t) + const { - BOOST_ASSERT( p->impl_ == this ); - this->interpreters_.erase(p->self_,this->interpreters_.end()); + return Packet(ptr()->prev()); } -prefix_ void senf::impl::PacketImpl::truncateInterpretersAfter(Packet const * p) +prefix_ senf::Packet senf::Packet::prev() + const { - BOOST_ASSERT( p->impl_ == this ); - this->interpreters_.erase(boost::next(p->self_),this->interpreters_.end()); + Packet p (prev(nothrow)); + if (!p) throw InvalidPacketChainException(); + return p; } -prefix_ senf::impl::PacketImpl* senf::impl::PacketImpl::impl(Packet const * p) +prefix_ senf::Packet senf::Packet::first() + const { - return p->impl_; + return Packet(ptr()->first()); } -/* -prefix_ std::ostream & senf::operator<<(std::ostream & os, Packet const & packet) +prefix_ senf::Packet senf::Packet::last() + const { - packet.dump(os); - return os; + Packet p (ptr()->last()); + return p.next(nothrow) ? checkLast() : p; } -*/ -// These methods are called by the user codes Packet::ptr's. They -// refcount both the Packet and the owning PacketImpl. -prefix_ void senf::intrusive_ptr_add_ref(Packet const * p) +prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory) + const { - impl::PacketImpl::packet_add_ref(p); + return Packet(ptr()->parseNextAs(factory)); } -prefix_ void senf::intrusive_ptr_release(Packet * p) +prefix_ senf::Packet senf::Packet::append(Packet const & packet) + const { - impl::PacketImpl::packet_release(p); + return Packet(ptr()->append(packet.ptr())); } -prefix_ void senf::impl::intrusive_ptr_add_ref(PacketImpl * p) +// Data access + +prefix_ senf::PacketData & senf::Packet::data() + const { - p->add_ref(); + return ptr()->data(); } -prefix_ void senf::impl::intrusive_ptr_release(PacketImpl * p) +prefix_ senf::Packet::size_type senf::Packet::size() + const { - if (p->release()) - delete p; + return data().size(); } -/////////////////////////////////////////////////////////////////////////// -// class Packet -prefix_ senf::Packet::iterator senf::Packet::begin() +// Other methods + +prefix_ bool senf::Packet::operator==(Packet const & other) const { - return impl_->data_.begin()+begin_; + return ptr() == other.ptr(); } -prefix_ senf::Packet::iterator senf::Packet::end() - const +prefix_ void senf::Packet::finalizeThis() { - return impl_->data_.begin()+end_; + ptr()->finalizeThis(); } -prefix_ size_t senf::Packet::size() - const +prefix_ void senf::Packet::finalizeTo(Packet const & other) +{ + ptr()->finalizeTo(other.ptr()); +} + +prefix_ void senf::Packet::finalizeAll() { - return end_-begin_; + ptr()->finalizeTo(last().ptr()); } -prefix_ senf::Packet::ptr senf::Packet::prev() +prefix_ void senf::Packet::dump(std::ostream & os) const { - if (this->self_ == this->impl_->interpreters_.begin()) - return ptr(0); - // Re-converting the to a smart pointer is correct here, since the - // shared_ptr really uses the intrusive refcount which makes this - // operation safe ... - return ptr(boost::prior(this->self_)->get(),true); + last(); // Make sure the packet is complete + ptr()->dump(os); } -prefix_ senf::Packet::ptr senf::Packet::head() +prefix_ senf::TypeIdValue senf::Packet::typeId() const { - // Re-converting the to a smart pointer is correct here, since the - // shared_ptr really uses the intrusive refcount which makes this - // operation safe ... - return ptr(this->impl_->interpreters_.front().get(),true); + return ptr()->typeId(); } -prefix_ senf::Packet::~Packet() +prefix_ senf::Packet::factory_t senf::Packet::factory() + const { - // FIXME: This is bad ... we cannot check this since this - // assertion fails at the moment if the Packet constructor throws - // ... hrmpf ... we really need to initialize refcount_ to 0 and - // remove the 'false' argument to the ptr constructor in ::create - // BOOST_ASSERT( !this->refcount_ && !this->impl_ ); - SATCOM_PKF_REFC_MSG("] Packet::~Packet (" << this << ")\n"); + return ptr()->factory(); } -prefix_ void senf::Packet::add_ref() +prefix_ bool senf::Packet::boolean_test() const { - ++this->refcount_; - SATCOM_PKF_REFC_MSG("] Packet::add_ref (" << this << "): refcount_ = " << this->refcount_ << "\n"); + return packet_ && packet_->valid(); } -prefix_ bool senf::Packet::release() +prefix_ bool senf::Packet::valid() + const { - BOOST_ASSERT( this->refcount_ > 0 ); - --this->refcount_; - SATCOM_PKF_REFC_MSG("] Packet::release (" << this << "): refcount_ = " << this->refcount_ << "\n"); - return !this->refcount_ && !this->impl_; + return *this; } -prefix_ bool senf::Packet::unlink() +template +prefix_ Parser senf::operator<<(Parser target, ConcretePacket const & packet) { - SATCOM_PKF_REFC_MSG("] Packet::unlink (" << this << "): refcount_ = " << this->refcount_ << "\n"); - this->impl_ = 0; - this->begin_ = this->end_; - return !this->refcount_; + target << packet.parser(); + return target; } ///////////////////////////////cci.e/////////////////////////////////////// @@ -191,5 +196,10 @@ prefix_ bool senf::Packet::unlink() // Local Variables: // mode: c++ +// fill-column: 100 // c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: