home *** CD-ROM | disk | FTP | other *** search
- #ifndef _ITRACE_
- #define _ITRACE_
- /*******************************************************************************
- * FILE NAME: itrace.hpp *
- * *
- * DESCRIPTION: *
- * Declaration of the class(es): *
- * ITrace - Trace Logging Facility *
- * *
- * COPYRIGHT: *
- * (C) Copyright IBM Corporation 1992 *
- * All Rights Reserved *
- * Licensed Materials * Property of IBM *
- * *
- * HISTORY: *
- * $Log: R:/IBMCLASS/IBASE/VCS/ITRACE.HPV $
- //
- // Rev 1.7 25 Oct 1992 16:46:44 nunn
- //changed library name to ICLUI
- //
- // Rev 1.6 24 Oct 1992 15:36:12 BOBLOVE
- //Fixed problem with IVBase inheritance
- //
- // Rev 1.5 24 Oct 1992 12:52:22 BOBLOVE
- //Updated documentation for External Beta
- * *
- *******************************************************************************/
- #ifndef _IVBASE_
- #include <ivbase.hpp>
- #endif
-
- // Forward declarations for other classes:
- class IString;
-
- class ITrace : public IVBase
- /*******************************************************************************
- * Trace Logging Facility *
- * *
- * Provides the capability for module tracing within the library. Tracing *
- * occurs based on the setting of the environment variables "ICLUI TRACE" *
- * "ICLUI TRACETO". Tracing is off by default but can be set on using *
- * "SET ICLUI TRACE=ON". By default tracing occurs to the OS/2 queue name *
- * "\\QUEUES\\PRINTF32" but can be routed to standard error using *
- * "SET ICLUI TRACETO=STDERR" or standard out using "SET ICLUI TRACETO=STDOUT".*
- * It can be be switched back to the queue by using "SET ICLUI TRACETO=QUEUE". *
- * Static functions also exist to accomplish these same things under program *
- * control. *
- * *
- * Trace input is supported as IString's or character arrays and a line feed *
- * is automatically added on all trace calls. *
- * *
- * To enable the trace calls to be compiled in and out of the code, 3 sets *
- * of macros are provided for tracing modules and data. *
- * *
- * If IC_TRACE_RUNTIME is defined, the following macros *
- * are expanded: *
- * IMODTRACE_RUNTIME() IFUNCTRACE_RUNTIME() ITRACE_RUNTIME() *
- * *
- * If IC_TRACE_DEVELOP is defined, the following macros, in *
- * addition to the RUNTIME macros, are defined: *
- * IMODTRACE_DEVELOP() IFUNCTRACE_DEVELOP() ITRACE_DEVELOP() *
- * *
- * If IC_TRACE_ALL is defined, the following macros, in *
- * addition to the RUNTIME & DEVELOP macros, are defined: *
- * IMODTRACE_ALL() IFUNCTRACE_ALL() ITRACE_ALL() *
- * *
- * The IMODTRACE version of the macros takes as input a module name that will *
- * be used for construction and destruction tracing. *
- * *
- * The IFUNCTRACE version of the macros takes no input and uses the predefined *
- * identifier __FUNCTION__ for construction and destruction tracing. *
- * *
- * The ITRACE version of the macros takes a text string to be traced. *
- * *
- * EXAMPLE: *
- * *
- * The following example traces the entry and exit of a function as well as *
- * writing a text string in the module. *
- * *
- * AnyClass :: anyFunction() *
- * { *
- * ITrace trc("AnyClass :: anyFunction"); *
- * . *
- * trc.write(IString("The answer is: ")+IString(10)); *
- * } *
- * Output produced is: *
- * *
- * +AnyClass :: anyFunction *
- * >The answer is 10 *
- * -AnyClass :: anyFunction *
- * *
- * *
- * Using macros to accomplish the same thing: *
- * *
- * AnyClass :: anyFunction() *
- * { *
- * IMODTRACE_DEVELOP("AnyClass :: anyFunction"); *
- * . *
- * ITRACE_DEVELOP(IString("The answer is: ")+IString(10)); *
- * } *
- * *
- * *
- *******************************************************************************/
- {
- friend void writeString(const IString& str);
-
- public:
- /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
- | There are 2 ways to construct instances of this class: |
- | 1. default |
- | An ITrace object is created but no logging occurs on construction |
- | or destruction. |
- | 2. By passing an optional name and line number |
- | If a name is passed then the name is written on construction and |
- | again on destruction. |
- ------------------------------------------------------------------------------*/
- ITrace(const char* pszTraceName=0,
- long LineNumber=0);
-
- ~ITrace();
-
- /*---------------------------Trace Output Functions ----------------------------
- | These functions cause trace data to be written to the current trace location.|
- | write - Write the passed character string or IString |
- ------------------------------------------------------------------------------*/
- static void
- write(const IString& str),
- write(const char* psz);
-
- /*-------------------------STATIC ACCESSORS ------------------------------------
- | These functions provide means of getting and setting the accessible |
- | attributes of instances of this class: |
- | traceLocation - Return an enumeration specifying the trace output |
- | location. |
- | enableTrace - Allow trace entries to be written. |
- | disableTrace - Stop trace entries from being written. |
- | sendTraceToQueue - Set the location for output to "\\QUEUES\\PRINTF32". |
- | sendTraceToStdError - Set the location for output to Standard Error |
- | Stream. |
- | sendTraceToStdOut - Set the location for output to Standard Output Stream.|
- | enableTraceLineNo - Enable the tracing of line number information. |
- | disableTraceLineNo - Disable the tracing of line number information. |
- | isTraceEnabled - Determine if tracing is currently enabled. |
- | isLineNoTraceEnabled - Determine if line numbers are currently being written.|
- ------------------------------------------------------------------------------*/
- enum traceLoc { toQueue, toStdError, toStdOut, readEnv };
-
- static long
- traceLocation();
-
- static void
- enableTrace(),
- disableTrace(),
- sendTraceToQueue(), /* Default */
- sendTraceToStdError(),
- sendTraceToStdOut(),
- enableTraceLineNo(),
- disableTraceLineNo();
-
- static Boolean
- isTraceEnabled(),
- isLineNoTraceEnabled();
-
- static void
- writeString(char* psz),
- writeString(IString& str);
-
- protected:
- /*----------------------------- IMPLEMENTATION ---------------------------------
- | Actual trace output functions after formating. |
- ------------------------------------------------------------------------------*/
- static long
- threadId();
-
- private:
- /*------------------------------ DATA MEMBERS ----------------------------------
- | pszTraceName - Function name passed on construction. |
- ------------------------------------------------------------------------------*/
- char
- *pszClTraceName;
- };
-
-
- /*--------------------------------------------------------------*/
- /* Selective inclusion of tracing accomplished based on prior */
- /* definition of Trace "level" macros. */
- /*--------------------------------------------------------------*/
- #ifdef IC_TRACE_ALL
- #define IMODTRACE_ALL(modname) ITrace trc(modname, __LINE__ )
- #define IFUNCTRACE_ALL() ITrace trc(__FUNCTION__, __LINE__ )
- #define ITRACE_ALL(p1) ITrace::write(p1)
- #else
- #define IMODTRACE_ALL(modname)
- #define IFUNCTRACE_ALL()
- #define ITRACE_ALL(p1)
- #endif
-
- #ifdef IC_TRACE_DEVELOP
- #define IMODTRACE_DEVELOP(modname) ITrace trc(modname, __LINE__ )
- #define IFUNCTRACE_DEVELOP() ITrace trc(__FUNCTION__, __LINE__ )
- #define ITRACE_DEVELOP(p1) ITrace::write(p1)
- #else
- #define IMODTRACE_DEVELOP(modname)
- #define IFUNCTRACE_DEVELOP()
- #define ITRACE_DEVELOP(p1)
- #endif
-
- #ifdef IC_TRACE_RUNTIME
- #define IMODTRACE_RUNTIME(modname) ITrace trc(modname, __LINE__ )
- #define IFUNCTRACE_RUNTIME() ITrace trc(__FUNCTION__, __LINE__ )
- #define ITRACE_RUNTIME(p1) ITrace::write(p1)
- #else
- #define IMODTRACE_RUNTIME(modname)
- #define IFUNCTRACE_RUNTIME()
- #define ITRACE_RUNTIME(p1)
- #endif
-
-
- #endif /* _ITRACE_ */