From: Tom H. <tom...@us...> - 2003-01-10 18:56:52
|
Update of /cvsroot/rccparser/rcclient/src In directory sc8-pr-cvs1:/tmp/cvs-serv3353/src Modified Files: rcclient.cpp rcclient.h rcctest.cpp Log Message: 2003-01-10 Tom Howard <tom...@us...> * ./README Updated readme * ./acinclude.m4 * ./configure.ac Added macro from rcssnet detection * ./src/rcclient.cpp * ./src/rcclient.h * ./src/rcctest.cpp Integrated with rcssnet and added compression support Index: rcclient.cpp =================================================================== RCS file: /cvsroot/rccparser/rcclient/src/rcclient.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** rcclient.cpp 6 Jan 2003 17:22:49 -0000 1.3 --- rcclient.cpp 10 Jan 2003 18:56:47 -0000 1.4 *************** *** 2,10 **** /*************************************************************************** ! rcclient.cpp RoboCup Client ------------------- ! begin : 24-MAY-2002 ! copyright : (C) 2002 by Tom Howard email : tom...@us... ***************************************************************************/ --- 2,10 ---- /*************************************************************************** ! rcclient.cpp RoboCup Client ------------------- ! begin : 03-JAN-2003 ! copyright : (C) 2003 by Tom Howard email : tom...@us... ***************************************************************************/ *************** *** 13,17 **** * * * This program is free software; you can redistribute it and/or modify * ! * it under the terms of the GNU LGPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * --- 13,17 ---- * * * This program is free software; you can redistribute it and/or modify * ! * it under the terms of the GNU GPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * *************** *** 19,27 **** --- 19,83 ---- ***************************************************************************/ + #ifdef HAVE_CONFIG_H + #include "config.h" + #endif #include "rcclient.h" + #include <rcssbase/net/udpsocket.hpp> + #include <rcssbase/net/iosocketstream.hpp> + #include <rcssbase/gzstream.h> namespace rcc { + class ClientImpl + { + public: + ClientImpl( Parser& parser, const rcss::net::Addr& addr, + int input_buffer_size, int output_buffer_size ) + : m_parser( parser ), + m_socket(), + m_input( m_socket, input_buffer_size ), + m_output( m_socket, output_buffer_size ), + m_cinput( (std::istream&)m_input ), + m_coutput( (std::ostream&)m_output ) + { + m_input.setEndPoint( addr ); + m_output.setEndPoint( addr ); + m_cinput.setLevel( -1 ); + m_coutput.setLevel( -1 ); + } + + ~ClientImpl() + { + m_socket.close(); + } + + Parser& + parser() + { return m_parser; } + + std::istream& + input() + { return m_cinput; } + + std::ostream& + output() + { return m_coutput; } + + void + setCompression( int level ) + { + m_cinput.setLevel( level ); + m_coutput.setLevel( level ); + } + private: + Parser& m_parser; + rcss::net::UDPSocket m_socket; + rcss::net::ISocketStream m_input; + rcss::net::OSocketStream m_output; + rcss::gz::gzistream m_cinput; + rcss::gz::gzostream m_coutput; + }; + const char* Client::PLAYERS[] = { "", "(goalie)" }; const char* Client::VIEW_WIDTHS[] = { "narrow", "normal", "wide" }; *************** *** 67,116 **** } ! Client::Client( Parser& parser, const rcss::UDPSocket::addr_type& addr, ! int input_buffer_size, int output_buffer_size ) ! : m_parser( parser ), ! m_socket(), ! m_input( m_socket, input_buffer_size ), ! m_output( m_socket, output_buffer_size ) ! { ! m_input.setEndPoint( addr ); ! m_output.setEndPoint( addr ); ! } ! ! Client::Client( Parser& parser, ! const rcss::UDPSocket::port_type& port, ! const rcss::UDPSocket::host_type& host, ! int input_buffer_size, int output_buffer_size ) ! : m_parser( parser ), ! m_socket(), ! m_input( m_socket, input_buffer_size ), ! m_output( m_socket, output_buffer_size ) ! { ! m_input.setEndPoint( port, host ); ! m_output.setEndPoint( port, host ); ! } ! ! Client::Client( Parser& parser, ! const rcss::UDPSocket::port_type& port, ! const std::string& host, int input_buffer_size, int output_buffer_size ) ! : m_parser( parser ), ! m_socket(), ! m_input( m_socket, input_buffer_size ), ! m_output( m_socket, output_buffer_size ) ! { ! m_input.setEndPoint( port, host ); ! m_output.setEndPoint( port, host ); ! } ! Client::~Client() ! { ! m_socket.close(); ! } bool Client::operator()() { ! return m_parser.parse( m_input ); } --- 123,160 ---- } ! Client::Client( Parser& parser, const rcss::net::Addr& addr, int input_buffer_size, int output_buffer_size ) ! : m_impl( new ClientImpl( parser, addr, ! input_buffer_size, output_buffer_size ) ) ! {} ! Client::~Client() ! {} ! ! void ! Client::setCompression( int level ) ! { m_impl->setCompression( level ); } ! ! std::istream& ! Client::input() ! { return m_impl->input(); } ! ! std::ostream& ! Client::output() ! { return m_impl->output(); } ! ! Parser& ! Client::parser() ! { return m_impl->parser(); } bool Client::operator()() { ! while( input().good() ) ! { ! if( !parser().parse( input() ) ) ! return false; ! } ! return true; } *************** *** 119,123 **** PlayerType type ) { ! m_output << "(init " << team_name << " (version " << version << ")" << type << ")" << std::ends << std::flush; } --- 163,167 ---- PlayerType type ) { ! output() << "(init " << team_name << " (version " << version << ")" << type << ")" << std::ends << std::flush; } *************** *** 126,130 **** Client::reconnect( const std::string& team_name, int unum ) { ! m_output << "(reconnect " << team_name << " " << unum << ")" << std::ends << std::flush; } --- 170,174 ---- Client::reconnect( const std::string& team_name, int unum ) { ! output() << "(reconnect " << team_name << " " << unum << ")" << std::ends << std::flush; } *************** *** 133,137 **** Client::dash( double power ) { ! m_output << "(dash " << power << ")" << std::ends << std::flush; } --- 177,181 ---- Client::dash( double power ) { ! output() << "(dash " << power << ")" << std::ends << std::flush; } *************** *** 139,143 **** Client::turn( double moment ) { ! m_output << "(turn " << moment << ")" << std::ends << std::flush; } --- 183,187 ---- Client::turn( double moment ) { ! output() << "(turn " << moment << ")" << std::ends << std::flush; } *************** *** 145,149 **** Client::turnNeck( double moment ) { ! m_output << "(turn_neck " << moment << ")" << std::ends << std::flush; } --- 189,193 ---- Client::turnNeck( double moment ) { ! output() << "(turn_neck " << moment << ")" << std::ends << std::flush; } *************** *** 151,155 **** Client::kick( double power, double dir ) { ! m_output << "(kick " << power << " " << dir << ")" << std::ends << std::flush; } --- 195,199 ---- Client::kick( double power, double dir ) { ! output() << "(kick " << power << " " << dir << ")" << std::ends << std::flush; } *************** *** 158,162 **** Client::catchBall( double dir ) { ! m_output << "(catch " << dir << ")" << std::ends << std::flush; } --- 202,206 ---- Client::catchBall( double dir ) { ! output() << "(catch " << dir << ")" << std::ends << std::flush; } *************** *** 164,168 **** Client::say( std::string message ) { ! m_output << "(say \"" << message << "\")" << std::ends << std::flush; } --- 208,212 ---- Client::say( std::string message ) { ! output() << "(say \"" << message << "\")" << std::ends << std::flush; } *************** *** 170,174 **** Client::senseBody() { ! m_output << "(sense_body)" << std::ends << std::flush; } --- 214,218 ---- Client::senseBody() { ! output() << "(sense_body)" << std::ends << std::flush; } *************** *** 176,180 **** Client::score() { ! m_output << "(score)" << std::ends << std::flush; } --- 220,224 ---- Client::score() { ! output() << "(score)" << std::ends << std::flush; } *************** *** 182,186 **** Client::move( double x, double y ) { ! m_output << "(move " << x << " " << y << ")" << std::ends << std::flush; } --- 226,230 ---- Client::move( double x, double y ) { ! output() << "(move " << x << " " << y << ")" << std::ends << std::flush; } *************** *** 189,203 **** Client::changeView( ViewWidthType width, ViewQualityType quality ) { ! m_output << "(change_view " << width << " " << quality << ")" << std::ends << std::flush; } ! // void ! // Client::compression( int level ); void Client::bye() { ! m_output << "(bye)" << std::ends << std::flush; } --- 233,251 ---- Client::changeView( ViewWidthType width, ViewQualityType quality ) { ! output() << "(change_view " << width << " " << quality << ")" << std::ends << std::flush; } ! void ! Client::compression( int level ) ! { ! output() << "(compression " << level << ")" ! << std::ends << std::flush; ! } void Client::bye() { ! output() << "(bye)" << std::ends << std::flush; } *************** *** 205,209 **** Client::done() { ! m_output << "(done)" << std::ends << std::flush; } --- 253,257 ---- Client::done() { ! output() << "(done)" << std::ends << std::flush; } *************** *** 211,215 **** Client::pointTo( double dist, double head ) { ! m_output << "(pointto " << dist << " " << head << ")" << std::ends << std::flush; } --- 259,263 ---- Client::pointTo( double dist, double head ) { ! output() << "(pointto " << dist << " " << head << ")" << std::ends << std::flush; } *************** *** 218,222 **** Client::pointToOff() { ! m_output << "(pointto off)" << std::ends << std::flush; } --- 266,270 ---- Client::pointToOff() { ! output() << "(pointto off)" << std::ends << std::flush; } *************** *** 224,228 **** Client::attentionTo( TeamType team, int unum ) { ! m_output << "(attentionto " << team << " " << unum << ")" << std::ends << std::flush; } --- 272,276 ---- Client::attentionTo( TeamType team, int unum ) { ! output() << "(attentionto " << team << " " << unum << ")" << std::ends << std::flush; } *************** *** 231,235 **** Client::attentionTo( const std::string& team_name, int unum ) { ! m_output << "(attentionto " << team_name << " " << unum << ")" << std::ends << std::flush; } --- 279,283 ---- Client::attentionTo( const std::string& team_name, int unum ) { ! output() << "(attentionto " << team_name << " " << unum << ")" << std::ends << std::flush; } *************** *** 238,242 **** Client::attentionToOff() { ! m_output << "(attentionto off)" << std::ends << std::flush; } --- 286,290 ---- Client::attentionToOff() { ! output() << "(attentionto off)" << std::ends << std::flush; } *************** *** 244,248 **** Client::tackle( double power ) { ! m_output << "(tackle " << power << ")" << std::ends << std::flush; } --- 292,296 ---- Client::tackle( double power ) { ! output() << "(tackle " << power << ")" << std::ends << std::flush; } *************** *** 250,254 **** Client::clangVer( int min, int max ) { ! m_output << "(clang (ver " << min << " " << max << "))" << std::ends << std::flush; } --- 298,302 ---- Client::clangVer( int min, int max ) { ! output() << "(clang (ver " << min << " " << max << "))" << std::ends << std::flush; } *************** *** 257,261 **** Client::ear( OnOffType on_off, TeamType side, EarModeType mode ) { ! m_output << "(ear (" << on_off << " " << side << " " << mode << "))" << std::ends << std::flush; } --- 305,309 ---- Client::ear( OnOffType on_off, TeamType side, EarModeType mode ) { ! output() << "(ear (" << on_off << " " << side << " " << mode << "))" << std::ends << std::flush; } *************** *** 264,268 **** Client::ear( OnOffType on_off, const std::string& team, EarModeType mode ) { ! m_output << "(ear (" << on_off << " " << team << " " << mode << "))" << std::ends << std::flush; } --- 312,316 ---- Client::ear( OnOffType on_off, const std::string& team, EarModeType mode ) { ! output() << "(ear (" << on_off << " " << team << " " << mode << "))" << std::ends << std::flush; } *************** *** 271,275 **** Client::ear( OnOffType on_off, TeamType side ) { ! m_output << "(ear (" << on_off << " " << side << "))" << std::ends << std::flush; } --- 319,323 ---- Client::ear( OnOffType on_off, TeamType side ) { ! output() << "(ear (" << on_off << " " << side << "))" << std::ends << std::flush; } *************** *** 278,282 **** Client::ear( OnOffType on_off, const std::string& team ) { ! m_output << "(ear (" << on_off << " " << team << "))" << std::ends << std::flush; } --- 326,330 ---- Client::ear( OnOffType on_off, const std::string& team ) { ! output() << "(ear (" << on_off << " " << team << "))" << std::ends << std::flush; } *************** *** 285,289 **** Client::ear( OnOffType on_off, EarModeType mode ) { ! m_output << "(ear (" << on_off << " " << mode << "))" << std::ends << std::flush; } --- 333,337 ---- Client::ear( OnOffType on_off, EarModeType mode ) { ! output() << "(ear (" << on_off << " " << mode << "))" << std::ends << std::flush; } *************** *** 292,299 **** Client::ear( OnOffType on_off ) { ! m_output << "(ear (" << on_off << "))" << std::ends << std::flush; } } --- 340,350 ---- Client::ear( OnOffType on_off ) { ! output() << "(ear (" << on_off << "))" << std::ends << std::flush; } + void + Client::sendUnknown( const std::string& message ) + { output() << message << std::ends << std::flush; } } Index: rcclient.h =================================================================== RCS file: /cvsroot/rccparser/rcclient/src/rcclient.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** rcclient.h 6 Jan 2003 17:22:53 -0000 1.2 --- rcclient.h 10 Jan 2003 18:56:48 -0000 1.3 *************** *** 5,10 **** RoboCup Client ------------------- ! begin : 24-MAY-2002 ! copyright : (C) 2002 by Tom Howard email : tom...@us... ***************************************************************************/ --- 5,10 ---- RoboCup Client ------------------- ! begin : 03-JAN-2003 ! copyright : (C) 2003 by Tom Howard email : tom...@us... ***************************************************************************/ *************** *** 13,17 **** * * * This program is free software; you can redistribute it and/or modify * ! * it under the terms of the GNU LGPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * --- 13,17 ---- * * * This program is free software; you can redistribute it and/or modify * ! * it under the terms of the GNU GPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * *************** *** 22,34 **** #define RCCLIENT_H - #ifdef HAVE_CONFIG_H - #include "config.h" - #endif - #include <rccparser/rccparser.h> ! #include <rcssbase/udpsocket.h> namespace rcc { class Client { --- 22,33 ---- #define RCCLIENT_H #include <rccparser/rccparser.h> ! #include <boost/shared_ptr.hpp> ! #include <rcssbase/net/addr.hpp> namespace rcc { + class ClientImpl; + class Client { *************** *** 73,91 **** operator<<( std::ostream& o, OnOffType on_off ); ! Client( Parser& parser, const rcss::UDPSocket::addr_type& addr, ! int input_buffer_size = 8192, int output_buffer_size = 8192 ); ! ! Client( Parser& parser, ! const rcss::UDPSocket::port_type& port, ! const rcss::UDPSocket::host_type& host = INADDR_ANY, ! int input_buffer_size = 8192, int output_buffer_size = 8192 ); ! ! Client( Parser& parser, ! const rcss::UDPSocket::port_type& port, ! const std::string& host, int input_buffer_size = 8192, int output_buffer_size = 8192 ); ! ~Client(); bool operator()(); --- 72,83 ---- operator<<( std::ostream& o, OnOffType on_off ); ! Client( Parser& parser, const rcss::net::Addr& addr, int input_buffer_size = 8192, int output_buffer_size = 8192 ); ! ~Client(); + void + setCompression( int level ); + bool operator()(); *************** *** 128,133 **** changeView( ViewWidthType width, ViewQualityType quality ); ! // void ! // compression( int level ); void --- 120,125 ---- changeView( ViewWidthType width, ViewQualityType quality ); ! void ! compression( int level ); void *************** *** 176,184 **** ear( OnOffType on_off ); private: ! Parser& m_parser; ! rcss::UDPSocket m_socket; ! rcss::IUDPSocketStream m_input; ! rcss::OUDPSocketStream m_output; }; } --- 168,184 ---- ear( OnOffType on_off ); + void + sendUnknown( const std::string& message ); private: ! std::istream& ! input(); ! ! std::ostream& ! output(); ! ! Parser& ! parser(); ! ! boost::shared_ptr< ClientImpl > m_impl; }; } Index: rcctest.cpp =================================================================== RCS file: /cvsroot/rccparser/rcclient/src/rcctest.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** rcctest.cpp 6 Jan 2003 15:11:07 -0000 1.1.1.1 --- rcctest.cpp 10 Jan 2003 18:56:48 -0000 1.2 *************** *** 2,10 **** /*************************************************************************** ! rcclient.cpp ! RoboCup Client ------------------- ! begin : 24-MAY-2002 ! copyright : (C) 2002 by Tom Howard email : tom...@us... ***************************************************************************/ --- 2,10 ---- /*************************************************************************** ! rcctest.cpp ! Dumb RoboCup Client ------------------- ! begin : 02-JAN-2003 ! copyright : (C) 2003 by Tom Howard email : tom...@us... ***************************************************************************/ *************** *** 13,17 **** * * * This program is free software; you can redistribute it and/or modify * ! * it under the terms of the GNU LGPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * --- 13,17 ---- * * * This program is free software; you can redistribute it and/or modify * ! * it under the terms of the GNU GPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * *************** *** 35,39 **** ClientParser( rcss::Parser& clp ) : rcc::Parser( clp ), ! m_client( NULL ) {} --- 35,40 ---- ClientParser( rcss::Parser& clp ) : rcc::Parser( clp ), ! m_client( NULL ), ! m_level( -1 ) {} *************** *** 49,58 **** doBuildInit( int unum ) { if( m_client ) ! m_client->move( 0, 0 ); } private: rcc::Client* m_client; }; --- 50,94 ---- doBuildInit( int unum ) { + std::cout << "Got init\n"; if( m_client ) ! { ! m_client->move( -10, -10 ); ! m_client->compression( 9 ); ! } ! } ! ! virtual ! void ! doBuildCompressionOK( int level ) ! { ! m_client->setCompression( level ); ! m_level = level; ! std::cout << "Compression level changed to " << level << std::endl; ! } + virtual + void + doBuildSenseBody( int time, + double stamina, + double effort, + double speed_mag, + double speed_head, + double head_angle, + int kick_count, + int dash_count, + int turn_count, + int say_count, + int turn_neck_count, + int catch_count, + int move_count, + int chg_view_count ) + { + if( m_level == 9 ) + m_client->move( -20, -20 ); + } private: rcc::Client* m_client; + int m_level; }; *************** *** 61,65 **** CLangParser clp; ClientParser parser( clp ); ! rcc::Client client( parser, 6000, "localhost" ); parser.setClient( client ); --- 97,101 ---- CLangParser clp; ClientParser parser( clp ); ! rcc::Client client( parser, rcss::net::Addr( 6000, "localhost" ) ); parser.setClient( client ); |