home *** CD-ROM | disk | FTP | other *** search
- #ifdef FW_DEBUG
- // This entire file is for debugging only
- //========================================================================================
- //
- // File: FWExcLog.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWEXCLOG_H
- #include "FWExcLog.h"
- #endif
-
- #ifndef FWTRACE_H
- #include "FWTrace.h"
- #endif
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifndef FWDBGSTR_H
- #include "FWDbgStr.h"
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment BEL
- #endif
-
- //========================================================================================
- // CLASS _FW_CExceptionLog
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // _FW_CExceptionLog::Initialize
- //----------------------------------------------------------------------------------------
- void _FW_CExceptionLog::Initialize(FW_SPrivExceptionLog& globals)
- {
- globals.gInitialized = 1;
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_CExceptionLog::StartLog
- //----------------------------------------------------------------------------------------
- // We increment the counter each time StartLog is called.
- // Logging is only enabled when the counter is above 0.
- // Logging requires tracing, so StartLog calls StartTrace.
- void _FW_CExceptionLog::StartLog()
- {
- FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
- globals.gLogEnabled++;
- FW_PRIV_ASSERT(globals.gLogEnabled>0); // if fails, StartLog called too many times!
- globals.gTriggerCounter = 0; // Reset the counter
- FW_CTraceRuntime::StartTrace();
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_CExceptionLog::StopLog
- //----------------------------------------------------------------------------------------
- unsigned long _FW_CExceptionLog::StopLog()
- {
- FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
- FW_CTraceRuntime::StopTrace();
- globals.gLogEnabled--;
- FW_PRIV_ASSERT(globals.gLogEnabled>=0); // if fails, StopLog called too many times!
- return globals.gTriggerCounter;
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_CExceptionLog::LogException
- //----------------------------------------------------------------------------------------
- void _FW_CExceptionLog::LogException(FW_ClassReference exceptionClass)
- {
- FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
- if (globals.gLogEnabled == 0)
- return;
-
- FW_CDebugStream * traceStream = FW_CPrivTraceTaskGlobals::GetTraceGlobals().gTraceStream;
-
- if (traceStream != NULL)
- {
- globals.gTriggerCounter++;
- const char *name = exceptionClass->GetClassName();
- (*traceStream) << "LOG: ";
- (*traceStream) << globals.gTriggerCounter;
- (*traceStream) << " Class " << name << EndLine;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_CExceptionLog::TriggerException
- //----------------------------------------------------------------------------------------
- void _FW_CExceptionLog::TriggerException(FW_ClassReference exceptionClass,
- const _FW_CException &theException)
- {
- FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
-
- globals.gTriggerCounter++;
-
- FW_ClassReference triggerClass = globals.gTriggerClass;
-
- //
- // If the Exception that is going to be triggered is not NULL, check if there is a
- // match. Else Check if the trigger point is the one we want.
- //
- if (triggerClass != NULL && triggerClass == exceptionClass)
- FW_THROW(theException);
- else if (globals.gTriggerPoint == globals.gTriggerCounter)
- FW_THROW(theException);
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_CExceptionLog::CauseException
- //----------------------------------------------------------------------------------------
- void _FW_CExceptionLog::CauseException(unsigned long triggerPoint)
- {
- FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
-
- globals.gTriggerCounter = 0;
- globals.gTriggerClass = 0;
- globals.gTriggerPoint = triggerPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_CExceptionLog::CauseException
- //----------------------------------------------------------------------------------------
- void _FW_CExceptionLog::CauseException(FW_ClassReference exceptionClass)
- {
- FW_SPrivExceptionLog& globals = _FW_CExceptionLog::GetExceptionLogGlobals();
-
- globals.gTriggerCounter = 0;
- globals.gTriggerClass = exceptionClass;
- globals.gTriggerPoint = 0;
- }
-
- #endif
-