From: Tom H. <tom...@us...> - 2004-07-08 02:16:57
|
Update of /cvsroot/rccparser/rcclient/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12925/src Modified Files: Makefile.am rcclient.cpp rcctest.cpp Added Files: rcclient.hpp rccofflinecoach.cpp rccofflinecoach.hpp rcconlinecoach.cpp rcconlinecoach.hpp rccplayer.cpp rccplayer.hpp Removed Files: rcclient.h Log Message: 2003-01-10 Tom Howard <tom...@us...> * ./configure.ac Released rcclient-0.0.1 --- NEW FILE: rcclient.hpp --- // -*-c++-*- /*************************************************************************** rcclient.hpp RoboCup Client ------------------- begin : 03-JAN-2003 copyright : (C) 2003 by Tom Howard email : tom...@us... ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef RCCLIENT_HPP #define RCCLIENT_HPP #include <rccparser/rccparser.h> #include <boost/shared_ptr.hpp> #include <rcssbase/net/addr.hpp> #include <rcssbase/net/udpsocket.hpp> #include <rcssbase/net/iosocketstream.hpp> #include <rcssbase/gz/gzstream.hpp> #include <rccserializer/rccplayerserializer.hpp> #include <rccserializer/rccofflinecoachserializer.hpp> #include <rccserializer/rcconlinecoachserializer.hpp> namespace rcc { template< typename S > class Client : public Parser, public S { public: typedef S Serializer; Client() : m_input( NULL ), m_output( NULL ), m_level( -1 ) {} Client( std::iostream& io, int io_buffer_size = 8192 ) : m_input( NULL ), m_output( NULL ), m_level( -1 ) { setInput( io, io_buffer_size ); setOutput( io, io_buffer_size ); } Client( std::istream& input, std::ostream& output, int input_buffer_size = 8192, int output_buffer_size = 8192 ) : m_input( NULL ), m_output( NULL ), m_level( -1 ) { setInput( input, input_buffer_size ); setOutput( output, output_buffer_size ); } ~Client() {} void setCompression( int level ) { m_cinput->setLevel( level ); m_coutput->setLevel( level ); m_level = level; } int getCompression() const { return m_level; } bool operator()() { while( input().good() ) { if( !parse( input() ) ) return false; } return true; } void setInput( std::istream& i, int input_buffer_size ) { m_input = &i; m_cinput.reset( new rcss::gz::gzistream( i, input_buffer_size ) ); m_cinput->setLevel( m_level ); } void setOutput( std::ostream& o, int output_buffer_size ) { m_output = &o; m_coutput.reset( new rcss::gz::gzostream( o, output_buffer_size ) ); m_coutput->setLevel( m_level ); Serializer::setOutput( *m_coutput ); } private: std::istream& input() { return *m_cinput; } std::ostream& output() { return *m_coutput; } std::istream* m_input; std::ostream* m_output; boost::shared_ptr< rcss::gz::gzistream > m_cinput; boost::shared_ptr< rcss::gz::gzostream > m_coutput; int m_level; }; template< typename S > class UDPClient { public: typedef S Serializer; UDPClient( Client< S >& client, const rcss::net::Addr& addr, int input_buffer_size = 8192, int output_buffer_size = 8192 ) : m_client( client ), m_input( m_socket, input_buffer_size ), m_output( m_socket, output_buffer_size ) { m_input.setEndPoint( addr ); m_output.setEndPoint( addr ); m_client.setInput( m_input, input_buffer_size ); m_client.setOutput( m_output, output_buffer_size ); } bool operator()() { m_client(); } Serializer& serializer() { return m_client; } private: Client< S >& m_client; rcss::net::UDPSocket m_socket; rcss::net::ISocketStream m_input; rcss::net::OSocketStream m_output; }; } #endif --- NEW FILE: rccofflinecoach.cpp --- // -*-c++-*- /*************************************************************************** rccofflinecoach.cpp RoboCup Offline Coach Client ------------------- begin : 08-JUL-2004 copyright : (C) 2004 by Tom Howard email : tom...@us... ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include "rccofflinecoach.hpp" namespace rcc { } --- NEW FILE: rccofflinecoach.hpp --- // -*-c++-*- /*************************************************************************** rccofflinecoach.hpp RoboCup Offline Coach Client ------------------- begin : 08-JUL-2004 copyright : (C) 2004 by Tom Howard email : tom...@us... ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef RCCOFFLINECOACH_HPP #define RCCOFFLINECOACH_HPP #include "rcclient.hpp" #include <rccserializer/rccofflinecoachserializer.hpp> namespace rcc { typedef Client< OfflineCoachSerializer > OfflineCoach; typedef UDPClient< OfflineCoachSerializer > UDPOfflineCoach; } #endif --- NEW FILE: rcconlinecoach.cpp --- // -*-c++-*- /*************************************************************************** rcconlinecoach.cpp RoboCup Online Coach Client ------------------- begin : 08-JUL-2004 copyright : (C) 2004 by Tom Howard email : tom...@us... ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include "rcconlinecoach.hpp" namespace rcc { } --- NEW FILE: rcconlinecoach.hpp --- // -*-c++-*- /*************************************************************************** rcconlinecoach.hpp RoboCup Online Coach Client ------------------- begin : 08-JUL-2004 copyright : (C) 2004 by Tom Howard email : tom...@us... ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef RCCONLINECOACH_HPP #define RCCONLINECOACH_HPP #include "rcclient.hpp" #include <rccserializer/rcconlinecoachserializer.hpp> namespace rcc { typedef Client< OnlineCoachSerializer > OnlineCoach; typedef UDPClient< OnlineCoachSerializer > UDPOnlineCoach; } #endif --- NEW FILE: rccplayer.cpp --- // -*-c++-*- /*************************************************************************** rccplayer.cpp RoboCup Player Client ------------------- begin : 08-JUL-2004 copyright : (C) 2004 by Tom Howard email : tom...@us... ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include "rccplayer.hpp" namespace rcc { } --- NEW FILE: rccplayer.hpp --- // -*-c++-*- /*************************************************************************** rccplayer.hpp RoboCup Player Client ------------------- begin : 08-JUL-2004 copyright : (C) 2004 by Tom Howard email : tom...@us... ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef RCCPLAYER_HPP #define RCCPLAYER_HPP #include "rcclient.hpp" #include <rccserializer/rccplayerserializer.hpp> namespace rcc { typedef Client< PlayerSerializer > Player; typedef UDPClient< PlayerSerializer > UDPPlayer; } #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/rccparser/rcclient/src/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.am 6 Jan 2003 17:22:46 -0000 1.2 --- Makefile.am 8 Jul 2004 02:16:46 -0000 1.3 *************** *** 1,3 **** ! lib_LTLIBRARIES = librcclient.la CLEANFILES = \ --- 1,7 ---- ! lib_LTLIBRARIES = \ ! librcclient.la \ ! librccplayer.la \ ! librcconlinecoach.la \ ! librccofflinecoach.la CLEANFILES = \ *************** *** 8,12 **** rcclient.cpp ! librcclient_la_LDFLAGS = -version-info 0:0:0 # 1. Start with version information of `0:0:0' for each libtool library. # --- 12,28 ---- rcclient.cpp ! librccplayer_la_SOURCES = \ ! rccplayer.cpp ! ! librcconlinecoach_la_SOURCES = \ ! rcconlinecoach.cpp ! ! librccofflinecoach_la_SOURCES = \ ! rccofflinecoach.cpp ! ! librcclient_la_LDFLAGS = -version-info 1:0:0 ! librccplayer_la_LDFLAGS = -version-info 0:0:0 ! librcconlinecoach_la_LDFLAGS = -version-info 0:0:0 ! librccofflinecoach_la_LDFLAGS = -version-info 0:0:0 # 1. Start with version information of `0:0:0' for each libtool library. # *************** *** 28,36 **** # then set AGE to 0. ! pkginclude_HEADERS = \ ! rcclient.h bin_PROGRAMS = rcctest rcctest_SOURCES = rcctest.cpp ! rcctest_LDADD = librcclient.la --- 44,59 ---- # then set AGE to 0. ! librcclient_la_LIBADD = -lrcssbase -lrcssnet -lrcssgz -lrccparser ! librccplayer_la_LIBADD = librcclient.la -lrccplayerserializer ! librcconlinecoach_la_LIBADD = librcclient.la -lrcconlinecoachserializer ! librccofflinecoach_la_LIBADD = librcclient.la -lrccofflinecoachserializer + pkginclude_HEADERS = \ + rcclient.hpp \ + rccplayer.hpp \ + rcconlinecoach.hpp \ + rccofflinecoach.hpp bin_PROGRAMS = rcctest rcctest_SOURCES = rcctest.cpp ! rcctest_LDADD = librccplayer.la Index: rcclient.cpp =================================================================== RCS file: /cvsroot/rccparser/rcclient/src/rcclient.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rcclient.cpp 10 Jan 2003 18:56:47 -0000 1.4 --- rcclient.cpp 8 Jul 2004 02:16:46 -0000 1.5 *************** *** 19,350 **** ***************************************************************************/ - #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" }; ! const char* Client::VIEW_QUALITIES[] = { "low", "high" }; ! const char* Client::TEAMS[] = { "left", "right", "our", "opp" }; ! const char* Client::EAR_MODES[] = { "partial", "complete" }; ! const char* Client::ON_OFF[] = { "on", "off" }; ! ! std::ostream& ! operator<<( std::ostream& o, Client::PlayerType player ) ! { ! o << Client::PLAYERS[ player ]; ! } ! ! std::ostream& ! operator<<( std::ostream& o, Client::ViewWidthType width ) ! { ! o << Client::VIEW_WIDTHS[ width ]; ! } ! ! std::ostream& ! operator<<( std::ostream& o, Client::ViewQualityType qual ) ! { ! o << Client::VIEW_QUALITIES[ qual ]; ! } ! ! std::ostream& ! operator<<( std::ostream& o, Client::TeamType team ) ! { ! o << Client::TEAMS[ team ]; ! } ! ! std::ostream& ! operator<<( std::ostream& o, Client::EarModeType ear_mode ) ! { ! o << Client::EAR_MODES[ ear_mode ]; ! } ! ! std::ostream& ! operator<<( std::ostream& o, Client::OnOffType on_off ) ! { ! o << Client::ON_OFF[ on_off ]; ! } ! ! 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; ! } ! ! void ! Client::init( const std::string& team_name, int version, ! PlayerType type ) ! { ! output() << "(init " << team_name << " (version " << version << ")" ! << type << ")" << std::ends << std::flush; ! } ! ! void ! Client::reconnect( const std::string& team_name, int unum ) ! { ! output() << "(reconnect " << team_name << " " << unum << ")" ! << std::ends << std::flush; ! } ! ! void ! Client::dash( double power ) ! { ! output() << "(dash " << power << ")" << std::ends << std::flush; ! } ! ! void ! Client::turn( double moment ) ! { ! output() << "(turn " << moment << ")" << std::ends << std::flush; ! } ! ! void ! Client::turnNeck( double moment ) ! { ! output() << "(turn_neck " << moment << ")" << std::ends << std::flush; ! } ! ! void ! Client::kick( double power, double dir ) ! { ! output() << "(kick " << power << " " << dir << ")" ! << std::ends << std::flush; ! } ! ! void ! Client::catchBall( double dir ) ! { ! output() << "(catch " << dir << ")" << std::ends << std::flush; ! } ! ! void ! Client::say( std::string message ) ! { ! output() << "(say \"" << message << "\")" << std::ends << std::flush; ! } ! ! void ! Client::senseBody() ! { ! output() << "(sense_body)" << std::ends << std::flush; ! } ! ! void ! Client::score() ! { ! output() << "(score)" << std::ends << std::flush; ! } ! ! void ! Client::move( double x, double y ) ! { ! output() << "(move " << x << " " << y << ")" ! << std::ends << std::flush; ! } ! ! void ! 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; ! } ! ! void ! Client::done() ! { ! output() << "(done)" << std::ends << std::flush; ! } ! ! void ! Client::pointTo( double dist, double head ) ! { ! output() << "(pointto " << dist << " " << head << ")" ! << std::ends << std::flush; ! } ! ! void ! Client::pointToOff() ! { ! output() << "(pointto off)" << std::ends << std::flush; ! } ! ! void ! Client::attentionTo( TeamType team, int unum ) ! { ! output() << "(attentionto " << team << " " << unum << ")" ! << std::ends << std::flush; ! } ! ! void ! Client::attentionTo( const std::string& team_name, int unum ) ! { ! output() << "(attentionto " << team_name << " " << unum << ")" ! << std::ends << std::flush; ! } ! ! void ! Client::attentionToOff() ! { ! output() << "(attentionto off)" << std::ends << std::flush; ! } ! ! void ! Client::tackle( double power ) ! { ! output() << "(tackle " << power << ")" << std::ends << std::flush; ! } ! ! void ! Client::clangVer( int min, int max ) ! { ! output() << "(clang (ver " << min << " " << max << "))" ! << std::ends << std::flush; ! } ! ! void ! Client::ear( OnOffType on_off, TeamType side, EarModeType mode ) ! { ! output() << "(ear (" << on_off << " " << side << " " << mode << "))" ! << std::ends << std::flush; ! } ! ! void ! Client::ear( OnOffType on_off, const std::string& team, EarModeType mode ) ! { ! output() << "(ear (" << on_off << " " << team << " " << mode << "))" ! << std::ends << std::flush; ! } ! ! void ! Client::ear( OnOffType on_off, TeamType side ) ! { ! output() << "(ear (" << on_off << " " << side << "))" ! << std::ends << std::flush; ! } ! ! void ! Client::ear( OnOffType on_off, const std::string& team ) ! { ! output() << "(ear (" << on_off << " " << team << "))" ! << std::ends << std::flush; ! } ! ! void ! Client::ear( OnOffType on_off, EarModeType mode ) ! { ! output() << "(ear (" << on_off << " " << mode << "))" ! << std::ends << std::flush; ! } ! ! void ! 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; } ! } --- 19,28 ---- ***************************************************************************/ ! #include "rcclient.hpp" namespace rcc { ! ! } Index: rcctest.cpp =================================================================== RCS file: /cvsroot/rccparser/rcclient/src/rcctest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** rcctest.cpp 10 Jan 2003 18:56:48 -0000 1.2 --- rcctest.cpp 8 Jul 2004 02:16:46 -0000 1.3 *************** *** 19,47 **** ***************************************************************************/ ! #include "rcclient.h" ! ! class CLangParser ! : public rcss::Parser ! { ! bool ! doParse( std::istream& ) ! { return true; } ! }; ! class ClientParser ! : public rcc::Parser { public: ! ClientParser( rcss::Parser& clp ) ! : rcc::Parser( clp ), ! m_client( NULL ), ! m_level( -1 ) ! {} ! ! void ! setClient( rcc::Client& client ) ! { ! m_client = &client; ! } private: --- 19,31 ---- ***************************************************************************/ ! #include "rccplayer.hpp" ! #include <rccserializer/rccplayerserializer.hpp> ! class TestClient ! : public rcc::Player { public: ! TestClient() ! {} private: *************** *** 51,59 **** { std::cout << "Got init\n"; ! if( m_client ) ! { ! m_client->move( -10, -10 ); ! m_client->compression( 9 ); ! } } --- 35,40 ---- { std::cout << "Got init\n"; ! move( -10, -10 ); ! compression( 9 ); } *************** *** 62,69 **** doBuildCompressionOK( int level ) { ! m_client->setCompression( level ); ! m_level = level; ! std::cout << "Compression level changed to " << level << std::endl; ! } --- 43,48 ---- doBuildCompressionOK( int level ) { ! setCompression( level ); ! std::cout << "Compression level changed to " << level << std::endl; } *************** *** 85,104 **** int chg_view_count ) { ! if( m_level == 9 ) ! m_client->move( -20, -20 ); } - private: - rcc::Client* m_client; - int m_level; }; int main() { ! CLangParser clp; ! ClientParser parser( clp ); ! rcc::Client client( parser, rcss::net::Addr( 6000, "localhost" ) ); ! parser.setClient( client ); ! ! client.init( "test", 8 ); ! client(); } --- 64,80 ---- int chg_view_count ) { ! if( getCompression() == 9 ) ! move( -20, -20 ); } }; int main() { ! rcss::net::Addr addr( 6000 ); ! if( !addr.setHost( "localhost" ) ) ! exit( EXIT_FAILURE ); ! TestClient player; ! rcc::UDPPlayer udpplayer( player, addr ); ! udpplayer.serializer().init( "test", 8 ); ! udpplayer(); } --- rcclient.h DELETED --- |