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 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 thilo.boehm 1.16 void TraceFileHandler::handleMessage(const char* message, Uint32 msgLen)
|
116 marek 1.12 {
117 Uint32 retCode;
118
|
119 mreddy 1.19 if (_configHasChanged)
120 {
121 _reConfigure();
122 }
123
|
124 marek 1.12 if (_fileHandle)
125 {
|
126 kumpf 1.13 AutoMutex writeLock(writeMutex);
127
|
128 marek 1.12 //Move to the End of File
129 fseek(_fileHandle,0,SEEK_SET);
130
131 // Write message to file
132 retCode = fprintf(_fileHandle,"%s\n", message);
133 if (retCode < 0)
134 {
135 // Unable to write message to file
136 // Log message
|
137 marek 1.22 MessageLoaderParms parm(
138 "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
139 "Unable to write trace message to File $0",
140 _fileName);
141 _logError(TRCFH_UNABLE_TO_WRITE_TRACE_TO_FILE,parm);
|
142 marek 1.12 }
143 else
144 {
145 fflush(_fileHandle);
|
146 marek 1.22 // trace message successful written, reset error log messages
147 // thus allow writing of errors to log again
148 _logErrorBitField = 0;
|
149 marek 1.12 }
150 }
151 }
152
153
|
154 mike 1.2 PEGASUS_NAMESPACE_END
|