Scheduler: Implement Timer helper
[senf.git] / Console / Server.cci
1 // $Id$
2 //
3 // Copyright (C) 2008 
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 Server inline non-template implementation */
25
26 #include "Server.ih"
27
28 // Custom includes
29
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::console::detail::NonblockingSocketSink
35
36 prefix_ senf::console::detail::NonblockingSocketSink::NonblockingSocketSink(Client & client)
37     : client_ (client)
38 {}
39
40 prefix_ senf::console::Client & senf::console::detail::NonblockingSocketSink::client()
41     const
42 {
43     return client_;
44 }
45
46 ///////////////////////////////////////////////////////////////////////////
47 // senf::console::Server
48
49 prefix_ senf::console::Server & senf::console::Server::name(std::string const & name)
50 {
51     name_ = name;
52     return *this;
53 }
54
55 prefix_ std::string const & senf::console::Server::name()
56     const
57 {
58     return name_;
59 }
60
61 prefix_ senf::console::Server & senf::console::Server::root(DirectoryNode & root)
62 {
63     root_ = root.thisptr();
64     return *this;
65 }
66
67 prefix_ senf::console::Server & senf::console::Server::mode(Mode m)
68 {
69     mode_ = m;
70     return *this;
71 }
72
73 prefix_ senf::console::Server::Mode senf::console::Server::mode()
74     const
75 {
76     return mode_;
77 }
78
79 prefix_ void senf::console::Server::stop()
80 {
81     // commit suicide
82     instancePtr().reset(0);
83 }
84
85 ///////////////////////////////////////////////////////////////////////////
86 // senf::console::Client
87
88 prefix_ senf::console::Client::~Client()
89 {
90     stream() << std::flush;
91 }
92
93 prefix_ void senf::console::Client::stop()
94 {
95     // THIS COMMITS SUICIDE. THE INSTANCE IS GONE AFTER removeClient RETURNS
96     server_.removeClient(*this);
97 }
98
99 prefix_ std::string const & senf::console::Client::name()
100     const
101 {
102     return name_;
103 }
104
105 prefix_ std::string senf::console::Client::promptString()
106     const
107 {
108     return name_ + ":" + executor_.cwdPath() + "$ ";
109 }
110
111 prefix_ senf::console::DirectoryNode & senf::console::Client::root()
112     const
113 {
114     return server_.root();
115 }
116
117 prefix_ senf::console::Server::Mode senf::console::Client::mode()
118     const
119 {
120     return mode_;
121 }
122
123 prefix_ senf::console::Client & senf::console::Client::get(std::ostream & os)
124 {
125     return dynamic_cast<detail::NonblockingSocketOStream&>(os)->client();
126 }
127
128 prefix_ senf::console::Client::ClientHandle senf::console::Client::handle()
129     const
130 {
131     return handle_;
132 }
133
134 prefix_ std::ostream & senf::console::Client::stream()
135 {
136     return out_t::member;
137 }
138
139 ///////////////////////////////////////////////////////////////////////////
140 // senf::console::detail::ClientReader
141
142 prefix_ senf::console::detail::ClientReader::~ClientReader()
143 {}
144
145 prefix_ senf::console::Client & senf::console::detail::ClientReader::client()
146     const
147 {
148     return client_;
149 }
150
151 prefix_ std::string senf::console::detail::ClientReader::promptString()
152     const
153 {
154     return client().promptString();
155 }
156
157 prefix_ senf::console::detail::ClientReader::ClientHandle senf::console::detail::ClientReader::handle()
158     const
159 {
160     return client().handle();
161 }
162
163 prefix_ std::ostream & senf::console::detail::ClientReader::stream()
164     const
165 {
166     return client().stream();
167 }
168
169 prefix_ void senf::console::detail::ClientReader::stopClient()
170 {
171     client().stop();
172 }
173
174 prefix_ std::string::size_type
175 senf::console::detail::ClientReader::handleInput(std::string const & input, bool incremental)
176     const
177 {
178     return client().handleInput(input, incremental);
179 }
180
181 prefix_ void senf::console::detail::ClientReader::disablePrompt()
182 {
183     v_disablePrompt();
184 }
185
186 prefix_ void senf::console::detail::ClientReader::enablePrompt()
187 {
188     v_enablePrompt();
189 }
190
191 prefix_ void senf::console::detail::ClientReader::translate(std::string & data)
192 {
193     v_translate(data);
194 }
195
196 prefix_ senf::console::detail::ClientReader::ClientReader(Client & client)
197     : client_ (client)
198 {}
199
200 ///////////////////////////////cci.e///////////////////////////////////////
201 #undef prefix_
202
203 \f
204 // Local Variables:
205 // mode: c++
206 // fill-column: 100
207 // comment-column: 40
208 // c-file-style: "senf"
209 // indent-tabs-mode: nil
210 // ispell-local-dictionary: "american"
211 // compile-command: "scons -u test"
212 // End: