00001 /*************************************************************************** 00002 * Copyright (C) 2006 by Gerd v. Egidy * 00003 * gve@intra2net.com * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Lesser General Public License version * 00007 * 2.1 as published by the Free Software Foundation. * 00008 * * 00009 * This library is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00012 * GNU Lesser General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU Lesser General Public * 00015 * License along with this program; if not, write to the * 00016 * Free Software Foundation, Inc., * 00017 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00018 ***************************************************************************/ 00019 #ifndef __LIBT2N_COMMAND_SERVER 00020 #define __LIBT2N_COMMAND_SERVER 00021 00022 #include "command.hxx" 00023 #include "server.hxx" 00024 00025 namespace libt2n 00026 { 00027 00029 class command_server 00030 { 00031 private: 00032 server& s; 00033 00034 void handle_packet(const std::string& packet, server_connection* conn); 00035 00036 int guard_handle; 00037 00038 protected: 00039 virtual command* cast_command(command* input) 00040 { return input; } 00041 00042 public: 00043 command_server(server& _s); 00044 00045 void handle(long long usec_timeout=-1, long long* usec_timeout_remaining=NULL); 00046 00047 void send_hello(unsigned int conn_id); 00048 00049 std::ostream* get_logstream(log_level_values level) 00050 { return s.get_logstream(level); } 00051 }; 00052 00053 template<class T, class B> struct Derived_from { 00054 static void constraints(T* p) { B* pb = p; } 00055 Derived_from() { void(*p)(T*) = constraints; } 00056 }; 00057 00062 template<class COMMAND_GROUP> 00063 class group_command_server : public command_server 00064 { 00065 private: 00066 virtual command* cast_command(command* input) 00067 { return dynamic_cast<COMMAND_GROUP*>(input); } 00068 00069 public: 00070 group_command_server(server& _s) 00071 : command_server(_s) 00072 { Derived_from<COMMAND_GROUP,command>(); } 00073 }; 00074 00075 } 00076 #endif 00077
1.5.6