PPI: Clean up time interface
[senf.git] / PPI / Module.hh
index aefe9a1..24fdf0c 100644 (file)
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 /** \file
-    \brief Module public header */
+    \brief Module public header 
+*/
 
 #ifndef HH_Module_
 #define HH_Module_ 1
 
 // Custom includes
+#include <vector>
 #include <boost/utility.hpp>
+#include <boost/ptr_container/ptr_vector.hpp>
+#include "Scheduler/ClockService.hh"
+#include "predecl.hh"
 
 //#include "Module.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
 
 namespace senf {
 namespace ppi {
+namespace module {
 
     /** \brief Module baseclass
 
@@ -39,7 +45,7 @@ namespace ppi {
         with interfaces to several PPI facilities:
         
         \li Connector management
-        \li Flow management
+        \li Flow management (routing)
         \li Event handling
 
         To provide internal bookkeeping, most access to the PPI infrastructure is managed through
@@ -51,12 +57,15 @@ namespace ppi {
     class Module
         : boost::noncopyable
     {
+    public:
+        virtual ~Module();
+
     protected:
         Module();
-        ~Module();
 
         template <class Source, class Target>
-        Route route(Source const & source, Target const & target); ///< Define flow information
+        Route<Source, Target> & route(Source & source, Target & target); 
+                                        ///< Define flow information
                                         /**< Using the route() and noroute() members, the
                                              information flow within the module is defined. Routing
                                              may be specified either between inputs, outputs and
@@ -74,30 +83,26 @@ namespace ppi {
 
                                              The return value may be used to alter routing
                                              parameters like throttling parameters.
-
-                                             \param[in] source Data source, object which controlls
+                                             
+                                             \param[in] source Data source, object which controls
                                                  incoming data
-                                             \param[in] target Data target, object which controlls
+                                             \param[in] target Data target, object which controls
                                                  outgoing data
                                              \returns Route instance describing this route */
 
-        template <class Connector>
-        void noroute(Connector const & 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
-                                            connector. <em>It is mandatory to define routing
-                                            information for terminal connectors</em>.
-
-                                            See the route() documentation for more on routing
+        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
+                                             connector. <em>It is mandatory to define routing
+                                             information for terminal connectors</em>.
 
-                                            \param[in] connector Terminal connector to declare */
+                                             See the route() documentation for more on routing
+                                             
+                                             \param[in] connector Terminal connector to declare */
 
         template <class Target, class Descriptor>
-        typename Descriptor::EventBinding const 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
@@ -108,27 +113,56 @@ namespace ppi {
                                              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.
 
-                                             The return value may be used to modify the
-                                             binding. This allows to temporarily inhibit event
-                                             delivery or to remove the binding explicitly. Depending
-                                             on the type of event, other operations may be
-                                             possible. See the event descriptor documentation.
-            
-                                            \param[in] target The handler to call whenever the event
-                                                is signaled
-                                            \param[in] descriptor The type of event to register
-                                            \returns An event binding instance of the appropriate
-                                                type. */
+                                             \param[in] target The handler to call whenever the
+                                                 event is signaled
+                                             \param[in] descriptor The type of event to register */
+
+        ClockService::clock_type time() const; ///< Return timestamp of the currently processing
+                                        ///< event
+
+        ClockService::clock_type now() const;
+
+        void destroy();
+
+#ifndef DOXYGEN
+        virtual void macro_SENF_PPI_MODULE_missing() = 0;
+#endif
+
+    private:
+        virtual void init();
+
+        EventManager & eventManager() const;
+        ModuleManager & moduleManager() const;
+        
+        void registerConnector(connector::Connector & connector);
+        RouteBase & addRoute(std::auto_ptr<RouteBase> route);
+
+        typedef std::vector<connector::Connector *> ConnectorRegistry;
+        ConnectorRegistry connectorRegistry_;
+
+        typedef boost::ptr_vector<RouteBase> RouteInfoBase;
+        RouteInfoBase routes_;
+
+        template <class Source, class Target>
+        friend class detail::RouteHelper;
+        friend class senf::ppi::ModuleManager;
     };
 
-}}
+#   define SENF_PPI_MODULE(name)                                                                  \
+    public:                                                                                       \
+        ~ name() { destroy(); }                                                                   \
+        void macro_SENF_PPI_MODULE_missing() {}                                                   \
+    private:
+
+}}}
 
 ///////////////////////////////hh.e////////////////////////////////////////
-//#include "Module.cci"
-//#include "Module.ct"
+#include "Module.cci"
+#include "Module.ct"
 //#include "Module.cti"
 #endif
 
@@ -139,4 +173,6 @@ namespace ppi {
 // c-file-style: "senf"
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
 // End: