00001 /* 00002 Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy 00003 00004 The software in this package is distributed under the GNU General 00005 Public License version 2 (with a special exception described below). 00006 00007 A copy of GNU General Public License (GPL) is included in this distribution, 00008 in the file COPYING.GPL. 00009 00010 As a special exception, if other files instantiate templates or use macros 00011 or inline functions from this file, or you compile this file and link it 00012 with other works to produce a work based on this file, this file 00013 does not by itself cause the resulting work to be covered 00014 by the GNU General Public License. 00015 00016 However the source code for this file must still be made available 00017 in accordance with section (3) of the GNU General Public License. 00018 00019 This exception does not invalidate any other reasons why a work based 00020 on this file might be covered by the GNU General Public License. 00021 */ 00022 #ifndef __LIBT2N_COMMAND_SERVER 00023 #define __LIBT2N_COMMAND_SERVER 00024 00025 #include "command.hxx" 00026 #include "server.hxx" 00027 00028 namespace libt2n 00029 { 00030 00032 class command_server 00033 { 00034 private: 00035 server& s; 00036 00037 void handle_packet(const std::string& packet, server_connection* conn); 00038 00039 int guard_handle; 00040 00041 protected: 00042 virtual command* cast_command(command* input) 00043 { return input; } 00044 00045 public: 00046 command_server(server& _s); 00047 ~command_server(); 00048 00049 void handle(long long usec_timeout=-1, long long* usec_timeout_remaining=NULL); 00050 00051 void send_hello(unsigned int conn_id); 00052 00053 std::ostream* get_logstream(log_level_values level) 00054 { return s.get_logstream(level); } 00055 }; 00056 00057 template<class T, class B> struct Derived_from { 00058 static void constraints(T* p) { B* pb = p; } 00059 Derived_from() { void(*/*p*/)(T*) = constraints; } 00060 }; 00061 00066 template<class COMMAND_GROUP> 00067 class group_command_server : public command_server 00068 { 00069 private: 00070 virtual command* cast_command(command* input) 00071 { return dynamic_cast<COMMAND_GROUP*>(input); } 00072 00073 public: 00074 group_command_server(server& _s) 00075 : command_server(_s) 00076 { Derived_from<COMMAND_GROUP,command>(); } 00077 }; 00078 00079 } 00080 #endif 00081