source: source/ariba/utility/transport/test_transport.hpp@ 6786

Last change on this file since 6786 was 5284, checked in by mies, 15 years ago

+ added new transport modules and adapted ariba to them
+ exchange endpoint descriptors an link establishment
+ clean up of base communication
+ link establishment with in the presence of multiple endpoints
+ local discovery for ipv6, ipv4 and bluetooth mac addresses

File size: 1.9 KB
Line 
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
16namespace ariba {
17namespace transport {
18namespace detail {
19
20using namespace std;
21using namespace ariba::transport;
22using namespace ariba::addressing;
23
24class listener : public transport_listener {
25public:
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
36void 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 */
50void 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
68void 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_ */
Note: See TracBrowser for help on using the repository browser.