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