X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fcommand_server.hxx;h=378ef08d97e696a08b15493bfeefcc2f56b31c29;hp=686be14fd138b2fdb38242dd90e0f91aaedafa11;hb=c7857475c8b0f02cac3ce29a617a4d542fa59f37;hpb=6cda58a6dad87ff6efe2277db2155be60edb8d48 diff --git a/src/command_server.hxx b/src/command_server.hxx index 686be14..378ef08 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,43 @@ class command_server void handle_packet(const std::string& packet, server_connection* conn); + protected: + virtual command* cast_command(command* input) + { return input; } + public: command_server(server& _s); - 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); - void new_connection_callback(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