Server.cci
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief Server inline non-template implementation */
16 
17 //#include "Server.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::console::detail::ServerManager
26 
27 prefix_ void senf::console::detail::ServerManager::add(ptr server)
28 {
29  instance().servers_.insert(server);
30 }
31 
32 prefix_ void senf::console::detail::ServerManager::remove(ptr server)
33 {
34  instance().servers_.erase(instance().servers_.find(server));
35 }
36 
37 prefix_ senf::console::detail::ServerManager & senf::console::detail::ServerManager::instance()
38 {
39  static ServerManager manager;
40  return manager;
41 }
42 
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44 // senf::console::detail::SocketStreamSink
45 
46 prefix_ senf::console::detail::SocketStreamSink::SocketStreamSink(Client & client)
47  : client_ (client)
48 {}
49 
50 prefix_ senf::console::Client & senf::console::detail::SocketStreamSink::client()
51  const
52 {
53  return client_;
54 }
55 
56 //-/////////////////////////////////////////////////////////////////////////////////////////////////
57 // senf::console::Server
58 
59 prefix_ senf::console::Server & senf::console::Server::name(std::string const & name)
60 {
61  name_ = name;
62  return *this;
63 }
64 
65 prefix_ std::string const & senf::console::Server::name()
66  const
67 {
68  return name_;
69 }
70 
71 prefix_ senf::console::DirectoryNode & senf::console::Server::root()
72  const
73 {
74  return *root_;
75 }
76 
77 prefix_ senf::console::Server & senf::console::Server::root(DirectoryNode & root)
78 {
79  root_ = root.thisptr();
80  return *this;
81 }
82 
83 prefix_ senf::console::Server & senf::console::Server::mode(Mode m)
84 {
85  mode_ = m;
86  return *this;
87 }
88 
89 prefix_ senf::console::Server::Mode senf::console::Server::mode()
90  const
91 {
92  return mode_;
93 }
94 
95 prefix_ void senf::console::Server::stop()
96 {
97  // commit suicide
98  detail::ServerManager::remove(boost::intrusive_ptr<Server>(this));
99 }
100 
101 //-/////////////////////////////////////////////////////////////////////////////////////////////////
102 // senf::console::Client
103 
104 prefix_ senf::console::Client::~Client()
105 {
106  stream() << std::flush;
107 }
108 
109 prefix_ void senf::console::Client::stop()
110 {
111  // THIS COMMITS SUICIDE. THE INSTANCE IS GONE AFTER removeClient RETURNS
112  server_.removeClient(*this);
113 }
114 
115 prefix_ std::string const & senf::console::Client::name()
116  const
117 {
118  return name_;
119 }
120 
121 prefix_ std::string senf::console::Client::promptString()
122  const
123 {
124  return name_ + ":" + executor_.cwdPath() + "$";
125 }
126 
127 prefix_ senf::console::DirectoryNode & senf::console::Client::root()
128  const
129 {
130  return server_.root();
131 }
132 
133 prefix_ senf::console::DirectoryNode & senf::console::Client::cwd()
134  const
135 {
136  return executor_.cwd();
137 }
138 
139 prefix_ senf::console::Server::Mode senf::console::Client::mode()
140  const
141 {
142  return mode_;
143 }
144 
145 prefix_ void senf::console::Client::write(std::string const & data)
146  const
147 {
148  reader_->write(data);
149 }
150 
151 prefix_ std::string const & senf::console::Client::backtrace()
152  const
153 {
154  return backtrace_;
155 }
156 
157 prefix_ unsigned senf::console::Client::width()
158  const
159 {
160  return reader_->width();
161 }
162 
163 prefix_ senf::console::Client & senf::console::Client::get(std::ostream & os)
164 {
165  return dynamic_cast<detail::SocketStreamOStream&>(os)->client();
166 }
167 
168 prefix_ senf::console::Client::ClientHandle senf::console::Client::handle()
169  const
170 {
171  return handle_;
172 }
173 
174 prefix_ std::ostream & senf::console::Client::stream()
175 {
176  return out_t::member;
177 }
178 
179 //-/////////////////////////////////////////////////////////////////////////////////////////////////
180 // senf::console::detail::ClientReader
181 
182 prefix_ senf::console::detail::ClientReader::~ClientReader()
183 {}
184 
185 prefix_ senf::console::Client & senf::console::detail::ClientReader::client()
186  const
187 {
188  return client_;
189 }
190 
191 prefix_ std::string senf::console::detail::ClientReader::promptString()
192  const
193 {
194  return client().promptString();
195 }
196 
197 prefix_ senf::console::detail::ClientReader::ClientHandle senf::console::detail::ClientReader::handle()
198  const
199 {
200  return client().handle();
201 }
202 
203 prefix_ std::ostream & senf::console::detail::ClientReader::stream()
204  const
205 {
206  return client().stream();
207 }
208 
209 prefix_ void senf::console::detail::ClientReader::stopClient()
210 {
211  client().stop();
212 }
213 
214 prefix_ std::string::size_type
215 senf::console::detail::ClientReader::handleInput(std::string const & input, bool incremental)
216  const
217 {
218  return client().handleInput(input, incremental);
219 }
220 
221 prefix_ void senf::console::detail::ClientReader::disablePrompt()
222 {
223  v_disablePrompt();
224 }
225 
226 prefix_ void senf::console::detail::ClientReader::enablePrompt()
227 {
228  v_enablePrompt();
229 }
230 
231 prefix_ void senf::console::detail::ClientReader::write(std::string const & data)
232 {
233  v_write(data);
234 }
235 
236 prefix_ unsigned senf::console::detail::ClientReader::width()
237  const
238 {
239  return v_width();
240 }
241 
242 prefix_ senf::console::detail::ClientReader::ClientReader(Client & client)
243  : client_ (client)
244 {}
245 
246 //-/////////////////////////////////////////////////////////////////////////////////////////////////
247 #undef prefix_
248 
249 
250 // Local Variables:
251 // mode: c++
252 // fill-column: 100
253 // comment-column: 40
254 // c-file-style: "senf"
255 // indent-tabs-mode: nil
256 // ispell-local-dictionary: "american"
257 // compile-command: "scons -u test"
258 // End: