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