LCOV - code coverage report
Current view: top level - co - dispatcher.h (source / functions) Hit Total Coverage
Test: Collage Lines: 3 3 100.0 %
Date: 2015-11-03 13:48:53 Functions: 14 14 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2006-2014, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                    2012, Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *
       5             :  * This file is part of Collage <https://github.com/Eyescale/Collage>
       6             :  *
       7             :  * This library is free software; you can redistribute it and/or modify it under
       8             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       9             :  * by the Free Software Foundation.
      10             :  *
      11             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      12             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      13             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      14             :  * details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public License
      17             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      18             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             :  */
      20             : 
      21             : #ifndef CO_DISPATCHER_H
      22             : #define CO_DISPATCHER_H
      23             : 
      24             : #include <co/api.h>
      25             : #include <co/commandFunc.h> // used inline
      26             : #include <co/types.h>
      27             : 
      28             : namespace co
      29             : {
      30             : namespace detail { class Dispatcher; }
      31             : 
      32             :     /**
      33             :      * A class providing command dispatch functionality to networked objects.
      34             :      *
      35             :      * Command dispatch in performed through a command queue and command handler
      36             :      * table.
      37             :      */
      38             :     class Dispatcher
      39             :     {
      40             :     public:
      41             :         /** The signature of the base Dispatcher callback. @version 1.0 */
      42             :         typedef CommandFunc< Dispatcher > Func;
      43             : 
      44             :         /** @internal NOP assignment operator. */
      45             :         Dispatcher& operator = ( const Dispatcher& ) { return *this; }
      46             : 
      47             :         /**
      48             :          * Register a command member function for a command.
      49             :          *
      50             :          * If the destination queue is 0, the command function is invoked
      51             :          * directly upon dispatch, otherwise it is pushed to the given queue and
      52             :          * invoked during the processing of the command queue.
      53             :          *
      54             :          * @param command the command.
      55             :          * @param func the functor to handle the command.
      56             :          * @param queue the queue to which the the command is dispatched
      57             :          * @version 1.0
      58             :          */
      59             :         template< typename T > void
      60             :         registerCommand( const uint32_t command, const CommandFunc< T >& func,
      61             :                          CommandQueue* queue );
      62             : 
      63             :         /**
      64             :          * Dispatch a command from the receiver thread to the registered queue.
      65             :          *
      66             :          * @param command the command.
      67             :          * @return true if the command was dispatched, false if not.
      68             :          * @sa registerCommand
      69             :          * @version 1.0
      70             :          */
      71             :         CO_API virtual bool dispatchCommand( ICommand& command );
      72             : 
      73             :     protected:
      74             :         CO_API Dispatcher();
      75             :         CO_API Dispatcher( const Dispatcher& from );
      76             :         CO_API virtual ~Dispatcher();
      77             : 
      78             :         /**
      79             :          * The default handler for handling commands.
      80             :          *
      81             :          * @param command the command
      82             :          * @return false
      83             :          */
      84             :         CO_API bool _cmdUnknown( ICommand& command );
      85             : 
      86             :     private:
      87             :         detail::Dispatcher* const _impl;
      88             : 
      89             :         CO_API void _registerCommand( const uint32_t command,
      90             :                                       const Func& func, CommandQueue* queue );
      91             :     };
      92             : 
      93             :     template< typename T >
      94        2522 :     void Dispatcher::registerCommand( const uint32_t command,
      95             :                                       const CommandFunc< T >& func,
      96             :                                       CommandQueue* queue )
      97             :     {
      98        2522 :         _registerCommand( command, Dispatcher::Func( func ), queue );
      99        2522 :     }
     100             : }
     101             : #endif // CO_DISPATCHER_H

Generated by: LCOV version 1.11