00001 // $Id: Server.cci 1781 2011-04-11 12:10:19Z tho $ 00002 // 00003 // Copyright (C) 2008 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 //#include "Server.ih" 00027 00028 // Custom includes 00029 00030 #define prefix_ inline 00031 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00032 00033 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00034 // senf::console::detail::ServerManager 00035 00036 prefix_ void senf::console::detail::ServerManager::add(ptr server) 00037 { 00038 instance().servers_.insert(server); 00039 } 00040 00041 prefix_ void senf::console::detail::ServerManager::remove(ptr server) 00042 { 00043 instance().servers_.erase(instance().servers_.find(server)); 00044 } 00045 00046 prefix_ senf::console::detail::ServerManager & senf::console::detail::ServerManager::instance() 00047 { 00048 static ServerManager manager; 00049 return manager; 00050 } 00051 00052 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00053 // senf::console::detail::NonblockingSocketSink 00054 00055 prefix_ senf::console::detail::NonblockingSocketSink::NonblockingSocketSink(Client & client) 00056 : client_ (client) 00057 {} 00058 00059 prefix_ senf::console::Client & senf::console::detail::NonblockingSocketSink::client() 00060 const 00061 { 00062 return client_; 00063 } 00064 00065 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00066 // senf::console::Server 00067 00068 prefix_ senf::console::Server & senf::console::Server::name(std::string const & name) 00069 { 00070 name_ = name; 00071 return *this; 00072 } 00073 00074 prefix_ std::string const & senf::console::Server::name() 00075 const 00076 { 00077 return name_; 00078 } 00079 00080 prefix_ senf::console::DirectoryNode & senf::console::Server::root() 00081 const 00082 { 00083 return *root_; 00084 } 00085 00086 prefix_ senf::console::Server & senf::console::Server::root(DirectoryNode & root) 00087 { 00088 root_ = root.thisptr(); 00089 return *this; 00090 } 00091 00092 prefix_ senf::console::Server & senf::console::Server::mode(Mode m) 00093 { 00094 mode_ = m; 00095 return *this; 00096 } 00097 00098 prefix_ senf::console::Server::Mode senf::console::Server::mode() 00099 const 00100 { 00101 return mode_; 00102 } 00103 00104 prefix_ void senf::console::Server::stop() 00105 { 00106 // commit suicide 00107 detail::ServerManager::remove(boost::intrusive_ptr<Server>(this)); 00108 } 00109 00110 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00111 // senf::console::Client 00112 00113 prefix_ senf::console::Client::~Client() 00114 { 00115 stream() << std::flush; 00116 } 00117 00118 prefix_ void senf::console::Client::stop() 00119 { 00120 // THIS COMMITS SUICIDE. THE INSTANCE IS GONE AFTER removeClient RETURNS 00121 server_.removeClient(*this); 00122 } 00123 00124 prefix_ std::string const & senf::console::Client::name() 00125 const 00126 { 00127 return name_; 00128 } 00129 00130 prefix_ std::string senf::console::Client::promptString() 00131 const 00132 { 00133 return name_ + ":" + executor_.cwdPath() + "$"; 00134 } 00135 00136 prefix_ senf::console::DirectoryNode & senf::console::Client::root() 00137 const 00138 { 00139 return server_.root(); 00140 } 00141 00142 prefix_ senf::console::DirectoryNode & senf::console::Client::cwd() 00143 const 00144 { 00145 return executor_.cwd(); 00146 } 00147 00148 prefix_ senf::console::Server::Mode senf::console::Client::mode() 00149 const 00150 { 00151 return mode_; 00152 } 00153 00154 prefix_ void senf::console::Client::write(std::string const & data) 00155 const 00156 { 00157 reader_->write(data); 00158 } 00159 00160 prefix_ std::string const & senf::console::Client::backtrace() 00161 const 00162 { 00163 return backtrace_; 00164 } 00165 00166 prefix_ unsigned senf::console::Client::width() 00167 const 00168 { 00169 return reader_->width(); 00170 } 00171 00172 prefix_ senf::console::Client & senf::console::Client::get(std::ostream & os) 00173 { 00174 return dynamic_cast<detail::NonblockingSocketOStream&>(os)->client(); 00175 } 00176 00177 prefix_ senf::console::Client::ClientHandle senf::console::Client::handle() 00178 const 00179 { 00180 return handle_; 00181 } 00182 00183 prefix_ std::ostream & senf::console::Client::stream() 00184 { 00185 return out_t::member; 00186 } 00187 00188 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00189 // senf::console::detail::ClientReader 00190 00191 prefix_ senf::console::detail::ClientReader::~ClientReader() 00192 {} 00193 00194 prefix_ senf::console::Client & senf::console::detail::ClientReader::client() 00195 const 00196 { 00197 return client_; 00198 } 00199 00200 prefix_ std::string senf::console::detail::ClientReader::promptString() 00201 const 00202 { 00203 return client().promptString(); 00204 } 00205 00206 prefix_ senf::console::detail::ClientReader::ClientHandle senf::console::detail::ClientReader::handle() 00207 const 00208 { 00209 return client().handle(); 00210 } 00211 00212 prefix_ std::ostream & senf::console::detail::ClientReader::stream() 00213 const 00214 { 00215 return client().stream(); 00216 } 00217 00218 prefix_ void senf::console::detail::ClientReader::stopClient() 00219 { 00220 client().stop(); 00221 } 00222 00223 prefix_ std::string::size_type 00224 senf::console::detail::ClientReader::handleInput(std::string const & input, bool incremental) 00225 const 00226 { 00227 return client().handleInput(input, incremental); 00228 } 00229 00230 prefix_ void senf::console::detail::ClientReader::disablePrompt() 00231 { 00232 v_disablePrompt(); 00233 } 00234 00235 prefix_ void senf::console::detail::ClientReader::enablePrompt() 00236 { 00237 v_enablePrompt(); 00238 } 00239 00240 prefix_ void senf::console::detail::ClientReader::write(std::string const & data) 00241 { 00242 v_write(data); 00243 } 00244 00245 prefix_ unsigned senf::console::detail::ClientReader::width() 00246 const 00247 { 00248 return v_width(); 00249 } 00250 00251 prefix_ senf::console::detail::ClientReader::ClientReader(Client & client) 00252 : client_ (client) 00253 {} 00254 00255 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00256 #undef prefix_ 00257 00258 00259 // Local Variables: 00260 // mode: c++ 00261 // fill-column: 100 00262 // comment-column: 40 00263 // c-file-style: "senf" 00264 // indent-tabs-mode: nil 00265 // ispell-local-dictionary: "american" 00266 // compile-command: "scons -u test" 00267 // End: