0691b00a5e3b8a8d42a41891d7ba835908a4a295
[senf.git] / senf / 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 <senf/Socket/Protocols/INet/UDPSocketHandle.hh>
32 #include <senf/Utils/Logger/SenfLog.hh>
33 #include <senf/Scheduler/FdEvent.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                                         /** \e Default: enabled */
84         UDPServer & replies(senf::INet4SocketAddress const & address);
85                                         ///< Send replies to \a address
86                                         /**< \e Default: no address set (send replies to sender) */
87         UDPServer & replies(senf::INet6SocketAddress const & address);
88                                         ///< Send replies to \a address
89                                         /**< \e Default: no address set (send replies to sender) */
90
91         UDPServer & emptyReplies(bool enable); ///< Enable or disable empty reply packets
92                                         /**< \e Default: enabled */
93
94         DirectoryNode & root() const;   ///< Get root node
95
96         UDPServer & root(DirectoryNode & root); ///< Set root node
97                                         /**< \a node will be the root node for all clients launched
98                                              from this server. */
99
100     protected:
101
102     private:
103         void handleInput(int events);
104
105         bool replies_;
106         bool emptyReplies_;
107         senf::GenericBSDSocketAddress target_;
108
109         Handle handle_;
110         senf::scheduler::FdEvent readevent_;
111         CommandParser parser_;
112         Executor executor_;
113     };
114
115
116 }}
117
118 ///////////////////////////////hh.e////////////////////////////////////////
119 //#include "UDPServer.cci"
120 //#include "UDPServer.ct"
121 //#include "UDPServer.cti"
122 #endif
123
124 \f
125 // Local Variables:
126 // mode: c++
127 // fill-column: 100
128 // comment-column: 40
129 // c-file-style: "senf"
130 // indent-tabs-mode: nil
131 // ispell-local-dictionary: "american"
132 // compile-command: "scons -u test"
133 // End: