Console: Documentation fixes
[senf.git] / Console / Readline.hh
1 // $Id$
2 //
3 // Copyright (C) 2008 
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 Readline public header */
25
26 #ifndef HH_Readline_
27 #define HH_Readline_ 1
28
29 // Custom includes
30 #include <boost/scoped_ptr.hpp>
31 #include "Server.hh"
32 #include "../Utils/Exception.hh"
33 #include "../Scheduler/Scheduler.hh"
34 #include "../Scheduler/Binding.hh"
35
36 //#include "Readline.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40 namespace console {
41 namespace detail {
42
43     /** \brief Internal: GNU readline based ClientReader implementation
44         
45         This implementation of the ClientReader interface uses GNU readline library to provide a
46         rich editing environment for console sessions. Since an application can only use readline
47         once, only one ReadlineReader can be allocated at any time.
48      */
49     class ReadlineClientReader
50         : public ClientReader
51     {
52     public:
53         ReadlineClientReader(Client & client);
54         ~ReadlineClientReader();
55
56         static bool active();
57         static ReadlineClientReader & instance();
58
59         struct DuplicateReaderException : public Exception
60         { DuplicateReaderException() : Exception("duplicate readline instantiation") {} };
61
62         int getc();
63         void callback(std::string line);
64         void write(std::string text);
65         void terminate();
66         
67     private:
68         virtual void v_disablePrompt();
69         virtual void v_enablePrompt();
70         virtual void v_translate(std::string & data);
71
72         void charEvent(Scheduler::EventId event);
73
74         static ReadlineClientReader * instance_;
75         int ch_;
76         unsigned skipChars_;
77         char nameBuffer_[256];
78         char promptBuffer_[1024];
79         SchedulerBinding schedBinding_;
80         bool terminate_;
81     };
82
83     /** \brief Internal: Safe GNU readline based ClientReader implementation
84         
85         This implementation of the ClientReader interface forwards all functionality to either
86         ReadlineClientReader or DumbClientReader. A RadlineClientReader is used, if none is active,
87         otherwise a DumbClientReader is allocated. Using this ClientReader implementation, the first
88         console client will have readline functionality enabled, all further will have it disabled.
89      */
90     class SafeReadlineClientReader
91         : public ClientReader
92     {
93     public:
94         SafeReadlineClientReader(Client & client);
95
96     private:
97         virtual void v_disablePrompt();
98         virtual void v_enablePrompt();
99         virtual void v_translate(std::string & data);
100
101         boost::scoped_ptr<ClientReader> reader_;
102     };
103
104 }}}
105
106 ///////////////////////////////hh.e////////////////////////////////////////
107 #include "Readline.cci"
108 //#include "Readline.ct"
109 //#include "Readline.cti"
110 #endif
111
112 \f
113 // Local Variables:
114 // mode: c++
115 // fill-column: 100
116 // comment-column: 40
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"
121 // End: