switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Termlib / TelnetTerminal.cc
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief TelnetTerminal non-inline non-template implementation */
30
31 #include "TelnetTerminal.hh"
32 //#include "TelnetTerminal.ih"
33
34 // Custom includes
35
36 //#include "TelnetTerminal.mpp"
37 #define prefix_
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 prefix_ senf::term::TelnetTerminal::TelnetTerminal()
41     : setupFailed_ (false)
42 {
43     requestPeerOption(telnetopt::SUPPRESS_GO_AHEAD);
44     requestLocalOption(telnetopt::SUPPRESS_GO_AHEAD);
45     requestLocalOption(telnetopt::ECHO);
46 }
47
48 prefix_ void senf::term::TelnetTerminal::setCallbacks(AbstractTerminal::Callbacks & cb)
49 {
50     callbacks_ = &cb;
51 }
52
53 prefix_ std::string senf::term::TelnetTerminal::terminalType()
54 {
55     return telnethandler::TerminalType::terminalType();
56 }
57
58 prefix_ unsigned senf::term::TelnetTerminal::width()
59     const
60 {
61     return telnethandler::NAWS::width();
62 }
63
64 prefix_ unsigned senf::term::TelnetTerminal::height()
65     const
66 {
67     return telnethandler::NAWS::height();
68 }
69
70 prefix_ void senf::term::TelnetTerminal::write(char ch)
71 {
72     BaseTelnetProtocol::write(ch);
73 }
74
75 prefix_ void senf::term::TelnetTerminal::v_setupComplete()
76 {
77     bool init (true);
78
79     if (setupFailed_)
80         v_setupFailed();
81     else if (! (width() > 0
82                 && ! terminalType().empty()
83                 && localOption(telnetopt::SUPPRESS_GO_AHEAD)
84                 && peerOption(telnetopt::SUPPRESS_GO_AHEAD)
85                 && localOption(telnetopt::ECHO)
86                 && (init = callbacks_->cb_init()))) {
87
88         SENF_LOG_BLOCK((senf::log::NOTICE)({
89             log << "TelnetTerminal setup failed:\n";
90             if (width() <= 0)
91                 log << "    missing telnet client NAWS support\n";
92             else
93                 log << "    size=" << width() << "x" << height() << "\n";
94             if (terminalType().empty())
95                 log << "    missing telnet client TERMINAL_TYPE support\n";
96             else
97                 log << "    TERM=" << terminalType() << "\n";
98             if (! localOption(telnetopt::SUPPRESS_GO_AHEAD) ||
99                 ! peerOption(telnetopt::SUPPRESS_GO_AHEAD))
100                 log << "    missing telnet clinet SGO support\n";
101             if (! localOption(telnetopt::ECHO))
102                 log << "    missing telnet client ECHO support\n";
103             if (! init)
104                 log << "    terminal initialization (cb_init) failed\n";
105         }));
106
107         setupFailed_ = true;
108         requestPeerOption(telnetopt::SUPPRESS_GO_AHEAD, false);
109         requestLocalOption(telnetopt::SUPPRESS_GO_AHEAD, false);
110         requestLocalOption(telnetopt::ECHO, false);
111         requestPeerOption(telnetopt::TERMINAL_TYPE, false);
112         requestPeerOption(telnetopt::NAWS, false);
113         if (! requestsPending())
114             v_setupFailed();
115     }
116     else
117         SENF_LOG((senf::log::NOTICE)(
118                      "Initialized TelnetTerminal: TERM=" << terminalType()
119                      << ", size=" << width() << "x" << height()));
120 }
121
122 prefix_ void senf::term::TelnetTerminal::v_charReceived(char ch)
123 {
124     callbacks_->cb_charReceived(ch);
125 }
126
127 prefix_ void senf::term::TelnetTerminal::v_windowSizeChanged()
128 {
129     callbacks_->cb_windowSizeChanged();
130 }
131
132 //-/////////////////////////////////////////////////////////////////////////////////////////////////
133 #undef prefix_
134 //#include "TelnetTerminal.mpp"
135
136 \f
137 // Local Variables:
138 // mode: c++
139 // fill-column: 100
140 // comment-column: 40
141 // c-file-style: "senf"
142 // indent-tabs-mode: nil
143 // ispell-local-dictionary: "american"
144 // compile-command: "scons -u test"
145 // End: