00001
00002
00003 #ifndef TEST_TRANSPORT_HPP_
00004 #define TEST_TRANSPORT_HPP_
00005
00006 #include "transport_peer.hpp"
00007 #include "transport_listener.hpp"
00008
00009 #include "rfcomm/rfcomm.hpp"
00010
00011 #include <iostream>
00012 #include <string>
00013 #include <sys/types.h>
00014 #include <unistd.h>
00015
00016 namespace ariba {
00017 namespace transport {
00018 namespace detail {
00019
00020 using namespace std;
00021 using namespace ariba::transport;
00022 using namespace ariba::addressing;
00023
00024 class listener : public transport_listener {
00025 public:
00026 virtual void receive_message(
00027 transport_protocol* transport,
00028 const address_vf local, const address_vf remote,
00029 const uint8_t* data, size_t size
00030 ) {
00031 cout << "transport_listener: " << endl;
00032 cout << "received message data='" << data << "' local=" << local->to_string() << " remote=" << remote->to_string() << endl;
00033 }
00034 };
00035
00036 void test_transport_process( endpoint_set& local, endpoint_set& remote ) {
00037 cout << "started " << local.to_string() << endl;
00038 transport_peer* peer = new transport_peer( local );
00039 peer->register_listener( new listener() );
00040 peer->start();
00041 peer->send( remote, (uint8_t*)"Hello!", 7 );
00042 getchar();
00043 }
00044
00050 void tcp_test() {
00051
00052 endpoint_set local = string("tcp{5001};ip{127.0.0.1 | 2001:638:204:6:216:d3ff:fece:1070}");
00053 endpoint_set remote = string("tcp{5002};ip{127.0.0.1 | 2001:638:204:6:216:d3ff:fece:1070}");
00054
00055 pid_t pID = fork();
00056 if (pID < 0) {
00057 cerr << "Failed to fork" << endl;
00058 } else
00059 if (pID == 0) {
00060 test_transport_process(local,remote);
00061 } else {
00062 getchar();
00063 test_transport_process(remote,local);
00064 }
00065 getchar();
00066 }
00067
00068 void bluetooth_test( string& endp_str ) {
00069 cout << endp_str << endl;
00070 rfcomm* rfc = new rfcomm( 3 );
00071 rfc->register_listener( new listener() );
00072 rfc->start();
00073 if (endp_str.size()!=0) {
00074 rfcomm_endpoint endp = endp_str;
00075 rfc->send( endp, (uint8_t*)"Hello!", 7 );
00076 }
00077 getchar();
00078 }
00079
00080 }}}
00081
00082 #endif