(file) Return to TraceFileHandlerWindows.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  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/Logger.h>
 34             #include <Pegasus/Common/TraceFileHandler.h>
 35 kumpf  1.13 #include <Pegasus/Common/Mutex.h>
 36 mike   1.2  
 37             PEGASUS_USING_STD;
 38             
 39             PEGASUS_NAMESPACE_BEGIN
 40             
 41 kumpf  1.13 static Mutex writeMutex;
 42             
 43 mike   1.2  ////////////////////////////////////////////////////////////////////////////////
 44 marek  1.12 //   On other platforms prepares the file handle (open file etc.).
 45             //   Implementation of this function is platform specific
 46             //
 47             //   Note: The current implementation on Windows does nothing.
 48             //         Should be optimized out by the compiler
 49             ////////////////////////////////////////////////////////////////////////////////
 50             void TraceFileHandler::prepareFileHandle(void)
 51             {
 52                 return;
 53             }
 54             
 55             ////////////////////////////////////////////////////////////////////////////////
 56 kumpf  1.11 //   Writes message to file.
 57 mike   1.2  //   Implementation of this function is platform specific
 58 kumpf  1.11 //
 59 mike   1.2  //   Note: The current implementation writes the message to the defined file.
 60             //         Will have to be enhanced to support synchronous write operations to
 61             //         the same file.
 62             ////////////////////////////////////////////////////////////////////////////////
 63             void TraceFileHandler::handleMessage(
 64                 const char* message,
 65 thilo.boehm 1.16     Uint32 msgLen,
 66 mike        1.2      const char* fmt,
 67 kumpf       1.11     va_list argList)
 68 mike        1.2  {
 69                      Uint32 retCode;
 70                  
 71 thilo.boehm 1.17     if (_configHasChanged)
 72                      {
 73 kumpf       1.18         _reConfigure();
 74 thilo.boehm 1.17     }
 75                  
 76 mike        1.2      if (_fileHandle)
 77                      {
 78 kumpf       1.13         AutoMutex writeLock(writeMutex);
 79                  
 80 mike        1.2          //Move to the End of File
 81                          fseek(_fileHandle,0,SEEK_SET);
 82                  
 83                          // Write message to file
 84                          fprintf(_fileHandle,"%s", message);
 85                          vfprintf(_fileHandle,fmt,argList);
 86                          retCode = fprintf(_fileHandle,"\n");
 87                  
 88                          if (retCode < 0)
 89                          {
 90 kumpf       1.11             // Unable to write message to file
 91                              // Log message
 92 marek       1.14             Logger::put_l(
 93 kumpf       1.15                 Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
 94                                  MessageLoaderParms(
 95                                      "Common.TraceFileHandlerWindows."
 96                                          "UNABLE_TO_WRITE_TRACE_TO_FILE",
 97                                      "Unable to write trace message to File $0",
 98                                      _fileName));
 99 mike        1.2          }
100 kumpf       1.11         else
101                          {
102 mike        1.2              fflush(_fileHandle);
103                          }
104                      }
105                      else
106                      {
107 kumpf       1.11         // Invalid file handle
108                          // Log message
109 marek       1.14         Logger::put_l(
110 kumpf       1.15             Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
111                              MessageLoaderParms(
112                                  "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
113                                  "Invalid file handle for file $0",
114                                  _fileName));
115 mike        1.2      }
116 kumpf       1.11 }
117 mike        1.2  
118 marek       1.12 ////////////////////////////////////////////////////////////////////////////////
119                  //   Writes message to file.
120                  //   Implementation of this function is platform specific
121                  //
122                  //   Note: The current implementation writes the message to the defined file.
123                  //         Will have to be enhanced to support synchronous write operations to
124                  //         the same file.
125                  ////////////////////////////////////////////////////////////////////////////////
126 thilo.boehm 1.16 void TraceFileHandler::handleMessage(const char* message, Uint32 msgLen)
127 marek       1.12 {
128                      Uint32 retCode;
129                  
130 mreddy      1.19     if (_configHasChanged)
131                      {
132                          _reConfigure();
133                      }
134                  
135 marek       1.12     if (_fileHandle)
136                      {
137 kumpf       1.13         AutoMutex writeLock(writeMutex);
138                  
139 marek       1.12         //Move to the End of File
140                          fseek(_fileHandle,0,SEEK_SET);
141                  
142                          // Write message to file
143                          retCode = fprintf(_fileHandle,"%s\n", message);
144                          if (retCode < 0)
145                          {
146                              // Unable to write message to file
147                              // Log message
148 marek       1.14             Logger::put_l(
149 kumpf       1.15                 Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
150                                  MessageLoaderParms(
151                                      "Common.TraceFileHandlerWindows."
152                                          "UNABLE_TO_WRITE_TRACE_TO_FILE",
153                                      "Unable to write trace message to File $0",
154                                      _fileName));
155 marek       1.12         }
156                          else
157                          {
158                              fflush(_fileHandle);
159                          }
160                      }
161                      else
162                      {
163                          // Invalid file handle
164                          // Log message
165 marek       1.14         Logger::put_l(
166 kumpf       1.15             Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
167                              MessageLoaderParms(
168                                  "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
169                                  "Invalid file handle for file $0",
170                                  _fileName));
171 marek       1.12     }
172                  }
173                  
174                  
175 mike        1.2  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2