Change license from LGPL to GPL version 2 + linking exception. This fixes C++ templat...
[libt2n] / src / command_server.hxx
... / ...
CommitLineData
1/*
2Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy
3
4The software in this package is distributed under the GNU General
5Public License version 2 (with a special exception described below).
6
7A copy of GNU General Public License (GPL) is included in this distribution,
8in the file COPYING.GPL.
9
10As a special exception, if other files instantiate templates or use macros
11or inline functions from this file, or you compile this file and link it
12with other works to produce a work based on this file, this file
13does not by itself cause the resulting work to be covered
14by the GNU General Public License.
15
16However the source code for this file must still be made available
17in accordance with section (3) of the GNU General Public License.
18
19This exception does not invalidate any other reasons why a work based
20on this file might be covered by the GNU General Public License.
21*/
22#ifndef __LIBT2N_COMMAND_SERVER
23#define __LIBT2N_COMMAND_SERVER
24
25#include "command.hxx"
26#include "server.hxx"
27
28namespace libt2n
29{
30
31/// a server handling incoming commands
32class command_server
33{
34 private:
35 server& s;
36
37 void handle_packet(const std::string& packet, server_connection* conn);
38
39 int guard_handle;
40
41 protected:
42 virtual command* cast_command(command* input)
43 { return input; }
44
45 public:
46 command_server(server& _s);
47 ~command_server();
48
49 void handle(long long usec_timeout=-1, long long* usec_timeout_remaining=NULL);
50
51 void send_hello(unsigned int conn_id);
52
53 std::ostream* get_logstream(log_level_values level)
54 { return s.get_logstream(level); }
55};
56
57template<class T, class B> struct Derived_from {
58 static void constraints(T* p) { B* pb = p; }
59 Derived_from() { void(*p)(T*) = constraints; }
60};
61
62/** @brief server handling group of incoming commands
63
64 the template must be derived from libt2n::command.
65*/
66template<class COMMAND_GROUP>
67class group_command_server : public command_server
68{
69 private:
70 virtual command* cast_command(command* input)
71 { return dynamic_cast<COMMAND_GROUP*>(input); }
72
73 public:
74 group_command_server(server& _s)
75 : command_server(_s)
76 { Derived_from<COMMAND_GROUP,command>(); }
77};
78
79}
80#endif
81