Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AsioDispatcher.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2008-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Erik Adolfsson / sterad
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 #ifndef __DOB_UTILITIES_ASIO_DISPATCHER_H__
25 #define __DOB_UTILITIES_ASIO_DISPATCHER_H__
26 
27 #include <Safir/Dob/Connection.h>
28 #include <Safir/Dob/Internal/Atomic.h>
29 #include <boost/asio.hpp>
30 #include <boost/bind.hpp>
31 #include <boost/noncopyable.hpp>
32 
33 namespace Safir
34 {
35 namespace Utilities
36 {
37 
42  : public Safir::Dob::Dispatcher
43  , private boost::noncopyable
44  {
45  public:
53  boost::asio::io_service& ioService)
54  : m_connection(connection)
55  , m_ioService(ioService)
56  , m_isNotified(0) {}
57 
58  private:
59 
63  void Dispatch()
64  {
65  m_isNotified = 0;
66  m_connection.Dispatch();
67  }
68 
73  virtual void OnDoDispatch()
74  {
75  if (m_isNotified == 0)
76  {
77  m_isNotified = 1;
78  m_ioService.post(boost::bind(&AsioDispatcher::Dispatch,this));
79  }
80  }
81 
82 
83  const Safir::Dob::Connection& m_connection;
84  boost::asio::io_service& m_ioService;
85  Safir::Dob::Internal::AtomicUint32 m_isNotified;
86  };
87 
88 
89 } // namespace Utilities
90 } // namespace Safir
91 
92 #endif // __DOB_UTILITIES_ASIO_DISPATCHER_H__
Interface for reception of a dispatch order.
Definition: Consumer.h:72
void Dispatch() const
When the dispatch event or callback is signalled, the application MUST call this method.
The class makes a thread switch and perform a dispatch on Dob connection.
Definition: AsioDispatcher.h:41
A connection to the DOB.
Definition: Connection.h:45
AsioDispatcher(const Safir::Dob::Connection &connection, boost::asio::io_service &ioService)
Constructor.
Definition: AsioDispatcher.h:52