CLogWndDoc Class Reference

#include <LogWndDoc.h>

Collaboration diagram for CLogWndDoc:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual BOOL OnNewDocument ()
virtual void Serialize (CArchive &ar)
virtual void lprintBuffer (Buffer buf, int input=LOG_RB_MESG)
virtual void lprintString (char *str, int input=LOG_RB_MESG)
virtual void lprintFormat (char *fmt,...)
virtual void lfprintFormat (int input, char *fmt,...)
virtual void printBuffer (Buffer buf, int input=LOG_RB_MESG)
virtual void printString (char *str, int input=LOG_RB_MESG)
virtual void printFormat (char *fmt,...)
virtual void fprintFormat (int input, char *fmt,...)
virtual void lock (void)
virtual void unlock (void)
virtual ~CLogWndDoc ()
virtual void AssertValid () const
virtual void Dump (CDumpContext &dc) const
void free (void)
void clear (void)
int writeLogFile (void)
CString easyGetSaveFileName (LPCTSTR title, HWND hWnd)
void DeleteContents (void)
CLogWndViewGetView (void)

Public Attributes

CLogWndFramepFrame
CLogWndViewpView
CString Title
BOOL binHexMode
CString save_fname
CLogRingBuffer * ringBuffer
CCriticalSection criticalKey

Protected Member Functions

 CLogWndDoc ()
 CLogWndDoc (int bufsz, BOOL binhex=TRUE)

Detailed Description

Definition at line 23 of file LogWndDoc.h.


Constructor & Destructor Documentation

CLogWndDoc (  )  [protected]

Definition at line 29 of file LogWndDoc.cpp.

References MAXBUFFERLINE.

00030 {
00031     //DEBUG_INFO("CONSTRUCTOR: CLogWndDoc\n");
00032 
00033     pFrame     = NULL;
00034     pView      = NULL;
00035     Title      = _T("");
00036     save_fname = _T("");
00037     binHexMode = TRUE;
00038 //  m_locked   = FALSE;
00039 
00040     ringBuffer = new CLogRingBuffer(MAXBUFFERLINE);
00041 }

CLogWndDoc ( int  bufsz,
BOOL  binhex = TRUE 
) [protected]

Definition at line 45 of file LogWndDoc.cpp.

References CLogWndDoc::binHexMode, MAXBUFFERLINE, CLogWndDoc::pFrame, CLogWndDoc::pView, CLogWndDoc::ringBuffer, CLogWndDoc::save_fname, and CLogWndDoc::Title.

00046 {
00047     //DEBUG_INFO("CONSTRUCTOR: CLogWndDoc 2\n");
00048 
00049     pFrame     = NULL;
00050     pView      = NULL;
00051     Title      = _T("");
00052     save_fname = _T("");
00053     binHexMode = binhex;
00054 
00055     if (bufsz<=0) bufsz = MAXBUFFERLINE;
00056     ringBuffer = new CLogRingBuffer(bufsz);
00057 }

~CLogWndDoc (  )  [virtual]

Definition at line 61 of file LogWndDoc.cpp.

References CLogWndDoc::free(), CLogWndDoc::pView, and CLogWndView::unlock().

00062 {
00063     DEBUG_INFO("DESTRUCTOR: CLogWndDoc: START\n");
00064 
00065     while(m_locked) ::Sleep(10);
00066     if (pView!=NULL) pView->unlock();
00067 
00068     CLogWndDoc::free();
00069 
00070     DEBUG_INFO("DESTRUCTOR: CLogWndDoc: END\n");
00071 }

Here is the call graph for this function:


Member Function Documentation

void AssertValid (  )  const [virtual]

Definition at line 117 of file LogWndDoc.cpp.

00118 {
00119     CDocument::AssertValid();
00120 }

void clear ( void   ) 

Definition at line 157 of file LogWndDoc.cpp.

References CLogWndDoc::criticalKey, CLogWndDoc::lock(), CLogWndDoc::ringBuffer, and CLogWndDoc::save_fname.

Referenced by CLogWndView::clearViewDoc().

00158 {
00159     save_fname = _T("");
00160 
00161     CSingleLock lock(&criticalKey);
00162     lock.Lock();
00163     while (!lock.IsLocked()) {
00164         Sleep(100);
00165         lock.Lock();
00166     }
00167     
00168     ringBuffer->clear();
00169     lock.Unlock();
00170 
00171     return;
00172 }

Here is the call graph for this function:

Here is the caller graph for this function:

void DeleteContents ( void   ) 

Definition at line 135 of file LogWndDoc.cpp.

00136 {
00137     //CLogWndDoc::clear();
00138     //DEBUG_WARN("CLogWndDoc::DeleteContents: IN\n");
00139     CDocument::DeleteContents();
00140 }

void Dump ( CDumpContext &  dc  )  const [virtual]

Definition at line 123 of file LogWndDoc.cpp.

00124 {
00125     CDocument::Dump(dc);
00126 }

CString easyGetSaveFileName ( LPCTSTR  title,
HWND  hWnd 
)

Definition at line 214 of file LogWndDoc.cpp.

Referenced by CLogWndFrame::OnLogSave().

00215 {   
00216     OPENFILENAME  ofn;
00217     TCHAR fn[LNAME];
00218     CString str = _T(""); 
00219 
00220     memset(fn, 0, LNAME);
00221     memset(&ofn, 0, sizeof(OPENFILENAME));
00222 
00223     ofn.lStructSize = sizeof(OPENFILENAME);
00224     ofn.hwndOwner = hWnd;
00225     ofn.Flags = 0;
00226     ofn.lpstrFile = fn;
00227     ofn.nMaxFile  = LNAME;
00228     ofn.lpstrTitle = title;
00229 
00230     BOOL ret = GetSaveFileName(&ofn);
00231     if (ret) str = fn;
00232 
00233     return str;
00234 }

Here is the caller graph for this function:

void fprintFormat ( int  input,
char *  fmt,
  ... 
) [virtual]

Definition at line 376 of file LogWndDoc.cpp.

References CLogWndDoc::pView, and CLogWndDoc::ringBuffer.

00377 {
00378     if (ringBuffer==NULL || pView==NULL || fmt==NULL) return;
00379 
00380     va_list  args;
00381     va_start(args, fmt);
00382     ringBuffer->putRingFormat(input, fmt, args);
00383     va_end(args);
00384     
00385     InvalidateRect(pView->m_hWnd, NULL, FALSE);
00386 
00387     return;
00388 }

void free ( void   ) 

Definition at line 75 of file LogWndDoc.cpp.

References CLogWndDoc::ringBuffer.

Referenced by CLogWndDoc::~CLogWndDoc().

00076 {
00077     if (ringBuffer!=NULL) {
00078         delete(ringBuffer);
00079         ringBuffer = NULL;
00080     }
00081 }

Here is the caller graph for this function:

CLogWndView * GetView ( void   ) 

Definition at line 144 of file LogWndDoc.cpp.

References CLogWndView::GetDocument().

00145 {
00146     //DEBUG_INFO("CLogWndDoc::GetView():\n");
00147     POSITION pos = GetFirstViewPosition();
00148     while (pos!=NULL) {
00149         CLogWndView* pview = (CLogWndView*)GetNextView(pos);
00150         if (this==pview->GetDocument()) return pview;
00151     }
00152     return NULL;
00153 }

Here is the call graph for this function:

void lfprintFormat ( int  input,
char *  fmt,
  ... 
) [virtual]

Definition at line 285 of file LogWndDoc.cpp.

References CLogWndDoc::criticalKey, CLogWndDoc::lock(), CLogWndDoc::pView, and CLogWndDoc::ringBuffer.

00286 {
00287     if (ringBuffer==NULL || pView==NULL || fmt==NULL) return;
00288 
00289     int no = 0, trymax = 100;
00290 
00291     CSingleLock lock(&criticalKey);
00292     lock.Lock();
00293     while (!lock.IsLocked() && no<trymax) {
00294         Sleep(100);
00295         lock.Lock();
00296         no++;
00297     }
00298 
00299     va_list  args;
00300     va_start(args, fmt);
00301     ringBuffer->putRingFormat(input, fmt, args);
00302     va_end(args);
00303     
00304     lock.Unlock();
00305 
00306     InvalidateRect(pView->m_hWnd, NULL, FALSE);
00307 
00308     return;
00309 }

Here is the call graph for this function:

virtual void lock ( void   )  [inline, virtual]

Definition at line 55 of file LogWndDoc.h.

References CLogWndView::lock(), and CLogWndDoc::pView.

Referenced by CLogWndDoc::clear(), CLogWndDoc::lfprintFormat(), CLogWndDoc::lprintBuffer(), CLogWndDoc::lprintFormat(), and CLogWndDoc::writeLogFile().

00055 { m_locked = TRUE;  if (pView!=NULL) pView->lock();}

Here is the call graph for this function:

Here is the caller graph for this function:

void lprintBuffer ( Buffer  buf,
int  input = LOG_RB_MESG 
) [virtual]

Definition at line 243 of file LogWndDoc.cpp.

References CLogWndDoc::binHexMode, CLogWndDoc::criticalKey, CLogWndDoc::lock(), CLogWndDoc::pView, and CLogWndDoc::ringBuffer.

00244 {
00245     if (ringBuffer==NULL || pView==NULL || buf.buf==NULL) return;
00246 
00247     int no = 0, trymax = 100;
00248 
00249     CSingleLock lock(&criticalKey);
00250     lock.Lock();
00251     while (!lock.IsLocked() && no<trymax) {
00252         Sleep(100);
00253         lock.Lock();
00254         no++;
00255     }
00256 
00257     ringBuffer->putRingBuffer(buf, input);
00258     
00259     int lastPos = ringBuffer->getLastPosition();
00260     if (binHexMode && ringBuffer->getKindData(lastPos-1)==LOG_RB_BINARY_DATA) {
00261         ringBuffer->rewriteBinHexRingBuffer(lastPos-1, input);
00262     }
00263     lock.Unlock();
00264 
00265     InvalidateRect(pView->m_hWnd, NULL, FALSE);
00266 
00267     return;
00268 }

Here is the call graph for this function:

void lprintFormat ( char *  fmt,
  ... 
) [virtual]

Definition at line 313 of file LogWndDoc.cpp.

References CLogWndDoc::criticalKey, CLogWndDoc::lock(), CLogWndDoc::pView, and CLogWndDoc::ringBuffer.

00314 {
00315     if (ringBuffer==NULL || pView==NULL || fmt==NULL) return;
00316 
00317     int no = 0, trymax = 100;
00318 
00319     CSingleLock lock(&criticalKey);
00320     lock.Lock();
00321     while (!lock.IsLocked() && no<trymax) {
00322         Sleep(100);
00323         lock.Lock();
00324         no++;
00325     }
00326 
00327     va_list  args;
00328     va_start(args, fmt);
00329     ringBuffer->putRingFormat(LOG_RB_MESG, fmt, args);
00330     va_end(args);
00331     
00332     lock.Unlock();
00333 
00334     InvalidateRect(pView->m_hWnd, NULL, FALSE);
00335 
00336     return;
00337 }

Here is the call graph for this function:

void lprintString ( char *  str,
int  input = LOG_RB_MESG 
) [virtual]

Definition at line 272 of file LogWndDoc.cpp.

References CLogWndDoc::printBuffer(), CLogWndDoc::pView, and CLogWndDoc::ringBuffer.

00273 {
00274     if (ringBuffer==NULL || pView==NULL || msg==NULL) return;
00275 
00276     Buffer buf = make_Buffer_bystr(msg);
00277     printBuffer(buf, input);
00278     free_Buffer(&buf);
00279 
00280     return;
00281 }

Here is the call graph for this function:

BOOL OnNewDocument (  )  [virtual]

Definition at line 85 of file LogWndDoc.cpp.

00086 {
00087     //DEBUG_INFO("CLogWndDoc::OnNewDocument():\n");
00088     if (!CDocument::OnNewDocument()) return FALSE;
00089     return TRUE;
00090 }

void printBuffer ( Buffer  buf,
int  input = LOG_RB_MESG 
) [virtual]

Definition at line 345 of file LogWndDoc.cpp.

References CLogWndDoc::binHexMode, CLogWndDoc::pView, and CLogWndDoc::ringBuffer.

Referenced by CLogWndDoc::lprintString(), and CLogWndDoc::printString().

00346 {
00347     if (ringBuffer==NULL || pView==NULL || buf.buf==NULL) return;
00348 
00349     ringBuffer->putRingBuffer(buf, input);
00350     
00351     int lastPos = ringBuffer->getLastPosition();
00352     if (binHexMode && ringBuffer->getKindData(lastPos-1)==LOG_RB_BINARY_DATA) {
00353         ringBuffer->rewriteBinHexRingBuffer(lastPos-1, input);
00354     }
00355 
00356     InvalidateRect(pView->m_hWnd, NULL, FALSE);
00357 
00358     return;
00359 }

Here is the caller graph for this function:

void printFormat ( char *  fmt,
  ... 
) [virtual]

Definition at line 392 of file LogWndDoc.cpp.

References CLogWndDoc::pView, and CLogWndDoc::ringBuffer.

00393 {
00394     if (ringBuffer==NULL || pView==NULL || fmt==NULL) return;
00395 
00396     va_list  args;
00397     va_start(args, fmt);
00398     ringBuffer->putRingFormat(LOG_RB_MESG, fmt, args);
00399     va_end(args);
00400     
00401     InvalidateRect(pView->m_hWnd, NULL, FALSE);
00402 
00403     return;
00404 }

void printString ( char *  str,
int  input = LOG_RB_MESG 
) [virtual]

Definition at line 363 of file LogWndDoc.cpp.

References CLogWndDoc::printBuffer(), CLogWndDoc::pView, and CLogWndDoc::ringBuffer.

00364 {
00365     if (ringBuffer==NULL || pView==NULL || msg==NULL) return;
00366 
00367     Buffer buf = make_Buffer_bystr(msg);
00368     printBuffer(buf, input);
00369     free_Buffer(&buf);
00370 
00371     return;
00372 }

Here is the call graph for this function:

void Serialize ( CArchive &  ar  )  [virtual]

Definition at line 98 of file LogWndDoc.cpp.

00099 {
00100     if (ar.IsStoring())
00101     {
00102         // TODO: 格納するコードをここに追加してください.
00103     }
00104     else
00105     {
00106         // TODO: 読み込むコードをここに追加してください.
00107     }
00108 }

virtual void unlock ( void   )  [inline, virtual]

Definition at line 56 of file LogWndDoc.h.

References CLogWndDoc::pView, and CLogWndView::unlock().

00056 { m_locked = FALSE; if (pView!=NULL) pView->unlock();}

Here is the call graph for this function:

int writeLogFile ( void   ) 

Definition at line 179 of file LogWndDoc.cpp.

References CLogWndDoc::criticalKey, CLogWndDoc::lock(), CLogWndDoc::ringBuffer, and CLogWndDoc::save_fname.

Referenced by CLogWndFrame::OnLogSave().

00180 {
00181     if (save_fname==_T("")) return -1;
00182 
00183     CSingleLock lock(&criticalKey);
00184     lock.Lock();
00185     while (!lock.IsLocked()) {
00186         Sleep(100);
00187         lock.Lock();
00188     }
00189     
00190     int size = 0;
00191     FILE* fp = tfopen(save_fname, _T("wb"));
00192     if (fp==NULL) {
00193         lock.Unlock();
00194         return -2;
00195     }
00196 
00197     for (int pos=0; pos<ringBuffer->getMaxLineY(); pos++) {
00198         Buffer buf = dup_Buffer(ringBuffer->pBuf[pos]);
00199         if (ringBuffer->getKindData(pos)!=LOG_RB_BINARY_DATA) {
00200             if (buf.buf[buf.vldsz-1]!='\n') cat_s2Buffer("\n", &buf);
00201         }
00202         fwrite((const char*)buf.buf, strlen((const char*)buf.buf), 1, fp);  // buf may be binary
00203         size += (int)strlen((const char*)buf.buf);
00204         free_Buffer(&buf);
00205     }
00206     fclose(fp);
00207     lock.Unlock();
00208 
00209     return size;
00210 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

BOOL binHexMode
CCriticalSection criticalKey

Definition at line 35 of file LogWndDoc.h.

Referenced by CLogWndDoc::CLogWndDoc().

CLogRingBuffer* ringBuffer
CString save_fname
CString Title

Definition at line 38 of file LogWndDoc.h.

Referenced by CLogWndDoc::CLogWndDoc().


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

Generated on 15 Nov 2023 for JunkBox_Win_Lib by  doxygen 1.6.1