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

Diff for /pegasus/src/Pegasus/Common/SystemWindows.cpp between version 1.79 and 1.91

version 1.79, 2007/09/11 17:56:33 version 1.91, 2012/07/10 12:34:17
Line 1 
Line 1 
 //%2006////////////////////////////////////////////////////////////////////////  //%LICENSE////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development  // Licensed to The Open Group (TOG) under one or more contributor license
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.  // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;  // this work for additional information regarding copyright ownership.
 // IBM Corp.; EMC Corporation, The Open Group.  // Each contributor licenses this file to you under the OpenPegasus Open
 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;  // Source License; you may not use this file except in compliance with the
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.  // License.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;  //
 // EMC Corporation; VERITAS Software Corporation; The Open Group.  // Permission is hereby granted, free of charge, to any person obtaining a
 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;  // copy of this software and associated documentation files (the "Software"),
 // EMC Corporation; Symantec Corporation; The Open Group.  // to deal in the Software without restriction, including without limitation
 //  // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 // Permission is hereby granted, free of charge, to any person obtaining a copy  // and/or sell copies of the Software, and to permit persons to whom the
 // of this software and associated documentation files (the "Software"), to  // Software is furnished to do so, subject to the following conditions:
 // deal in the Software without restriction, including without limitation the  //
 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  // The above copyright notice and this permission notice shall be included
 // sell copies of the Software, and to permit persons to whom the Software is  // in all copies or substantial portions of the Software.
 // furnished to do so, subject to the following conditions:  //
 //  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN  // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT  // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR  // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN  // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION  
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  
 // //
 //==============================================================================  //////////////////////////////////////////////////////////////////////////
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 83 
Line 81 
     microseconds = long((largeInt.QuadPart % (10000 * 1000)) / 10);     microseconds = long((largeInt.QuadPart % (10000 * 1000)) / 10);
 } }
  
   Uint64 System::getCurrentTimeUsec()
   {
       FILETIME ft;
       GetSystemTimeAsFileTime(&ft);
       ULARGE_INTEGER largeInt = { ft.dwLowDateTime, ft.dwHighDateTime };
       largeInt.QuadPart -= 0x19db1ded53e8000;
   
       return Uint64(largeInt.QuadPart / 10);
   }
   
 String System::getCurrentASCIITime() String System::getCurrentASCIITime()
 { {
     char tmpbuf[128];     char tmpbuf[128];
Line 162 
Line 170 
  
 Boolean System::renameFile(const char* oldPath, const char* newPath) Boolean System::renameFile(const char* oldPath, const char* newPath)
 { {
     return rename(oldPath, newPath) == 0;      if (exists(oldPath))
 }  
   
 String System::getHostName()  
 {  
     static String _hostname;  
     if (0 == _hostname.size())  
     {     {
         char hostname[PEGASUS_MAXHOSTNAMELEN + 1];          removeFile(newPath);
         //initialize the buffer to handle the case where gethostname fails.  
         hostname[0] = 0;  
         gethostname(hostname, sizeof(hostname));  
         hostname[sizeof(hostname)-1] = 0;  
         _hostname.assign(hostname);  
     }     }
     return _hostname;      return rename(oldPath, newPath) == 0;
 }  
   
 String System::getFullyQualifiedHostName ()  
 {  
     static char FQHostName[PEGASUS_MAXHOSTNAMELEN + 1];  
   
     if (!*FQHostName)  
     {  
         String hostname = getHostName();  
         struct hostent* hostEnt;  
   
         hostEnt = getHostByName((const char *)hostname.getCString());  
         if (hostEnt == NULL)  
         {  
             return String::EMPTY;  
         }  
         strncpy(FQHostName, hostEnt->h_name, sizeof(FQHostName)-1);  
     }  
   
     return FQHostName;  
 } }
  
 String System::getSystemCreationClassName () String System::getSystemCreationClassName ()
Line 942 
Line 919 
 // check if a given IP address is defined on the local network interfaces // check if a given IP address is defined on the local network interfaces
 Boolean System::isIpOnNetworkInterface(Uint32 inIP) Boolean System::isIpOnNetworkInterface(Uint32 inIP)
 { {
       Socket::initializeInterface();
     SOCKET sock;     SOCKET sock;
     int interfaces = 0;     int interfaces = 0;
     int errcode;     int errcode;
Line 982 
Line 960 
                 {                 {
                     free(output_buf);                     free(output_buf);
                     closesocket(sock);                     closesocket(sock);
                       Socket::uninitializeInterface();
                     return true;                     return true;
                 }                 }
             }             }
Line 989 
Line 968 
         else         else
         {         {
             free(output_buf);             free(output_buf);
               Socket::uninitializeInterface();
             return false;             return false;
         }         }
         free(output_buf);         free(output_buf);
         closesocket(sock);         closesocket(sock);
           Socket::uninitializeInterface();
     }     }
     return false;     return false;
 } }
  
   void _getInterfaceAddrs(Array<String> &ips, int af)
   {
       SOCKET sock;
   
       if (INVALID_SOCKET != (sock = WSASocket(af, SOCK_RAW,
           0, NULL, 0, 0)))
       {
           DWORD  bytesReturned;
           char buf[2048];
           int interfaces = 0;
           char str[PEGASUS_INET6_ADDRSTR_LEN];
           void *p = 0;
           if (0 == WSAIoctl(sock, SIO_ADDRESS_LIST_QUERY, NULL, 0,
               buf, 2048, &bytesReturned, NULL,
               NULL))
           {
   
               SOCKET_ADDRESS_LIST *addr_list;
               SOCKET_ADDRESS *addr;
               struct sockaddr *sin;
               addr_list = (SOCKET_ADDRESS_LIST *)buf;
               addr = addr_list->Address;
               int rc = 0;
               for (sin = (struct sockaddr *) addr->lpSockaddr ;
                   interfaces < addr_list->iAddressCount;
                   interfaces++)
               {
                   if (af == AF_INET)
                   {
                       p = &((struct sockaddr_in*)sin)->sin_addr;
                   }
                   else
                   {
                       p = &((struct sockaddr_in6*)sin)->sin6_addr;
                   }
                   // Don't gather loopback addrs
                   if (!System::isLoopBack(af, p))
                   {
                       if (af == AF_INET)
                       {
                           if ((rc = ::getnameinfo(
                               sin,
                               sizeof(struct sockaddr_in),
                               str,
                               sizeof(str),
                               NULL,
                               0,
                               NI_NUMERICHOST)) == 0)
                           {
                               ips.append(str);
                           }
                           //Error detected in getting name info,
                           //display the error string
                           else
                           {
                               PEG_TRACE((TRC_OS_ABSTRACTION, Tracer::LEVEL1,
                                   "getnameinfo failed: %s", gai_strerror(rc)));
                           }
                       }
   #ifdef PEGASUS_ENABLE_IPV6
                       else if (af == AF_INET6)
                       {
                           if((rc = ::getnameinfo(
                               sin,
                               sizeof(struct sockaddr_in6),
                               str,
                               sizeof(str),
                               NULL,
                               0,
                               NI_NUMERICHOST)) == 0)
                           {
                               ips.append(str);
                           }
                           //Error detected in getting name info,
                           //display the error string
                           else
                           {
                               PEG_TRACE((TRC_OS_ABSTRACTION, Tracer::LEVEL1,
                                   "getnameinfo failed: %s", gai_strerror(rc)));
                           }
                       }
   #endif
                   }
                   addr++;
                   sin = (struct sockaddr*)addr->lpSockaddr;
               }
           }
       }
   }
   
   Array<String> System::getInterfaceAddrs()
   {
       Socket::initializeInterface();
       Array<String> ips;
       _getInterfaceAddrs(ips, AF_INET);
   #ifdef PEGASUS_ENABLE_IPV6
       _getInterfaceAddrs(ips, AF_INET6);
   #endif
       Socket::uninitializeInterface();
       return ips;
   }
   
   String System::getErrorMSG_NLS(int errorCode,int errorCode2)
   {
       LPVOID winErrorMsg = NULL;
   
       if (FormatMessage(
               FORMAT_MESSAGE_ALLOCATE_BUFFER |
               FORMAT_MESSAGE_FROM_SYSTEM |
               FORMAT_MESSAGE_IGNORE_INSERTS,
               NULL,
               errorCode,
               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
               (LPTSTR)&winErrorMsg,
               0,
               NULL))
       {
           MessageLoaderParms parms(
               "Common.System.ERROR_MESSAGE.STANDARD",
               "$0 (error code $1)",(char*)winErrorMsg,errorCode);
           LocalFree(winErrorMsg);
           return MessageLoader::getMessage(parms);
       }
   
       MessageLoaderParms parms(
           "Common.System.ERROR_MESSAGE.STANDARD",
           "$0 (error code $1)","",errorCode);
       return MessageLoader::getMessage(parms);
   
   }
   
   String System::getErrorMSG(int errorCode,int errorCode2)
   {
   
       String buffer;
       LPVOID winErrorMsg = NULL;
   
       char strErrorCode[32];
       sprintf(strErrorCode, "%d", errorCode);
   
       if (FormatMessage(
               FORMAT_MESSAGE_ALLOCATE_BUFFER |
               FORMAT_MESSAGE_FROM_SYSTEM |
               FORMAT_MESSAGE_IGNORE_INSERTS,
               NULL,
               errorCode,
               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
               (LPTSTR)&winErrorMsg,
               0,
               NULL))
       {
           buffer.append((char*)winErrorMsg);
           LocalFree(winErrorMsg);
       }
   
       buffer.append(" (error code ");
       buffer.append(strErrorCode);
       buffer.append(")");
   
       return buffer;
   }
  
  
 /////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
Line 1018 
Line 1160 
        && (GetLastError() != ERROR_ALREADY_EXISTS)        && (GetLastError() != ERROR_ALREADY_EXISTS)
        && (GetLastError() != ERROR_SUCCESS))        && (GetLastError() != ERROR_SUCCESS))
    {    {
        PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2,         PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
           "AutoFileLock: Failed to open lock file '%s', error code %d.",           "AutoFileLock: Failed to open lock file '%s', error code %d.",
           fileName, GetLastError()));           fileName, GetLastError()));
        return;        return;
Line 1027 
Line 1169 
    OVERLAPPED l={0,0,0,0,0};    OVERLAPPED l={0,0,0,0,0};
    if(LockFileEx(_hFile,LOCKFILE_EXCLUSIVE_LOCK, 0, 0, 0, &l) == 0)    if(LockFileEx(_hFile,LOCKFILE_EXCLUSIVE_LOCK, 0, 0, 0, &l) == 0)
    {    {
        PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2,         PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
            "AutoFileLock: Failed to Acquire lock on file %s, error code %d.",            "AutoFileLock: Failed to Acquire lock on file %s, error code %d.",
            fileName, GetLastError()));            fileName, GetLastError()));
        CloseHandle(_hFile);        CloseHandle(_hFile);
Line 1050 
Line 1192 
     }     }
 } }
  
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.79  
changed lines
  Added in v.1.91

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2