Utils: Fix hexump() of nevative values
[senf.git] / Utils / Termlib / TelnetTerminal.cc
1 // $Id$
2 //
3 // Copyright (C) 2009 
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 TelnetTerminal non-inline non-template implementation */
25
26 #include "TelnetTerminal.hh"
27 //#include "TelnetTerminal.ih"
28
29 // Custom includes
30 #include <senf/Utils/membind.hh>
31
32 //#include "TelnetTerminal.mpp"
33 #define prefix_
34 ///////////////////////////////cc.p////////////////////////////////////////
35
36 prefix_ senf::term::TelnetTerminal::TelnetTerminal()
37     : keyTimeout_ (senf::ClockService::milliseconds(DEFAULT_KEY_TIMEOUT_MS)),
38       timer_ ("senf::term::TelnetTerminal::keySequenceTimeout", 
39               senf::membind(&TelnetTerminal::keySequenceTimeout, this))
40 {
41     requestPeerOption(telnetopt::SUPPRESS_GO_AHEAD);
42     requestLocalOption(telnetopt::SUPPRESS_GO_AHEAD);
43     requestLocalOption(telnetopt::ECHO);
44 }
45
46 prefix_ void senf::term::TelnetTerminal::v_setupComplete()
47 {
48     tifo_.load(terminalType());
49     keyParser_.load(tifo_);
50 }
51
52 prefix_ void senf::term::TelnetTerminal::v_charReceived(char c)
53 {
54     inputBuffer_ += c;
55     timer_.timeout(senf::scheduler::eventTime() + keyTimeout_);
56     processKeys();
57 }
58
59 prefix_ void senf::term::TelnetTerminal::keySequenceTimeout()
60 {
61     while (!inputBuffer_.empty()) {
62         processKeys();
63         v_keyReceived(keycode_t(inputBuffer_[0]));
64         inputBuffer_.erase(0, 1);
65     }
66 }
67
68 prefix_ void senf::term::TelnetTerminal::processKeys()
69 {
70     do {
71         std::pair<senf::term::KeyParser::keycode_t, std::string::size_type> result
72             (keyParser_.lookup(inputBuffer_));
73         if (result.first == senf::term::KeyParser::Incomplete)
74             return;
75         v_keyReceived(result.first);
76         inputBuffer_.erase(0, result.second);
77     } while (! inputBuffer_.empty());
78     timer_.disable();
79 }
80
81 ///////////////////////////////cc.e////////////////////////////////////////
82 #undef prefix_
83 //#include "TelnetTerminal.mpp"
84
85 \f
86 // Local Variables:
87 // mode: c++
88 // fill-column: 100
89 // comment-column: 40
90 // c-file-style: "senf"
91 // indent-tabs-mode: nil
92 // ispell-local-dictionary: "american"
93 // compile-command: "scons -u test"
94 // End: