X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fcommand_server.hxx;h=04508b56f15d260dec6e2946518fac93d4f3fb51;hp=cb41a762ee70dd3e330a05b6d8bbe7116af74792;hb=238ad35f4e3b6516d4ba7611b540a0edeea71427;hpb=8104c8f70605ee24230e5988d7bf68e3fce7465a diff --git a/src/command_server.hxx b/src/command_server.hxx index cb41a76..04508b5 100644 --- a/src/command_server.hxx +++ b/src/command_server.hxx @@ -19,6 +19,7 @@ #ifndef __LIBT2N_COMMAND_SERVER #define __LIBT2N_COMMAND_SERVER +#include "command.hxx" #include "server.hxx" namespace libt2n @@ -32,15 +33,46 @@ class command_server void handle_packet(const std::string& packet, server_connection* conn); + int guard_handle; + + protected: + virtual command* cast_command(command* input) + { return input; } + public: command_server(server& _s); + // TODO: No (virtual) destructor - void handle(long long usec_timeout=-1); + void handle(long long usec_timeout=-1, long long* usec_timeout_remaining=NULL); void send_hello(unsigned int conn_id); + + std::ostream* get_logstream(log_level_values level) + { return s.get_logstream(level); } }; -} +template struct Derived_from { + static void constraints(T* p) { B* pb = p; } + Derived_from() { void(*p)(T*) = constraints; } +}; + +/** @brief server handling group of incoming commands + the template must be derived from libt2n::command. +*/ +template +class group_command_server : public command_server +{ + private: + virtual command* cast_command(command* input) + { return dynamic_cast(input); } + + public: + group_command_server(server& _s) + : command_server(_s) + { Derived_from(); } +}; + +} #endif