YAMI4 C++
incoming_message_generic_dispatcher.h
1 // Copyright Maciej Sobczak 2008-2019.
2 // This file is part of YAMI4.
3 //
4 // YAMI4 is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // YAMI4 is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with YAMI4. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef YAMICPP_INCOMING_MESSAGE_GENERIC_DISPATCHER_H_INCLUDED
18 #define YAMICPP_INCOMING_MESSAGE_GENERIC_DISPATCHER_H_INCLUDED
19 
20 #include "incoming_message_dispatcher_base.h"
21 #include <yami4-core/dll.h>
22 #include <string>
23 
24 namespace yami
25 {
26 
27 class incoming_message;
28 
29 namespace details
30 {
31 
32 template <typename functor>
33 class DLL incoming_message_generic_dispatcher
34  : public incoming_message_dispatcher_base
35 {
36 public:
37  incoming_message_generic_dispatcher(functor & f) : f_(f) {}
38 
39  virtual void dispatch(incoming_message & im)
40  {
41  f_(im);
42  }
43 
44 private:
45  functor & f_;
46 };
47 
48 class DLL incoming_message_raw_dispatcher
49  : public incoming_message_dispatcher_base
50 {
51 public:
52  incoming_message_raw_dispatcher(
53  void (* callback)(incoming_message & im, void * hint), void * hint)
54  : callback_(callback),
55  hint_(hint)
56  {
57  }
58 
59  virtual void dispatch(incoming_message & im)
60  {
61  callback_(im, hint_);
62  }
63 
64 private:
65  void (* callback_)(incoming_message & im, void * hint);
66  void * hint_;
67 };
68 
69 } // namespace details
70 
71 } // namespace yami
72 
73 #endif // YAMICPP_INCOMING_MESSAGE_GENERIC_DISPATCHER_H_INCLUDED
Namespace devoted to everything related to YAMI4.
Definition: activity_statistics_monitor.cpp:27