Collage  1.1.2
High-performance C++ library for developing object-oriented distributed applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
dispatcher.h
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 
38  class Dispatcher
39  {
40  public:
43 
45  Dispatcher& operator = ( const Dispatcher& ) { return *this; }
46 
59  template< typename T > void
60  registerCommand( const uint32_t command, const CommandFunc< T >& func,
61  CommandQueue* queue );
62 
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 
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  void Dispatcher::registerCommand( const uint32_t command,
95  const CommandFunc< T >& func,
96  CommandQueue* queue )
97  {
98  _registerCommand( command, Dispatcher::Func( func ), queue );
99  }
100 }
101 #endif // CO_DISPATCHER_H
Defines export visibility macros for Collage.
A thread-safe, blocking queue for ICommand buffers.
Definition: commandQueue.h:33
void registerCommand(const uint32_t command, const CommandFunc< T > &func, CommandQueue *queue)
Register a command member function for a command.
Definition: dispatcher.h:94
CommandFunc< Dispatcher > Func
The signature of the base Dispatcher callback.
Definition: dispatcher.h:42
virtual CO_API bool dispatchCommand(ICommand &command)
Dispatch a command from the receiver thread to the registered queue.
A class managing received commands.
Definition: iCommand.h:43
CO_API bool _cmdUnknown(ICommand &command)
The default handler for handling commands.
A wrapper to register a function callback on an object instance.
Definition: commandFunc.h:38
A class providing command dispatch functionality to networked objects.
Definition: dispatcher.h:38