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 marek 1.12
43 ////////////////////////////////////////////////////////////////////////////////
|
44 kumpf 1.11 // Writes message to file.
|
45 mike 1.2 // Implementation of this function is platform specific
|
46 kumpf 1.11 //
|
47 mike 1.2 // Note: The current implementation writes the message to the defined file.
48 // Will have to be enhanced to support synchronous write operations to
49 // the same file.
50 ////////////////////////////////////////////////////////////////////////////////
51 void TraceFileHandler::handleMessage(
52 const char* message,
|
53 marek 1.25 Uint32,
|
54 mike 1.2 const char* fmt,
|
55 kumpf 1.11 va_list argList)
|
56 mike 1.2 {
57 Uint32 retCode;
|
58 amit99shah 1.26
|
59 mike 1.2
|
60 thilo.boehm 1.17 if (_configHasChanged)
61 {
|
62 kumpf 1.18 _reConfigure();
|
63 thilo.boehm 1.17 }
64
|
65 amit99shah 1.26 if (!_fileHandle)
66 {
67 // The trace file is not open, which means an earlier fopen() was
68 // unsuccessful. Stop now to avoid logging duplicate error messages.
69 return;
70 }
71
|
72 amit99shah 1.27 AutoMutex writeLock(writeMutex);
73
|
74 amit99shah 1.26 if(!_fileExists(_fileName))
|
75 mike 1.2 {
|
76 amit99shah 1.26 return;
|
77 amit99shah 1.27 }
|
78 kumpf 1.13
|
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 amit99shah 1.26
|
105 kumpf 1.11 }
|
106 mike 1.2
|
107 marek 1.12 ////////////////////////////////////////////////////////////////////////////////
108 // Writes message to file.
109 // Implementation of this function is platform specific
110 //
111 // Note: The current implementation writes the message to the defined file.
112 // Will have to be enhanced to support synchronous write operations to
113 // the same file.
114 ////////////////////////////////////////////////////////////////////////////////
|
115 marek 1.25 void TraceFileHandler::handleMessage(const char* message, Uint32)
|
116 marek 1.12 {
117 Uint32 retCode;
|
118 amit99shah 1.26
|
119 mreddy 1.19 if (_configHasChanged)
120 {
121 _reConfigure();
122 }
123
|
124 amit99shah 1.26 if (!_fileHandle)
125 {
126 // The trace file is not open, which means an earlier fopen() was
127 // unsuccessful. Stop now to avoid logging duplicate error messages.
128 return;
129 }
130
|
131 amit99shah 1.27 AutoMutex writeLock(writeMutex);
132
|
133 amit99shah 1.26 if(!_fileExists(_fileName))
|
134 marek 1.12 {
|
135 amit99shah 1.26 return;
136 }
|
137 kumpf 1.13
|
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 amit99shah 1.26
|
161 marek 1.12 }
162
163
|
164 mike 1.2 PEGASUS_NAMESPACE_END
|