[232] | 1 | // created: 2018/03/13
|
---|
| 2 | // filename: main.cpp
|
---|
| 3 | //
|
---|
| 4 | // author: Guillaume Sanahuja
|
---|
| 5 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 6 | //
|
---|
| 7 | // version: $Id: $
|
---|
| 8 | //
|
---|
| 9 | // purpose: vrpn bridge, to forward it to bth for exemple
|
---|
| 10 | //
|
---|
| 11 | //
|
---|
| 12 | /*********************************************************************/
|
---|
| 13 | #include <vrpn_Connection.h>
|
---|
| 14 | #include <vrpn_Forwarder.h>
|
---|
| 15 |
|
---|
| 16 | #include <stdio.h>
|
---|
| 17 | #include <stdlib.h>
|
---|
| 18 | #include <signal.h>
|
---|
[233] | 19 | #include <unistd.h>
|
---|
[232] | 20 |
|
---|
| 21 | vrpn_Connection * server_connection;
|
---|
| 22 | vrpn_Connection * client_connection;
|
---|
| 23 | vrpn_StreamForwarder * forwarder;
|
---|
| 24 |
|
---|
| 25 | void sighandler (int signal) {
|
---|
| 26 | delete forwarder;
|
---|
| 27 | delete server_connection;
|
---|
| 28 | delete client_connection;
|
---|
| 29 | exit(0);
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | void install_handler (void) {
|
---|
| 33 | signal( SIGINT, sighandler );
|
---|
| 34 | signal( SIGKILL, sighandler );
|
---|
| 35 | signal( SIGTERM, sighandler );
|
---|
| 36 | signal( SIGPIPE, sighandler );
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | int main (int argc, char ** argv) {
|
---|
| 40 |
|
---|
| 41 | int retval;
|
---|
| 42 |
|
---|
[233] | 43 | //server_connection = vrpn_get_connection_by_name ("192.168.147.197:3883");
|
---|
[232] | 44 | server_connection = vrpn_get_connection_by_name ("127.0.0.1:3883");
|
---|
| 45 | client_connection = vrpn_create_server_connection(3884);
|
---|
| 46 |
|
---|
| 47 | forwarder = new vrpn_StreamForwarder(server_connection, "target", client_connection, "target");
|
---|
| 48 |
|
---|
| 49 | retval = forwarder->forward("vrpn_Tracker Pos_Quat", "vrpn_Tracker Pos_Quat");
|
---|
| 50 | if (retval)
|
---|
| 51 | fprintf(stderr, "forwarder->forward (vrpn_Tracker Pos_Quat) failed.\n");
|
---|
| 52 |
|
---|
| 53 | retval = forwarder->forward("vrpn_Base ping_message", "vrpn_Base ping_message");
|
---|
| 54 | if (retval)
|
---|
| 55 | fprintf(stderr, "forwarder->forward (vrpn_Base ping_message) failed.\n");
|
---|
| 56 |
|
---|
| 57 | install_handler();
|
---|
| 58 |
|
---|
| 59 | while (1) {
|
---|
[234] | 60 | usleep(5000);
|
---|
[232] | 61 | server_connection->mainloop();
|
---|
| 62 | client_connection->mainloop();
|
---|
| 63 | }
|
---|
| 64 | } |
---|