1 martin 1.20 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.21 //
|
3 martin 1.20 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.21 //
|
10 martin 1.20 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.21 //
|
17 martin 1.20 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.21 //
|
20 martin 1.20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.21 //
|
28 martin 1.20 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <iostream>
33 #include <Pegasus/Common/TraceFileHandler.h>
|
34 kumpf 1.13 #include <Pegasus/Common/Mutex.h>
|
35 mike 1.2
36 PEGASUS_USING_STD;
37
38 PEGASUS_NAMESPACE_BEGIN
39
|
40 kumpf 1.13 static Mutex writeMutex;
41
|
42 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
43 marek 1.12 // On other platforms prepares the file handle (open file etc.).
44 // Implementation of this function is platform specific
45 //
46 // Note: The current implementation on Windows does nothing.
47 // Should be optimized out by the compiler
48 ////////////////////////////////////////////////////////////////////////////////
49 void TraceFileHandler::prepareFileHandle(void)
50 {
51 return;
52 }
53
54 ////////////////////////////////////////////////////////////////////////////////
|
55 kumpf 1.11 // Writes message to file.
|
56 mike 1.2 // Implementation of this function is platform specific
|
57 kumpf 1.11 //
|
58 mike 1.2 // Note: The current implementation writes the message to the defined file.
59 // Will have to be enhanced to support synchronous write operations to
60 // the same file.
61 ////////////////////////////////////////////////////////////////////////////////
62 void TraceFileHandler::handleMessage(
63 const char* message,
|
64 thilo.boehm 1.16 Uint32 msgLen,
|
65 mike 1.2 const char* fmt,
|
66 kumpf 1.11 va_list argList)
|
67 mike 1.2 {
68 Uint32 retCode;
69
|
70 thilo.boehm 1.17 if (_configHasChanged)
71 {
|
72 kumpf 1.18 _reConfigure();
|
73 thilo.boehm 1.17 }
74
|
75 mike 1.2 if (_fileHandle)
76 {
|
77 kumpf 1.13 AutoMutex writeLock(writeMutex);
78
|
79 mike 1.2 //Move to the End of File
80 fseek(_fileHandle,0,SEEK_SET);
81
82 // Write message to file
83 fprintf(_fileHandle,"%s", message);
84 vfprintf(_fileHandle,fmt,argList);
85 retCode = fprintf(_fileHandle,"\n");
86
87 if (retCode < 0)
88 {
|
89 kumpf 1.11 // Unable to write message to file
90 // Log message
|
91 marek 1.22 MessageLoaderParms parm(
92 "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
93 "Unable to write trace message to File $0",
94 _fileName);
95 _logError(TRCFH_UNABLE_TO_WRITE_TRACE_TO_FILE,parm);
|
96 mike 1.2 }
|
97 kumpf 1.11 else
98 {
|
99 mike 1.2 fflush(_fileHandle);
|
100 marek 1.22 // trace message successful written, reset error log messages
101 // thus allow writing of errors to log again
102 _logErrorBitField = 0;
|
103 mike 1.2 }
104 }
105 else
106 {
|
107 kumpf 1.11 // Invalid file handle
108 // Log message
|
109 marek 1.22 MessageLoaderParms parm(
110 "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
111 "Invalid file handle for file $0",
112 _fileName);
113 _logError(TRCFH_INVALID_FILE_HANDLE,parm);
|
114 mike 1.2 }
|
115 kumpf 1.11 }
|
116 mike 1.2
|
117 marek 1.12 ////////////////////////////////////////////////////////////////////////////////
118 // Writes message to file.
119 // Implementation of this function is platform specific
120 //
121 // Note: The current implementation writes the message to the defined file.
122 // Will have to be enhanced to support synchronous write operations to
123 // the same file.
124 ////////////////////////////////////////////////////////////////////////////////
|
125 thilo.boehm 1.16 void TraceFileHandler::handleMessage(const char* message, Uint32 msgLen)
|
126 marek 1.12 {
127 Uint32 retCode;
128
|
129 mreddy 1.19 if (_configHasChanged)
130 {
131 _reConfigure();
132 }
133
|
134 marek 1.12 if (_fileHandle)
135 {
|
136 kumpf 1.13 AutoMutex writeLock(writeMutex);
137
|
138 marek 1.12 //Move to the End of File
139 fseek(_fileHandle,0,SEEK_SET);
140
141 // Write message to file
142 retCode = fprintf(_fileHandle,"%s\n", message);
143 if (retCode < 0)
144 {
145 // Unable to write message to file
146 // Log message
|
147 marek 1.22 MessageLoaderParms parm(
148 "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
149 "Unable to write trace message to File $0",
150 _fileName);
151 _logError(TRCFH_UNABLE_TO_WRITE_TRACE_TO_FILE,parm);
|
152 marek 1.12 }
153 else
154 {
155 fflush(_fileHandle);
|
156 marek 1.22 // trace message successful written, reset error log messages
157 // thus allow writing of errors to log again
158 _logErrorBitField = 0;
|
159 marek 1.12 }
160 }
161 else
162 {
163 // Invalid file handle
164 // Log message
|
165 marek 1.22 MessageLoaderParms parm(
166 "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
167 "Invalid file handle for file $0",
168 _fileName);
169 _logError(TRCFH_INVALID_FILE_HANDLE,parm);
|
170 marek 1.12 }
171 }
172
173
|
174 mike 1.2 PEGASUS_NAMESPACE_END
|