From: g0dil Date: Wed, 8 Aug 2007 22:12:05 +0000 (+0000) Subject: PPI: Checkin of first compiling (yet not working) version X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=81ffa1c459b96dd44472bcef37e1e373934ee138;p=senf.git PPI: Checkin of first compiling (yet not working) version Socket/Protocols/INet: Slightly optimized generic INet6Address algorithms Utils: Add ios_all_saver to hexdump() senfscons: Add automatic image-copy to Doxygen builder (fixes weird doxygen copy problem) Socket/Protocols/Inet: Add ConnectedUDPSocketHandle git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@384 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/Connectors.cc b/PPI/Connectors.cc new file mode 100644 index 0000000..d8e74dc --- /dev/null +++ b/PPI/Connectors.cc @@ -0,0 +1,91 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Connectors non-inline non-template implementation */ + +#include "Connectors.hh" +//#include "Connectors.ih" + +// Custom includes + +//#include "Connectors.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// protected members + +prefix_ senf::ppi::connector::Connector::~Connector() +{} + +prefix_ void senf::ppi::connector::Connector::connect(Connector & target) +{ + peer_ = & target; + target.peer_ = this; +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::InputConnector + +//////////////////////////////////////// +// private members + +prefix_ void senf::ppi::connector::InputConnector::v_enqueueEvent() +{} + +prefix_ void senf::ppi::connector::InputConnector::v_dequeueEvent() +{} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::PassiveInput + +//////////////////////////////////////// +// private members + +prefix_ void senf::ppi::connector::PassiveInput::v_enqueueEvent() +{ + ///\fixme Emit notifications when qstate_ changes + qstate_ = qdisc_->update(*this, QueueingDiscipline::ENQUEUE); + emit(); +} + +prefix_ void senf::ppi::connector::PassiveInput::v_dequeueEvent() +{ + ///\fixme Emit notifications when qstate_ changes + qstate_ = qdisc_->update(*this, QueueingDiscipline::DEQUEUE); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ +//#include "Connectors.mpp" + + +// 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/PPI/Connectors.cci b/PPI/Connectors.cci new file mode 100644 index 0000000..60be4bd --- /dev/null +++ b/PPI/Connectors.cci @@ -0,0 +1,212 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Connectors inline non-template implementation */ + +// Custom includes + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::Connector + +prefix_ senf::ppi::connector::Connector & senf::ppi::connector::Connector::peer() +{ + BOOST_ASSERT(peer_); + return *peer_; +} + +prefix_ senf::ppi::module::Module & senf::ppi::connector::Connector::module() +{ + BOOST_ASSERT(module_); + return *module_; +} + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::connector::Connector::Connector() + : peer_(), module_() +{} + +//////////////////////////////////////// +// private members + +prefix_ void senf::ppi::connector::Connector::setModule(module::Module & module) +{ + module_ = &module; +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::ActiveConnector + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::connector::ActiveConnector::ActiveConnector() +{} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::PassiveConnector + +prefix_ senf::ppi::connector::ActiveConnector & senf::ppi::connector::PassiveConnector::peer() +{ + return dynamic_cast(Connector::peer()); +} + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::connector::PassiveConnector::PassiveConnector() + : callback_() +{} + +prefix_ void senf::ppi::connector::PassiveConnector::emit() +{ + BOOST_ASSERT(callback_); + callback_(); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::InputConnector + +prefix_ senf::Packet senf::ppi::connector::InputConnector::operator()() +{ + Packet p (queue_.back()); + queue_.pop_back(); + v_dequeueEvent(); + return p; +} + +prefix_ bool senf::ppi::connector::InputConnector::boolean_test() +{ + ///\fixme Add additional active/passive throttle/unthrottle conditions (make virtual ?) + return ! empty(); +} + +prefix_ senf::ppi::connector::OutputConnector & senf::ppi::connector::InputConnector::peer() +{ + return dynamic_cast(Connector::peer()); +} + +prefix_ senf::ppi::connector::InputConnector::queue_iterator +senf::ppi::connector::InputConnector::begin() +{ + return queue_.begin(); +} + +prefix_ senf::ppi::connector::InputConnector::queue_iterator +senf::ppi::connector::InputConnector::end() +{ + return queue_.end(); +} + +prefix_ senf::Packet senf::ppi::connector::InputConnector::peek() +{ + return queue_.back(); +} + +prefix_ senf::ppi::connector::InputConnector::size_type +senf::ppi::connector::InputConnector::queueSize() +{ + return queue_.size(); +} + +prefix_ bool senf::ppi::connector::InputConnector::empty() +{ + return queue_.empty(); +} + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::connector::InputConnector::InputConnector() +{} + +//////////////////////////////////////// +// private members + +prefix_ void senf::ppi::connector::InputConnector::enqueue(Packet p) +{ + queue_.push_front(p); + v_enqueueEvent(); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::OutputConnector + +prefix_ void senf::ppi::connector::OutputConnector::operator()(Packet p) +{ + peer().enqueue(p); +} + +prefix_ senf::ppi::connector::InputConnector & senf::ppi::connector::OutputConnector::peer() +{ + return dynamic_cast(Connector::peer()); +} + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::connector::OutputConnector::OutputConnector() +{} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::PassiveInput + +prefix_ senf::ppi::connector::PassiveInput::PassiveInput() + : qdisc_(), qstate_(QueueingDiscipline::UNTHROTTLED) +{} + +prefix_ senf::ppi::connector::ActiveOutput & senf::ppi::connector::PassiveInput::peer() +{ + return dynamic_cast(Connector::peer()); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::ActiveOutput + +prefix_ senf::ppi::connector::ActiveInput & senf::ppi::connector::ActiveOutput::peer() +{ + return dynamic_cast(Connector::peer()); +} + +prefix_ void senf::ppi::connector::ActiveOutput::connect(PassiveInput & target) +{ + Connector::connect(target); +} + +///////////////////////////////cci.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Connectors.cti b/PPI/Connectors.cti new file mode 100644 index 0000000..9c77368 --- /dev/null +++ b/PPI/Connectors.cti @@ -0,0 +1,63 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Connectors inline template implementation */ + +//#include "Connectors.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::PassiveConnector + +template +prefix_ void senf::ppi::connector::PassiveConnector::onRequest(Handler handler) +{ + callback_ = detail::Callback<>::make(handler, module()); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::connector::PassiveInput + +template +prefix_ void senf::ppi::connector::PassiveInput::qdisc(QDisc const & disc) +{ + qdisc_ = boost::scoped_ptr(new QDisc(disc)); +} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Connectors.hh b/PPI/Connectors.hh index c915c06..655e225 100644 --- a/PPI/Connectors.hh +++ b/PPI/Connectors.hh @@ -19,7 +19,7 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief Conenctors public header */ + \brief Connectors public header */ /** \defgroup connectors Connector classes @@ -37,13 +37,20 @@ senf::ppi::PassiveInput and senf::ppi::PassiveOutput. */ -#ifndef HH_Conenctors_ -#define HH_Conenctors_ 1 +#ifndef HH_Connectors_ +#define HH_Connectors_ 1 // Custom includes +#include #include - -//#include "Conenctors.mpp" +#include +#include "Utils/SafeBool.hh" +#include "Packets/Packets.hh" +#include "predecl.hh" +#include "detail/Callback.hh" +#include "Queueing.hh" + +//#include "Connectors.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { @@ -61,12 +68,21 @@ namespace connector { { public: Connector & peer(); ///< Get peer connected to this connector - Module & module(); ///< Get this connectors containing module + module::Module & module(); ///< Get this connectors containing module protected: - // here to protect Connector(); - ~Connector(); + virtual ~Connector(); + + void connect(Connector & target); + + private: + void setModule(module::Module & module); + + Connector * peer_; + module::Module * module_; + + friend class module::Module; }; /** \brief Passive connector baseclass @@ -115,9 +131,14 @@ namespace connector { ActiveConnector & peer(); protected: - // here to protect PassiveConnector(); - ~PassiveConnector(); + + void emit(); + + private: + + typedef detail::Callback<>::type Callback; + Callback callback_; }; /** \brief Active connector baseclass @@ -161,9 +182,7 @@ namespace connector { PassiveConnector & peer(); protected: - // here to protect - PassiveConnector(); - ~PassiveConnector(); + ActiveConnector(); }; /** \brief Input connector baseclass @@ -187,13 +206,15 @@ namespace connector { be added to the queue before it can be processed. */ class InputConnector - : public virtual Connector + : public virtual Connector, + public SafeBool { + typedef std::deque Queue; public: - typedef unspecified queue_iterator; ///< Iterator type of the embedded queue - typedef unspecified size_type; ///< Unsigned type representing the number of queue elements + typedef Queue::const_iterator queue_iterator; ///< Iterator type of the embedded queue + typedef Queue::size_type size_type; ///< Unsigned type for counting queue elements - Packet::ptr operator(); ///< Get a packet + Packet operator()(); ///< Get a packet /**< This member is the primary method to access received data. On passive connectors, this operator will just dequeue a packet from the packet queue. If the @@ -202,7 +223,7 @@ namespace connector { request cannot be fulfilled, this is considered to be a logic error in the module implementation and an exception is raised. */ - operator unspecified_boolean_type (); ///< Check packet availability + bool boolean_test (); ///< Check packet availability /**< Using any input connector in a boolean context will check, whether an input request can be fulfilled. This is always possible if the queue is non-empty. If the @@ -215,24 +236,28 @@ namespace connector { \returns \c true if operator() can be called, \c false otherwise */ - operator ! (); ///< Check packet availability - /**< Inverse of the boolean conversion operator - \returns \c false if operator() can be called, \c true - otherwise */ OutputConnector & peer(); queue_iterator begin(); ///< Access queue begin (head) queue_iterator end(); ///< Access queue past-the-end (tail) - Packet::ptr head(); ///< Return head element from the queue + Packet peek(); ///< Return head element from the queue size_type queueSize(); ///< Return number of elements in the queue bool empty(); ///< Return queueSize() == 0 protected: - // here to protect - PassiveConnector(); - ~PassiveConnector(); + InputConnector(); + + private: + void enqueue(Packet p); + + virtual void v_enqueueEvent(); + virtual void v_dequeueEvent(); + + Queue queue_; + + friend class OutputConnector; }; /** \brief Output connector baseclass @@ -245,14 +270,12 @@ namespace connector { : public virtual Connector { public: - void operator(Packet::ptr); ///< Send out a packet + void operator()(Packet p); ///< Send out a packet InputConnector & peer(); protected: - // here to protect - PassiveConnector(); - ~PassiveConnector(); + OutputConnector(); }; ///@{ @@ -272,14 +295,23 @@ namespace connector { : public PassiveConnector, public InputConnector { public: + PassiveInput(); + ActiveOutput & peer(); - template - void qdisc(QueueingDiscipline const & disc); ///< Change the queueing discipline + template + void qdisc(QDisc const & disc); ///< Change the queueing discipline /**< The queueing discipline is a class which provides the QueueingDiscipline interface. \param[in] disc New queueing discipline */ + + private: + void v_enqueueEvent(); + void v_dequeueEvent(); + + boost::scoped_ptr qdisc_; + QueueingDiscipline::State qstate_; }; /** \brief Combination of PassiveConnector and OutputConnector @@ -289,6 +321,8 @@ namespace connector { { public: ActiveInput & peer(); + + void connect(ActiveInput & target); }; /** \brief Combination of ActiveConnector and InputConnector @@ -309,6 +343,8 @@ namespace connector { { public: ActiveInput & peer(); + + void connect(PassiveInput & target); }; ///@} @@ -316,9 +352,9 @@ namespace connector { }}} ///////////////////////////////hh.e//////////////////////////////////////// -//#include "Conenctors.cci" -//#include "Conenctors.ct" -//#include "Conenctors.cti" +#include "Connectors.cci" +//#include "Connectors.ct" +#include "Connectors.cti" #endif diff --git a/PPI/Connectors.test.cc b/PPI/Connectors.test.cc new file mode 100644 index 0000000..acf957f --- /dev/null +++ b/PPI/Connectors.test.cc @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Connectors.test unit tests */ + +//#include "Connectors.test.hh" +//#include "Connectors.test.ih" + +// Custom includes +#include "Connectors.hh" + +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(connectors) +{} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Doxyfile b/PPI/Doxyfile index d68c399..73ee2a5 100644 --- a/PPI/Doxyfile +++ b/PPI/Doxyfile @@ -2,5 +2,7 @@ PROJECT_NAME = libPPI GENERATE_TAGFILE = doc/ppi.tag +RECURSIVE = Yes +SHOW_DIRECTORIES = Yes TAGFILES = "$(TOPDIR)/Packets/doc/Packets.tag" "$(TOPDIR)/Socket/doc/Socket.tag" diff --git a/PPI/EventManager.cci b/PPI/EventManager.cci new file mode 100644 index 0000000..2d82a05 --- /dev/null +++ b/PPI/EventManager.cci @@ -0,0 +1,67 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 EventManager inline non-template implementation */ + +//#include "EventManager.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::EventManager + +prefix_ senf::ppi::EventManager & senf::ppi::EventManager::instance() +{ + static EventManager manager; + return manager; +} + +prefix_ boost::posix_time::ptime senf::ppi::EventManager::eventTime() +{ + return eventTime_; +} + +//////////////////////////////////////// +// private members + +prefix_ void senf::ppi::EventManager::eventTime(boost::posix_time::ptime time) +{ + eventTime_ = time; +} + +///////////////////////////////cci.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/EventManager.ct b/PPI/EventManager.ct new file mode 100644 index 0000000..778ad5d --- /dev/null +++ b/PPI/EventManager.ct @@ -0,0 +1,61 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 EventManager non-inline template implementation */ + +//#include "EventManager.ih" + +// Custom includes +#include + +#define prefix_ +///////////////////////////////ct.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::EventManager + +template +prefix_ void +senf::ppi::EventManager::registerEvent(module::Module & module, + typename Callback::type callback, + Descriptor & descriptor) +{ + registrations_.push_back( + new detail::EventBinding(*this, module, callback, descriptor)); + descriptor.setBinding( + static_cast< detail::EventBinding & >(registrations_.back())); +} + +///////////////////////////////ct.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/EventManager.hh b/PPI/EventManager.hh new file mode 100644 index 0000000..46631e6 --- /dev/null +++ b/PPI/EventManager.hh @@ -0,0 +1,114 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 EventManager public header */ + +#ifndef HH_EventManager_ +#define HH_EventManager_ 1 + +// Custom includes +#include +#include +#include "predecl.hh" +#include "detail/Callback.hh" +#include "detail/EventBinding.hh" + +//#include "EventManager.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { +namespace ppi { + + /** \brief + */ + class EventManager + { + public: + /////////////////////////////////////////////////////////////////////////// + // Types + + template +#ifndef DOXYGEN + struct Callback +#else + // This is SO stupid but doxygen must have some scoping problems if the + // struct is called 'Callback' and will hang in an endless loop somewhere + struct Callback_ +#endif + : public detail::Callback + {}; + + /////////////////////////////////////////////////////////////////////////// + ///\name Structors and default members + ///@{ + + static EventManager & instance(); + + // default default constructor + // default copy constructor + // default copy assignment + // default destructor + + // no conversion constructors + + ///@} + /////////////////////////////////////////////////////////////////////////// + + template + void registerEvent(module::Module & module, + typename Callback::type callback, + Descriptor & descriptor); + + boost::posix_time::ptime eventTime(); + + protected: + + private: + typedef boost::ptr_vector EventRegistrations; + EventRegistrations registrations_; + + void eventTime(boost::posix_time::ptime time); + + boost::posix_time::ptime eventTime_; + + friend class detail::EventBindingBase; + }; + +}} + +///////////////////////////////hh.e//////////////////////////////////////// +#include "EventManager.cci" +#include "EventManager.ct" +//#include "EventManager.cti" +#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/PPI/EventManager.test.cc b/PPI/EventManager.test.cc new file mode 100644 index 0000000..ea9b886 --- /dev/null +++ b/PPI/EventManager.test.cc @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 EventManager.test unit tests */ + +//#include "EventManager.test.hh" +//#include "EventManager.test.ih" + +// Custom includes +#include "EventManager.hh" + +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(eventManager) +{} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Events.cci b/PPI/Events.cci new file mode 100644 index 0000000..8ffd90e --- /dev/null +++ b/PPI/Events.cci @@ -0,0 +1,72 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Events inline non-template implementation */ + +// Custom includes +#include + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::EventDescriptor + +prefix_ senf::ppi::EventDescriptor::~EventDescriptor() +{} + +prefix_ bool senf::ppi::EventDescriptor::enabled() +{ + return enabled_; +} + +prefix_ void senf::ppi::EventDescriptor::enabled(bool v) +{ + BOOST_ASSERT(v_isRegistered()); + if (v && ! enabled_) + v_enable(); + else if (! v && enabled_) + v_disable(); + enabled_ = v; +} + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::EventDescriptor::EventDescriptor() + : enabled_(false) +{} + +///////////////////////////////cci.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Events.cti b/PPI/Events.cti new file mode 100644 index 0000000..a7db87c --- /dev/null +++ b/PPI/Events.cti @@ -0,0 +1,88 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Events inline template implementation */ + +#include "Events.ih" + +// Custom includes +#include "detail/EventBinding.hh" + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::EventImplementation + +//////////////////////////////////////// +// protected members + +template +prefix_ senf::ppi::EventImplementation::EventImplementation() + : binding_(0) +{} + +template +prefix_ void senf::ppi::EventImplementation::callback(EventArg event, + boost::posix_time::ptime time) +{ + BOOST_ASSERT(binding_); + binding_->callback(event,time); +} + +template +prefix_ void senf::ppi::EventImplementation::callback(EventArg event) +{ + BOOST_ASSERT(binding_); + binding_->callback(event); +} + +//////////////////////////////////////// +// private members + +template +prefix_ bool senf::ppi::EventImplementation::v_isRegistered() +{ + return binding_; +} + +template +prefix_ void +senf::ppi::EventImplementation::setBinding(detail::EventBinding & binding) +{ + binding_ = & binding; +} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Events.hh b/PPI/Events.hh index 154beba..cb21dd7 100644 --- a/PPI/Events.hh +++ b/PPI/Events.hh @@ -25,6 +25,8 @@ #define HH_Events_ 1 // Custom includes +#include +#include "predecl.hh" //#include "Events.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -32,6 +34,14 @@ namespace senf { namespace ppi { + // Implementation: The concrete EventDescriptor implementation will need to set things up so + // some callback (within the EventDescriptor implementation) will be called when the event + // happens. This setup happens in 'v_enable()'. This internal handler sets up an EventType + // instance if needed and calls 'callback()'. + // + // 'callback()' will access the EventBinding wrapper to find the user-callback to signal. It + // will do any needed internal processing, call that user callback and clean up afterwards. + /** \brief Generic event interface baseclass The EventDescriptor baseclass provides an interface to manipulate events in a generic @@ -40,35 +50,52 @@ namespace ppi { class EventDescriptor { public: + virtual ~EventDescriptor(); + bool enabled(); ///< Check, whether the event is currently enabled - void enabled(bool); ///< Enable or disable the event + void enabled(bool v); ///< Enable or disable the event protected: - typedef unspecified CallbackType; ///< Fixed type of the (internal) event handler. - - void register(CallbackType handler); ///< Register the event - void unregister(); ///< Unregister the event + EventDescriptor(); private: - virtual void v_register(CallbackType handler) = 0; ///< Called to register the event - virtual void v_unregister() = 0; ///< Called to unregister the event virtual void v_enable() = 0; ///< Called to enable the event delivery virtual void v_disable() = 0; ///< Called to disable the event delivery - virtual void v_process() = 0; ///< Called whenever the event is signaled - /**< This virtual method is called \e after every call to - the event handler to provide a hook for further - processing (example: calculate the next time, an - interval timer expires) */ + + virtual bool v_isRegistered() = 0; bool enabled_; }; + template + class EventImplementation + : public EventDescriptor + { + public: + typedef EventType Event; + typedef typename detail::EventArgType::type EventArg; + + protected: + EventImplementation(); + + void callback(EventArg event, boost::posix_time::ptime time); + void callback(EventArg event); + + private: + virtual bool v_isRegistered(); + void setBinding(detail::EventBinding & binding); + + detail::EventBinding * binding_; + + friend class EventManager; + }; + }} ///////////////////////////////hh.e//////////////////////////////////////// -//#include "Events.cci" +#include "Events.cci" //#include "Events.ct" -//#include "Events.cti" +#include "Events.cti" #endif diff --git a/PPI/Events.ih b/PPI/Events.ih new file mode 100644 index 0000000..02c0586 --- /dev/null +++ b/PPI/Events.ih @@ -0,0 +1,63 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Events internal header */ + +#ifndef IH_Events_ +#define IH_Events_ 1 + +// Custom includes + +///////////////////////////////ih.p//////////////////////////////////////// + +namespace senf { +namespace ppi { +namespace detail { + + template + struct EventArgType + { + typedef EventType const & type; + }; + + template <> + struct EventArgType + { + typedef void type; + }; + +}}} + +///////////////////////////////ih.e//////////////////////////////////////// +#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/PPI/Events.test.cc b/PPI/Events.test.cc new file mode 100644 index 0000000..5f3b4f2 --- /dev/null +++ b/PPI/Events.test.cc @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Events.test unit tests */ + +//#include "Events.test.hh" +//#include "Events.test.ih" + +// Custom includes +#include "Events.hh" + +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(events) +{} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/IOEvent.cc b/PPI/IOEvent.cc new file mode 100644 index 0000000..2010b6b --- /dev/null +++ b/PPI/IOEvent.cc @@ -0,0 +1,72 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 IOEvent non-inline non-template implementation */ + +#include "IOEvent.hh" +//#include "IOEvent.ih" + +// Custom includes +#include + +//#include "IOEvent.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::IOEvent + +//////////////////////////////////////// +// private members + +prefix_ void senf::ppi::IOEvent::v_enable() +{ + Scheduler::instance().add(fd_, boost::bind(&IOEvent::cb,this,_1,_2), + Scheduler::EventId(events_)); +} + +prefix_ void senf::ppi::IOEvent::v_disable() +{ + Scheduler::instance().remove(fd_, Scheduler::EventId(events_)); +} + +prefix_ void senf::ppi::IOEvent::cb(int, Scheduler::EventId event) +{ + IOEventInfo info = { event }; + callback(info); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ +//#include "IOEvent.mpp" + + +// 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/PPI/IOEvent.cti b/PPI/IOEvent.cti new file mode 100644 index 0000000..73c4fd8 --- /dev/null +++ b/PPI/IOEvent.cti @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 IOEvent inline template implementation */ + +//#include "IOEvent.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::IOEvent + +template +prefix_ senf::ppi::IOEvent::IOEvent(Handle handle, unsigned events) + : fd_(retrieve_filehandle(handle)), events_(events) +{} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/IOEvent.hh b/PPI/IOEvent.hh new file mode 100644 index 0000000..4e143b2 --- /dev/null +++ b/PPI/IOEvent.hh @@ -0,0 +1,96 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 IOEvent public header */ + +#ifndef HH_IOEvent_ +#define HH_IOEvent_ 1 + +// Custom includes +#include "Events.hh" +#include "Scheduler/Scheduler.hh" + +//#include "IOEvent.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { +namespace ppi { + + struct IOEventInfo + { + unsigned events; + }; + + /** \brief + */ + class IOEvent + : public EventImplementation + { + public: + /////////////////////////////////////////////////////////////////////////// + // Types + + enum EventFlags { Read = Scheduler::EV_READ, + Write = Scheduler::EV_WRITE }; + + /////////////////////////////////////////////////////////////////////////// + ///\name Structors and default members + ///@{ + + template + IOEvent(Handle handle, unsigned events); + + ///@} + /////////////////////////////////////////////////////////////////////////// + + protected: + + private: + virtual void v_enable(); + virtual void v_disable(); + + void cb(int, Scheduler::EventId event); + + int fd_; + unsigned events_; + }; + + +}} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "IOEvent.cci" +//#include "IOEvent.ct" +#include "IOEvent.cti" +#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/PPI/Mainpage.dox b/PPI/Mainpage.dox index 040811f..5bac781 100644 --- a/PPI/Mainpage.dox +++ b/PPI/Mainpage.dox @@ -388,6 +388,10 @@ handler has finished processing. Forward throttling notifications are not generated automatically within the connector. However, the Passive-Passive adaptor will generate Forward-throttling notifications whenever the input queue is empty. + + \section class_diagram Class Diagram + + \image html classes.png */ diff --git a/PPI/Module.cc b/PPI/Module.cc new file mode 100644 index 0000000..e742e3e --- /dev/null +++ b/PPI/Module.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Module non-inline non-template implementation */ + +#include "Module.hh" +#include "Module.ih" + +// Custom includes + +//#include "Module.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ +//#include "Module.mpp" + + +// 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/PPI/Module.cci b/PPI/Module.cci new file mode 100644 index 0000000..04ecc61 --- /dev/null +++ b/PPI/Module.cci @@ -0,0 +1,87 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Module inline non-template implementation */ + +// Custom includes +#include "Route.hh" +#include "Connectors.hh" +#include "EventManager.hh" + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::Module + +prefix_ void senf::ppi::module::Module::noroute(connector::Connector & connector) +{ + registerConnector(connector); + connector.setModule(*this); +} + +prefix_ boost::posix_time::ptime senf::ppi::module::Module::eventTime() +{ + return eventManager().eventTime(); +} + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::module::Module::Module() +{} + +//////////////////////////////////////// +// private members + +prefix_ senf::ppi::EventManager & senf::ppi::module::Module::eventManager() +{ + return EventManager::instance(); +} + +prefix_ void senf::ppi::module::Module::registerConnector(connector::Connector & connector) +{ + connectorRegistry_.push_back(&connector); + connector.setModule(*this); +} + +prefix_ senf::ppi::RouteBase & +senf::ppi::module::Module::addRoute(std::auto_ptr route) +{ + routes_.push_back(route.release()); + return routes_.back(); +} + +///////////////////////////////cci.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Module.ct b/PPI/Module.ct new file mode 100644 index 0000000..0fc3339 --- /dev/null +++ b/PPI/Module.ct @@ -0,0 +1,93 @@ +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Module non-inline template implementation */ + +#include "Module.ih" + +// Custom includes + +#define prefix_ +///////////////////////////////ct.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::Module + +template +prefix_ senf::ppi::Route & +senf::ppi::module::Module::route(Source & source, Target & target) +{ + detail::RouteHelper::route(*this, source, target, source, target); + return static_cast< Route & >( + addRoute(std::auto_ptr< RouteBase >( + new Route(*this, source, target)))); +} + +template +prefix_ void senf::ppi::module::Module::registerEvent(Target target, Descriptor & descriptor) +{ + eventManager().registerEvent( + *this, + EventManager::Callback::make(target,*this), + descriptor); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::detail namespace members + +template +prefix_ void senf::ppi::module::detail::RouteHelper:: +route(Module & module, Source & source, Target & target, + connector::InputConnector &, connector::OutputConnector &) +{ + module.registerConnector(source); + module.registerConnector(target); +} + +template +prefix_ void senf::ppi::module::detail::RouteHelper:: +route(Module & module, Source & source, Target & target, + connector::InputConnector &, EventDescriptor &) +{ + module.registerConnector(source); +} + +template +prefix_ void senf::ppi::module::detail::RouteHelper:: +route(Module & module, Source & source, Target & target, + EventDescriptor &, connector::OutputConnector &) +{ + module.registerConnector(target); +} + +///////////////////////////////ct.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Module.hh b/PPI/Module.hh index 30d52d9..1a3d22b 100644 --- a/PPI/Module.hh +++ b/PPI/Module.hh @@ -26,8 +26,11 @@ #define HH_Module_ 1 // Custom includes +#include #include #include +#include +#include "predecl.hh" //#include "Module.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -56,10 +59,9 @@ namespace module { { protected: Module(); - ~Module(); template - Route & route(Source const & source, Target const & target); + Route & route(Source & source, Target & target); ///< Define flow information /**< Using the route() and noroute() members, the information flow within the module is defined. Routing @@ -85,8 +87,7 @@ namespace module { outgoing data \returns Route instance describing this route */ - template - void noroute(Connector const & connector); ///< Define terminal connectors + void noroute(connector::Connector & connector); ///< Define terminal connectors /**< The noroute() member explicitly declares, that a connector is terminal and does not directly receive/forward data from/to some other @@ -98,7 +99,7 @@ namespace module { \param[in] connector Terminal connector to declare */ template - void registerEvent(Target target, Descriptor const & descriptor); + void registerEvent(Target target, Descriptor & descriptor); ///< Register an external event /**< The \a target argument may be either an arbitrary callable object or it may be a member function pointer @@ -109,6 +110,7 @@ namespace module { information on the event delivered. The \a descriptor describes the event to signal. This + may be a timer event or some type of I/O event on a file descriptor or socket. @@ -118,6 +120,21 @@ namespace module { boost::posix_time::ptime eventTime(); ///< Return timestamp of the currently processing ///< event + + private: + EventManager & eventManager(); + + void registerConnector(connector::Connector & connector); + RouteBase & addRoute(std::auto_ptr route); + + typedef std::vector ConnectorRegistry; + ConnectorRegistry connectorRegistry_; + + typedef boost::ptr_vector RouteInfoBase; + RouteInfoBase routes_; + + template + friend class detail::RouteHelper; }; /** \brief Connect compatible connectors @@ -131,8 +148,8 @@ namespace module { }}} ///////////////////////////////hh.e//////////////////////////////////////// -//#include "Module.cci" -//#include "Module.ct" +#include "Module.cci" +#include "Module.ct" //#include "Module.cti" #endif diff --git a/PPI/Module.ih b/PPI/Module.ih new file mode 100644 index 0000000..697fa7b --- /dev/null +++ b/PPI/Module.ih @@ -0,0 +1,68 @@ +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Module internal header */ + +#ifndef IH_Module_ +#define IH_Module_ 1 + +// Custom includes + +///////////////////////////////ih.p//////////////////////////////////////// + +namespace senf { +namespace ppi { +namespace module { +namespace detail { + + // Placing these into a class simplifies the friend declaration + template + struct RouteHelper + { + static void route(Module & module, Source & source, Target & target, + connector::InputConnector &, + connector::OutputConnector &); + + + static void route(Module & module, Source & source, Target & target, + connector::InputConnector &, + EventDescriptor &); + + static void route(Module & module, Source & source, Target & target, + EventDescriptor &, + connector::OutputConnector &); + }; + +}}}} + +///////////////////////////////ih.e//////////////////////////////////////// +#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/PPI/Module.test.cc b/PPI/Module.test.cc new file mode 100644 index 0000000..01434df --- /dev/null +++ b/PPI/Module.test.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Module.test unit tests */ + +//#include "Module.test.hh" +//#include "Module.test.ih" + +// Custom includes +#include "Module.hh" + +#include +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(module) +{} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Queueing.cc b/PPI/Queueing.cc new file mode 100644 index 0000000..c084f51 --- /dev/null +++ b/PPI/Queueing.cc @@ -0,0 +1,54 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Queueing non-inline non-template implementation */ + +#include "Queueing.hh" +//#include "Queueing.ih" + +// Custom includes + +//#include "Queueing.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::QueueingDiscipline + +prefix_ senf::ppi::QueueingDiscipline::~QueueingDiscipline() +{} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ +//#include "Queueing.mpp" + + +// 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/PPI/Queueing.hh b/PPI/Queueing.hh index 9e3acf8..7b7421e 100644 --- a/PPI/Queueing.hh +++ b/PPI/Queueing.hh @@ -25,6 +25,7 @@ #define HH_Queueing_ 1 // Custom includes +#include "predecl.hh" //#include "Queueing.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -46,10 +47,13 @@ namespace ppi { class QueueingDiscipline { public: + virtual ~QueueingDiscipline(); + enum Event { ENQUEUE, DEQUEUE }; ///< Possible queueing events enum State { THROTTLED, UNTHROTTLED }; ///< Possible queueing states - - State update(PassiveInput & input, Event event) = 0; ///< Calculate new queueing state + + virtual State update(connector::PassiveInput & input, Event event) = 0; + ///< Calculate new queueing state /**< Whenever the queue is manipulated, this member is called to calculate the new throttling state. diff --git a/PPI/Route.cci b/PPI/Route.cci new file mode 100644 index 0000000..100b09c --- /dev/null +++ b/PPI/Route.cci @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Route inline non-template implementation */ + +// Custom includes + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::RouteBase + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::RouteBase::RouteBase(module::Module & module) + : module_(&module) +{} + +///////////////////////////////cci.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Route.cti b/PPI/Route.cti new file mode 100644 index 0000000..3d0f465 --- /dev/null +++ b/PPI/Route.cti @@ -0,0 +1,94 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Route inline template implementation */ + +#include "Route.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::Route + +//////////////////////////////////////// +// protected members + +template +prefix_ senf::ppi::Route::Route(module::Module & module, Source & source, + Target & target) + : Implementation(module, source, target) +{} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::detail::RouteImplementation + +//////////////////////////////////////// +// protected members + +template +prefix_ senf::ppi::detail::RouteImplementation:: +RouteImplementation(module::Module & module, connector::InputConnector & source, + connector::OutputConnector & target) + : RouteBase(module), source_(&source), target_(&target) +{} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::detail::RouteImplementation + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::detail::RouteImplementation:: +RouteImplementation(module::Module & module, EventDescriptor & source, + connector::OutputConnector & target) + : RouteBase(module), source_(&source), target_(&target) +{} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::detail::RouteImplementation + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::detail::RouteImplementation:: +RouteImplementation(module::Module & module, connector::InputConnector & source, + EventDescriptor & target) +: RouteBase(module), source_(&source), target_(&target) +{} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Route.hh b/PPI/Route.hh index 79e478d..54c4139 100644 --- a/PPI/Route.hh +++ b/PPI/Route.hh @@ -25,6 +25,8 @@ #define HH_Route_ 1 // Custom includes +#include +#include "predecl.hh" //#include "Route.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -32,13 +34,7 @@ namespace senf { namespace ppi { - /** \brief Route descriptor - - Route instances are created by Module::route statements. The Route class provides an - interface to manipulate the flow processing. - */ - template - class Route + class RouteBase { public: void autoThrottling(bool state); ///< Change automatic throttle notification forwarding @@ -61,14 +57,47 @@ namespace ppi { specializations. However, this is an implementation detail which does not affect the exposed interface. */ + + protected: + RouteBase(module::Module & module); + + private: + module::Module * module_; + }; + +}} + +#include "Route.ih" + +namespace senf { +namespace ppi { + + /** \brief Route descriptor + + Route instances are created by Module::route statements. The Route class provides an + interface to manipulate the flow processing. + */ + template + class Route + : public detail::RouteImplementation< boost::is_base_of::value, + boost::is_base_of::value > + { + private: + typedef detail::RouteImplementation< + boost::is_base_of::value, + boost::is_base_of::value > Implementation; + + Route(module::Module & module, Source & source, Target & target); + + friend class module::Module; }; }} ///////////////////////////////hh.e//////////////////////////////////////// -//#include "Route.cci" +#include "Route.cci" //#include "Route.ct" -//#include "Route.cti" +#include "Route.cti" #endif diff --git a/PPI/Route.ih b/PPI/Route.ih new file mode 100644 index 0000000..b3de6ab --- /dev/null +++ b/PPI/Route.ih @@ -0,0 +1,93 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Route internal header */ + +#ifndef IH_Route_ +#define IH_Route_ 1 + +// Custom includes + +///////////////////////////////ih.p//////////////////////////////////////// + +namespace senf { +namespace ppi { +namespace detail { + + template + class RouteImplementation + : public RouteBase + { + protected: + RouteImplementation(module::Module & module, + connector::InputConnector & source, + connector::OutputConnector & target); + + private: + connector::InputConnector * source_; + connector::OutputConnector * target_; + }; + + template <> + class RouteImplementation + : public RouteBase + { + protected: + RouteImplementation(module::Module & module, + EventDescriptor & source, + connector::OutputConnector & target); + + private: + EventDescriptor * source_; + connector::OutputConnector * target_; + }; + + template<> + class RouteImplementation + : public RouteBase + { + protected: + RouteImplementation(module::Module & module, + connector::InputConnector & source, + EventDescriptor & target); + + private: + connector::InputConnector * source_; + EventDescriptor * target_; + }; + +}}} + +///////////////////////////////ih.e//////////////////////////////////////// +#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/PPI/Route.test.cc b/PPI/Route.test.cc new file mode 100644 index 0000000..2337e9e --- /dev/null +++ b/PPI/Route.test.cc @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Route.test unit tests */ + +//#include "Route.test.hh" +//#include "Route.test.ih" + +// Custom includes +#include "Route.hh" + +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(route) +{} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/SConscript b/PPI/SConscript index a1b65ae..199c62d 100644 --- a/PPI/SConscript +++ b/PPI/SConscript @@ -1,10 +1,20 @@ Import('env') -import SENFSCons +import SENFSCons, glob ########################################################################### +SConscript(glob.glob("*/SConscript")) + +sources = SENFSCons.GlobSources(subdirs=[ 'detail' ]) + SENFSCons.StandardTargets(env) +SENFSCons.Lib(env, + library = 'PPI', + sources = sources, + LIBS = [ 'Scheduler', 'Packets', 'Socket', 'Utils' ]) + SENFSCons.Doxygen(env, extra_sources=[ env.Dia2Png('scenario.dia'), + env.Dia2Png('classes.dia'), ]) diff --git a/PPI/Setup.cci b/PPI/Setup.cci new file mode 100644 index 0000000..f14f33b --- /dev/null +++ b/PPI/Setup.cci @@ -0,0 +1,62 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Setup inline non-template implementation */ + +// Custom includes +#include "Connectors.hh" +#include "Scheduler/Scheduler.hh" + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +prefix_ void senf::ppi::connect(connector::ActiveOutput & source, + connector::PassiveInput & target) +{ + source.connect(target); +} + +prefix_ void senf::ppi::connect(connector::PassiveOutput & source, + connector::ActiveInput & target) +{ + source.connect(target); +} + +prefix_ void senf::ppi::run() +{ + Scheduler::instance().process(); +} + +///////////////////////////////cci.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/Setup.hh b/PPI/Setup.hh new file mode 100644 index 0000000..5f0613a --- /dev/null +++ b/PPI/Setup.hh @@ -0,0 +1,60 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Setup public header */ + +#ifndef HH_Setup_ +#define HH_Setup_ 1 + +// Custom includes +#include "predecl.hh" + +//#include "Setup.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { +namespace ppi { + + void connect(connector::ActiveOutput & source, connector::PassiveInput & target); + void connect(connector::PassiveOutput & source, connector::ActiveInput & target); + + void run(); + +}} + +///////////////////////////////hh.e//////////////////////////////////////// +#include "Setup.cci" +//#include "Setup.ct" +//#include "Setup.cti" +#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/PPI/SocketReader.ct b/PPI/SocketReader.ct new file mode 100644 index 0000000..b56cf21 --- /dev/null +++ b/PPI/SocketReader.ct @@ -0,0 +1,76 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 SocketReader non-inline template implementation */ + +//#include "SocketReader.ih" + +// Custom includes + +#define prefix_ +///////////////////////////////ct.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::PacketReader + +template +prefix_ Packet senf::ppi::PacketReader::operator()(Handle handle) +{ + Packet packet (Packet::create(Packet::noinit)); + handle.read(packet.data(),0u); + return packet; +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::ActiveSocketReader + +template +prefix_ senf::ppi::module::ActiveSocketReader::ActiveSocketReader(Handle handle) + : handle_(handle), event_(handle_, IOEvent::Read), reader_() +{ + registerEvent( &ActiveSocketReader::read, event_ ); + route(event_, output); +} + +//////////////////////////////////////// +// private members + +template +prefix_ void senf::ppi::module::ActiveSocketReader::read() +{ + output(reader_(handle_)); +} + +///////////////////////////////ct.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/SocketReader.hh b/PPI/SocketReader.hh index 4d0c626..723daef 100644 --- a/PPI/SocketReader.hh +++ b/PPI/SocketReader.hh @@ -25,10 +25,14 @@ #define HH_SocketReader_ 1 // Custom includes -#include "Packets/Packet.hh" -#include "Packets/DataPacket.hh" +#include "Packets/Packets.hh" +#include "Socket/ClientSocketHandle.hh" +#include "Socket/SocketPolicy.hh" +#include "Socket/ReadWritePolicy.hh" +#include "Socket/FramingPolicy.hh" #include "Module.hh" -#include "Connector.hh" +#include "Connectors.hh" +#include "IOEvent.hh" //#include "SocketReader.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -49,10 +53,10 @@ namespace ppi { public: typedef senf::ClientSocketHandle< senf::MakeSocketPolicy< senf::ReadablePolicy, - senf::DatagramFramingPolicy > > Handle; + senf::DatagramFramingPolicy >::policy > Handle; ///< Handle type supported by this reader - Packet::ptr operator()(Handle handle); + Packet operator()(Handle handle); ///< Read packet from \a handle /**< Read a datagram from \a handle and interpret is as packet of type \c Packet. @@ -95,13 +99,20 @@ namespace module { /**< Data will be read from \a handle and be parsed by \a Reader. \param[in] handle Handle to read data from */ + + private: + void read(); + + Handle handle_; + IOEvent event_; + Reader reader_; }; }}} ///////////////////////////////hh.e//////////////////////////////////////// //#include "SocketReader.cci" -//#include "SocketReader.ct" +#include "SocketReader.ct" //#include "SocketReader.cti" #endif diff --git a/PPI/SocketReader.test.cc b/PPI/SocketReader.test.cc new file mode 100644 index 0000000..7738e6f --- /dev/null +++ b/PPI/SocketReader.test.cc @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 SocketReader.test unit tests */ + +//#include "SocketReader.test.hh" +//#include "SocketReader.test.ih" + +// Custom includes +#include "SocketReader.hh" + +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(socketReader) +{} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/SocketWriter.cci b/PPI/SocketWriter.cci new file mode 100644 index 0000000..3f157c2 --- /dev/null +++ b/PPI/SocketWriter.cci @@ -0,0 +1,51 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 SocketWriter inline non-template implementation */ + +// Custom includes + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::PacketWriter + +prefix_ void senf::ppi::PacketWriter::operator()(Handle handle, Packet packet) +{ + handle.write(packet.data()); +} + +///////////////////////////////cci.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/SocketWriter.ct b/PPI/SocketWriter.ct new file mode 100644 index 0000000..c2dc70f --- /dev/null +++ b/PPI/SocketWriter.ct @@ -0,0 +1,65 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 SocketWriter non-inline template implementation */ + +//#include "SocketWriter.ih" + +// Custom includes + +#define prefix_ +///////////////////////////////ct.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::PassiveSocketWriter + +template +prefix_ senf::ppi::module::PassiveSocketWriter::PassiveSocketWriter(Handle handle) + : handle_(handle), writer_() +{ + noroute(input); + input.onRequest(&PassiveSocketWriter::write); +} + +//////////////////////////////////////// +// private members + +template +prefix_ void senf::ppi::module::PassiveSocketWriter::write() +{ + writer_(handle_,input()); +} + +///////////////////////////////ct.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/SocketWriter.hh b/PPI/SocketWriter.hh index 7e13438..f2f8611 100644 --- a/PPI/SocketWriter.hh +++ b/PPI/SocketWriter.hh @@ -25,9 +25,14 @@ #define HH_SocketWriter_ 1 // Custom includes -#include "Packets/Packet.hh" +#include "Packets/Packets.hh" +#include "Socket/ClientSocketHandle.hh" +#include "Socket/SocketPolicy.hh" +#include "Socket/ReadWritePolicy.hh" +#include "Socket/FramingPolicy.hh" +#include "Socket/CommunicationPolicy.hh" #include "Module.hh" -#include "Connector.hh" +#include "Connectors.hh" //#include "SocketWriter.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -44,10 +49,11 @@ namespace ppi { public: typedef senf::ClientSocketHandle< senf::MakeSocketPolicy< senf::WriteablePolicy, - senf::DatagramFramingPolicy > > Handle; + senf::DatagramFramingPolicy, + senf::ConnectedCommunicationPolicy>::policy > Handle; ///< Handle type supported by this writer - void operator()(Handle handle, Packet::ptr packet); + void operator()(Handle handle, Packet packet); ///< Write \a packet to \a handle /**< Write the complete \a packet as a datagram to \a handle. @@ -74,7 +80,7 @@ namespace module { public: typedef unspecified Handle; // type of handle requested SomeWriter(); // default constructible - void operator()(Handle handle, Packet::ptr packet); // insertion function + void operator()(Handle handle, Packet packet); // insertion function }; \endcode */ @@ -82,7 +88,7 @@ namespace module { class ActiveSocketWriter : public Module { public: - typedef typename Writer:Handle Handle; ///< Handle type requested by writer + typedef typename Writer::Handle Handle; ///< Handle type requested by writer connector::ActiveInput input; ///< Input connector from which data is received @@ -106,7 +112,7 @@ namespace module { public: typedef unspecified Handle; // type of handle requested SomeWriter(); // default constructible - void operator()(Handle handle, Packet::ptr packet); // insertion function + void operator()(Handle handle, Packet packet); // insertion function }; \endcode */ @@ -114,21 +120,27 @@ namespace module { class PassiveSocketWriter : public Module { public: - typedef typename Writer:Handle Handle; ///< Handle type requested by writer + typedef typename Writer::Handle Handle; ///< Handle type requested by writer connector::PassiveInput input; ///< Input connector from which data is received - ActiveSocketWriter(Handle handle); ///< Create new writer for the given handle + PassiveSocketWriter(Handle handle); ///< Create new writer for the given handle /**< Data will be written to \a handle using \a Writer. \param[in] handle Handle to write data to */ + + private: + void write(); + + Handle handle_; + Writer writer_; }; }}} ///////////////////////////////hh.e//////////////////////////////////////// -//#include "SocketWriter.cci" -//#include "SocketWriter.ct" +#include "SocketWriter.cci" +#include "SocketWriter.ct" //#include "SocketWriter.cti" #endif diff --git a/PPI/SocketWriter.test.cc b/PPI/SocketWriter.test.cc new file mode 100644 index 0000000..a6f6055 --- /dev/null +++ b/PPI/SocketWriter.test.cc @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 SocketWriter.test unit tests */ + +//#include "SocketWriter.test.hh" +//#include "SocketWriter.test.ih" + +// Custom includes +#include "SocketWriter.hh" + +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(socketWriter) +{} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/classes.dia b/PPI/classes.dia new file mode 100644 index 0000000..379f5fa Binary files /dev/null and b/PPI/classes.dia differ diff --git a/PPI/detail/Callback.cti b/PPI/detail/Callback.cti new file mode 100644 index 0000000..0dd4ea2 --- /dev/null +++ b/PPI/detail/Callback.cti @@ -0,0 +1,98 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Callback inline template implementation */ + +//#include "Callback.ih" + +// Custom includes +#include + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::detail::Callback + +template +template +prefix_ typename senf::ppi::detail::Callback::type +senf::ppi::detail::Callback::make(void (FnClass::* memfn )(), Owner & owner) +{ + return boost::bind(memfn,static_cast(&owner)); +} + +template +template +prefix_ typename senf::ppi::detail::Callback::type +senf::ppi::detail::Callback::make(void (FnClass::* memfn )(FnArg arg), Owner & owner) +{ + return boost::bind(memfn,static_cast(&owner),1); +} + +template +template +prefix_ typename senf::ppi::detail::Callback::type +senf::ppi::detail::Callback::make(type callable, Owner &) +{ + return callable; +} + +template +template +prefix_ typename senf::ppi::detail::Callback::type +senf::ppi::detail::Callback::make(boost::function callable, Owner &) +{ + return boost::bind(callable); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::detail::Callback + +template +prefix_ typename senf::ppi::detail::Callback::type +senf::ppi::detail::Callback::make(void (FnClass::* memfn )(), Owner & owner) +{ + return boost::bind(memfn,static_cast(&owner)); +} + +template +prefix_ typename senf::ppi::detail::Callback::type +senf::ppi::detail::Callback::make(type callable, Owner &) +{ + return callable; +} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/detail/Callback.hh b/PPI/detail/Callback.hh new file mode 100644 index 0000000..768cb98 --- /dev/null +++ b/PPI/detail/Callback.hh @@ -0,0 +1,96 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 Callback public header */ + +#ifndef HH_Callback_ +#define HH_Callback_ 1 + +// Custom includes +#include + +//#include "Callback.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { +namespace ppi { +namespace detail { + + /** \brief Provide callbacks with a single optional argument + + This helper implements callbacks with an optional single argument. In addition to + boost::function, this helper provides the following functionality: + + \li It allows the callback to ignore the argument: A callable with no argument may be used + as callback. + \li It allows to use member function pointers as callbacks. These will be automatically + bound to the \a owner argument of \ref make(). + + The callbacks follow the same restrictions as Boost.Function: They must be + either function, member function pointers or callable objects defining the appropriate + typedef members. + */ + template + struct Callback + { + typedef boost::function type; + + template + static type make(void (FnClass::* memfn )(), Owner & owner); + template + static type make(void (FnClass::* memfn )(FnArg arg), Owner & owner); + template + static type make(type callable, Owner &); + template + static type make(boost::function callable, Owner &); + }; + + template <> + struct Callback + { + typedef boost::function type; + + template + static type make(void (FnClass::* memfn )(), Owner & owner); + template + static type make(type callable, Owner &); + }; + +}}} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "Callback.cci" +//#include "Callback.ct" +#include "Callback.cti" +#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/PPI/detail/EventBinding.cc b/PPI/detail/EventBinding.cc new file mode 100644 index 0000000..5a359ad --- /dev/null +++ b/PPI/detail/EventBinding.cc @@ -0,0 +1,55 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 EventBinding non-inline non-template implementation */ + +#include "EventBinding.hh" +//#include "EventBinding.ih" + +// Custom includes +#include "../EventManager.hh" + +//#include "EventBinding.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +prefix_ void senf::ppi::detail::EventBindingBase::eventTime(boost::posix_time::ptime time) +{ + // It's hard to make this inline because of a circular header dependency ... + manager_->eventTime(time); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ +//#include "EventBinding.mpp" + + +// 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/PPI/detail/EventBinding.cci b/PPI/detail/EventBinding.cci new file mode 100644 index 0000000..ad4e89e --- /dev/null +++ b/PPI/detail/EventBinding.cci @@ -0,0 +1,55 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 EventBinding inline non-template implementation */ + +// Custom includes + +#define prefix_ inline +///////////////////////////////cci.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::detail::EventBindingBase + +//////////////////////////////////////// +// protected members + +prefix_ senf::ppi::detail::EventBindingBase::EventBindingBase(EventManager & manager, + module::Module & module, + EventDescriptor & descriptor) + : manager_(&manager), module_(&module), descriptor_(&descriptor) +{} + +///////////////////////////////cci.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/detail/EventBinding.cti b/PPI/detail/EventBinding.cti new file mode 100644 index 0000000..aeb0555 --- /dev/null +++ b/PPI/detail/EventBinding.cti @@ -0,0 +1,70 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 EventBinding inline template implementation */ + +//#include "EventBinding.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::detail::EventBinding + +template +prefix_ senf::ppi::detail::EventBinding::EventBinding(EventManager & manager, + module::Module & module, + Callback callback, + EventDescriptor & descriptor) + : EventBindingBase(manager, module, descriptor), callback_(callback) +{} + +template +prefix_ void senf::ppi::detail::EventBinding::callback(EventArg event, + boost::posix_time::ptime time) +{ + eventTime(time); + callback_(event); +} + +template +prefix_ void senf::ppi::detail::EventBinding::callback(EventArg event) +{ + callback(event, boost::posix_time::microsec_clock::universal_time()); +} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// 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/PPI/detail/EventBinding.hh b/PPI/detail/EventBinding.hh new file mode 100644 index 0000000..10959d7 --- /dev/null +++ b/PPI/detail/EventBinding.hh @@ -0,0 +1,91 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 EventBinding public header */ + +#ifndef HH_EventBinding_ +#define HH_EventBinding_ 1 + +// Custom includes +#include +#include "../predecl.hh" +#include "Callback.hh" + +//#include "EventBinding.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { +namespace ppi { +namespace detail { + + class EventBindingBase + { + protected: + EventBindingBase(EventManager & manager, module::Module & module, + EventDescriptor & descriptor); + + void eventTime(boost::posix_time::ptime time); + + private: + EventManager * manager_; + module::Module * module_; + EventDescriptor * descriptor_; + }; + + template + class EventBinding + : public EventBindingBase + { + public: + typedef EventType Event; + typedef typename detail::EventArgType::type EventArg; + typedef typename detail::Callback::type Callback; + + EventBinding(EventManager & manager, module::Module & module, Callback callback, + EventDescriptor & descriptor); + + void callback(EventArg event, boost::posix_time::ptime time); + void callback(EventArg event); + + private: + Callback callback_; + }; + +}}} + +///////////////////////////////hh.e//////////////////////////////////////// +#include "EventBinding.cci" +//#include "EventBinding.ct" +#include "EventBinding.cti" +#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/PPI/main.test.cc b/PPI/main.test.cc new file mode 100644 index 0000000..91e601d --- /dev/null +++ b/PPI/main.test.cc @@ -0,0 +1,49 @@ +// $Id: main.test.cc 296 2007-07-10 20:39:34Z g0dil $ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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. + +// Definition of non-inline non-template functions + +//#include "test.hh" +//#include "test.ih" + +// Custom includes +#define BOOST_AUTO_TEST_MAIN +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// 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: diff --git a/PPI/ppitest/SConscript b/PPI/ppitest/SConscript new file mode 100644 index 0000000..d204c90 --- /dev/null +++ b/PPI/ppitest/SConscript @@ -0,0 +1,7 @@ +Import('env') +import SENFSCons + +########################################################################### + +SENFSCons.Binary( env, 'ppitest', SENFSCons.GlobSources(), + LIBS = [ 'PPI', 'Scheduler', 'Packets', 'Socket', 'Utils' ] ); diff --git a/PPI/ppitest/ppitest.cc b/PPI/ppitest/ppitest.cc new file mode 100644 index 0000000..205db94 --- /dev/null +++ b/PPI/ppitest/ppitest.cc @@ -0,0 +1,71 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 ppitest non-inline non-template implementation */ + +//#include "ppitest.hh" +//#include "ppitest.ih" + +// Custom includes +#include "Socket/Protocols/INet/UDPSocketHandle.hh" +#include "Socket/Protocols/INet/ConnectedUDPSocketHandle.hh" +#include "PPI/SocketReader.hh" +#include "PPI/SocketWriter.hh" +#include "PPI/Setup.hh" + +//#include "ppitest.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +int main(int argc, char * argv[]) +{ + namespace module = senf::ppi::module; + namespace ppi = senf::ppi; + + senf::UDPv4ClientSocketHandle inputSocket; + module::ActiveSocketReader<> udpReader (inputSocket); + + senf::ConnectedUDPv4ClientSocketHandle outputSocket; + module::PassiveSocketWriter<> udpWriter (outputSocket); + + ppi::connect(udpReader.output, udpWriter.input); + + ppi::run(); + + return 0; +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ +//#include "ppitest.mpp" + + +// 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" +// End: diff --git a/PPI/predecl.hh b/PPI/predecl.hh new file mode 100644 index 0000000..92dd000 --- /dev/null +++ b/PPI/predecl.hh @@ -0,0 +1,88 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 predecl public header */ + +#ifndef HH_predecl_ +#define HH_predecl_ 1 + +// Custom includes +#include + +//#include "predecl.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { +namespace ppi { + + class EventDescriptor; + template class EventImplementation; + class EventManager; + class RouteBase; + template class Route; + class QueueingDiscipline; + + namespace detail { + class EventBindingBase; + template class EventBinding; + template struct EventArgType; + template class RouteImplementation; + } + + namespace module { + class Module; + namespace detail { + template class RouteHelper; + } + } + + namespace connector { + class Connector; + class ActiveConnector; + class PassiveConnector; + class InputConnector; + class OutputConnector; + class ActiveInput; + class ActiveOutput; + class PassiveInput; + class PassiveOutput; + } + +}} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "predecl.cci" +//#include "predecl.ct" +//#include "predecl.cti" +#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/.dir.el b/Packets/.dir.el index 77d54f9..16ab6cc 100644 --- a/Packets/.dir.el +++ b/Packets/.dir.el @@ -1 +1 @@ -(set (make-local-variable 'ccide-all-includes-guard) "SENF_PACKETS_DECL_ONLY") +(set (make-local-variable 'ccide-all-includes) "Packets.hh") diff --git a/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc b/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc new file mode 100644 index 0000000..a356068 --- /dev/null +++ b/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc @@ -0,0 +1,106 @@ +// $Id: ConnectedUDPSocketHandle.cc 357 2007-07-26 22:48:39Z g0dil $ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 ConnectedUDPv4SocketHandle and ConnectedUDPv6SocketHandle non-inline non-template implementation + */ + +#include "ConnectedUDPSocketHandle.hh" +//#include "ConnectedUDPSocketHandle.ih" + +// Custom includes +#include +#include +#include + +#include "Utils/Exception.hh" + +//#include "ConnectedUDPSocketHandle.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ConnectedUDPv4SocketProtocol + +prefix_ void senf::ConnectedUDPv4SocketProtocol::init_client() + const +{ + int sock = ::socket(PF_INET,SOCK_DGRAM,0); + if (sock < 0) + throw SystemException(errno); + body().fd(sock); +} + +prefix_ void +senf::ConnectedUDPv4SocketProtocol::init_client(INet4SocketAddress const & address) + const +{ + init_client(); + connect(address); +} + +prefix_ std::auto_ptr senf::ConnectedUDPv4SocketProtocol::clone() + const +{ + return std::auto_ptr(new ConnectedUDPv4SocketProtocol()); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::ConnectedUDPv6SocketProtocol:: + +prefix_ void senf::ConnectedUDPv6SocketProtocol::init_client() + const +{ + int sock = ::socket(PF_INET6,SOCK_DGRAM,0); + if (sock < 0) + throw SystemException(errno); + body().fd(sock); +} + +prefix_ void +senf::ConnectedUDPv6SocketProtocol::init_client(INet6SocketAddress const & address) + const +{ + init_client(); + connect(address); +} + +prefix_ std::auto_ptr senf::ConnectedUDPv6SocketProtocol::clone() + const +{ + return std::auto_ptr(new ConnectedUDPv6SocketProtocol()); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ +//#include "ConnectedUDPSocketHandle.mpp" + + +// 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: diff --git a/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh b/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh new file mode 100644 index 0000000..c3d1ed0 --- /dev/null +++ b/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh @@ -0,0 +1,206 @@ +// $Id: ConnectedUDPSocketHandle.hh 357 2007-07-26 22:48:39Z g0dil $ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 UDPv4SocketHandle and UDPv6SocketHandle public header + + \todo Implement possibly non-blocking connect and SO_ERROR in the + protocol interface + */ + +#ifndef HH_ConnectedUDPSocketHandle_ +#define HH_ConnectedUDPSocketHandle_ 1 + +// Custom includes +#include "INetProtocol.hh" +#include "UDPProtocol.hh" +#include "Socket/Protocols/BSDSocketProtocol.hh" +#include "Socket/FramingPolicy.hh" +#include "Socket/CommunicationPolicy.hh" +#include "Socket/ReadWritePolicy.hh" +#include "Socket/BufferingPolicy.hh" +#include "Socket/ProtocolClientSocketHandle.hh" + +//#include "ConnectedUDPSocketHandle.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { + + /// \addtogroup concrete_protocol_group + /// @{ + + typedef MakeSocketPolicy< + INet4AddressingPolicy, + DatagramFramingPolicy, + ConnectedCommunicationPolicy, + ReadablePolicy, + WriteablePolicy, + SocketBufferingPolicy + >::policy ConnectedUDPv4Socket_Policy; ///< Socket Policy of the UDPv4 Protocol + + /** \brief IPv4 UDP Socket Protocol, connected + + \par Socket Handle typedefs: + \ref ConnectedUDPv4ClientSocketHandle (ProtocolClientSocketHandle) + + \par Policy Interface: + ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(), + ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(), + ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf() + + \par Address Type: + INet4Address + + ConnectedUDPv4SocketProtocol provides an internet protocol stream socket based on the UDP + protocol and IPv4 addressing. + + This class is utilized as the protocol class of the ProtocolClientSocketHandle + via the Socket Handle typedefs above. + + \see ConnectedUDPv6SocketProtocol + */ + class ConnectedUDPv4SocketProtocol + : public ConcreteSocketProtocol, + public IPv4Protocol, + public UDPProtocol, + public BSDSocketProtocol, + public AddressableBSDSocketProtocol, + public senf::pool_alloc_mixin + { + public: + /////////////////////////////////////////////////////////////////////////// + // internal interface + + ///\name Constructors + ///@{ + + void init_client() const; ///< Create unconnected client socket + /**< \note This member is implicitly called from the + ProtocolClientSocketHandle::ProtocolClientSocketHandle() + constructor */ + void init_client(INet4SocketAddress const & address) const; + ///< Create client socket and connect + /**< Creates a new client socket and connects to the given + address. + + \param[in] address remote address to connect to */ + /**< \note This member is implicitly called from the + ProtocolClientSocketHandle::ProtocolClientSocketHandle() + constructor */ + + ///@} + ///\name Abstract Interface Implementation + + std::auto_ptr clone() const; + + ///@} + }; + + typedef ProtocolClientSocketHandle< + ConnectedUDPv4SocketProtocol> ConnectedUDPv4ClientSocketHandle; + + typedef MakeSocketPolicy< + ConnectedUDPv4Socket_Policy, + INet6AddressingPolicy + >::policy ConnectedUDPv6Socket_Policy; + + /** \brief IPv6 UDP Socket Protocol, connected + + \par Socket Handle typedefs: + \ref ConnectedUDPv6ClientSocketHandle (ProtocolClientSocketHandle) + + \par Policy Interface: + ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(), + ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(), + ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf() + + \par Address Type: + INet6Address + + ConnectedUDPv6SocketProtocol provides an internet protocol stream socket based on the UDP + protocol and IPv6 addressing. + + This class is utilized as the protocol class of the ProtocolClientSocketHandle + via the Socket Handle typedefs above. + + \see ConnectedUDPv4SocketProtocol + */ + class ConnectedUDPv6SocketProtocol + : public ConcreteSocketProtocol, + public IPv6Protocol, + public UDPProtocol, + public BSDSocketProtocol, + public AddressableBSDSocketProtocol, + public senf::pool_alloc_mixin + { + public: + /////////////////////////////////////////////////////////////////////////// + // internal interface + + ///\name Constructors + ///@{ + + void init_client() const; ///< Create unconnected client socket + /**< \note This member is implicitly called from the + ProtocolClientSocketHandle::ProtocolClientSocketHandle() + constructor */ + void init_client(INet6SocketAddress const & address) const; + ///< Create client socket and connect + /**< Creates a new client socket and connects to the given + address. + + \param[in] address remote address to connect to */ + /**< \note This member is implicitly called from the + ProtocolClientSocketHandle::ProtocolClientSocketHandle() + constructor */ + + ///@} + ///\name Abstract Interface Implementation + + std::auto_ptr clone() const; + + ///@} + }; + + typedef ProtocolClientSocketHandle< + ConnectedUDPv6SocketProtocol> ConnectedUDPv6ClientSocketHandle; + + /// @} + +} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "ConnectedUDPSocketHandle.cci" +//#include "ConnectedUDPSocketHandle.ct" +//#include "ConnectedUDPSocketHandle.cti" +#endif + + +// 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: diff --git a/Socket/Protocols/INet/INet6Address.cci b/Socket/Protocols/INet/INet6Address.cci index 5c09acc..d149f4a 100644 --- a/Socket/Protocols/INet/INet6Address.cci +++ b/Socket/Protocols/INet/INet6Address.cci @@ -284,7 +284,6 @@ prefix_ senf::INet6Network senf::INet6Network::subnet(boost::uint64_t net, unsig { using boost::lambda::_1; using boost::lambda::_2; - using boost::lambda::_3; using boost::lambda::var; using boost::lambda::ret; INet6Address addr (address()); diff --git a/Socket/Protocols/INet/INet6Address.ct b/Socket/Protocols/INet/INet6Address.ct index fa63745..1ee2a02 100644 --- a/Socket/Protocols/INet/INet6Address.ct +++ b/Socket/Protocols/INet/INet6Address.ct @@ -51,17 +51,12 @@ template prefix_ void senf::detail::apply_mask(unsigned bits, ForwardIterator b, ForwardIterator e, Function fn) { - for(; b != e; ++b) { - boost::uint8_t mask (0); - if (bits > 8) { - mask = 0xFFu; - bits -= 8; - } else if (bits > 0) { - mask = ~ low_bits_mask(8-bits); - bits = 0; - } - fn(*b,mask); - } + for(; bits>8 && b != e; bits -= 8, ++b) + fn(*b, boost::lambda::make_const(0xFFu)); + if (bits > 0 && b != e) + fn( *(b++), boost::lambda::make_const(~ low_bits_mask(8-bits))); + for(; b != e; ++b) + fn(*b, boost::lambda::make_const(0u)); } template @@ -69,18 +64,15 @@ prefix_ ForwardIterator1 senf::detail::find_if_mask(unsigned bits, ForwardIterat ForwardIterator1 e1, ForwardIterator2 b2, Function fn) { - for(; b1 != e1; ++b1, ++b2) { - boost::uint8_t mask (0); - if (bits > 8) { - mask = 0xFFu; - bits -= 8; - } else if (bits > 0) { - mask = ~ low_bits_mask(8-bits); - bits = 0; - } - if (fn(*b1,*b2,mask)) + for(; bits>8 && b1 != e1; bits -= 8, ++b1, ++b2) + if (fn(*b1, *b2, boost::lambda::make_const(0xFFu))) + return b1; + if (bits > 0 && b1 != e1) + if (fn( *(b1++), *(b2++), boost::lambda::make_const(~ low_bits_mask(8-bits)))) + return b1; + for(; b1 != e1; ++b1, ++b2) + if (fn(*b1, *b2, boost::lambda::make_const(0u))) return b1; - } return e1; } diff --git a/Socket/Protocols/INet/UDPSocketHandle.hh b/Socket/Protocols/INet/UDPSocketHandle.hh index 35003e7..ae1df0f 100644 --- a/Socket/Protocols/INet/UDPSocketHandle.hh +++ b/Socket/Protocols/INet/UDPSocketHandle.hh @@ -60,15 +60,15 @@ namespace senf { /** \brief IPv4 UDP Socket Protocol \par Socket Handle typedefs: - \ref UDPv4ClientSocketHandle (ProtocolClientSocketHandle) + \ref UDPv4ClientSocketHandle (ProtocolClientSocketHandle) \par Policy Interface: - ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(), - ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(), - ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf() + ClientSocketHandle::read(), ClientSocketHandle::readfrom(), + ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local(), + ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf() \par Address Type: - INet4Address + INet4Address UDPv4SocketProtocol provides an internet protocol stream socket based on the UDP protocol and IPv4 addressing. @@ -127,13 +127,13 @@ namespace senf { \par Socket Handle typedefs: \ref UDPv6ClientSocketHandle (ProtocolClientSocketHandle) - \par Policy Interface: - ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(), - ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(), - ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf() + \par Policy Interface: + ClientSocketHandle::read(), ClientSocketHandle::readfrom(), + ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local(), + ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf() \par Address Type: - INet6Address + INet6Address UDPv6SocketProtocol provides an internet protocol stream socket based on the UDP protocol and IPv6 addressing. diff --git a/Socket/SConscript b/Socket/SConscript index 41dd658..aef098c 100644 --- a/Socket/SConscript +++ b/Socket/SConscript @@ -24,10 +24,8 @@ SENFSCons.Lib(env, SENFSCons.Doxygen(env, extra_sources = [ env.Dia2Png('SocketLibrary-classes.dia'), env.Dia2Png('FhHierarchy.dia'), - env.Command('doc/html/SocketPolicy.png', env.Dia2Png('SocketPolicy.dia'), - Copy('$TARGET','$SOURCE')), - env.Command('doc/html/Protocols.png', env.Dia2Png('Protocols.dia'), - Copy('$TARGET','$SOURCE')), + env.Dia2Png('SocketPolicy.dia'), + env.Dia2Png('Protocols.dia'), env.Dia2Png('Handle.dia'), ]) diff --git a/Utils/hexdump.ct b/Utils/hexdump.ct index 40aa12d..76b95e6 100644 --- a/Utils/hexdump.ct +++ b/Utils/hexdump.ct @@ -26,6 +26,7 @@ //#include "hexdump.ih" // Custom includes +#include #include //#include "hexdump.mpp" @@ -33,8 +34,10 @@ ///////////////////////////////cc.p//////////////////////////////////////// template -prefix_ void senf::hexdump(Iterator i, Iterator const & i_end, std::ostream& stream, unsigned block_size=16) +prefix_ void senf::hexdump(Iterator i, Iterator i_end, std::ostream & stream, + unsigned block_size) { + boost::io::ios_all_saver ias (stream); unsigned offset (0); std::string ascii; for (; i != i_end; ++i, ++offset) { @@ -44,14 +47,14 @@ prefix_ void senf::hexdump(Iterator i, Iterator const & i_end, std::ostream& str ascii = ""; } stream << " " - << std::hex << std::setw(4) << std::setfill('0') - << offset << ' '; + << std::hex << std::setw(4) << std::setfill('0') + << offset << ' '; } else if ((offset % block_size) == block_size/2) { stream << " "; ascii += ' '; } stream << ' ' << std::hex << std::setw(2) << std::setfill('0') - << unsigned(*i); + << unsigned(*i); ascii += (*i >= ' ' && *i < 126) ? *i : '.'; } if (!ascii.empty()) { @@ -62,7 +65,6 @@ prefix_ void senf::hexdump(Iterator i, Iterator const & i_end, std::ostream& str } stream << " " << ascii << "\n"; } - stream << std::dec; } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Utils/hexdump.hh b/Utils/hexdump.hh index 9001097..dc6b3f4 100644 --- a/Utils/hexdump.hh +++ b/Utils/hexdump.hh @@ -37,7 +37,7 @@ namespace senf { /** \brief write the contents from Iterator i to i_end to the output stream in hexadecimal format. */ template - void hexdump(Iterator i, Iterator const & i_end, std::ostream& stream, unsigned block_size=16); + void hexdump(Iterator i, Iterator i_end, std::ostream & stream, unsigned block_size=16); } ///////////////////////////////hh.e//////////////////////////////////////// diff --git a/senfscons/CopyToDir.py b/senfscons/CopyToDir.py new file mode 100644 index 0000000..7f001ef --- /dev/null +++ b/senfscons/CopyToDir.py @@ -0,0 +1,23 @@ +## \file +# \brief CopyToDir builder + +## \package senfscons.CopyToDir +# \brief Copy source file(s) to a given directory +# +# \ingroup builder + +import os.path +import SCons.Builder, SCons.Defaults + +def emitter(source, target, env): + return ([ os.path.join(str(target[0]),source[0].name) ], source) + +CopyToDir = SCons.Builder.Builder(emitter = emitter, + action = SCons.Defaults.Copy("$TARGET","$SOURCE"), + single_source = True) + +def generate(env): + env['BUILDERS']['CopyToDir'] = CopyToDir + +def exists(env): + return 1 diff --git a/senfscons/SENFSCons.py b/senfscons/SENFSCons.py index f111a7f..c281919 100644 --- a/senfscons/SENFSCons.py +++ b/senfscons/SENFSCons.py @@ -49,6 +49,7 @@ import SCons.Defaults, SCons.Action SCONS_TOOLS = [ "Doxygen", "Dia2Png", + "CopyToDir", ] opts = None @@ -245,9 +246,13 @@ def MakeEnvironment(): # in the current directory. The sources will be returned as a tuple of # sources, test-sources. The target helpers all accept such a tuple as # their source argument. -def GlobSources(exclude=[]): +def GlobSources(exclude=[], subdirs=[]): testSources = glob.glob("*.test.cc") sources = [ x for x in glob.glob("*.cc") if x not in testSources and x not in exclude ] + for subdir in subdirs: + testSources += glob.glob(os.path.join(subdir,"*.test.cc")) + sources += [ x for x in glob.glob(os.path.join(subdir,"*.cc")) + if x not in testSources and x not in exclude ] return (sources, testSources) ## \brief Add generic standard targets for every module @@ -427,7 +432,19 @@ def Doxygen(env, doxyfile = "Doxyfile", extra_sources = []): xrefs.extend(xref_pp) docs.extend(xrefs) - env.Depends(docs, extra_sources) + if extra_sources and htmlnode: + env.Depends(docs, + [ env.CopyToDir( source=source, target=htmlnode.dir ) + for source in extra_sources ]) + + if extra_sources and xmlnode: + env.Depends(docs, + [ env.CopyToDir( source=source, target=xmlnode.dir ) + for source in extra_sources ]) + + if not htmlnode and not xmlnode: + env.Depends(docs, extra_sources) + for doc in docs : env.Alias('all_docs', doc) env.Clean('all_docs', doc)