1 | #ifndef RFCOMM_HPP_
|
---|
2 | #define RFCOMM_HPP_
|
---|
3 |
|
---|
4 | #include "../transport.hpp"
|
---|
5 | #include "../asio/asio_io_service.h"
|
---|
6 | #include "../asio/bluetooth_endpoint.hpp"
|
---|
7 | #include "../asio/rfcomm.hpp"
|
---|
8 |
|
---|
9 | #include <boost/thread.hpp>
|
---|
10 | #include <boost/system/system_error.hpp>
|
---|
11 | #include <boost/asio/io_service.hpp>
|
---|
12 |
|
---|
13 | namespace ariba {
|
---|
14 | namespace transport {
|
---|
15 |
|
---|
16 | using boost::system::error_code;
|
---|
17 | using namespace boost::asio;
|
---|
18 |
|
---|
19 | class link_info;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * TODO: Doc
|
---|
23 | *
|
---|
24 | * @author Sebastian Mies <mies@tm.uka.de>
|
---|
25 | */
|
---|
26 | class rfcomm : public transport_protocol {
|
---|
27 | public:
|
---|
28 | rfcomm( uint16_t channel );
|
---|
29 | virtual ~rfcomm();
|
---|
30 | virtual void start();
|
---|
31 | virtual void stop();
|
---|
32 | virtual void send( const address_v* remote, const uint8_t* data, size_t size );
|
---|
33 | virtual void send( const endpoint_set& endpoints, const uint8_t* data, size_t size );
|
---|
34 | virtual void terminate( const address_v* local, const address_v* remote );
|
---|
35 | virtual void register_listener( transport_listener* listener );
|
---|
36 |
|
---|
37 | private:
|
---|
38 | uint16_t channel;
|
---|
39 | boost::mutex links_mutex;
|
---|
40 | vector<link_info*> links;
|
---|
41 | io_service& io;
|
---|
42 | transport_listener* listener;
|
---|
43 | bluetooth::rfcomm::acceptor* acceptor;
|
---|
44 |
|
---|
45 | void start_accept();
|
---|
46 |
|
---|
47 | void handle_accept( const error_code& error, link_info* info );
|
---|
48 |
|
---|
49 | void start_read( link_info* info );
|
---|
50 |
|
---|
51 | void handle_read_header( const error_code& error, size_t bytes, link_info* info );
|
---|
52 |
|
---|
53 | void handle_read_data( const error_code& error, size_t bytes, link_info* info );
|
---|
54 |
|
---|
55 | void handle_connect( const error_code& error, link_info* info );
|
---|
56 |
|
---|
57 | void start_write( link_info* info );
|
---|
58 |
|
---|
59 | void handle_write_data(const error_code& error, size_t bytes,
|
---|
60 | link_info* info, size_t size, uint8_t* buffer );
|
---|
61 | };
|
---|
62 |
|
---|
63 | }} // namespace ariba::transport
|
---|
64 |
|
---|
65 | #endif /* RFCOMM_HPP_ */
|
---|