Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PacketInterpreter.cc

Go to the documentation of this file.
00001 // $Id: PacketInterpreter.cc 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 //#include "PacketInterpreter.ih"
00027 
00028 // Custom includes
00029 #include "Packets.hh"
00030 
00031 //#include "PacketInterpreter.mpp"
00032 #define prefix_
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 // senf::PacketInterpreterBase
00037 
00038 // structors and default members
00039 
00040 prefix_  senf::PacketInterpreterBase::~PacketInterpreterBase()
00041 {}
00042 
00043 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::clone()
00044 {
00045     detail::PacketImpl::Guard p (new detail::PacketImpl(begin(),end()));
00046     ptr pi (appendClone(p.p,begin(),p.p->begin()));
00047     for (ptr i (next()); i; i = i->next())
00048         i->appendClone(p.p,begin(),p.p->begin());
00049     pi->impl().assignAnnotations( impl());
00050     return pi;
00051 }
00052 
00053 // Interpreter chain access
00054 
00055 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::append(ptr packet)
00056 {
00057     if (next())
00058         impl().truncateInterpreters(next().get());
00059 
00060     optional_range r (nextPacketRange());
00061     if (!r)
00062         throw InvalidPacketChainException();
00063 
00064     ptr rv (packet->appendClone(&impl(), *r));
00065     rv->data().resize(packet->data().size());
00066     std::copy(packet->data().begin(), packet->data().end(), rv->data().begin());
00067 
00068     for (ptr p (packet->next()) ; p ; p = p->next())
00069         p->appendClone(&impl(), packet->data().begin(), rv->data().begin());
00070 
00071     return rv;
00072 }
00073 
00074 prefix_ void senf::PacketInterpreterBase::reparse()
00075 {
00076     if (next())
00077         impl().truncateInterpreters(next().get());
00078 }
00079 
00080 // Access to the abstract interface
00081 
00082 prefix_ void senf::PacketInterpreterBase::dump(std::ostream & os)
00083 {
00084     try {
00085         if (detail::AnnotationRegistry::instance().begin()
00086             != detail::AnnotationRegistry::instance().end()) {
00087             os << "Annotations:\n";
00088             impl().dumpAnnotations(os);
00089         }
00090         v_dump(os);
00091         for (ptr i (next()); i; i = i->next())
00092             i->v_dump(os);
00093     }
00094     catch (senf::Exception & e) {
00095         os << "[Exception: " << e.message() << "]\n";
00096     }
00097 }
00098 
00099 prefix_ void senf::PacketInterpreterBase::finalizeThis()
00100 {
00101     v_finalize();
00102 }
00103 
00104 prefix_ void senf::PacketInterpreterBase::finalizeTo(ptr other)
00105 {
00106     for (ptr i (other); i.get() != this && i.get(); i = i->prev())
00107         i->finalizeThis();
00108     finalizeThis();
00109 }
00110 
00111 // reference/memory management
00112 
00113 prefix_ void senf::PacketInterpreterBase::add_ref()
00114 {
00115     if (impl_ && !refcount())
00116         impl_->add_ref();
00117     intrusive_refcount_t<PacketInterpreterBase>::add_ref();
00118 }
00119 
00120 prefix_ void senf::PacketInterpreterBase::release()
00121 {
00122     if (impl_ && refcount()==1)
00123         // This call will set impl_ to 0 if we just removed the last reference ...
00124         impl_->release();
00125     if (intrusive_refcount_t<PacketInterpreterBase>::release() && !impl_)
00126         delete this;
00127 }
00128 
00129 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00130 // senf::PacketInterpreterBase::Factory
00131 
00132 prefix_  senf::PacketInterpreterBase::Factory::~Factory()
00133 {}
00134 
00135 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00136 #undef prefix_
00137 //#include "PacketInterpreter.mpp"
00138 
00139 
00140 // Local Variables:
00141 // mode: c++
00142 // fill-column: 100
00143 // c-file-style: "senf"
00144 // indent-tabs-mode: nil
00145 // ispell-local-dictionary: "american"
00146 // compile-command: "scons -u test"
00147 // comment-column: 40
00148 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research