4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief Readline public header */
26 #ifndef HH_SENF_Scheduler_Console_Readline_
27 #define HH_SENF_Scheduler_Console_Readline_ 1
30 #include <boost/scoped_ptr.hpp>
32 #include "../../Utils/Exception.hh"
33 #include "../Scheduler.hh"
35 //#include "Readline.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
44 /** \brief Internal: GNU readline based ClientReader implementation
46 This implementation of the ClientReader interface uses GNU readline library to provide a
47 rich editing environment for console sessions. Since an application can only use readline
48 once, only one ReadlineReader can be allocated at any time.
50 class ReadlineClientReader
54 ReadlineClientReader(Client & client);
55 ~ReadlineClientReader();
58 static ReadlineClientReader & instance();
60 struct DuplicateReaderException : public Exception
61 { DuplicateReaderException() : Exception("duplicate readline instantiation") {} };
64 void callback(std::string line);
65 void write(std::string text);
70 virtual void v_disablePrompt();
71 virtual void v_enablePrompt();
72 virtual void v_translate(std::string & data);
74 void charEvent(int event);
76 static ReadlineClientReader * instance_;
79 char nameBuffer_[256];
80 char promptBuffer_[1024];
81 scheduler::FdEvent readevent_;
84 char * savedLineBuffer_;
90 /** \brief Internal: Safe GNU readline based ClientReader implementation
92 This implementation of the ClientReader interface forwards all functionality to either
93 ReadlineClientReader or DumbClientReader. A RadlineClientReader is used, if none is active,
94 otherwise a DumbClientReader is allocated. Using this ClientReader implementation, the first
95 console client will have readline functionality enabled, all further will have it disabled.
97 class SafeReadlineClientReader
101 SafeReadlineClientReader(Client & client);
104 virtual void v_disablePrompt();
105 virtual void v_enablePrompt();
106 virtual void v_translate(std::string & data);
108 boost::scoped_ptr<ClientReader> reader_;
115 ///////////////////////////////hh.e////////////////////////////////////////
116 #include "Readline.cci"
117 //#include "Readline.ct"
118 //#include "Readline.cti"
125 // comment-column: 40
126 // c-file-style: "senf"
127 // indent-tabs-mode: nil
128 // ispell-local-dictionary: "american"
129 // compile-command: "scons -u test"