Utils/Console: UDPServer documentation
[senf.git] / Utils / Console / UDPServer.hh
1 // $Id$
2 //
3 // Copyright (C) 2009 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief UDPServer public header */
25
26 #ifndef HH_SENF_Utils_Console_UDPServer_
27 #define HH_SENF_Utils_Console_UDPServer_ 1
28
29 // Custom includes
30 #include <boost/utility.hpp>
31 #include "../../Socket/Protocols/INet/UDPSocketHandle.hh"
32 #include "../Logger/SenfLog.hh"
33 #include "../../Scheduler/Scheduler.hh"
34 #include "Parse.hh"
35 #include "Executor.hh"
36
37 //#include "UDPServer.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
39
40 namespace senf {
41 namespace console {
42
43     /** \brief UDP Console server
44
45         This class provides UDP access to the console to allow remote scripting. The UDP console
46         does support multicast operation.
47
48         Every UDP packet will be executed in a clean context: No directory groups are open/closed,
49         and the current directory is always the root directory. 
50
51         By default, the server will send command replies via UDP to the sender of the corresponding
52         incoming command. Replies may however either be completely disabled or be sent to a fixed
53         address (which may be a multicast address).
54
55         \ingroup console_access
56       */
57     class UDPServer
58         : public boost::noncopyable
59     {
60         SENF_LOG_CLASS_AREA();
61         SENF_LOG_DEFAULT_LEVEL(senf::log::NOTICE);
62     public:
63         ///////////////////////////////////////////////////////////////////////////
64         // Types
65
66         typedef senf::ClientSocketHandle<
67             senf::MakeSocketPolicy<senf::UDPv4SocketProtocol::Policy,
68                                    senf::BSDAddressingPolicy>::policy > Handle;
69
70         ///////////////////////////////////////////////////////////////////////////
71         ///\name Structors and default members
72         ///@{
73
74         explicit UDPServer(senf::INet4SocketAddress const & address);
75                                         ///< Open UDP server on \a address
76         explicit UDPServer(senf::INet6SocketAddress const & address);
77                                         ///< Open UDP server on \a address
78         
79         ///@}
80         ///////////////////////////////////////////////////////////////////////////
81
82         UDPServer & replies(bool enable); ///< Enable or disable reply packets
83         UDPServer & replies(senf::INet4SocketAddress const & address);
84                                         ///< Send replies to \a address
85         UDPServer & replies(senf::INet6SocketAddress const & address);
86                                         ///< Send replies to \a address
87
88         DirectoryNode & root() const;   ///< Get root node
89
90         UDPServer & root(DirectoryNode & root); ///< Set root node
91                                         /**< \a node will be the root node for all clients launched
92                                              from this server. */
93
94     protected:
95
96     private:
97         void handleInput(int events);
98
99         bool replies_;
100         senf::GenericBSDSocketAddress target_;
101
102         Handle handle_;
103         senf::scheduler::FdEvent readevent_;
104         CommandParser parser_;
105         Executor executor_;
106     };
107
108
109 }}
110
111 ///////////////////////////////hh.e////////////////////////////////////////
112 //#include "UDPServer.cci"
113 //#include "UDPServer.ct"
114 //#include "UDPServer.cti"
115 #endif
116
117 \f
118 // Local Variables:
119 // mode: c++
120 // fill-column: 100
121 // comment-column: 40
122 // c-file-style: "senf"
123 // indent-tabs-mode: nil
124 // ispell-local-dictionary: "american"
125 // compile-command: "scons -u test"
126 // End: