Console: Implement short-option and non-option parsing
[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::NonblockingSocketSink
35
36 prefix_ senf::console::detail::NonblockingSocketSink::NonblockingSocketSink(Client & client)
37     : client_ (client)
38 {}
39
40 prefix_ senf::console::Client & senf::console::detail::NonblockingSocketSink::client()
41     const
42 {
43     return client_;
44 }
45
46 ///////////////////////////////////////////////////////////////////////////
47 // senf::console::Server
48
49 prefix_ senf::console::Server & senf::console::Server::name(std::string const & name)
50 {
51     name_ = name;
52     return *this;
53 }
54
55 prefix_ void senf::console::Server::stop()
56 {
57     // commit suicide
58     instancePtr().reset(0);
59 }
60
61 ///////////////////////////////////////////////////////////////////////////
62 // senf::console::Client
63
64 prefix_ senf::console::Client::~Client()
65 {}
66
67 prefix_ void senf::console::Client::stop()
68 {
69     // THIS COMMITS SUICIDE. THE INSTANCE IS GONE AFTER removeClient RETURNS
70     server_.removeClient(*this);
71 }
72
73 prefix_ std::string const & senf::console::Client::name()
74     const
75 {
76     return name_;
77 }
78
79 prefix_ std::string senf::console::Client::promptString()
80     const
81 {
82     return name_ + ":" + executor_.cwdPath() + "$ ";
83 }
84
85 prefix_ senf::console::Client & senf::console::Client::get(std::ostream & os)
86 {
87     return dynamic_cast<detail::NonblockingSocketOStream&>(os)->client();
88 }
89
90 prefix_ senf::console::Client::ClientHandle senf::console::Client::handle()
91     const
92 {
93     return handle_;
94 }
95
96 prefix_ std::ostream & senf::console::Client::stream()
97 {
98     return out_t::member;
99 }
100
101 ///////////////////////////////////////////////////////////////////////////
102 // senf::console::detail::ClientReader
103
104 prefix_ senf::console::detail::ClientReader::~ClientReader()
105 {}
106
107 prefix_ senf::console::Client & senf::console::detail::ClientReader::client()
108     const
109 {
110     return client_;
111 }
112
113 prefix_ std::string senf::console::detail::ClientReader::promptString()
114     const
115 {
116     return client().promptString();
117 }
118
119 prefix_ senf::console::detail::ClientReader::ClientHandle senf::console::detail::ClientReader::handle()
120     const
121 {
122     return client().handle();
123 }
124
125 prefix_ std::ostream & senf::console::detail::ClientReader::stream()
126     const
127 {
128     return client().stream();
129 }
130
131 prefix_ void senf::console::detail::ClientReader::stopClient()
132 {
133     client().stop();
134 }
135
136 prefix_ void senf::console::detail::ClientReader::handleInput(std::string const & input)
137     const
138 {
139     client().handleInput(input);
140 }
141
142 prefix_ void senf::console::detail::ClientReader::disablePrompt()
143 {
144     v_disablePrompt();
145 }
146
147 prefix_ void senf::console::detail::ClientReader::enablePrompt()
148 {
149     v_enablePrompt();
150 }
151
152 prefix_ void senf::console::detail::ClientReader::translate(std::string & data)
153 {
154     v_translate(data);
155 }
156
157 prefix_ senf::console::detail::ClientReader::ClientReader(Client & client)
158     : client_ (client)
159 {}
160
161 ///////////////////////////////cci.e///////////////////////////////////////
162 #undef prefix_
163
164 \f
165 // Local Variables:
166 // mode: c++
167 // fill-column: 100
168 // comment-column: 40
169 // c-file-style: "senf"
170 // indent-tabs-mode: nil
171 // ispell-local-dictionary: "american"
172 // compile-command: "scons -u test"
173 // End: