[5284] | 1 |
|
---|
[7464] | 2 | #include "ariba/config.h"
|
---|
[5284] | 3 | #include "transport_peer.hpp"
|
---|
| 4 | #include "transport.hpp"
|
---|
| 5 |
|
---|
| 6 | // namespace ariba::transport
|
---|
| 7 | namespace ariba {
|
---|
| 8 | namespace transport {
|
---|
| 9 |
|
---|
| 10 | using namespace ariba::addressing;
|
---|
| 11 |
|
---|
| 12 | transport_peer::transport_peer( endpoint_set& local_set ) : local(local_set) {
|
---|
| 13 | // setup tcp transports
|
---|
| 14 | tcp = NULL;
|
---|
| 15 | cout << "#tcpip_transports = " << local.tcp.size() << endl;
|
---|
| 16 | if (local.tcp.size()==1) {
|
---|
| 17 | tcp = new tcpip(local.tcp.begin()->value());
|
---|
| 18 | cout << "Started tcpip_transport on port " << local.tcp.begin()->value() << endl;
|
---|
| 19 | }
|
---|
[7041] | 20 |
|
---|
| 21 | #ifdef HAVE_LIBBLUETOOTH
|
---|
[5284] | 22 | // setup rfcomm transports
|
---|
| 23 | rfc = NULL;
|
---|
| 24 | cout << "#rfcomm_transports = " << local.rfcomm.size() << endl;
|
---|
| 25 | if ( local.rfcomm.size() == 1 ) {
|
---|
| 26 | rfc = new rfcomm( local.rfcomm.begin()->value() );
|
---|
| 27 | cout << "Started rfcomm_transport on port " << local.rfcomm.begin()->value() << endl;
|
---|
| 28 | }
|
---|
[7041] | 29 | #endif
|
---|
[5284] | 30 | }
|
---|
| 31 |
|
---|
| 32 | transport_peer::~transport_peer() {
|
---|
| 33 | if (tcp !=NULL ) delete tcp;
|
---|
[7041] | 34 | #ifdef HAVE_LIBBLUETOOTH
|
---|
[5284] | 35 | if (rfc !=NULL ) delete rfc;
|
---|
[7041] | 36 | #endif
|
---|
[5284] | 37 | }
|
---|
| 38 |
|
---|
| 39 | void transport_peer::start() {
|
---|
| 40 | if (tcp!=NULL) tcp->start();
|
---|
[7041] | 41 | #ifdef HAVE_LIBBLUETOOTH
|
---|
[5284] | 42 | if (rfc!=NULL) rfc->start();
|
---|
[7041] | 43 | #endif
|
---|
[5284] | 44 | }
|
---|
| 45 |
|
---|
| 46 | void transport_peer::stop() {
|
---|
| 47 | if (tcp!=NULL) tcp->stop();
|
---|
[7041] | 48 | #ifdef HAVE_LIBBLUETOOTH
|
---|
[5284] | 49 | if (rfc!=NULL) rfc->stop();
|
---|
[7041] | 50 | #endif
|
---|
[5284] | 51 | }
|
---|
| 52 |
|
---|
| 53 | void transport_peer::send( const address_v* remote, const uint8_t* data, size_t size ) {
|
---|
| 54 | if (remote->instanceof<tcpip_endpoint>() && tcp!=NULL) {
|
---|
| 55 | tcp->send(remote,data,size);
|
---|
| 56 | } else
|
---|
[7041] | 57 | #ifdef HAVE_LIBBLUETOOTH
|
---|
[5284] | 58 | if (remote->instanceof<rfcomm_endpoint>() && rfc!=NULL) {
|
---|
| 59 | rfc->send(remote,data,size);
|
---|
| 60 | } else
|
---|
[7041] | 61 | #endif
|
---|
[5284] | 62 | cerr << "Could not send message to " << remote->to_string() << endl;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void transport_peer::send( const endpoint_set& endpoints, const uint8_t* data, size_t size ) {
|
---|
| 66 | if (tcp!=NULL) tcp->send(endpoints,data,size);
|
---|
[7041] | 67 | #ifdef HAVE_LIBBLUETOOTH
|
---|
[5284] | 68 | if (rfc!=NULL) rfc->send(endpoints,data,size);
|
---|
[7041] | 69 | #endif
|
---|
[5284] | 70 | }
|
---|
| 71 |
|
---|
[5614] | 72 | void transport_peer::terminate( const address_v* remote ) {
|
---|
[5284] | 73 | if (remote->instanceof<tcpip_endpoint>() && tcp!=NULL)
|
---|
[5614] | 74 | tcp->terminate(remote);
|
---|
[7041] | 75 | #ifdef HAVE_LIBBLUETOOTH
|
---|
[5284] | 76 | if (remote->instanceof<rfcomm_endpoint>() && rfc!=NULL)
|
---|
[5614] | 77 | rfc->terminate(remote);
|
---|
[7041] | 78 | #endif
|
---|
[5284] | 79 | }
|
---|
| 80 |
|
---|
| 81 | void transport_peer::register_listener( transport_listener* listener ) {
|
---|
| 82 | if (tcp!=NULL) tcp->register_listener(listener);
|
---|
[7041] | 83 | #ifdef HAVE_LIBBLUETOOTH
|
---|
[5284] | 84 | if (rfc!=NULL) rfc->register_listener(listener);
|
---|
[7041] | 85 | #endif
|
---|
[5284] | 86 | }
|
---|
| 87 |
|
---|
| 88 | }} // namespace ariba::transport
|
---|