1 /*****************************************************************************/
2 /* Software Testing Automation Framework (STAF)                              */
3 /* (C) Copyright IBM Corp. 2001                                              */
4 /*                                                                           */
5 /* This software is licensed under the Eclipse Public License (EPL) V1.0.    */
6 /*****************************************************************************/
7 
8 #ifndef STAF_Trace
9 #define STAF_Trace
10 
11 #include "STAF.h"
12 #include "STAFString.h"
13 
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 typedef enum STAFTracePoint_e
20 {
21     // No trace points
22     kSTAFTraceNone                = 0x00000000,
23 
24     // Service Auditing
25     kSTAFTraceServiceRequest      = 0x00000001,
26     kSTAFTraceServiceResult       = 0x00000002,
27     kSTAFTraceServiceError        = 0x00000004,
28     kSTAFTraceServiceAccessDenied = 0x00000008,
29     kSTAFTraceServiceManagement   = 0x00000010,
30     kSTAFTraceRemoteRequests      = 0x00000020,
31 
32     // Unexpected/Error conditions
33     kSTAFTraceError               = 0x00000100,
34 
35     // Registration Auditing
36     kSTAFTraceRegistration        = 0x00000200,
37 
38     // Warning conditions
39     kSTAFTraceWarning             = 0x00000400,
40 
41     // Info conditions
42     kSTAFTraceInfo                = 0x00000800,
43 
44     // Deprecated options
45     kSTAFTraceDeprecated          = 0x00001000,
46 
47     // Debug conditions
48     kSTAFTraceDebug               = 0x00002000,
49 
50     // Service Complete
51     kSTAFTraceServiceComplete     = 0x00004000,
52 
53     // All trace points
54     kSTAFTraceAll                 = 0xFFFFFFFF
55 } STAFTracePoint_t;
56 
57 typedef enum STAFTraceDestination_e
58 {
59     kSTAFTraceToStdout        = 0,
60     kSTAFTraceToStderr        = 1,
61     kSTAFTraceToFile          = 2,
62     kSTAFTraceToStdoutAndFile = 3,
63     kSTAFTraceToStderrAndFile = 4
64 } STAFTraceDestination_t;
65 
66 typedef enum STAFTraceFileMode_e
67 {
68     kSTAFTraceFileReplace  = 0,
69     kSTAFTraceFileAppend   = 1
70 } STAFTraceFileMode_t;
71 
72 
73 /****************************************************************************/
74 /* STAFTraceGetEnabledTracePoints - Retrieves the currently enabled trace   */
75 /*                                  points                                  */
76 /*                                                                          */
77 /* Accepts:  Nothing                                                        */
78 /*                                                                          */
79 /* Returns:  The currently enabled trace points                             */
80 /****************************************************************************/
81 STAFTracePoint_t STAFTraceGetEnabledTracePoints();
82 
83 
84 /****************************************************************************/
85 /* STAFTraceEnableTracePoints - Enables specified trace points              */
86 /*                                                                          */
87 /* Accepts: (IN)  The trace points to enable                                */
88 /*                                                                          */
89 /* Returns:  Nothing                                                        */
90 /****************************************************************************/
91 void STAFTraceEnableTracePoints(STAFTracePoint_t tracePoints);
92 
93 
94 /****************************************************************************/
95 /* STAFTraceDisableTracePoints - Disables specified trace points            */
96 /*                                                                          */
97 /* Accepts: (IN)  The trace points to disable                               */
98 /*                                                                          */
99 /* Returns:  Nothing                                                        */
100 /****************************************************************************/
101 void STAFTraceDisableTracePoints(STAFTracePoint_t tracePoints);
102 
103 
104 /****************************************************************************/
105 /* STAFTraceSetTraceDestination - Sets the destination for trace messages   */
106 /*                                                                          */
107 /* Accepts: (IN)  The trace destination                                     */
108 /*          (IN)  The file to trace to if destination is kSTAFTraceToFile   */
109 /*          (IN)  The file mode (replace or append) if destination is       */
110 /*                kSTAFTraceToFile (default is replace)                     */
111 /*          (OUT) Pointer to operating system return code                   */
112 /*                                                                          */
113 /* Returns:  kSTAFOk, if successful                                         */
114 /*           other,   if unsuccessful                                       */
115 /****************************************************************************/
116 STAFRC_t STAFTraceSetTraceDestination(STAFTraceDestination_t traceDestination,
117                                       STAFStringConst_t filename,
118                                       STAFTraceFileMode_t traceFileMode,
119                                       unsigned int *osRC);
120 
121 /****************************************************************************/
122 /* STAFTraceGetTraceDestination - Gets the destination for trace messages   */
123 /*                                                                          */
124 /* Accepts: (OUT) Pointer to trace destination                              */
125 /*          (OUT) Pointer to trace file name                                */
126 /*          (OUT) Pointer to operating system return code                   */
127 /*                                                                          */
128 /* Returns:  kSTAFOk, if successful                                         */
129 /*           other,   if unsuccessful                                       */
130 /*                                                                          */
131 /* Notes: 1) The trace file name will be non-NULL only if the trace         */
132 /*           destination is kSTAFTraceToFile                                */
133 /*        2) If the trace file name is non-NULL, you are responsible for    */
134 /*           calling STAFStringDestruct()                                   */
135 /****************************************************************************/
136 STAFRC_t STAFTraceGetTraceDestination(STAFTraceDestination_t *traceDestination,
137                                       STAFString_t *filename,
138                                       unsigned int *osRC);
139 
140 
141 /****************************************************************************/
142 /* STAFTraceGetTraceFileMode - Gets the trace file mode                     */
143 /* Accepts: (OUT) Pointer to trace file mode                                */
144 /*          (OUT) Pointer to operating system return code                   */
145 /*                                                                          */
146 /* Returns:  kSTAFOk, if successful                                         */
147 /*           other,   if unsuccessful                                       */
148 /*                                                                          */
149 /****************************************************************************/
150 STAFRC_t STAFTraceGetTraceFileMode(STAFTraceFileMode_t *traceFileMode,
151                                    unsigned int *osRC);
152 
153 
154 /****************************************************************************/
155 /* STAFTraceLogCStringMessage - Logs a trace message provided via a         */
156 /*                              NULL-terminated string                      */
157 /*                                                                          */
158 /* Accepts: (IN)  The trace point                                           */
159 /*          (IN)  Message                                                   */
160 /*          (OUT) Pointer to operating system return code                   */
161 /*                                                                          */
162 /* Returns:  kSTAFOk, if successful                                         */
163 /*           other,   if unsuccessful                                       */
164 /****************************************************************************/
165 STAFRC_t STAFTraceLogCStringMessage(STAFTracePoint_t tracePoint,
166                                     const char *message,
167                                     unsigned int *osRC);
168 
169 
170 /****************************************************************************/
171 /* STAFTraceLogSTAFStringMessage - Logs a trace message provided via a      */
172 /*                                 STAFString                               */
173 /*                                                                          */
174 /* Accepts: (IN)  The trace point                                           */
175 /*          (IN)  Message                                                   */
176 /*          (OUT) Pointer to operating system return code                   */
177 /*                                                                          */
178 /* Returns:  kSTAFOk, if successful                                         */
179 /*           other,   if unsuccessful                                       */
180 /****************************************************************************/
181 STAFRC_t STAFTraceLogSTAFStringMessage(STAFTracePoint_t tracePoint,
182                                        STAFStringConst_t message,
183                                        unsigned int *osRC);
184 
185 #ifdef __cplusplus
186 }
187 
188 // Begin C++ language declarations
189 
190 // STAFTrace - This class provides a thin wrapper around the C STAFTrace APIs.
191 //             It also provides the utility method doTrace(), which will
192 //             determine if a specific tracePoint would be traced before
193 //             actually trying to trace it.
194 
195 class STAFTrace
196 {
197 public:
198 
199     static void traceOn(STAFTracePoint_t mask);
200     static void traceOff(STAFTracePoint_t mask);
201     static STAFTracePoint_t getTraceMask();
202 
203     static STAFRC_t setTraceDestination(STAFTraceDestination_t traceDestination,
204                                         const STAFString &filename =
205                                                           STAFString(),
206                                         STAFTraceFileMode_t traceFileMode =
207                                                        kSTAFTraceFileReplace,
208                                         unsigned int *osRC = 0);
209     static STAFTraceDestination_t getTraceDestination(STAFString &filenam);
210     static STAFTraceFileMode_t getTraceFileMode();
211 
212     static bool doTrace(STAFTracePoint_t tracePoint);
213 
214     static STAFRC_t trace(STAFTracePoint_t tracePoint, const char *message);
215     static STAFRC_t trace(STAFTracePoint_t tracePoint,
216                           const STAFString &message);
217 };
218 
219 // Now include inline definitions
220 
221 inline STAFTracePoint_t operator|(const STAFTracePoint_t lhs,
222                                   const STAFTracePoint_t rhs)
223 {
224     return static_cast<STAFTracePoint_t>(static_cast<unsigned int>(lhs) |
225                                          static_cast<unsigned int>(rhs));
226 }
227 
228 #ifndef STAF_NATIVE_COMPILER
229 #include "STAFTraceInlImpl.cpp"
230 #endif
231 
232 // End C++ language definitions
233 
234 // End #ifdef __cplusplus
235 #endif
236 
237 #endif
238