LCOV - code coverage report
Current view: top level - co - dispatcher.h (source / functions) Hit Total Coverage
Test: Collage Lines: 3 3 100.0 %
Date: 2018-01-09 16:37:03 Functions: 14 14 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2006-2016, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                          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
      31             : {
      32             : class Dispatcher;
      33             : }
      34             : 
      35             : /**
      36             :  * A class providing command dispatch functionality to networked objects.
      37             :  *
      38             :  * Command dispatch in performed through a command queue and command handler
      39             :  * table.
      40             :  */
      41             : class Dispatcher
      42             : {
      43             : public:
      44             :     /** The signature of the base Dispatcher callback. @version 1.0 */
      45             :     typedef CommandFunc<Dispatcher> Func;
      46             : 
      47             :     /** @internal NOP assignment operator. */
      48             :     Dispatcher& operator=(const Dispatcher&) { return *this; }
      49             :     /**
      50             :      * Register a command member function for a command.
      51             :      *
      52             :      * If the destination queue is 0, the command function is invoked directly
      53             :      * upon dispatch, otherwise it is pushed to the given queue and invoked
      54             :      * during the processing of the command queue.
      55             :      *
      56             :      * @param command the command.
      57             :      * @param func the functor to handle the command.
      58             :      * @param queue the queue to which the the command is dispatched
      59             :      * @version 1.0
      60             :      */
      61             :     template <typename T>
      62             :     void registerCommand(const uint32_t command, const CommandFunc<T>& func,
      63             :                          CommandQueue* queue);
      64             : 
      65             :     /**
      66             :      * Dispatch a command from the receiver thread to the registered queue.
      67             :      *
      68             :      * @param command the command.
      69             :      * @return true if the command was dispatched, false if not.
      70             :      * @sa registerCommand
      71             :      * @version 1.0
      72             :      */
      73             :     CO_API virtual bool dispatchCommand(ICommand& command);
      74             : 
      75             : protected:
      76             :     CO_API Dispatcher();
      77             :     CO_API Dispatcher(const Dispatcher& from);
      78             :     CO_API virtual ~Dispatcher();
      79             : 
      80             :     /**
      81             :      * The default handler for handling commands.
      82             :      *
      83             :      * @param command the command
      84             :      * @return false
      85             :      */
      86             :     CO_API bool _cmdUnknown(ICommand& command);
      87             : 
      88             : private:
      89             :     detail::Dispatcher* const _impl;
      90             : 
      91             :     CO_API void _registerCommand(const uint32_t command, const Func& func,
      92             :                                  CommandQueue* queue);
      93             : };
      94             : 
      95             : template <typename T>
      96        2453 : void Dispatcher::registerCommand(const uint32_t command,
      97             :                                  const CommandFunc<T>& func,
      98             :                                  CommandQueue* queue)
      99             : {
     100        2453 :     _registerCommand(command, Dispatcher::Func(func), queue);
     101        2453 : }
     102             : }
     103             : #endif // CO_DISPATCHER_H

Generated by: LCOV version 1.11