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

  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                        Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING,
 89                            "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
 90                            "Unable to write trace message to File $0", _fileName);
 91 mike  1.2          }
 92 kumpf 1.11         else
 93                    {
 94 mike  1.2              fflush(_fileHandle);
 95                    }
 96                }
 97                else
 98                {
 99 kumpf 1.11         // Invalid file handle
100                    // Log message
101                    Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING,
102                        "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
103                        "Invalid file handle for file $0", _fileName);
104 mike  1.2      }
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            void TraceFileHandler::handleMessage(const char* message)
116            {
117                Uint32 retCode;
118            
119                if (_fileHandle)
120                {
121 kumpf 1.13         AutoMutex writeLock(writeMutex);
122            
123 marek 1.12         //Move to the End of File
124                    fseek(_fileHandle,0,SEEK_SET);
125            
126                    // Write message to file
127                    retCode = fprintf(_fileHandle,"%s\n", message);
128                    if (retCode < 0)
129                    {
130                        // Unable to write message to file
131                        // Log message
132                        Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING,
133                            "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
134                            "Unable to write trace message to File $0", _fileName);
135                    }
136                    else
137                    {
138                        fflush(_fileHandle);
139                    }
140                }
141                else
142                {
143                    // Invalid file handle
144 marek 1.12         // Log message
145                    Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING,
146                        "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
147                        "Invalid file handle for file $0", _fileName);
148                }
149            }
150            
151            
152 mike  1.2  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2