OS_NS_sys_utsname.cpp

Go to the documentation of this file.
00001 // OS_NS_sys_utsname.cpp,v 1.10 2006/05/05 07:53:03 jwillemsen Exp
00002 
00003 #include "ace/OS_NS_sys_utsname.h"
00004 
00005 ACE_RCSID(ace, OS_NS_sys_utsname, "OS_NS_sys_utsname.cpp,v 1.10 2006/05/05 07:53:03 jwillemsen Exp")
00006 
00007 #include "ace/OS_NS_string.h"
00008 #include "ace/OS_NS_stdio.h"
00009 #include "ace/OS_NS_unistd.h"
00010 
00011 #if defined (ACE_VXWORKS) && defined (ACE_LACKS_UNAME)
00012 // for sysBspRev(), sysModel()
00013 #  include /**/ <sysLib.h>
00014 #endif /* ACE_VXWORKS && ACE_LACKS_UNAME */
00015 
00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 int
00019 ACE_OS::uname (ACE_utsname *name)
00020 {
00021   ACE_OS_TRACE ("ACE_OS::uname");
00022 #if !defined (ACE_LACKS_UNAME)
00023   ACE_OSCALL_RETURN (::uname (name), int, -1);
00024 #elif defined (ACE_WIN32)
00025   size_t maxnamelen = sizeof name->nodename;
00026   ACE_OS::strcpy (name->sysname,
00027                   ACE_LIB_TEXT ("Win32"));
00028 
00029   OSVERSIONINFO vinfo;
00030   vinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00031   ::GetVersionEx (&vinfo);
00032 
00033   SYSTEM_INFO sinfo;
00034 #   if defined (ACE_HAS_PHARLAP)
00035   // PharLap doesn't do GetSystemInfo.  What's really wanted is the
00036   // CPU architecture, so we can get that with EtsGetSystemInfo. Fill
00037   // in what's wanted in the SYSTEM_INFO structure, and carry on. Note
00038   // that the CPU type values in EK_KERNELINFO have the same values
00039   // are the ones defined for SYSTEM_INFO.
00040   EK_KERNELINFO ets_kern;
00041   EK_SYSTEMINFO ets_sys;
00042   EtsGetSystemInfo (&ets_kern, &ets_sys);
00043   sinfo.wProcessorLevel = static_cast<WORD> (ets_kern.CpuType);
00044   sinfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
00045   sinfo.dwProcessorType = ets_kern.CpuType * 100 + 86;
00046 #   else
00047   ::GetSystemInfo(&sinfo);
00048 
00049   ACE_OS::strcpy (name->sysname, ACE_LIB_TEXT ("Win32"));
00050 #   endif /* ACE_HAS_PHARLAP */
00051 
00052   const ACE_TCHAR* unknown = ACE_LIB_TEXT ("???");
00053 
00054   if (
00055       vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT
00056 #   if defined (VER_PLATFORM_WIN32_CE)
00057       || vinfo.dwPlatformId == VER_PLATFORM_WIN32_CE
00058 #   endif
00059       )
00060     {
00061       // Get information from the two structures
00062       const ACE_TCHAR *os;
00063       if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
00064         os = ACE_LIB_TEXT ("Windows NT %d.%d");
00065       else
00066         os = ACE_LIB_TEXT ("Windows CE %d.%d");
00067       ACE_OS::sprintf (name->release,
00068                        os,
00069                        (int) vinfo.dwMajorVersion,
00070                        (int) vinfo.dwMinorVersion);
00071       ACE_OS::sprintf (name->version,
00072                        ACE_LIB_TEXT ("Build %d %s"),
00073                        (int) vinfo.dwBuildNumber,
00074                        vinfo.szCSDVersion);
00075 
00076       // We have to make sure that the size of (processor + subtype)
00077       // is not greater than the size of name->machine.  So we give
00078       // half the space to the processor and half the space to
00079       // subtype.  The -1 is necessary for because of the space
00080       // between processor and subtype in the machine name.
00081       const int bufsize = ((sizeof (name->machine) / sizeof (ACE_TCHAR)) / 2) - 1;
00082       ACE_TCHAR processor[bufsize] = ACE_LIB_TEXT ("Unknown");
00083       ACE_TCHAR subtype[bufsize] = ACE_LIB_TEXT ("Unknown");
00084 
00085 #   if defined (ghs)
00086     WORD arch = sinfo.u.s.wProcessorArchitecture;
00087 #   else
00088     WORD arch = sinfo.wProcessorArchitecture;
00089 #   endif
00090 
00091       switch (arch)
00092         {
00093         case PROCESSOR_ARCHITECTURE_INTEL:
00094           ACE_OS::strcpy (processor, ACE_LIB_TEXT ("Intel"));
00095           if (sinfo.wProcessorLevel == 3)
00096             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("80386"));
00097           else if (sinfo.wProcessorLevel == 4)
00098             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("80486"));
00099           else if (sinfo.wProcessorLevel == 5)
00100             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("Pentium"));
00101           else if (sinfo.wProcessorLevel == 6)
00102             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("Pentium Pro"));
00103           else if (sinfo.wProcessorLevel == 7)  // I'm guessing here
00104             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("Pentium II"));
00105           break;
00106         case PROCESSOR_ARCHITECTURE_MIPS:
00107           ACE_OS::strcpy (processor, ACE_LIB_TEXT ("MIPS"));
00108           ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("R4000"));
00109           break;
00110         case PROCESSOR_ARCHITECTURE_ALPHA:
00111           ACE_OS::strcpy (processor, ACE_LIB_TEXT ("Alpha"));
00112           ACE_OS::sprintf (subtype, ACE_LIB_TEXT ("%d"), sinfo.wProcessorLevel);
00113           break;
00114         case PROCESSOR_ARCHITECTURE_PPC:
00115           ACE_OS::strcpy (processor, ACE_LIB_TEXT ("PPC"));
00116           if (sinfo.wProcessorLevel == 1)
00117             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("601"));
00118           else if (sinfo.wProcessorLevel == 3)
00119             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("603"));
00120           else if (sinfo.wProcessorLevel == 4)
00121             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("604"));
00122           else if (sinfo.wProcessorLevel == 6)
00123             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("603+"));
00124           else if (sinfo.wProcessorLevel == 9)
00125             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("804+"));
00126           else if (sinfo.wProcessorLevel == 20)
00127             ACE_OS::strcpy (subtype, ACE_LIB_TEXT ("620"));
00128           break;
00129 #     if defined PROCESSOR_ARCHITECTURE_IA64
00130         case PROCESSOR_ARCHITECTURE_IA64:
00131           ACE_OS::strcpy (processor, ACE_LIB_TEXT ("Itanium"));
00132           ACE_OS::sprintf (subtype, ACE_LIB_TEXT ("%d"),
00133                            sinfo.wProcessorLevel);
00134           break;
00135 #     endif
00136 #     if defined PROCESSOR_ARCHITECTURE_AMD64
00137         case PROCESSOR_ARCHITECTURE_AMD64:
00138           ACE_OS::strcpy (processor, ACE_LIB_TEXT ("x64"));
00139           ACE_OS::sprintf (subtype, ACE_LIB_TEXT ("%d"),
00140                            sinfo.wProcessorLevel);
00141           break;
00142 #     endif
00143 #     if defined PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
00144         case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
00145           ACE_OS::strcpy (processor, ACE_LIB_TEXT ("WOW64"));
00146           ACE_OS::sprintf (subtype, ACE_LIB_TEXT ("%d"),
00147                            sinfo.wProcessorLevel);
00148           break;
00149 #     endif
00150 #     if defined PROCESSOR_ARCHITECTURE_ARM
00151         case PROCESSOR_ARCHITECTURE_ARM:
00152           ACE_OS::strcpy (processor, ACE_LIB_TEXT ("ARM"));
00153           ACE_OS::sprintf (subtype, ACE_LIB_TEXT ("%d"),
00154                            sinfo.wProcessorLevel);
00155           break;
00156 #     endif
00157         case PROCESSOR_ARCHITECTURE_UNKNOWN:
00158         default:
00159           // @@ We could provide WinCE specific info here.  But let's
00160           //    defer that to some later point.
00161           ACE_OS::strcpy (processor, ACE_LIB_TEXT ("Unknown"));
00162           break;
00163         }
00164       ACE_OS::sprintf (name->machine,
00165                        ACE_LIB_TEXT ("%s %s"),
00166                        processor, subtype);
00167     }
00168   else if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
00169     {
00170       if (vinfo.dwMajorVersion == 4 && vinfo.dwMinorVersion == 0)
00171         {
00172           ACE_OS::strcpy (name->release, ACE_LIB_TEXT ("Windows 95"));
00173           if (vinfo.szCSDVersion[1] == 'C')
00174             ACE_OS::strcat (name->release, ACE_LIB_TEXT (" OSR2"));
00175         }
00176       else if (vinfo.dwMajorVersion == 4 && vinfo.dwMinorVersion == 10)
00177         {
00178           ACE_OS::strcpy (name->release, ACE_LIB_TEXT ("Windows 98"));
00179           if (vinfo.szCSDVersion[1] == 'A')
00180             ACE_OS::strcat (name->release, ACE_LIB_TEXT (" SE"));
00181         }
00182       else if (vinfo.dwMajorVersion == 4 && vinfo.dwMinorVersion == 90)
00183         {
00184           ACE_OS::strcpy (name->release, ACE_LIB_TEXT ("Windows Me"));
00185         }
00186       else
00187         {
00188           ACE_OS::strcpy (name->release, unknown);
00189         }
00190 
00191       ACE_OS::sprintf (name->version, ACE_LIB_TEXT ("%d"),
00192                        LOWORD (vinfo.dwBuildNumber));
00193       if (sinfo.dwProcessorType == PROCESSOR_INTEL_386)
00194         ACE_OS::strcpy (name->machine, ACE_LIB_TEXT ("Intel 80386"));
00195       else if (sinfo.dwProcessorType == PROCESSOR_INTEL_486)
00196         ACE_OS::strcpy (name->machine, ACE_LIB_TEXT ("Intel 80486"));
00197       else if (sinfo.dwProcessorType == PROCESSOR_INTEL_PENTIUM)
00198         ACE_OS::strcpy (name->machine, ACE_LIB_TEXT ("Intel Pentium"));
00199       else
00200         ACE_OS::strcpy (name->machine, unknown);
00201     }
00202   else
00203     {
00204       // We don't know what this is!
00205 
00206       ACE_OS::strcpy (name->release, unknown);
00207       ACE_OS::strcpy (name->version, unknown);
00208       ACE_OS::strcpy (name->machine, unknown);
00209     }
00210 
00211 # if defined (ACE_LACKS_HOSTNAME)
00212   return 0;
00213 # else /* ACE_LACKS_HOSTNAME */
00214   return ACE_OS::hostname (name->nodename, maxnamelen);
00215 # endif /* ACE_LACKS_HOSTNAME */
00216 
00217 #elif defined (ACE_VXWORKS)
00218   size_t maxnamelen = sizeof name->nodename;
00219   ACE_OS::strcpy (name->sysname, "VxWorks");
00220   ACE_OS::strcpy (name->release, "???");
00221   ACE_OS::strcpy (name->version, sysBspRev ());
00222   ACE_OS::strcpy (name->machine, sysModel ());
00223 
00224   return ACE_OS::hostname (name->nodename, maxnamelen);
00225 #elif defined (INTEGRITY)
00226   if(!name) {
00227     errno = EFAULT;
00228     return -1;
00229   }
00230   strcpy(name->sysname,"INTEGRITY");
00231   int status = gethostname(name->nodename,_SYS_NMLN);
00232   strcpy(name->release,"4.0");
00233   strcpy(name->version,"4.0.9");
00234   strcpy(name->machine,"a standard name");
00235   return status;
00236 #endif /* ACE_WIN32 */
00237 }
00238 
00239 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:58 2006 for ACE by doxygen 1.3.6