]> git.mxchange.org Git - simgear.git/blob - simgear/io/sg_netChat.hxx
Ensure individual log-level setting works.
[simgear.git] / simgear / io / sg_netChat.hxx
1 /*
2     Copied from PLIB into SimGear
3
4      PLIB - A Suite of Portable Game Libraries
5      Copyright (C) 1998,2002  Steve Baker
6  
7      This library is free software; you can redistribute it and/or
8      modify it under the terms of the GNU Library General Public
9      License as published by the Free Software Foundation; either
10      version 2 of the License, or (at your option) any later version.
11  
12      This library is distributed in the hope that it will be useful,
13      but WITHOUT ANY WARRANTY; without even the implied warranty of
14      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15      Library General Public License for more details.
16  
17      You should have received a copy of the GNU Library General Public
18      License along with this library; if not, write to the Free Software
19      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
20  
21      For further information visit http://plib.sourceforge.net
22
23      $Id: netChat.h 1568 2002-09-02 06:05:49Z sjbaker $
24 */
25
26 /****
27 * NAME
28 *   netChat - network chat class
29 *
30 * DESCRIPTION
31 *   This class adds support for 'chat' style protocols -
32 *   where one side sends a 'command', and the other sends
33 *   a response (examples would be the common internet
34 *   protocols - smtp, nntp, ftp, etc..).
35 *
36 *   The handle_buffer_read() method looks at the input
37 *   stream for the current 'terminator' (usually '\r\n'
38 *   for single-line responses, '\r\n.\r\n' for multi-line
39 *   output), calling found_terminator() on its receipt.
40 *
41 * EXAMPLE
42 *   Say you build an nntp client using this class.
43 *   At the start of the connection, you'll have
44 *   terminator set to '\r\n', in order to process
45 *   the single-line greeting.  Just before issuing a
46 *   'LIST' command you'll set it to '\r\n.\r\n'.
47 *   The output of the LIST command will be accumulated
48 *   (using your own 'collect_incoming_data' method)
49 *   up to the terminator, and then control will be
50 *   returned to you - by calling your found_terminator()
51 *
52 * AUTHORS
53 *   Sam Rushing <rushing@nightmare.com> - original version for Medusa
54 *   Dave McClurg <dpm@efn.org> - modified for use in PLIB
55 *
56 * CREATION DATE
57 *   Dec-2000
58 *
59 ****/
60
61 #ifndef SG_NET_CHAT_H
62 #define SG_NET_CHAT_H
63
64 #include <memory>
65 #include <cstdlib>
66 #include <simgear/io/sg_netBuffer.hxx>
67
68 namespace simgear
69 {
70
71 class NetChat : public NetBufferChannel
72 {
73   char* terminator;
74   int bytesToCollect;
75   virtual void handleBufferRead (NetBuffer& buffer) ;
76
77 public:
78
79   NetChat () : 
80     terminator (NULL),
81     bytesToCollect(-1) 
82   {}
83
84   void setTerminator (const char* t);
85   const char* getTerminator (void);
86
87   /**
88    * set byte count to collect - 'foundTerminator' will be called once
89    * this many bytes have been collected
90    */
91   void setByteCount(int bytes);
92
93   bool push (const char* s);
94   
95   virtual void collectIncomingData      (const char* s, int n) {}
96   virtual void foundTerminator (void) {}
97 };
98
99 } // of namespace simgear
100
101 #endif // SG_NET_CHAT_H