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