JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
CLogRingBuffer Class Reference

#include <LogRingBuffer.h>

Collaboration diagram for CLogRingBuffer:

Public Member Functions

 CLogRingBuffer (int size)
 
virtual ~CLogRingBuffer (void)
 
int init (int size)
 
void clear (void)
 
void putRingBuffer (Buffer buf, int input=LOG_RB_MESG, int kind=LOG_RB_UNKNOWN_DATA)
 
void rewriteBinHexRingBuffer (int n, int input)
 
void putRingFormat (int input, char *fmt,...)
 
void putRingFormat (int input, char *fmt, va_list args)
 
Buffer getRingBuffer (void)
 
Buffer getRingBuffer (int pos)
 
int getMaxBufSize (void)
 
int getMaxLineX (void)
 
int getMaxLineY (void)
 
int getTotalSize (void)
 
int getLastPosition (void)
 
int getLengthX (int n)
 
int getKindData (int n)
 

Public Attributes

BufferpBuf
 

Protected Attributes

int maxBufSize
 
int tlDataSize
 
int maxLineX
 
int maxLineY
 
int indentSize
 
int rPos
 
int wPos
 
int * kindData
 
int * inputSrc
 

Detailed Description

Definition at line 35 of file LogRingBuffer.h.

Constructor & Destructor Documentation

◆ CLogRingBuffer()

CLogRingBuffer ( int size)
inline

Definition at line 38 of file LogRingBuffer.h.

38{ init(size);}

References CLogRingBuffer::init().

Here is the call graph for this function:

◆ ~CLogRingBuffer()

~CLogRingBuffer ( void )
virtual

Definition at line 13 of file LogRingBuffer.cpp.

14{
15 //DEBUG_INFO("INFO: DESTRUCTOR: CLogRingBuffer");
16
17 if (pBuf!=NULL) del_Buffer_dim(&pBuf);
18
19 //DEBUG_INFO("INFO: DESTRUCTOR: CLogRingBuffer");
20}
void del_Buffer_dim(Buffer **dim)
配列を削除する.
Definition xtools.cpp:1567

References del_Buffer_dim(), and CLogRingBuffer::pBuf.

Here is the call graph for this function:

Member Function Documentation

◆ clear()

void clear ( void )

Definition at line 66 of file LogRingBuffer.cpp.

67{
68 for (int i=0; i<maxBufSize; i++) {
69 pBuf[i].buf[0] = '\0';
70 pBuf[i].vldsz = 0;
71 }
72
73 tlDataSize = 0;
74 maxLineX = maxLineY = 0;
75 rPos = wPos = 0;
76
77 return;
78}
int vldsz
データの長さ.バイナリデータの場合も使用可能.文字列の場合は 0x00 を含まない.
Definition buffer.h:37
unsigned char * buf
バッファの先頭へのポインタ.str[bufsz]は必ず 0x00となる.
Definition buffer.h:39

References Buffer::buf, CLogRingBuffer::maxBufSize, CLogRingBuffer::maxLineX, CLogRingBuffer::maxLineY, CLogRingBuffer::pBuf, CLogRingBuffer::rPos, CLogRingBuffer::tlDataSize, Buffer::vldsz, and CLogRingBuffer::wPos.

◆ getKindData()

int getKindData ( int n)
inline

Definition at line 59 of file LogRingBuffer.h.

59{ if(n<0) n+=maxBufSize; return kindData[n%maxBufSize];}

References CLogRingBuffer::kindData, and CLogRingBuffer::maxBufSize.

◆ getLastPosition()

int getLastPosition ( void )
inline

Definition at line 56 of file LogRingBuffer.h.

56{ return wPos;}

References CLogRingBuffer::wPos.

◆ getLengthX()

int getLengthX ( int n)
inline

Definition at line 58 of file LogRingBuffer.h.

58{ if(n<0) n+=maxBufSize; return (int)strlen((const char*)pBuf[n%maxBufSize].buf);}

References CLogRingBuffer::maxBufSize, and CLogRingBuffer::pBuf.

Referenced by CLogRingBuffer::putRingBuffer().

Here is the caller graph for this function:

◆ getMaxBufSize()

int getMaxBufSize ( void )
inline

Definition at line 52 of file LogRingBuffer.h.

52{ return maxBufSize;}

References CLogRingBuffer::maxBufSize.

◆ getMaxLineX()

int getMaxLineX ( void )
inline

Definition at line 53 of file LogRingBuffer.h.

53{ return maxLineX;}

References CLogRingBuffer::maxLineX.

◆ getMaxLineY()

int getMaxLineY ( void )
inline

Definition at line 54 of file LogRingBuffer.h.

54{ return maxLineY;}

References CLogRingBuffer::maxLineY.

◆ getRingBuffer() [1/2]

Buffer getRingBuffer ( int pos)

Buffer CLogRingBuffer::getRingBuffer(int pos)

バッファの位置を指定して読み込む.データポインタの移動無し.

Returns
指定した位置のデータ

Definition at line 305 of file LogRingBuffer.cpp.

306{
307 Buffer buf = init_Buffer();
308 buf.state = -1;
309
310 if (pos<0) return buf;
311 if (pos>=maxBufSize) pos = pos%maxBufSize;
312
313 buf = make_Buffer(LBUF);
314 copy_Buffer(&pBuf[pos], &buf);
315 buf.state = inputSrc[pos];
316
317 return buf;
318}
Buffer make_Buffer(int sz)
Buffer型変数のバッファ部をつくり出す.
Definition buffer.cpp:71
Buffer init_Buffer()
初期化したBuffer型変数を返す.
Definition buffer.cpp:47
int copy_Buffer(Buffer *src, Buffer *dst)
Buffer型変数 srcから dstへバッファをコピーする.
Definition buffer.cpp:315
#define LBUF
Definition common.h:146
int state
変数の状態を表す.正常は JBXL_NORMAL
Definition buffer.h:38

References copy_Buffer(), init_Buffer(), CLogRingBuffer::inputSrc, LBUF, make_Buffer(), CLogRingBuffer::maxBufSize, CLogRingBuffer::pBuf, and Buffer::state.

Here is the call graph for this function:

◆ getRingBuffer() [2/2]

Buffer getRingBuffer ( void )

Buffer CLogRingBuffer::getRingBuffer(void)

バッファの先頭のデータを読み込む.データポインタを移動させる.

Returns
バッファの先頭のデータ

Definition at line 284 of file LogRingBuffer.cpp.

285{
286 Buffer buf = make_Buffer(LBUF);
287
288 copy_Buffer(&pBuf[rPos], &buf);
289 buf.state = inputSrc[rPos];
290
291 rPos++;
293
294 return buf;
295}

References copy_Buffer(), CLogRingBuffer::inputSrc, LBUF, make_Buffer(), CLogRingBuffer::maxBufSize, CLogRingBuffer::pBuf, CLogRingBuffer::rPos, and Buffer::state.

Here is the call graph for this function:

◆ getTotalSize()

int getTotalSize ( void )
inline

Definition at line 55 of file LogRingBuffer.h.

55{ return tlDataSize;}

References CLogRingBuffer::tlDataSize.

◆ init()

int init ( int size)

Definition at line 23 of file LogRingBuffer.cpp.

24{
25 bool err_flag = false;
26
28 maxLineX = maxLineY = 0;
29 rPos = wPos = 0;
30 indentSize = 13; // 5 + 8 "1234 SERVER: "
31
32 pBuf = (Buffer*)malloc(sizeof(Buffer)*size);
33 kindData = (int*)malloc(sizeof(int)*size);
34 inputSrc = (int*)malloc(sizeof(int)*size);
35
36 if (pBuf!=NULL && inputSrc!=NULL && kindData!=NULL) {
37 memset(pBuf, 0, sizeof(Buffer)*size);
38 memset(kindData, 0, sizeof(int)*size);
39 memset(inputSrc, 0, sizeof(int)*size);
40 maxBufSize = size;
41
42 for (int i=0; i<size; i++) {
43 pBuf[i] = make_Buffer(LBUF);
44 if (pBuf[i].buf==NULL) {
45 err_flag = true;
46 break;
47 }
48 pBuf[i].state = size;
49 }
50 }
51 else {
52 err_flag = true;
53 }
54
55 if (err_flag) {
56 if (pBuf!=NULL) del_Buffer_dim(&pBuf);
57 if (kindData!=NULL) free(kindData);
58 if (inputSrc!=NULL) free(inputSrc);
59 kindData = inputSrc = NULL;
60 return 1;
61 }
62 return 0;
63}

References del_Buffer_dim(), CLogRingBuffer::indentSize, CLogRingBuffer::inputSrc, CLogRingBuffer::kindData, LBUF, make_Buffer(), CLogRingBuffer::maxBufSize, CLogRingBuffer::maxLineX, CLogRingBuffer::maxLineY, CLogRingBuffer::pBuf, CLogRingBuffer::rPos, Buffer::state, CLogRingBuffer::tlDataSize, and CLogRingBuffer::wPos.

Referenced by CLogRingBuffer::CLogRingBuffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ putRingBuffer()

void putRingBuffer ( Buffer buf,
int input = LOG_RB_MESG,
int kind = LOG_RB_UNKNOWN_DATA )

void CLogRingBuffer::putRingBuffer(Buffer buf, int input, int kind)

バッファの最後にデータを追加する.

Parameters
buf追加するデータ.
inputデータのタグ LOG_RB_MESG, LOG_RB_INFO, LOG_RB_DEBUG, LOG_RB_WARN, LOG_RB_ERR
kindデータの種類 LOG_RB_UNKNOWN_DATA, LOG_RB_TEXT_DATA, LOG_RB_TEXT_HALF_DATA, LOG_RB_BINARY_DATA, LOG_RB_BINHEX_DATA

Definition at line 90 of file LogRingBuffer.cpp.

91{
92 int i, nxt = 0;
93 bool recalcX = false;
94 char num[10];
95
96 if (buf.buf==NULL || buf.vldsz<=0) return;
97 Buffer* dim = decompline_Buffer_dim(buf, ON);
98 if (dim==NULL || dim->state<=0) return;
99 tlDataSize += buf.vldsz;
100
101#ifdef DEBUG
102 int total = 0;
103 for (i=0; i<dim->state; i++) {
104 total += dim[i].vldsz;
105 }
106 if (buf.vldsz!=total) {
107 DEBUG_ERR("ERROR: CLogRingBuffer::putRingBuffer(): mismatch total data size!! %d %d", buf.vldsz, total);
108 }
109#endif
110
111 // 前の行の続き
112 int pos = wPos - 1;
113 if (pos<0) pos += maxBufSize;
114 if (kindData[pos]==LOG_RB_TEXT_HALF_DATA && isText_Buffer(dim[0])
115 && inputSrc[pos]==input && input!=LOG_RB_INFO && kind==LOG_RB_UNKNOWN_DATA) {
116 cat_Buffer(&dim[0], &pBuf[pos]);
119 nxt = 1; // 処理済
120 }
121
122 // 新しい行.
123 pos = wPos - 1;
124 for (i=nxt; i<dim->state; i++) {
125 pos++; // == wPos
126 if (pos>=maxBufSize) pos -= maxBufSize;
127 if (!recalcX && maxLineY==maxBufSize && maxLineX==getLengthX(pos)) recalcX = true;
128
129 snprintf(num, 10, "%05d| ", pos);
130 copy_s2Buffer(num, &pBuf[pos]);
131 if (input==LOG_RB_ERROR) cat_s2Buffer("ERROR: ", &pBuf[pos]);
132 else if (input==LOG_RB_WARNING) cat_s2Buffer("WARN : ", &pBuf[pos]);
133 else if (input==LOG_RB_DEBUG) cat_s2Buffer("DEBUG: ", &pBuf[pos]);
134 else if (input==LOG_RB_INFO) cat_s2Buffer("INFO : ", &pBuf[pos]);
135 //else cat_s2Buffer(" ", &pBuf[pos]);
136
137 cat_Buffer(&dim[i], &pBuf[pos]);
139 else kindData[pos] = kind;
140 inputSrc[pos] = input;
142 }
143
144 // 最後のデータの再確認
145 if (nxt<dim->state && kind==LOG_RB_UNKNOWN_DATA) {
146 if (isText_Buffer(dim[dim->state-1])) {
147 unsigned char end = dim[dim->state-1].buf[dim[dim->state-1].vldsz-1];
148 if (end!=CHAR_CR && end!=CHAR_LF) kindData[pos] = LOG_RB_TEXT_HALF_DATA;
149 }
150 else {
152 }
153 }
154
155 pos++;
156 if (pos>=maxBufSize) pos -= maxBufSize;
157 wPos = pos;
158
159 // 次のn行を目印行にする.
160 Buffer spbuf = rept_Buffer(' ', 80);
161 cat_s2Buffer("\n", &spbuf);
162 for (i=0; i<2; i++) {
163 copy_Buffer(&spbuf, &pBuf[pos]);
164 inputSrc[pos] = LOG_RB_INFO;
166 pos++;
167 if (pos>=maxBufSize) pos -= maxBufSize;
168 }
169 free_Buffer(&spbuf);
170
171 // コンテキストのサイズを計算
172 if (maxLineY<maxBufSize) {
174 else maxLineY = wPos + 1;
175 }
176 //DEBUG_WARN("WARNING: MaxY = %d", maxLineY);
177
178 if (recalcX) {
179 maxLineX = 0;
180 for (i=0; i<maxBufSize; i++) {
182 }
183 }
184
185 del_Buffer_dim(&dim);
186 return;
187}
#define LOG_RB_BINARY_DATA
#define LOG_RB_WARNING
#define LOG_RB_TEXT_DATA
#define LOG_RB_DEBUG
#define LOG_RB_UNKNOWN_DATA
#define LOG_RB_INFO
#define LOG_RB_ERROR
#define LOG_RB_TEXT_HALF_DATA
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Definition buffer.cpp:128
Buffer rept_Buffer(unsigned char cc, int n)
文字 ccを n回繰り返したBuffer型データを返す.
Definition buffer.cpp:234
int isText_Buffer(Buffer buf)
Buffer型変数 bufのバッファ部がテキストかどうか検査する.
Definition buffer.cpp:1373
int cat_Buffer(Buffer *src, Buffer *dst)
Buffer変数 srcから dstへバッファを catする.
Definition buffer.cpp:384
#define copy_s2Buffer(src, dst)
copy_b2Buffer()
Definition buffer.h:108
#define cat_s2Buffer(src, dst)
cat_b2Buffer()
Definition buffer.h:122
#define Max(x, y)
Definition common.h:247
#define snprintf
Definition common.h:56
#define ON
Definition common.h:230
#define CHAR_CR
改行
Definition tools.h:78
#define CHAR_LF
ラインフィード
Definition tools.h:79
Buffer * decompline_Buffer_dim(Buffer buf, int mode)
データを行単位に分解する.改行は \r\n
Definition xtools.cpp:1479

References Buffer::buf, cat_Buffer(), cat_s2Buffer, CHAR_CR, CHAR_LF, copy_Buffer(), copy_s2Buffer, decompline_Buffer_dim(), del_Buffer_dim(), free_Buffer(), CLogRingBuffer::getLengthX(), CLogRingBuffer::inputSrc, isText_Buffer(), CLogRingBuffer::kindData, LOG_RB_BINARY_DATA, LOG_RB_DEBUG, LOG_RB_ERROR, LOG_RB_INFO, LOG_RB_TEXT_DATA, LOG_RB_TEXT_HALF_DATA, LOG_RB_UNKNOWN_DATA, LOG_RB_WARNING, Max, CLogRingBuffer::maxBufSize, CLogRingBuffer::maxLineX, CLogRingBuffer::maxLineY, ON, CLogRingBuffer::pBuf, rept_Buffer(), snprintf, Buffer::state, CLogRingBuffer::tlDataSize, Buffer::vldsz, and CLogRingBuffer::wPos.

Referenced by CLogRingBuffer::putRingFormat(), CLogRingBuffer::putRingFormat(), and CLogRingBuffer::rewriteBinHexRingBuffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ putRingFormat() [1/2]

void putRingFormat ( int input,
char * fmt,
va_list args )

void CLogRingBuffer::putRingFormat(int input, char* fmt, va_list args)

可変数変数用の書き込み用関数.バッファの最後に生成された文字列を追加する. 上位の関数から呼び出して使用する.

Definition at line 253 of file LogRingBuffer.cpp.

254{
255 char* nfmt;
256 int len;
257 Buffer buf;
258
259 len = (int)strlen(fmt);
260 nfmt = (char*)malloc(len+1);
261 if (nfmt==NULL) return;
262 strncpy(nfmt, fmt, len);
263 nfmt[len] = '\0';
264
265 buf = make_Buffer(LBUF);
266 vsnprintf((char*)buf.buf, LBUF-1, nfmt, args);
268 free(nfmt);
269
270 putRingBuffer(buf, input, LOG_RB_TEXT_DATA);
271 free_Buffer(&buf);
272
273 return;
274}
int recalc_strlen_Buffer(Buffer *buf)
Buffer型変数のデータ部を文字列と見なして,その長さを返す.
Definition buffer.cpp:1310
void putRingBuffer(Buffer buf, int input=LOG_RB_MESG, int kind=LOG_RB_UNKNOWN_DATA)
#define vsnprintf
Definition common.h:57

References Buffer::buf, free_Buffer(), LBUF, LOG_RB_TEXT_DATA, make_Buffer(), CLogRingBuffer::putRingBuffer(), recalc_strlen_Buffer(), and vsnprintf.

Here is the call graph for this function:

◆ putRingFormat() [2/2]

void putRingFormat ( int input,
char * fmt,
... )

void CLogRingBuffer::putRingFormat(int input, char* fmt, ...)

可変数変数用の書き込み用関数.バッファの最後に生成された文字列を追加する.

Definition at line 218 of file LogRingBuffer.cpp.

219{
220 char* nfmt;
221 int len;
222 Buffer buf;
223
224 va_list args;
225 va_start(args, fmt);
226
227 len = (int)strlen(fmt);
228 nfmt = (char*)malloc(len+1);
229 if (nfmt==NULL) return;
230 strncpy(nfmt, fmt, len);
231 nfmt[len] = '\0';
232
233 buf = make_Buffer(LBUF);
234 vsnprintf((char*)buf.buf, LBUF-1, nfmt, args);
236 free(nfmt);
237
238 va_end(args);
239
240 putRingBuffer(buf, input, LOG_RB_TEXT_DATA);
241 free_Buffer(&buf);
242
243 return;
244}

References Buffer::buf, free_Buffer(), LBUF, LOG_RB_TEXT_DATA, make_Buffer(), CLogRingBuffer::putRingBuffer(), recalc_strlen_Buffer(), and vsnprintf.

Here is the call graph for this function:

◆ rewriteBinHexRingBuffer()

void rewriteBinHexRingBuffer ( int n,
int input )

void CLogRingBuffer::rewriteBinHexRingBuffer(int n, int input)

バッファ位置 nにあるデータを 16進表示で書き直す. 主に,位置 nにあるデータがバイナリの場合に使用する.

Definition at line 196 of file LogRingBuffer.cpp.

197{
198 while (n<0) n += maxBufSize;
199 if (n>=maxBufSize) n = n%maxBufSize;
200
201 Buffer dup = pBuf[n];
202 dup.buf = dup.buf + indentSize;
203 dup.vldsz = dup.vldsz - indentSize;
204
205 Buffer buf = dump_Buffer(dup);
206 wPos = n;
208
209 free_Buffer(&buf);
210}
#define LOG_RB_BINHEX_DATA
Buffer dump_Buffer(Buffer buf)
Buffer型変数のデバッグ用 16進を Buffer型変数に出力する.
Definition buffer.cpp:1254

References Buffer::buf, dump_Buffer(), free_Buffer(), CLogRingBuffer::indentSize, LOG_RB_BINHEX_DATA, CLogRingBuffer::maxBufSize, CLogRingBuffer::pBuf, CLogRingBuffer::putRingBuffer(), Buffer::vldsz, and CLogRingBuffer::wPos.

Here is the call graph for this function:

Member Data Documentation

◆ indentSize

int indentSize
protected

◆ inputSrc

◆ kindData

int* kindData
protected

◆ maxBufSize

◆ maxLineX

◆ maxLineY

◆ pBuf

◆ rPos

int rPos
protected

◆ tlDataSize

int tlDataSize
protected

◆ wPos


The documentation for this class was generated from the following files: