Safir SDK Core
Loading...
Searching...
No Matches
AsioDispatcher.h
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright Saab AB, 2008-2015 (http://safirsdkcore.com)
4*
5* Created by: Lars Hagström / lars.hagstrom@consoden.se
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#pragma once
25
26#include <memory>
28
29#ifdef _MSC_VER
30#pragma warning (push)
31#pragma warning (disable: 4267)
32#endif
33
34#include <boost/asio.hpp>
35
36#ifdef _MSC_VER
37#pragma warning (pop)
38#endif
39
40namespace Safir
41{
42namespace Utilities
43{
44
50 {
51 public:
64 boost::asio::io_context& ioContext)
65 : m_connection(connection)
66 , m_strand(new boost::asio::io_context::strand(ioContext))
67 , m_isNotified()
68 {
69
70 }
71
82 boost::asio::io_context::strand& strand)
83 : m_connection(connection)
84 , m_strand(&strand,null_deleter())
85 , m_isNotified()
86 {
87
88 }
89
92
96 boost::asio::io_context::strand& Strand() {return *m_strand;}
97
98 private:
99 struct null_deleter
100 {
101 void operator()(void const *) const
102 {
103 }
104 };
105
109 void CallDobDispatch()
110 {
111 m_isNotified.clear();
112 m_connection.Dispatch();
113 }
114
119 void OnDoDispatch() override
120 {
121 if (!m_isNotified.test_and_set())
122 {
123 boost::asio::dispatch(*m_strand, [this]{CallDobDispatch();});
124 }
125 }
126
127 const Safir::Dob::Connection& m_connection;
128 std::shared_ptr<boost::asio::io_context::strand> m_strand;
129 std::atomic_flag m_isNotified;
130 };
131
132
133}
134}
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
A connection to the DOB.
Definition Connection.h:46
void Dispatch() const
When the dispatch event or callback is signalled, the application MUST call this method.
Interface for reception of a dispatch order.
Definition Consumer.h:74
The class makes a thread switch and perform a dispatch on Dob connection.
Definition AsioDispatcher.h:50
AsioDispatcher(const Safir::Dob::Connection &connection, boost::asio::io_context &ioContext)
Strandless constructor.
Definition AsioDispatcher.h:63
AsioDispatcher & operator=(const AsioDispatcher &)=delete
boost::asio::io_context::strand & Strand()
Get the strand that the dispatcher uses.
Definition AsioDispatcher.h:96
AsioDispatcher(const AsioDispatcher &)=delete
AsioDispatcher(const Safir::Dob::Connection &connection, boost::asio::io_context::strand &strand)
Stranded constructor.
Definition AsioDispatcher.h:81