Utils/Termlib: Implement LineEditor auxiliary display support
[senf.git] / Utils / 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::ServerManager
35
36 prefix_ void senf::console::detail::ServerManager::add(ptr server)
37 {
38     instance().servers_.insert(server);
39 }
40
41 prefix_ void senf::console::detail::ServerManager::remove(ptr server)
42 {
43     instance().servers_.erase(instance().servers_.find(server));
44 }
45
46 prefix_ senf::console::detail::ServerManager & senf::console::detail::ServerManager::instance()
47 {
48     static ServerManager manager;
49     return manager;
50 }
51
52 ///////////////////////////////////////////////////////////////////////////
53 // senf::console::detail::NonblockingSocketSink
54
55 prefix_ senf::console::detail::NonblockingSocketSink::NonblockingSocketSink(Client & client)
56     : client_ (client)
57 {}
58
59 prefix_ senf::console::Client & senf::console::detail::NonblockingSocketSink::client()
60     const
61 {
62     return client_;
63 }
64
65 ///////////////////////////////////////////////////////////////////////////
66 // senf::console::Server
67
68 prefix_ senf::console::Server & senf::console::Server::name(std::string const & name)
69 {
70     name_ = name;
71     return *this;
72 }
73
74 prefix_ std::string const & senf::console::Server::name()
75     const
76 {
77     return name_;
78 }
79
80 prefix_ senf::console::DirectoryNode & senf::console::Server::root()
81     const
82 {
83     return *root_;
84 }
85
86 prefix_ senf::console::Server & senf::console::Server::root(DirectoryNode & root)
87 {
88     root_ = root.thisptr();
89     return *this;
90 }
91
92 prefix_ senf::console::Server & senf::console::Server::mode(Mode m)
93 {
94     mode_ = m;
95     return *this;
96 }
97
98 prefix_ senf::console::Server::Mode senf::console::Server::mode()
99     const
100 {
101     return mode_;
102 }
103
104 prefix_ void senf::console::Server::stop()
105 {
106     // commit suicide
107     detail::ServerManager::remove(boost::intrusive_ptr<Server>(this));
108 }
109
110 ///////////////////////////////////////////////////////////////////////////
111 // senf::console::Client
112
113 prefix_ senf::console::Client::~Client()
114 {
115     stream() << std::flush;
116 }
117
118 prefix_ void senf::console::Client::stop()
119 {
120     // THIS COMMITS SUICIDE. THE INSTANCE IS GONE AFTER removeClient RETURNS
121     server_.removeClient(*this);
122 }
123
124 prefix_ std::string const & senf::console::Client::name()
125     const
126 {
127     return name_;
128 }
129
130 prefix_ std::string senf::console::Client::promptString()
131     const
132 {
133     return name_ + ":" + executor_.cwdPath() + "$";
134 }
135
136 prefix_ senf::console::DirectoryNode & senf::console::Client::root()
137     const
138 {
139     return server_.root();
140 }
141
142 prefix_ senf::console::DirectoryNode & senf::console::Client::cwd()
143     const
144 {
145     return executor_.cwd();
146 }
147
148 prefix_ senf::console::Server::Mode senf::console::Client::mode()
149     const
150 {
151     return mode_;
152 }
153
154 prefix_ void senf::console::Client::write(std::string const & data)
155     const
156 {
157     reader_->write(data);
158 }
159
160 prefix_ senf::console::Client & senf::console::Client::get(std::ostream & os)
161 {
162     return dynamic_cast<detail::NonblockingSocketOStream&>(os)->client();
163 }
164
165 prefix_ senf::console::Client::ClientHandle senf::console::Client::handle()
166     const
167 {
168     return handle_;
169 }
170
171 prefix_ std::ostream & senf::console::Client::stream()
172 {
173     return out_t::member;
174 }
175
176 ///////////////////////////////////////////////////////////////////////////
177 // senf::console::detail::ClientReader
178
179 prefix_ senf::console::detail::ClientReader::~ClientReader()
180 {}
181
182 prefix_ senf::console::Client & senf::console::detail::ClientReader::client()
183     const
184 {
185     return client_;
186 }
187
188 prefix_ std::string senf::console::detail::ClientReader::promptString()
189     const
190 {
191     return client().promptString();
192 }
193
194 prefix_ senf::console::detail::ClientReader::ClientHandle senf::console::detail::ClientReader::handle()
195     const
196 {
197     return client().handle();
198 }
199
200 prefix_ std::ostream & senf::console::detail::ClientReader::stream()
201     const
202 {
203     return client().stream();
204 }
205
206 prefix_ void senf::console::detail::ClientReader::stopClient()
207 {
208     client().stop();
209 }
210
211 prefix_ std::string::size_type
212 senf::console::detail::ClientReader::handleInput(std::string const & input, bool incremental)
213     const
214 {
215     return client().handleInput(input, incremental);
216 }
217
218 prefix_ void senf::console::detail::ClientReader::disablePrompt()
219 {
220     v_disablePrompt();
221 }
222
223 prefix_ void senf::console::detail::ClientReader::enablePrompt()
224 {
225     v_enablePrompt();
226 }
227
228 prefix_ void senf::console::detail::ClientReader::write(std::string const & data)
229 {
230     v_write(data);
231 }
232
233 prefix_ senf::console::detail::ClientReader::ClientReader(Client & client)
234     : client_ (client)
235 {}
236
237 ///////////////////////////////cci.e///////////////////////////////////////
238 #undef prefix_
239
240 \f
241 // Local Variables:
242 // mode: c++
243 // fill-column: 100
244 // comment-column: 40
245 // c-file-style: "senf"
246 // indent-tabs-mode: nil
247 // ispell-local-dictionary: "american"
248 // compile-command: "scons -u test"
249 // End: