1 |
786 |
skrzyp |
#ifndef CYGONCE_LIBC_STDIO_STREAMBUF_HXX
|
2 |
|
|
#define CYGONCE_LIBC_STDIO_STREAMBUF_HXX
|
3 |
|
|
//===========================================================================
|
4 |
|
|
//
|
5 |
|
|
// streambuf.hxx
|
6 |
|
|
//
|
7 |
|
|
// Internal C library stdio stream buffer interface definitions
|
8 |
|
|
//
|
9 |
|
|
//===========================================================================
|
10 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
18 |
|
|
// version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
21 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License
|
26 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use
|
30 |
|
|
// macros or inline functions from this file, or you compile this file
|
31 |
|
|
// and link it with other works to produce a work based on this file,
|
32 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
33 |
|
|
// the GNU General Public License. However the source code for this file
|
34 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
35 |
|
|
// General Public License v2.
|
36 |
|
|
//
|
37 |
|
|
// This exception does not invalidate any other reasons why a work based
|
38 |
|
|
// on this file might be covered by the GNU General Public License.
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//===========================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): jlarmour
|
45 |
|
|
// Contributors:
|
46 |
|
|
// Date: 2000-04-19
|
47 |
|
|
// Purpose:
|
48 |
|
|
// Description: This file implements the buffer class used by Cyg_StdioStream
|
49 |
|
|
// for file buffers. It is simple, and not thread-safe - that
|
50 |
|
|
// is better done at a higher level for our purposes.
|
51 |
|
|
// Usage: #include
|
52 |
|
|
//
|
53 |
|
|
//####DESCRIPTIONEND####
|
54 |
|
|
//
|
55 |
|
|
//===========================================================================
|
56 |
|
|
|
57 |
|
|
// CONFIGURATION
|
58 |
|
|
|
59 |
|
|
#include // Configuration header
|
60 |
|
|
|
61 |
|
|
// Include buffered I/O?
|
62 |
|
|
#if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO)
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
// INCLUDES
|
66 |
|
|
|
67 |
|
|
#include // Common project-wide type definitions
|
68 |
|
|
#include // Cyg_ErrNo
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
// TYPE DEFINITIONS
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
class Cyg_StdioStreamBuffer
|
75 |
|
|
{
|
76 |
|
|
private:
|
77 |
|
|
// Buffering data
|
78 |
|
|
|
79 |
|
|
#if defined(CYGSEM_LIBC_STDIO_SETVBUF_MALLOC)
|
80 |
|
|
cyg_bool call_free; // should we free the old buffer if set_buffer is
|
81 |
|
|
// called?
|
82 |
|
|
#else
|
83 |
|
|
cyg_uint8 static_buffer[BUFSIZ]; // Static buffer used when we cannot
|
84 |
|
|
// use malloc()/free().
|
85 |
|
|
#endif
|
86 |
|
|
|
87 |
|
|
cyg_uint8 *buffer_bottom;
|
88 |
|
|
|
89 |
|
|
cyg_ucount32 buffer_size;
|
90 |
|
|
|
91 |
|
|
cyg_uint8 *buffer_top;
|
92 |
|
|
|
93 |
|
|
cyg_uint8 *current_buffer_position;
|
94 |
|
|
|
95 |
|
|
public:
|
96 |
|
|
|
97 |
|
|
// CONSTRUCTORS
|
98 |
|
|
|
99 |
|
|
// You can change the size, or even supply your own buffer, although
|
100 |
|
|
// this only has an effect with dynamic buffers. Otherwise it is
|
101 |
|
|
// silently ignored
|
102 |
|
|
Cyg_StdioStreamBuffer( cyg_ucount32 size=BUFSIZ,
|
103 |
|
|
cyg_uint8 *new_buffer=NULL );
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
// DESTRUCTORS
|
107 |
|
|
|
108 |
|
|
~Cyg_StdioStreamBuffer();
|
109 |
|
|
|
110 |
|
|
// METHODS
|
111 |
|
|
|
112 |
|
|
// Set up the buffer. As with the constructor, supplying a new_buffer
|
113 |
|
|
// only has an effect with dynamic buffers, although EINVAL is returned
|
114 |
|
|
// in that case. ENOMEM may also be returned
|
115 |
|
|
Cyg_ErrNo
|
116 |
|
|
set_buffer( cyg_ucount32 size=BUFSIZ, cyg_uint8 *new_buffer=NULL );
|
117 |
|
|
|
118 |
|
|
// Find out how much buffer space is in use
|
119 |
|
|
cyg_ucount32
|
120 |
|
|
get_buffer_space_used( void );
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
// What total size is the current buffer set to be. Can be -1 if the
|
124 |
|
|
// the buffer is invalid
|
125 |
|
|
cyg_count32
|
126 |
|
|
get_buffer_size( void );
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
// get buffer address to read from, and return the number of bytes
|
130 |
|
|
// available to read
|
131 |
|
|
cyg_ucount32
|
132 |
|
|
get_buffer_addr_to_read( cyg_uint8 **buffer );
|
133 |
|
|
|
134 |
|
|
// when finished reading from said space, tell the buffer how much was
|
135 |
|
|
// actually read
|
136 |
|
|
void
|
137 |
|
|
set_bytes_read( cyg_ucount32 bytes );
|
138 |
|
|
|
139 |
|
|
// return address of buffer that can be used to write into, and its
|
140 |
|
|
// available capacity
|
141 |
|
|
cyg_ucount32
|
142 |
|
|
get_buffer_addr_to_write( cyg_uint8 **buffer );
|
143 |
|
|
|
144 |
|
|
// when finished writing into said space, tell the buffer how much was
|
145 |
|
|
// actually written
|
146 |
|
|
void
|
147 |
|
|
set_bytes_written( cyg_ucount32 bytes );
|
148 |
|
|
|
149 |
|
|
// just empty the whole buffer contents
|
150 |
|
|
void
|
151 |
|
|
drain_buffer( void );
|
152 |
|
|
}; // class Cyg_StdioStreamBuffer
|
153 |
|
|
|
154 |
|
|
// INLINE FUNCTIONS
|
155 |
|
|
|
156 |
|
|
#include
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
#endif // if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO)
|
160 |
|
|
|
161 |
|
|
#endif // CYGONCE_LIBC_STDIO_STREAMBUF_HXX multiple inclusion protection
|
162 |
|
|
|
163 |
|
|
// EOF streambuf.hxx
|