Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

TelnetTerminal.cc

Go to the documentation of this file.
00001 // $Id: TelnetTerminal.cc 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2009
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 "TelnetTerminal.hh"
00027 //#include "TelnetTerminal.ih"
00028 
00029 // Custom includes
00030 
00031 //#include "TelnetTerminal.mpp"
00032 #define prefix_
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 
00035 prefix_ senf::term::TelnetTerminal::TelnetTerminal()
00036     : setupFailed_ (false)
00037 {
00038     requestPeerOption(telnetopt::SUPPRESS_GO_AHEAD);
00039     requestLocalOption(telnetopt::SUPPRESS_GO_AHEAD);
00040     requestLocalOption(telnetopt::ECHO);
00041 }
00042 
00043 prefix_ void senf::term::TelnetTerminal::setCallbacks(AbstractTerminal::Callbacks & cb)
00044 {
00045     callbacks_ = &cb;
00046 }
00047 
00048 prefix_ std::string senf::term::TelnetTerminal::terminalType()
00049 {
00050     return telnethandler::TerminalType::terminalType();
00051 }
00052 
00053 prefix_ unsigned senf::term::TelnetTerminal::width()
00054     const
00055 {
00056     return telnethandler::NAWS::width();
00057 }
00058 
00059 prefix_ unsigned senf::term::TelnetTerminal::height()
00060     const
00061 {
00062     return telnethandler::NAWS::height();
00063 }
00064 
00065 prefix_ void senf::term::TelnetTerminal::write(char ch)
00066 {
00067     BaseTelnetProtocol::write(ch);
00068 }
00069 
00070 prefix_ void senf::term::TelnetTerminal::v_setupComplete()
00071 {
00072     bool init (true);
00073 
00074     if (setupFailed_)
00075         v_setupFailed();
00076     else if (! (width() > 0
00077                 && ! terminalType().empty()
00078                 && localOption(telnetopt::SUPPRESS_GO_AHEAD)
00079                 && peerOption(telnetopt::SUPPRESS_GO_AHEAD)
00080                 && localOption(telnetopt::ECHO)
00081                 && (init = callbacks_->cb_init()))) {
00082 
00083         SENF_LOG_BLOCK((senf::log::NOTICE)({
00084             log << "TelnetTerminal setup failed:\n";
00085             if (width() <= 0)
00086                 log << "    missing telnet client NAWS support\n";
00087             else
00088                 log << "    size=" << width() << "x" << height() << "\n";
00089             if (terminalType().empty())
00090                 log << "    missing telnet client TERMINAL_TYPE support\n";
00091             else
00092                 log << "    TERM=" << terminalType() << "\n";
00093             if (! localOption(telnetopt::SUPPRESS_GO_AHEAD) ||
00094                 ! peerOption(telnetopt::SUPPRESS_GO_AHEAD))
00095                 log << "    missing telnet clinet SGO support\n";
00096             if (! localOption(telnetopt::ECHO))
00097                 log << "    missing telnet client ECHO support\n";
00098             if (! init)
00099                 log << "    terminal initialization (cb_init) failed\n";
00100         }));
00101 
00102         setupFailed_ = true;
00103         requestPeerOption(telnetopt::SUPPRESS_GO_AHEAD, false);
00104         requestLocalOption(telnetopt::SUPPRESS_GO_AHEAD, false);
00105         requestLocalOption(telnetopt::ECHO, false);
00106         requestPeerOption(telnetopt::TERMINAL_TYPE, false);
00107         requestPeerOption(telnetopt::NAWS, false);
00108         if (! requestsPending())
00109             v_setupFailed();
00110     }
00111     else
00112         SENF_LOG((senf::log::NOTICE)(
00113                      "Initialized TelnetTerminal: TERM=" << terminalType()
00114                      << ", size=" << width() << "x" << height()));
00115 }
00116 
00117 prefix_ void senf::term::TelnetTerminal::v_charReceived(char ch)
00118 {
00119     callbacks_->cb_charReceived(ch);
00120 }
00121 
00122 prefix_ void senf::term::TelnetTerminal::v_windowSizeChanged()
00123 {
00124     callbacks_->cb_windowSizeChanged();
00125 }
00126 
00127 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00128 #undef prefix_
00129 //#include "TelnetTerminal.mpp"
00130 
00131 
00132 // Local Variables:
00133 // mode: c++
00134 // fill-column: 100
00135 // comment-column: 40
00136 // c-file-style: "senf"
00137 // indent-tabs-mode: nil
00138 // ispell-local-dictionary: "american"
00139 // compile-command: "scons -u test"
00140 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research