Jpp
19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
software
DataQueue
CLBInterface
input_channel_handler.hh
Go to the documentation of this file.
1
#ifndef INPUT_CHANNEL_HANDLER_HH
2
#define INPUT_CHANNEL_HANDLER_HH
3
4
#include <boost/bind.hpp>
5
#include <boost/asio.hpp>
6
#include <boost/atomic.hpp>
7
8
#include <
FrameFactory/input_buffer_collector.hh
>
9
#include <
FrameFactory/frame_farm.hh
>
10
11
/**
12
* \author cpellegrino
13
*/
14
15
class
InChannelHandler
16
{
17
boost::asio::ip::udp::socket
m_socket
;
18
CLBDataGram
*
m_buffer
;
19
FrameFarm
*
const
m_farm
;
20
boost::atomic<bool>
m_paused
;
21
22
void
handle
(
const
boost::system::error_code& error,
size_t
size)
23
{
24
// The error_code should be handled in principle, but
25
// it is not mandatory, since all possibilities should be already
26
// handled somewhere else.
27
28
if
(size && !
m_paused
)
29
{
30
m_buffer
->
resize
(size);
31
m_farm
->
insert
(
m_buffer
);
32
33
m_buffer
=
InBufferCollector::getCollector
().
getEmptyDataGram
();
34
}
35
36
m_socket
.async_receive(
37
boost::asio::buffer(
m_buffer
->
raw
(),
m_buffer
->
capacity
()),
38
boost::bind(
39
&
InChannelHandler::handle
,
40
this
,
41
boost::asio::placeholders::error,
42
boost::asio::placeholders::bytes_transferred));
43
}
44
45
public
:
46
47
// Receive buffer size (see SOL_SOCKET/SO_RCVBUF) set to 64MB
48
// (default between 32 and 128KB)
49
#if __APPLE__
50
static
const
int
recv_buf_size
= 6108864;
51
#else
52
static
const
int
recv_buf_size
= 67108864;
53
#endif
54
55
void
pause
()
56
{
57
m_paused
=
true
;
58
}
59
60
void
cont
()
61
{
62
m_paused
=
false
;
63
}
64
65
InChannelHandler
(boost::asio::io_service& service,
66
unsigned
short
port,
67
FrameFarm
& farm)
68
:
69
m_socket
(service, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port)),
70
m_buffer
(
71
InBufferCollector
::getCollector().getEmptyDataGram()),
72
m_farm
(&farm),
73
m_paused
(false)
74
{
75
boost::asio::ip::udp::socket::receive_buffer_size option(
recv_buf_size
);
76
m_socket
.set_option(option);
77
handle
(boost::system::error_code(), 0);
78
}
79
80
~InChannelHandler
()
81
{
82
InBufferCollector::getCollector
().
putDataGram
(
m_buffer
);
83
}
84
};
85
86
#endif
// INPUT_CHANNEL_HANDLER_HH
CLBDataGram
Definition
clb_datagram.hh:16
CLBDataGram::resize
void resize(size_t s)
Definition
clb_datagram.hh:54
CLBDataGram::raw
char * raw()
Definition
clb_datagram.hh:65
CLBDataGram::capacity
size_t capacity() const
Definition
clb_datagram.hh:75
FrameFarm
Definition
frame_farm.hh:24
FrameFarm::insert
bool insert(CLBDataGram *datagram)
Definition
frame_farm.cc:100
InBufferCollector
Definition
input_buffer_collector.hh:15
InBufferCollector::putDataGram
void putDataGram(CLBDataGram *p)
Definition
input_buffer_collector.hh:53
InBufferCollector::getCollector
static InBufferCollector & getCollector()
Definition
input_buffer_collector.hh:27
InBufferCollector::getEmptyDataGram
CLBDataGram * getEmptyDataGram()
Definition
input_buffer_collector.hh:34
InChannelHandler
Definition
input_channel_handler.hh:16
InChannelHandler::m_socket
boost::asio::ip::udp::socket m_socket
Definition
input_channel_handler.hh:17
InChannelHandler::pause
void pause()
Definition
input_channel_handler.hh:55
InChannelHandler::handle
void handle(const boost::system::error_code &error, size_t size)
Definition
input_channel_handler.hh:22
InChannelHandler::m_paused
boost::atomic< bool > m_paused
Definition
input_channel_handler.hh:20
InChannelHandler::recv_buf_size
static const int recv_buf_size
Definition
input_channel_handler.hh:52
InChannelHandler::m_farm
FrameFarm *const m_farm
Definition
input_channel_handler.hh:19
InChannelHandler::InChannelHandler
InChannelHandler(boost::asio::io_service &service, unsigned short port, FrameFarm &farm)
Definition
input_channel_handler.hh:65
InChannelHandler::cont
void cont()
Definition
input_channel_handler.hh:60
InChannelHandler::m_buffer
CLBDataGram * m_buffer
Definition
input_channel_handler.hh:18
InChannelHandler::~InChannelHandler
~InChannelHandler()
Definition
input_channel_handler.hh:80
frame_farm.hh
input_buffer_collector.hh
Generated by
1.12.0