/*************************************************************************** * Copyright (C) 2006 by Gerd v. Egidy * * gve@intra2net.com * * * * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef __LIBT2N_SERVER #define __LIBT2N_SERVER #include #include #include #include "connection.hxx" #include "types.hxx" namespace libt2n { class server; /** Basic connection class */ class server_connection : public connection { private: int timeout; int last_action_time; unsigned int connection_id; protected: server_connection(int _timeout) : connection() { set_timeout(_timeout); reset_timeout(); connection_id=0; my_server=0; } server *my_server; public: void check_timeout(); void reset_timeout(); void set_timeout(int _timeout) { timeout=_timeout; } void set_server(server* _my_server) { my_server=_my_server; } void set_id(unsigned int _connection_id) { connection_id=_connection_id; } unsigned int get_id() { return connection_id; } }; /** Basic server class */ class server { private: int default_timeout; log_level_values log_level; std::ostream *logstream; unsigned int next_id; protected: std::map connections; server() { set_default_timeout(30); set_logging(NULL,none); next_id=1; } int add_connection(server_connection* newconn); public: virtual ~server(); void set_default_timeout(int _default_timeout) { default_timeout=_default_timeout; } int get_default_timeout(void) { return default_timeout; } void set_logging(std::ostream *_logstream, log_level_values _log_level) { log_level=_log_level; logstream=_logstream; } server_connection* get_connection(unsigned int conn_id); virtual void fill_buffer(long long usec_timeout=-1)=0; void cleanup(); bool get_packet(std::string& data) { unsigned int x; return get_packet(data,x); } bool get_packet(std::string& data, unsigned int& conn_id); virtual void fill_connection_buffers(void)=0; void log(log_level_values level, const std::string& message) { log(level,message.c_str()); } void log(log_level_values level, const char* message); }; } #endif