playertcp.h

00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2005 -
00004  *     Brian Gerkey
00005  *
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 /*
00024  * Interface to libplayertcp
00025  *
00026  * $Id: playertcp.h,v 1.20.2.1 2006/04/20 00:11:22 gerkey Exp $
00027  */
00028 
00076 #ifndef _PLAYERTCP_H_
00077 #define _PLAYERTCP_H_
00078 
00079 #include <sys/types.h>
00080 #include <sys/socket.h>
00081 #include <netinet/in.h>
00082 #include <pthread.h>
00083 
00084 #include <libplayercore/playercore.h>
00085 
00087 #define PLAYERTCP_DEFAULT_PORT 6665
00088 
00091 #define PLAYERTCP_READBUFFER_SIZE 65536
00092 
00095 #define PLAYERTCP_WRITEBUFFER_SIZE 65536
00096 
00097 // Forward declarations
00098 struct pollfd;
00099 
00100 struct playertcp_listener;
00101 struct playertcp_conn;
00102 
00103 class PlayerTCP
00104 {
00105   private:
00106     uint32_t host;
00107     int num_listeners;
00108     playertcp_listener* listeners;
00109     struct pollfd* listen_ufds;
00110 
00111     pthread_mutex_t clients_mutex;
00112     int size_clients;
00113     int num_clients;
00114     playertcp_conn* clients;
00115     struct pollfd* client_ufds;
00116 
00118     char* decode_readbuffer;
00120     int decode_readbuffersize;
00121 
00122   public:
00123     PlayerTCP();
00124     ~PlayerTCP();
00125 
00126     pthread_t thread;
00127 
00128     int Listen(int* ports, int num_ports);
00129     MessageQueue* AddClient(struct sockaddr_in* cliaddr,
00130                             unsigned int local_host,
00131                             unsigned int local_port,
00132                             int newsock,
00133                             bool send_banner,
00134                             int* kill_flag);
00135     int Accept(int timeout);
00136     void Close(int cli);
00137     int ReadClient(int cli);
00138     int Read(int timeout);
00139     int Write();
00140     int WriteClient(int cli);
00141     void DeleteClients();
00142     void ParseBuffer(int cli);
00143     int HandlePlayerMessage(int cli, Message* msg);
00144     void DeleteClient(MessageQueue* q);
00145     bool Listening(int port);
00146     uint32_t GetHost() {return host;};
00147 };
00148 
00151 #endif

Last updated 12 September 2005 21:38:45