1 | // test_transport.hpp, created on 01.07.2009 by Sebastian Mies |
---|
2 | |
---|
3 | #ifndef TEST_TRANSPORT_HPP_ |
---|
4 | #define TEST_TRANSPORT_HPP_ |
---|
5 | |
---|
6 | #include "transport_peer.hpp" |
---|
7 | #include "transport_listener.hpp" |
---|
8 | |
---|
9 | #include "rfcomm/rfcomm.hpp" |
---|
10 | |
---|
11 | #include <iostream> |
---|
12 | #include <string> |
---|
13 | #include <sys/types.h> |
---|
14 | #include <unistd.h> |
---|
15 | |
---|
16 | namespace ariba { |
---|
17 | namespace transport { |
---|
18 | namespace detail { |
---|
19 | |
---|
20 | using namespace std; |
---|
21 | using namespace ariba::transport; |
---|
22 | using namespace ariba::addressing; |
---|
23 | |
---|
24 | class listener : public transport_listener { |
---|
25 | public: |
---|
26 | virtual void receive_message( |
---|
27 | transport_protocol* transport, |
---|
28 | const address_vf local, const address_vf remote, |
---|
29 | const uint8_t* data, size_t size |
---|
30 | ) { |
---|
31 | cout << "transport_listener: " << endl; |
---|
32 | cout << "received message data='" << data << "' local=" << local->to_string() << " remote=" << remote->to_string() << endl; |
---|
33 | } |
---|
34 | }; |
---|
35 | |
---|
36 | void test_transport_process( endpoint_set& local, endpoint_set& remote ) { |
---|
37 | cout << "started " << local.to_string() << endl; |
---|
38 | transport_peer* peer = new transport_peer( local ); |
---|
39 | peer->register_listener( new listener() ); |
---|
40 | peer->start(); |
---|
41 | peer->send( remote, (uint8_t*)"Hello!", 7 ); |
---|
42 | getchar(); |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * TODO: Doc |
---|
47 | * |
---|
48 | * @author Sebastian Mies <mies@tm.uka.de> |
---|
49 | */ |
---|
50 | void tcp_test() { |
---|
51 | |
---|
52 | endpoint_set local = string("tcp{5001};ip{127.0.0.1 | 2001:638:204:6:216:d3ff:fece:1070}"); |
---|
53 | endpoint_set remote = string("tcp{5002};ip{127.0.0.1 | 2001:638:204:6:216:d3ff:fece:1070}"); |
---|
54 | |
---|
55 | pid_t pID = fork(); |
---|
56 | if (pID < 0) { |
---|
57 | cerr << "Failed to fork" << endl; |
---|
58 | } else |
---|
59 | if (pID == 0) { |
---|
60 | test_transport_process(local,remote); |
---|
61 | } else { |
---|
62 | getchar(); |
---|
63 | test_transport_process(remote,local); |
---|
64 | } |
---|
65 | getchar(); |
---|
66 | } |
---|
67 | |
---|
68 | void bluetooth_test( string& endp_str ) { |
---|
69 | cout << endp_str << endl; |
---|
70 | rfcomm* rfc = new rfcomm( 3 ); |
---|
71 | rfc->register_listener( new listener() ); |
---|
72 | rfc->start(); |
---|
73 | if (endp_str.size()!=0) { |
---|
74 | rfcomm_endpoint endp = endp_str; |
---|
75 | rfc->send( endp, (uint8_t*)"Hello!", 7 ); |
---|
76 | } |
---|
77 | getchar(); |
---|
78 | } |
---|
79 | |
---|
80 | }}} // namespace ariba::transport::detail |
---|
81 | |
---|
82 | #endif /* TEST_TRANSPORT_HPP_ */ |
---|