Merge branch 'durk/terrasync'
This commit is contained in:
commit
2a29c8c604
1 changed files with 78 additions and 38 deletions
|
@ -35,6 +35,7 @@
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -56,9 +57,7 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using std::string;
|
using namespace std;
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
const char* source_base = NULL;
|
const char* source_base = NULL;
|
||||||
const char* svn_base =
|
const char* svn_base =
|
||||||
|
@ -77,16 +76,33 @@ const char* svn_cmd = "svn checkout";
|
||||||
|
|
||||||
// display usage
|
// display usage
|
||||||
static void usage( const string& prog ) {
|
static void usage( const string& prog ) {
|
||||||
cout << "Usage: " << endl
|
cout <<
|
||||||
<< prog << " -p <port> "
|
"Usage: terrasync [options]\n"
|
||||||
<< "-R [ -s <rsync_source> ] -d <dest>" << endl
|
"Options: \n"
|
||||||
<< prog << " -p <port> "
|
" -d <dest> destination directory [required]\n"
|
||||||
<< "-S [ -s <svn_source> ] -d <dest>" << endl;
|
" -R transport using pipe to rsync\n"
|
||||||
|
" -S transport using built-in svn\n"
|
||||||
|
" -p <port> listen on UDP port [default: 5501]\n"
|
||||||
|
" -s <source> source base [default: '']\n"
|
||||||
|
" -pid <pidfile> write PID to file\n"
|
||||||
|
" -v be more verbose\n"
|
||||||
|
;
|
||||||
|
|
||||||
#ifdef HAVE_SVN_CLIENT_H
|
#ifdef HAVE_SVN_CLIENT_H
|
||||||
cout << " (defaults to the built in subversion)" << endl;
|
cout << " (defaults to the built in subversion)" << endl;
|
||||||
#else
|
#else
|
||||||
cout << " (defaults to rsync, using external commands)" << endl;
|
cout << " (defaults to rsync, using external commands)" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
cout << "\nExample:\n"
|
||||||
|
"pid=$(cat $pidfile 2>/dev/null)\n"
|
||||||
|
"if test -n \"$pid\" && kill -0 $pid ; then\n"
|
||||||
|
" echo \"terrasync already running: $pid\"\n"
|
||||||
|
"else\n"
|
||||||
|
" nice /games/sport/fgs/utils/TerraSync/terrasync \\\n"
|
||||||
|
" -v -pid $pidfile -S -p 5500 -d /games/orig/terrasync &\n"
|
||||||
|
"fi" << endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::deque<std::string> waitingTiles;
|
std::deque<std::string> waitingTiles;
|
||||||
|
@ -404,6 +420,9 @@ int main( int argc, char **argv ) {
|
||||||
int port = 5501;
|
int port = 5501;
|
||||||
char host[256] = ""; // accept messages from anyone
|
char host[256] = ""; // accept messages from anyone
|
||||||
bool testing = false;
|
bool testing = false;
|
||||||
|
bool do_checkout(true);
|
||||||
|
int verbose(0);
|
||||||
|
const char* pidfn = "";
|
||||||
|
|
||||||
// parse arguments
|
// parse arguments
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
@ -411,6 +430,10 @@ int main( int argc, char **argv ) {
|
||||||
if ( (string)argv[i] == "-p" ) {
|
if ( (string)argv[i] == "-p" ) {
|
||||||
++i;
|
++i;
|
||||||
port = atoi( argv[i] );
|
port = atoi( argv[i] );
|
||||||
|
} else if ( string(argv[i]).find("-pid") == 0 ) {
|
||||||
|
++i;
|
||||||
|
pidfn = argv[i];
|
||||||
|
cout << "pidfn: " << pidfn << endl;
|
||||||
} else if ( (string)argv[i] == "-s" ) {
|
} else if ( (string)argv[i] == "-s" ) {
|
||||||
++i;
|
++i;
|
||||||
source_base = argv[i];
|
source_base = argv[i];
|
||||||
|
@ -421,15 +444,33 @@ int main( int argc, char **argv ) {
|
||||||
use_svn = false;
|
use_svn = false;
|
||||||
} else if ( (string)argv[i] == "-S" ) {
|
} else if ( (string)argv[i] == "-S" ) {
|
||||||
use_svn = true;
|
use_svn = true;
|
||||||
|
} else if ( (string)argv[i] == "-v" ) {
|
||||||
|
verbose++;
|
||||||
} else if ( (string)argv[i] == "-T" ) {
|
} else if ( (string)argv[i] == "-T" ) {
|
||||||
testing = true;
|
testing = true;
|
||||||
|
} else if ( (string)argv[i] == "-h" ) {
|
||||||
|
usage( argv[0] );
|
||||||
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
|
cerr << "Unrecognized verbiage '" << argv[i] << "'" << endl;
|
||||||
usage( argv[0] );
|
usage( argv[0] );
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*pidfn) {
|
||||||
|
ofstream pidstream;
|
||||||
|
pidstream.open(pidfn);
|
||||||
|
if (!pidstream.good()) {
|
||||||
|
cerr << "Cannot open pid file '" << pidfn << "': ";
|
||||||
|
perror(0);
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
pidstream << getpid() << endl;
|
||||||
|
pidstream.close();
|
||||||
|
}
|
||||||
|
|
||||||
// Use the appropriate default for the "-s" flag
|
// Use the appropriate default for the "-s" flag
|
||||||
if (source_base == NULL) {
|
if (source_base == NULL) {
|
||||||
if (use_svn)
|
if (use_svn)
|
||||||
|
@ -448,8 +489,6 @@ int main( int argc, char **argv ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s.setBlocking( false );
|
|
||||||
|
|
||||||
if ( s.bind( host, port ) == -1 ) {
|
if ( s.bind( host, port ) == -1 ) {
|
||||||
printf("error binding to port %d\n", port);
|
printf("error binding to port %d\n", port);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -464,33 +503,39 @@ int main( int argc, char **argv ) {
|
||||||
bool recv_msg = false;
|
bool recv_msg = false;
|
||||||
|
|
||||||
char synced_other;
|
char synced_other;
|
||||||
for ( synced_other = 'K'; synced_other <= 'Z'; synced_other++ ) {
|
if (do_checkout) {
|
||||||
char dir[512];
|
for ( synced_other = 'K'; synced_other <= 'Z'; synced_other++ ) {
|
||||||
snprintf( dir, 512, "Airports/%c", synced_other );
|
char dir[512];
|
||||||
waitingTiles.push_back( dir );
|
snprintf( dir, 512, "Airports/%c", synced_other );
|
||||||
}
|
waitingTiles.push_back( dir );
|
||||||
for ( synced_other = 'A'; synced_other <= 'J'; synced_other++ ) {
|
}
|
||||||
char dir[512];
|
for ( synced_other = 'A'; synced_other <= 'J'; synced_other++ ) {
|
||||||
snprintf( dir, 512, "Airports/%c", synced_other );
|
char dir[512];
|
||||||
waitingTiles.push_back( dir );
|
snprintf( dir, 512, "Airports/%c", synced_other );
|
||||||
}
|
waitingTiles.push_back( dir );
|
||||||
if ( use_svn ) {
|
}
|
||||||
waitingTiles.push_back( "Models" );
|
if ( use_svn ) {
|
||||||
|
waitingTiles.push_back( "Models" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( true ) {
|
|
||||||
|
while ( true ) { // main loop
|
||||||
recv_msg = false;
|
recv_msg = false;
|
||||||
if ( testing ) {
|
if ( testing ) {
|
||||||
// No FGFS communications
|
// No FGFS communications
|
||||||
lat = 37;
|
lat = 37;
|
||||||
lon = -123;
|
lon = -123;
|
||||||
recv_msg = (lat != last_lat) || (lon != last_lon);
|
recv_msg = (lat != last_lat) || (lon != last_lon);
|
||||||
}
|
} else {
|
||||||
while ( (len = s.recv(msg, maxlen, 0)) >= 0 ) {
|
s.setBlocking(waitingTiles.empty());
|
||||||
msg[len] = '\0';
|
len = s.recv(msg, maxlen, 0);
|
||||||
recv_msg = true;
|
if (len >= 0) {
|
||||||
|
msg[len] = '\0';
|
||||||
parse_message( msg, &lat, &lon );
|
recv_msg = true;
|
||||||
|
if (verbose) cout << "recv length: " << len << endl;
|
||||||
|
parse_message( msg, &lat, &lon );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( recv_msg ) {
|
if ( recv_msg ) {
|
||||||
|
@ -527,22 +572,17 @@ int main( int argc, char **argv ) {
|
||||||
last_lat = lat;
|
last_lat = lat;
|
||||||
last_lon = lon;
|
last_lon = lon;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
|
||||||
// No messages inbound, so process some pending work
|
// No messages inbound, so process some pending work
|
||||||
if ( !waitingTiles.empty() ) {
|
else if ( !waitingTiles.empty() ) {
|
||||||
getWaitingTile();
|
getWaitingTile();
|
||||||
} else
|
}
|
||||||
|
|
||||||
if ( testing ) {
|
else if ( testing ) {
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if ( last_lat == nowhere || last_lon == nowhere ) {
|
|
||||||
cout << "FlightGear is not running, exiting." << endl;
|
|
||||||
exit( 1 );
|
|
||||||
} else
|
|
||||||
|
|
||||||
ulSleep( 1 );
|
ulSleep( 1 );
|
||||||
} // while true
|
} // while true
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue