00001
00002 #include "transport_peer.hpp"
00003 #include "transport.hpp"
00004
00005
00006 namespace ariba {
00007 namespace transport {
00008
00009 using namespace ariba::addressing;
00010
00011 transport_peer::transport_peer( endpoint_set& local_set ) : local(local_set) {
00012
00013 tcp = NULL;
00014 cout << "#tcpip_transports = " << local.tcp.size() << endl;
00015 if (local.tcp.size()==1) {
00016 tcp = new tcpip(local.tcp.begin()->value());
00017 cout << "Started tcpip_transport on port " << local.tcp.begin()->value() << endl;
00018 }
00019
00020 rfc = NULL;
00021 cout << "#rfcomm_transports = " << local.rfcomm.size() << endl;
00022 if ( local.rfcomm.size() == 1 ) {
00023 rfc = new rfcomm( local.rfcomm.begin()->value() );
00024 cout << "Started rfcomm_transport on port " << local.rfcomm.begin()->value() << endl;
00025 }
00026 }
00027
00028 transport_peer::~transport_peer() {
00029 if (tcp !=NULL ) delete tcp;
00030 if (rfc !=NULL ) delete rfc;
00031 }
00032
00033 void transport_peer::start() {
00034 if (tcp!=NULL) tcp->start();
00035 if (rfc!=NULL) rfc->start();
00036 }
00037
00038 void transport_peer::stop() {
00039 if (tcp!=NULL) tcp->stop();
00040 if (rfc!=NULL) rfc->stop();
00041 }
00042
00043 void transport_peer::send( const address_v* remote, const uint8_t* data, size_t size ) {
00044 if (remote->instanceof<tcpip_endpoint>() && tcp!=NULL) {
00045 tcp->send(remote,data,size);
00046 } else
00047 if (remote->instanceof<rfcomm_endpoint>() && rfc!=NULL) {
00048 rfc->send(remote,data,size);
00049 } else
00050 cerr << "Could not send message to " << remote->to_string() << endl;
00051 }
00052
00053 void transport_peer::send( const endpoint_set& endpoints, const uint8_t* data, size_t size ) {
00054 if (tcp!=NULL) tcp->send(endpoints,data,size);
00055 if (rfc!=NULL) rfc->send(endpoints,data,size);
00056 }
00057
00058 void transport_peer::terminate( const address_v* remote ) {
00059 if (remote->instanceof<tcpip_endpoint>() && tcp!=NULL)
00060 tcp->terminate(remote);
00061 if (remote->instanceof<rfcomm_endpoint>() && rfc!=NULL)
00062 rfc->terminate(remote);
00063 }
00064
00065 void transport_peer::register_listener( transport_listener* listener ) {
00066 if (tcp!=NULL) tcp->register_listener(listener);
00067 if (rfc!=NULL) rfc->register_listener(listener);
00068 }
00069
00070 }}