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 */
27 #define HH_Readline_ 1
30 #include <boost/scoped_ptr.hpp>
32 #include "../Utils/Exception.hh"
33 #include "../Scheduler/Scheduler.hh"
34 #include "../Scheduler/Binding.hh"
36 //#include "Readline.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
45 /** \brief Internal: GNU readline based ClientReader implementation
47 This implementation of the ClientReader interface uses GNU readline library to provide a
48 rich editing environment for console sessions. Since an application can only use readline
49 once, only one ReadlineReader can be allocated at any time.
51 class ReadlineClientReader
55 ReadlineClientReader(Client & client);
56 ~ReadlineClientReader();
59 static ReadlineClientReader & instance();
61 struct DuplicateReaderException : public Exception
62 { DuplicateReaderException() : Exception("duplicate readline instantiation") {} };
65 void callback(std::string line);
66 void write(std::string text);
71 virtual void v_disablePrompt();
72 virtual void v_enablePrompt();
73 virtual void v_translate(std::string & data);
75 void charEvent(Scheduler::EventId event);
77 static ReadlineClientReader * instance_;
80 char nameBuffer_[256];
81 char promptBuffer_[1024];
82 SchedulerBinding schedBinding_;
85 char * savedLineBuffer_;
91 /** \brief Internal: Safe GNU readline based ClientReader implementation
93 This implementation of the ClientReader interface forwards all functionality to either
94 ReadlineClientReader or DumbClientReader. A RadlineClientReader is used, if none is active,
95 otherwise a DumbClientReader is allocated. Using this ClientReader implementation, the first
96 console client will have readline functionality enabled, all further will have it disabled.
98 class SafeReadlineClientReader
102 SafeReadlineClientReader(Client & client);
105 virtual void v_disablePrompt();
106 virtual void v_enablePrompt();
107 virtual void v_translate(std::string & data);
109 boost::scoped_ptr<ClientReader> reader_;
116 ///////////////////////////////hh.e////////////////////////////////////////
117 #include "Readline.cci"
118 //#include "Readline.ct"
119 //#include "Readline.cti"
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"