replaced some tabs with spaces
[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::Server::Mode senf::console::Client::mode()
143     const
144 {
145     return mode_;
146 }
147
148 prefix_ senf::console::Client & senf::console::Client::get(std::ostream & os)
149 {
150     return dynamic_cast<detail::NonblockingSocketOStream&>(os)->client();
151 }
152
153 prefix_ senf::console::Client::ClientHandle senf::console::Client::handle()
154     const
155 {
156     return handle_;
157 }
158
159 prefix_ std::ostream & senf::console::Client::stream()
160 {
161     return out_t::member;
162 }
163
164 ///////////////////////////////////////////////////////////////////////////
165 // senf::console::detail::ClientReader
166
167 prefix_ senf::console::detail::ClientReader::~ClientReader()
168 {}
169
170 prefix_ senf::console::Client & senf::console::detail::ClientReader::client()
171     const
172 {
173     return client_;
174 }
175
176 prefix_ std::string senf::console::detail::ClientReader::promptString()
177     const
178 {
179     return client().promptString();
180 }
181
182 prefix_ senf::console::detail::ClientReader::ClientHandle senf::console::detail::ClientReader::handle()
183     const
184 {
185     return client().handle();
186 }
187
188 prefix_ std::ostream & senf::console::detail::ClientReader::stream()
189     const
190 {
191     return client().stream();
192 }
193
194 prefix_ void senf::console::detail::ClientReader::stopClient()
195 {
196     client().stop();
197 }
198
199 prefix_ std::string::size_type
200 senf::console::detail::ClientReader::handleInput(std::string const & input, bool incremental)
201     const
202 {
203     return client().handleInput(input, incremental);
204 }
205
206 prefix_ void senf::console::detail::ClientReader::disablePrompt()
207 {
208     v_disablePrompt();
209 }
210
211 prefix_ void senf::console::detail::ClientReader::enablePrompt()
212 {
213     v_enablePrompt();
214 }
215
216 prefix_ void senf::console::detail::ClientReader::translate(std::string & data)
217 {
218     v_translate(data);
219 }
220
221 prefix_ senf::console::detail::ClientReader::ClientReader(Client & client)
222     : client_ (client)
223 {}
224
225 ///////////////////////////////cci.e///////////////////////////////////////
226 #undef prefix_
227
228 \f
229 // Local Variables:
230 // mode: c++
231 // fill-column: 100
232 // comment-column: 40
233 // c-file-style: "senf"
234 // indent-tabs-mode: nil
235 // ispell-local-dictionary: "american"
236 // compile-command: "scons -u test"
237 // End: