switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Console / UDPServer.hh
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief UDPServer public header */
30
31 #ifndef HH_SENF_Utils_Console_UDPServer_
32 #define HH_SENF_Utils_Console_UDPServer_ 1
33
34 // Custom includes
35 #include <boost/utility.hpp>
36 #include <senf/Socket/Protocols/INet/UDPSocketHandle.hh>
37 #include <senf/Utils/Logger/SenfLog.hh>
38 #include <senf/Scheduler/FdEvent.hh>
39 #include "Parse.hh"
40 #include "Executor.hh"
41
42 //#include "UDPServer.mpp"
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44
45 namespace senf {
46 namespace console {
47
48     /** \brief UDP Console server
49
50         This class provides UDP access to the console to allow remote scripting. The UDP console
51         does support multicast operation.
52
53         Every UDP packet will be executed in a clean context: No directory groups are open/closed,
54         and the current directory is always the root directory.
55
56         By default, the server will send command replies via UDP to the sender of the corresponding
57         incoming command. Replies may however either be completely disabled or be sent to a fixed
58         address (which may be a multicast address).
59
60         \ingroup console_access
61       */
62     class UDPServer
63         : public boost::noncopyable
64     {
65         SENF_LOG_CLASS_AREA();
66         SENF_LOG_DEFAULT_LEVEL(senf::log::NOTICE);
67     public:
68         //-////////////////////////////////////////////////////////////////////////
69         // Types
70
71         typedef senf::ClientSocketHandle<
72             senf::MakeSocketPolicy<senf::UDPv4SocketProtocol::Policy,
73                                    senf::BSDAddressingPolicy>::policy > Handle;
74
75         //-////////////////////////////////////////////////////////////////////////
76         ///\name Structors and default members
77         //\{
78
79         explicit UDPServer(senf::INet4SocketAddress const & address);
80                                         ///< Open UDP server on \a address
81         explicit UDPServer(senf::INet6SocketAddress const & address);
82                                         ///< Open UDP server on \a address
83
84         //\}
85         //-////////////////////////////////////////////////////////////////////////
86
87         UDPServer & replies(bool enable); ///< Enable or disable reply packets
88                                         /** \e Default: enabled */
89         UDPServer & replies(senf::INet4SocketAddress const & address);
90                                         ///< Send replies to \a address
91                                         /**< \e Default: no address set (send replies to sender) */
92         UDPServer & replies(senf::INet6SocketAddress const & address);
93                                         ///< Send replies to \a address
94                                         /**< \e Default: no address set (send replies to sender) */
95
96         UDPServer & emptyReplies(bool enable); ///< Enable or disable empty reply packets
97                                         /**< \e Default: enabled */
98
99         DirectoryNode & root() const;   ///< Get root node
100
101         UDPServer & root(DirectoryNode & root); ///< Set root node
102                                         /**< \a node will be the root node for all clients launched
103                                              from this server. */
104
105     protected:
106
107     private:
108         void handleInput(int events);
109
110         bool replies_;
111         bool emptyReplies_;
112         senf::GenericBSDSocketAddress target_;
113
114         Handle handle_;
115         senf::scheduler::FdEvent readevent_;
116         CommandParser parser_;
117         Executor executor_;
118     };
119
120
121 }}
122
123 //-/////////////////////////////////////////////////////////////////////////////////////////////////
124 //#include "UDPServer.cci"
125 //#include "UDPServer.ct"
126 //#include "UDPServer.cti"
127 #endif
128
129 \f
130 // Local Variables:
131 // mode: c++
132 // fill-column: 100
133 // comment-column: 40
134 // c-file-style: "senf"
135 // indent-tabs-mode: nil
136 // ispell-local-dictionary: "american"
137 // compile-command: "scons -u test"
138 // End: