LogSink.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 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 __LOGSINK_H__
00018 #define __LOGSINK_H__
00019 
00020 namespace oasys {
00021 
00022 //----------------------------------------------------------------------------
00028 class LogSink {
00029 public:
00030     virtual ~LogSink() {}
00031     
00032     virtual void rotate()       = 0;
00033     virtual void log(char* str) = 0;
00034 };
00035 
00036 //----------------------------------------------------------------------------
00040 class ForkSink : public LogSink {
00041 public:
00042     ForkSink(LogSink* a, LogSink* b)
00043         : a_(a), b_(b) {}
00044 
00045     void rotate() { 
00046         a->rotate(); 
00047         b->rotate(); 
00048     }
00049 
00050     void log(const char* str) {
00051         a->log(str);
00052         b->log(str);
00053     }
00054 };
00055 
00056 //----------------------------------------------------------------------------
00060 class FileLogSink : public LogSink {
00061 public:
00066     FileLogSink(const char* filename);
00067     ~FileLogSink();
00068 
00069     void rotate();
00070     void log(const char* str);
00071 
00072 private:
00073     char filename_[256];
00074     int  fd_;
00075 };
00076 
00077 //----------------------------------------------------------------------------
00078 class RingBufferLogSink : public LogSink {
00079 public:
00080     RingBufferLogSink();
00081 
00082     void rotate() {}
00083     void log(char* str);
00084 
00085     static const int NUM_BUFFERS = 32;
00086     static const int BUF_LEN     = 512;
00087 
00088 private:
00089     int   cur_buf_;
00090     char* buf_;
00091     char  static_buf_[NUM_BUFFERS * BUF_LEN + 16];
00092 
00093     size_t buf(int i) {
00094         return &buf_[i * BUF_LEN];
00095     }
00096 };
00097 
00098 } // namespace oasys
00099 
00100 #endif /* __LOGSINK_H__ */

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