TelnetTerminal.cc
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 
17 #include "TelnetTerminal.hh"
18 //#include "TelnetTerminal.ih"
19 
20 // Custom includes
21 
22 //#include "TelnetTerminal.mpp"
23 #define prefix_
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
27  : setupFailed_ (false)
28 {
32 }
33 
35 {
36  callbacks_ = &cb;
37 }
38 
40 {
42 }
43 
45  const
46 {
48 }
49 
51  const
52 {
54 }
55 
57 {
59 }
60 
61 prefix_ void senf::term::TelnetTerminal::v_setupComplete()
62 {
63  bool init (true);
64 
65  if (setupFailed_)
66  v_setupFailed();
67  else if (! (width() > 0
68  && ! terminalType().empty()
72  && (init = callbacks_->cb_init()))) {
73 
75  log << "TelnetTerminal setup failed:\n";
76  if (width() <= 0)
77  log << " missing telnet client NAWS support\n";
78  else
79  log << " size=" << width() << "x" << height() << "\n";
80  if (terminalType().empty())
81  log << " missing telnet client TERMINAL_TYPE support\n";
82  else
83  log << " TERM=" << terminalType() << "\n";
86  log << " missing telnet clinet SGO support\n";
88  log << " missing telnet client ECHO support\n";
89  if (! init)
90  log << " terminal initialization (cb_init) failed\n";
91  }));
92 
93  setupFailed_ = true;
99  if (! requestsPending())
100  v_setupFailed();
101  }
102  else
104  "Initialized TelnetTerminal: TERM=" << terminalType()
105  << ", size=" << width() << "x" << height()));
106 }
107 
108 prefix_ void senf::term::TelnetTerminal::v_charReceived(char ch)
109 {
110  callbacks_->cb_charReceived(ch);
111 }
112 
113 prefix_ void senf::term::TelnetTerminal::v_windowSizeChanged()
114 {
115  callbacks_->cb_windowSizeChanged();
116 }
117 
118 //-/////////////////////////////////////////////////////////////////////////////////////////////////
119 #undef prefix_
120 //#include "TelnetTerminal.mpp"
121 
122 
123 // Local Variables:
124 // mode: c++
125 // fill-column: 100
126 // comment-column: 40
127 // c-file-style: "senf"
128 // indent-tabs-mode: nil
129 // ispell-local-dictionary: "american"
130 // compile-command: "scons -u test"
131 // End:
BaseTelnetProtocol::option_type const SUPPRESS_GO_AHEAD
Definition: Telnet.hh:350
#define SENF_LOG_BLOCK(args)
void init()
bool empty()
virtual void cb_charReceived(char ch)=0
Called whenever a char is received.
bool localOption(option_type option)
true, if option locally enabled
void write(std::string const &s)
Send string to peer.
Definition: Telnet.cc:58
virtual std::string terminalType()
Get the terminal type.
void requestLocalOption(option_type option, bool enabled=true)
Request option to be enabled here.
#define prefix_
std::string const & terminalType() const
Return current terminal type.
virtual void setCallbacks(AbstractTerminal::Callbacks &cb)
Register terminal callbacks.
virtual unsigned width() const
Get current terminal window width.
bool requestsPending()
true, if there are pending requests
virtual void v_setupFailed()=0
Called when the telnet setup has failed.
unsigned height() const
Get current client window height.
BaseTelnetProtocol::option_type const NAWS
Definition: Telnet.hh:352
virtual bool cb_init()=0
Called after terminal initialization is complete.
BaseTelnetProtocol::option_type const ECHO
Definition: Telnet.hh:348
virtual unsigned height() const
Get current terminal window height.
virtual void write(char ch)
Write character to terminal.
TelnetTerminal public header.
BaseTelnetProtocol::option_type const TERMINAL_TYPE
Definition: Telnet.hh:351
virtual void cb_windowSizeChanged()=0
Called when the terminal window is changed.
bool peerOption(option_type option)
true, if option enabled in peer
#define SENF_LOG(args)
void requestPeerOption(option_type option, bool enabled=true)
Request peer to enable an option.
unsigned width() const
Get current client window width.