(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           
 38           PEGASUS_USING_STD;
 39           
 40           PEGASUS_NAMESPACE_BEGIN
 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                const char* fmt,
 65 kumpf 1.11     va_list argList)
 66 mike  1.2  {
 67                Uint32 retCode;
 68            
 69                if (_fileHandle)
 70                {
 71                    //Move to the End of File
 72                    fseek(_fileHandle,0,SEEK_SET);
 73            
 74                    // Write message to file
 75                    fprintf(_fileHandle,"%s", message);
 76                    vfprintf(_fileHandle,fmt,argList);
 77                    retCode = fprintf(_fileHandle,"\n");
 78            
 79                    if (retCode < 0)
 80                    {
 81 kumpf 1.11             // Unable to write message to file
 82                        // Log message
 83                        Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING,
 84                            "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
 85                            "Unable to write trace message to File $0", _fileName);
 86 mike  1.2          }
 87 kumpf 1.11         else
 88                    {
 89 mike  1.2              fflush(_fileHandle);
 90                    }
 91                }
 92                else
 93                {
 94 kumpf 1.11         // Invalid file handle
 95                    // Log message
 96                    Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING,
 97                        "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
 98                        "Invalid file handle for file $0", _fileName);
 99 mike  1.2      }
100 kumpf 1.11 }
101 mike  1.2  
102 marek 1.12 ////////////////////////////////////////////////////////////////////////////////
103            //   Writes message to file.
104            //   Implementation of this function is platform specific
105            //
106            //   Note: The current implementation writes the message to the defined file.
107            //         Will have to be enhanced to support synchronous write operations to
108            //         the same file.
109            ////////////////////////////////////////////////////////////////////////////////
110            void TraceFileHandler::handleMessage(const char* message)
111            {
112                Uint32 retCode;
113            
114                if (_fileHandle)
115                {
116                    //Move to the End of File
117                    fseek(_fileHandle,0,SEEK_SET);
118            
119                    // Write message to file
120                    retCode = fprintf(_fileHandle,"%s\n", message);
121                    if (retCode < 0)
122                    {
123 marek 1.12             // Unable to write message to file
124                        // Log message
125                        Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING,
126                            "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
127                            "Unable to write trace message to File $0", _fileName);
128                    }
129                    else
130                    {
131                        fflush(_fileHandle);
132                    }
133                }
134                else
135                {
136                    // Invalid file handle
137                    // Log message
138                    Logger::put_l(Logger::DEBUG_LOG, System::CIMSERVER, Logger::WARNING,
139                        "Common.TraceFileHandlerWindows.INVALID_FILE_HANDLE",
140                        "Invalid file handle for file $0", _fileName);
141                }
142            }
143            
144 marek 1.12 
145 mike  1.2  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2