Utils/Console: Small code cleanup in telnet implementation
[senf.git] / Utils / Console / Telnet.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 Telnet inline non-template implementation */
25
26 //#include "Telnet.ih"
27
28 // Custom includes
29
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::console::detail::BaseTelnetProtocol::OptInfo
35
36 prefix_ senf::console::detail::BaseTelnetProtocol::OptInfo::OptInfo()
37     : local (false), option (0u), wantState (DISABLED), optionState (NONE), enabled (false)
38 {}
39
40 prefix_ senf::console::detail::BaseTelnetProtocol::OptInfo::OptInfo(bool l, option_type o)
41     : local (l), option (o), wantState (DISABLED), optionState (NONE), enabled (false)
42 {}
43
44 ///////////////////////////////////////////////////////////////////////////
45 // senf::console::detail::BaseTelnetProtocol::TelnetHandler
46
47 prefix_ senf::console::detail::BaseTelnetProtocol::TelnetHandler::~TelnetHandler()
48 {}
49
50 prefix_ std::string const & senf::console::detail::telnethandler::TerminalType::terminalType()
51     const
52 {
53     return type_;
54 }
55
56 ///////////////////////////////////////////////////////////////////////////
57 // senf::console::detail::telnethandler::NAWS
58
59 prefix_ unsigned senf::console::detail::telnethandler::NAWS::width()
60     const
61 {
62     return width_;
63 }
64
65 prefix_ unsigned senf::console::detail::telnethandler::NAWS::height()
66     const
67 {
68     return height_;
69 }
70
71 ///////////////////////////////////////////////////////////////////////////
72 // senf::console::detail::BaseTelnetProtocol
73
74 prefix_ senf::console::detail::BaseTelnetProtocol::~BaseTelnetProtocol()
75 {}
76
77 prefix_ void senf::console::detail::BaseTelnetProtocol::incrementRequestCounter()
78 {
79     ++ pendingRequests_;
80     timeout_.timeout(senf::scheduler::eventTime() + requestTimeout_);
81 }
82
83 prefix_ bool senf::console::detail::BaseTelnetProtocol::requestsPending()
84 {
85     return pendingRequests_ > 0u;
86 }
87
88 prefix_ void senf::console::detail::BaseTelnetProtocol::sendNOP()
89 {
90     transmit(CMD_IAC);
91     transmit(CMD_NOP);
92 }
93
94 prefix_ void senf::console::detail::BaseTelnetProtocol::sendBRK()
95 {
96     transmit(CMD_IAC);
97     transmit(CMD_BRK);
98 }
99
100 prefix_ void senf::console::detail::BaseTelnetProtocol::sendIP()
101 {
102     transmit(CMD_IAC);
103     transmit(CMD_IP);
104 }
105
106 prefix_ void senf::console::detail::BaseTelnetProtocol::sendAO()
107 {
108     transmit(CMD_IAC);
109     transmit(CMD_AO);
110 }
111
112 prefix_ void senf::console::detail::BaseTelnetProtocol::sendAYT()
113 {
114     transmit(CMD_IAC);
115     transmit(CMD_AYT);
116 }
117
118 prefix_ void senf::console::detail::BaseTelnetProtocol::sendEC()
119 {
120     transmit(CMD_IAC);
121     transmit(CMD_EC);
122 }
123
124 prefix_ void senf::console::detail::BaseTelnetProtocol::sendEL()
125 {
126     transmit(CMD_IAC);
127     transmit(CMD_EL);
128 }
129
130 prefix_ void senf::console::detail::BaseTelnetProtocol::sendGA()
131 {
132     transmit(CMD_IAC);
133     transmit(CMD_GA);
134 }
135
136 prefix_ void senf::console::detail::BaseTelnetProtocol::requestLocalOption(option_type option,
137                                                                            bool enabled)
138 {
139     request(getOption(true, option), enabled);
140 }
141
142 prefix_ void senf::console::detail::BaseTelnetProtocol::acceptLocalOption(option_type option,
143                                                                           bool enabled)
144 {
145     getOption(true, option).wantState = OptInfo::ACCEPTED;
146 }
147
148 prefix_ void senf::console::detail::BaseTelnetProtocol::requestPeerOption(option_type option,
149                                                                           bool enabled)
150 {
151     request(getOption(false, option), enabled);
152 }
153
154 prefix_ void senf::console::detail::BaseTelnetProtocol::acceptPeerOption(option_type option,
155                                                                          bool enabled)
156 {
157     getOption(false, option).wantState = OptInfo::ACCEPTED;
158 }
159
160 prefix_ void senf::console::detail::BaseTelnetProtocol::emit(char c)
161 {
162     v_charReceived(c);
163 }
164
165 ///////////////////////////////cci.e///////////////////////////////////////
166 #undef prefix_
167
168 \f
169 // Local Variables:
170 // mode: c++
171 // fill-column: 100
172 // comment-column: 40
173 // c-file-style: "senf"
174 // indent-tabs-mode: nil
175 // ispell-local-dictionary: "american"
176 // compile-command: "scons -u test"
177 // End: