BufferedIO.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _OASYS_BUFFERED_IO_H_
00018 #define _OASYS_BUFFERED_IO_H_
00019 
00020 #include "../debug/Logger.h"
00021 #include "../io/IOClient.h"
00022 #include "../util/StreamBuffer.h"
00023 
00024 namespace oasys {
00025 
00030 class BufferedInput : public Logger {
00031 public:
00032     BufferedInput(IOClient* client, const char* logbase = "/BufferedInput");
00033     ~BufferedInput();
00034     
00046     int read_line(const char* nl, char** buf, int timeout = -1);
00047 
00061     int read_bytes(size_t len, char** buf, int timeout = -1);
00062 
00063 
00072     int read_some_bytes(char** buf, int timeout = -1);
00073 
00078     char get_char(int timeout = -1);
00079 
00083     bool eof();
00084 
00085 private:    
00094     int internal_read(size_t len = 0, int timeout_ms = -1);
00095 
00100     int find_nl(const char* nl);
00101     
00102     IOClient*    client_;
00103     StreamBuffer buf_;
00104 
00105     bool seen_eof_;
00106 
00107     static const size_t READ_AHEAD = 256;  
00108     static const size_t MAX_LINE   = 4096; 
00109 };
00110 
00111 class BufferedOutput : public Logger {
00112 public:
00113     BufferedOutput(IOClient* client, const char* logbase = "/BufferedOutput");
00114 
00121     int write(const char* bp, size_t len = 0);
00122 
00126     void clear_buf();
00127 
00132     int format_buf(const char* format, ...) PRINTFLIKE(2, 3);
00133     int vformat_buf(const char* format, va_list args);
00134         
00139     int flush();
00140     
00146     void set_flush_limit(size_t limit);
00147     
00151     int printf(const char* format, ...) PRINTFLIKE(2, 3);
00152 
00153 private:
00154     IOClient*    client_;
00155     StreamBuffer buf_;
00156 
00157     size_t flush_limit_;
00158 
00159     static const size_t DEFAULT_FLUSH_LIMIT = 256;
00160 };
00161 
00162 } // namespace oasys
00163 
00164 #endif /* _OASYS_BUFFERED_IO_H_ */

Generated on Thu Jun 7 16:56:48 2007 for DTN Reference Implementation by  doxygen 1.5.1