1 karl 1.8 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.6 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.5 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.6 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.7 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.8 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.2 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 kumpf 1.3 //
|
21 mike 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <iostream>
35 #include <Pegasus/Common/Logger.h>
36 #include <Pegasus/Common/TraceFileHandler.h>
|
37 kumpf 1.13 #include <Pegasus/Common/Mutex.h>
|
38 mike 1.2
39 PEGASUS_USING_STD;
40
41 PEGASUS_NAMESPACE_BEGIN
42
|
43 kumpf 1.13 static Mutex writeMutex;
44
|
45 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
46 marek 1.12 // On other platforms prepares the file handle (open file etc.).
47 // Implementation of this function is platform specific
48 //
49 // Note: The current implementation on Windows does nothing.
50 // Should be optimized out by the compiler
51 ////////////////////////////////////////////////////////////////////////////////
52 void TraceFileHandler::prepareFileHandle(void)
53 {
54 return;
55 }
56
57 ////////////////////////////////////////////////////////////////////////////////
|
58 kumpf 1.11 // Writes message to file.
|
59 mike 1.2 // Implementation of this function is platform specific
|
60 kumpf 1.11 //
|
61 mike 1.2 // Note: The current implementation writes the message to the defined file.
62 // Will have to be enhanced to support synchronous write operations to
63 // the same file.
64 ////////////////////////////////////////////////////////////////////////////////
65 void TraceFileHandler::handleMessage(
66 const char* message,
67 const char* fmt,
|
68 kumpf 1.11 va_list argList)
|
69 mike 1.2 {
70 Uint32 retCode;
71
72 if (_fileHandle)
73 {
|
74 kumpf 1.13 AutoMutex writeLock(writeMutex);
75
|
76 mike 1.2 //Move to the End of File
77 fseek(_fileHandle,0,SEEK_SET);
78
79 // Write message to file
80 fprintf(_fileHandle,"%s", message);
81 vfprintf(_fileHandle,fmt,argList);
82 retCode = fprintf(_fileHandle,"\n");
83
84 if (retCode < 0)
85 {
|
86 kumpf 1.11 // Unable to write message to file
87 // Log message
|
88 marek 1.14 Logger::put_l(
89 Logger::ERROR_LOG,
90 System::CIMSERVER,
91 Logger::WARNING,
|
92 kumpf 1.11 "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
|
93 marek 1.14 "Unable to write trace message to File $0",
94 _fileName);
|
95 mike 1.2 }
|
96 kumpf 1.11 else
97 {
|
98 mike 1.2 fflush(_fileHandle);
99 }
100 }
101 else
102 {
|
103 kumpf 1.11 // Invalid file handle
104 // Log message
|
105 marek 1.14 Logger::put_l(
106 Logger::ERROR_LOG,
107 System::CIMSERVER,
108 Logger::WARNING,
|
109 kumpf 1.11 "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
|
110 marek 1.14 "Invalid file handle for file $0",
111 _fileName);
|
112 mike 1.2 }
|
113 kumpf 1.11 }
|
114 mike 1.2
|
115 marek 1.12 ////////////////////////////////////////////////////////////////////////////////
116 // Writes message to file.
117 // Implementation of this function is platform specific
118 //
119 // Note: The current implementation writes the message to the defined file.
120 // Will have to be enhanced to support synchronous write operations to
121 // the same file.
122 ////////////////////////////////////////////////////////////////////////////////
123 void TraceFileHandler::handleMessage(const char* message)
124 {
125 Uint32 retCode;
126
127 if (_fileHandle)
128 {
|
129 kumpf 1.13 AutoMutex writeLock(writeMutex);
130
|
131 marek 1.12 //Move to the End of File
132 fseek(_fileHandle,0,SEEK_SET);
133
134 // Write message to file
135 retCode = fprintf(_fileHandle,"%s\n", message);
136 if (retCode < 0)
137 {
138 // Unable to write message to file
139 // Log message
|
140 marek 1.14 Logger::put_l(
141 Logger::ERROR_LOG,
142 System::CIMSERVER,
143 Logger::WARNING,
|
144 marek 1.12 "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
|
145 marek 1.14 "Unable to write trace message to File $0",
146 _fileName);
|
147 marek 1.12 }
148 else
149 {
150 fflush(_fileHandle);
151 }
152 }
153 else
154 {
155 // Invalid file handle
156 // Log message
|
157 marek 1.14 Logger::put_l(
158 Logger::ERROR_LOG,
159 System::CIMSERVER,
160 Logger::WARNING,
|
161 marek 1.12 "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
|
162 marek 1.14 "Invalid file handle for file $0",
163 _fileName);
|
164 marek 1.12 }
165 }
166
167
|
168 mike 1.2 PEGASUS_NAMESPACE_END
|