source: source/ariba/utility/transport/transport_peer.cpp@ 6939

Last change on this file since 6939 was 5614, checked in by mies, 15 years ago

added termination of transports when no link is up anymore to an end-point

File size: 2.0 KB
RevLine 
[5284]1
2#include "transport_peer.hpp"
3#include "transport.hpp"
4
5// namespace ariba::transport
6namespace ariba {
7namespace transport {
8
9using namespace ariba::addressing;
10
11transport_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
28transport_peer::~transport_peer() {
29 if (tcp !=NULL ) delete tcp;
30 if (rfc !=NULL ) delete rfc;
31}
32
33void transport_peer::start() {
34 if (tcp!=NULL) tcp->start();
35 if (rfc!=NULL) rfc->start();
36}
37
38void transport_peer::stop() {
39 if (tcp!=NULL) tcp->stop();
40 if (rfc!=NULL) rfc->stop();
41}
42
43void 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
53void 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]58void 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
65void 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
Note: See TracBrowser for help on using the repository browser.