NCBI C++ ToolKit
GBenchVersionInfo.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

00001 /* $Id: GBenchVersionInfo.cpp 25100 2012-01-23 17:17:38Z falkrb $
00002  * ===========================================================================
00003  *
00004  *                            PUBLIC DOMAIN NOTICE
00005  *               National Center for Biotechnology Information
00006  *
00007  *  This software/database is a "United States Government Work" under the
00008  *  terms of the United States Copyright Act.  It was written as part of
00009  *  the author's official duties as a United States Government employee and
00010  *  thus cannot be copyrighted.  This software/database is freely available
00011  *  to the public for use. The National Library of Medicine and the U.S.
00012  *  Government have not placed any restriction on its use or reproduction.
00013  *
00014  *  Although all reasonable efforts have been taken to ensure the accuracy
00015  *  and reliability of the software and data, the NLM and the U.S.
00016  *  Government do not and cannot warrant the performance or results that
00017  *  may be obtained by using this software or data. The NLM and the U.S.
00018  *  Government disclaim all warranties, express or implied, including
00019  *  warranties of performance, merchantability or fitness for any particular
00020  *  purpose.
00021  *
00022  *  Please cite the author in any work or product based on this material.
00023  *
00024  * ===========================================================================
00025  *
00026  * Author:  .......
00027  *
00028  * File Description:
00029  *   .......
00030  *
00031  * Remark:
00032  *   This code was originally generated by application DATATOOL
00033  *   using the following specifications:
00034  *   'gbench_svc.asn'.
00035  */
00036 
00037 // standard includes
00038 #include <ncbi_pch.hpp>
00039 
00040 #if defined(NCBI_OS_DARWIN)
00041 #include <CoreServices/CoreServices.h>
00042 #endif
00043 
00044 // generated includes
00045 #include <gui/objects/GBenchVersionInfo.hpp>
00046 #include <gui/objects/OS_Ver.hpp>
00047 
00048 // generated classes
00049 
00050 BEGIN_NCBI_SCOPE
00051 
00052 BEGIN_objects_SCOPE // namespace ncbi::objects::
00053 
00054 
00055 int CGBenchVersionInfo::major = 0;//CPluginVersion::eMajor;
00056 int CGBenchVersionInfo::minor = 0;//CPluginVersion::eMinor;
00057 int CGBenchVersionInfo::patch = 0;//CPluginVersion::ePatchLevel;
00058 int CGBenchVersionInfo::osver = eOS_Ver_unknown;
00059 int CGBenchVersionInfo::osarch = -1;
00060 
00061 bool CGBenchVersionInfo::sInitialized = false;
00062 
00063 void CGBenchVersionInfo::Initialize( size_t ver_major, size_t ver_minor, size_t ver_patch_level )
00064 {
00065     if( sInitialized ) return;
00066 
00067     CGBenchVersionInfo::major = (int)ver_major;
00068     CGBenchVersionInfo::minor = (int)ver_minor;
00069     CGBenchVersionInfo::patch = (int)ver_patch_level;
00070 
00071 #if defined(NCBI_OS_MSWIN)
00072     ///
00073     /// determine the OS version
00074     ///
00075     CGBenchVersionInfo::osver = eOS_Ver_windows_generic;
00076                            
00077     OSVERSIONINFOEX osinfo;
00078     memset(&osinfo, 0, sizeof(osinfo));
00079     osinfo.dwOSVersionInfoSize = sizeof(osinfo);
00080 
00081     GetVersionEx((OSVERSIONINFO*)&osinfo);
00082     switch( osinfo.dwMajorVersion ){
00083     default:
00084         break;
00085 
00086     case 3:
00087         CGBenchVersionInfo::osver = eOS_Ver_windows_351;
00088         break;
00089 
00090     case 4:
00091         switch( osinfo.dwMinorVersion ){
00092         case 0:
00093             CGBenchVersionInfo::osver = eOS_Ver_windows_95;
00094             break;
00095 
00096         case 10:
00097             CGBenchVersionInfo::osver = eOS_Ver_windows_98;
00098             break;
00099 
00100         case 90:
00101             CGBenchVersionInfo::osver = eOS_Ver_windows_me;
00102             break;
00103 
00104         default:
00105             CGBenchVersionInfo::osver = eOS_Ver_windows_95;
00106             break;
00107         }
00108         break;
00109 
00110     case 5:
00111         switch( osinfo.dwMinorVersion ){
00112         case 0:
00113         default:
00114             CGBenchVersionInfo::osver = eOS_Ver_windows_2000;
00115             break;
00116 
00117         case 1:
00118             CGBenchVersionInfo::osver = eOS_Ver_windows_xp;
00119             break;
00120 
00121         case 2:
00122             CGBenchVersionInfo::osver = eOS_Ver_windows_2003;
00123             // SMSERVERR2 is not defined; it is needed for distinction of R2
00124             break;
00125         }
00126         break;
00127 
00128     case 6:
00129         switch( osinfo.dwMinorVersion ){
00130         case 0:
00131         default:
00132             CGBenchVersionInfo::osver = 
00133                 (osinfo.wProductType == VER_NT_WORKSTATION)
00134                 ? eOS_Ver_windows_vista 
00135                 : eOS_Ver_windows_2008
00136             ;
00137             break;
00138 
00139         case 1:
00140             CGBenchVersionInfo::osver = 
00141                 (osinfo.wProductType == VER_NT_WORKSTATION)
00142                 ? eOS_Ver_windows_seven 
00143                 : eOS_Ver_windows_2008_R2
00144             ;
00145             break;
00146         }
00147         break;
00148     }
00149 
00150     CGBenchVersionInfo::osarch = -1;
00151     TOs_ver arch_flag = 0;
00152 
00153     SYSTEM_INFO sysinfo;
00154     memset(&sysinfo, 0, sizeof(sysinfo));
00155 
00156     typedef void (WINAPI *PGetSysInfo)(SYSTEM_INFO*);
00157 
00158     PGetSysInfo pGetSysInfo = (PGetSysInfo) GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo" );
00159     if( pGetSysInfo != NULL ){
00160         pGetSysInfo( &sysinfo );
00161     } else {
00162         GetSystemInfo( &sysinfo );
00163     }
00164     switch( sysinfo.wProcessorArchitecture ){
00165     case PROCESSOR_ARCHITECTURE_UNKNOWN:
00166     default:
00167         CGBenchVersionInfo::osarch = -1;
00168         arch_flag = 0;
00169         break;
00170 
00171     case PROCESSOR_ARCHITECTURE_INTEL:
00172         CGBenchVersionInfo::osarch = 0;
00173         arch_flag = eOS_Ver_intel_x32;
00174         break;
00175     case PROCESSOR_ARCHITECTURE_AMD64:
00176         CGBenchVersionInfo::osarch = 1;
00177         arch_flag = eOS_Ver_amd_x64;
00178         break;
00179     case PROCESSOR_ARCHITECTURE_IA64:
00180         CGBenchVersionInfo::osarch = 2;
00181         arch_flag = eOS_Ver_intel_x64;
00182         break;
00183     }
00184     CGBenchVersionInfo::osver |= arch_flag;
00185 
00186 
00187 #elif defined(NCBI_OS_DARWIN)
00188 
00189     SInt32 garch;
00190     Gestalt( gestaltSysArchitecture, &garch );
00191 
00192     TOs_ver arch_flag = 0;
00193 
00194     if( garch == gestalt68k ){
00195         arch_flag = eOS_Ver_cpu_generic;
00196 
00197     } else if( garch == gestaltPowerPC ){
00198         arch_flag = eOS_Ver_ppc;
00199 
00200     } else if( garch == gestaltIntel ){
00201         size_t ver_bits = sizeof(void*)*8;
00202 
00203         arch_flag = (ver_bits == 64) ? eOS_Ver_intel_x64 : eOS_Ver_intel_x32;
00204     }
00205 
00206 
00207     SInt32 vers_maj;
00208     Gestalt( gestaltSystemVersionMajor, &vers_maj );
00209 
00210     CGBenchVersionInfo::osver = eOS_Ver_macosx_generic;
00211 
00212     if( vers_maj < 10 ){
00213          CGBenchVersionInfo::osver = eOS_Ver_macosx_generic | arch_flag;
00214 
00215     } else {
00216         SInt32 vers_min;
00217         Gestalt( gestaltSystemVersionMinor, &vers_min );
00218         //SInt32 vers_bug_fix;
00219         //Gestalt( gestaltSystemVersionBugFix, &vers_bug_fix );
00220 
00221         switch( vers_min ){
00222         case 1:
00223             CGBenchVersionInfo::osver = eOS_Ver_macosx_10_1 | arch_flag;
00224             break;
00225         case 2:
00226             CGBenchVersionInfo::osver = eOS_Ver_macosx_10_2 | arch_flag;
00227             break;
00228         case 3:
00229             CGBenchVersionInfo::osver = eOS_Ver_macosx_10_3 | arch_flag;
00230             break;
00231         case 4:
00232             CGBenchVersionInfo::osver = eOS_Ver_macosx_10_4 | arch_flag;
00233             break;
00234         case 5:
00235             CGBenchVersionInfo::osver = eOS_Ver_macosx_10_5 | arch_flag;
00236             break;
00237         case 6:
00238             CGBenchVersionInfo::osver = eOS_Ver_macosx_10_6 | arch_flag;
00239             break;
00240         case 7:
00241             CGBenchVersionInfo::osver = eOS_Ver_macosx_10_7 | arch_flag;
00242             break;
00243         }
00244     }
00245 
00246 #elif defined(NCBI_OS_UNIX)
00247 
00248     CGBenchVersionInfo::osver = eOS_Ver_unix_generic;
00249 #else
00250 
00251     CGBenchVersionInfo::osver = eOS_Ver_unknown;
00252 #endif
00253 
00254     sInitialized = true;
00255 }
00256 
00257 CGBenchVersionInfo::CGBenchVersionInfo()
00258 {
00259     if( sInitialized ){
00260         SetVer_major(CGBenchVersionInfo::major);
00261         SetVer_minor(CGBenchVersionInfo::minor);
00262         SetVer_patch(CGBenchVersionInfo::patch);
00263         SetOs_ver(CGBenchVersionInfo::osver);
00264 
00265         // Commented out until cgi update on server
00266         // SetOs_arch(CGBenchVersionInfo::osarch);
00267     }
00268 }
00269 
00270 // destructor
00271 CGBenchVersionInfo::~CGBenchVersionInfo(void)
00272 {
00273 }
00274 
00275 
00276 void CGBenchVersionInfo::GetLabel( string* str ) const
00277 {
00278     if( !str ){
00279         return;
00280     }
00281 
00282     AddVersionString( str );
00283 
00284     *str += " (";
00285     AddOsString( str );
00286     *str += ")";
00287 
00288     if (IsSetBuild_date()) {
00289         *str += " [" + GetBuild_date().AsCTime().AsString() + "]";
00290     }
00291 }
00292 
00293 void CGBenchVersionInfo::GetVersionString( string* str ) const
00294 {
00295     if( str ){
00296         str->clear();
00297         AddVersionString( str );
00298     }
00299 }
00300 
00301 void CGBenchVersionInfo::AddVersionString( string* str ) const
00302 {
00303     *str += NStr::IntToString(GetVer_major());
00304     *str += '.';
00305     *str += NStr::IntToString(GetVer_minor());
00306     *str += '.';
00307     *str += NStr::IntToString(GetVer_patch());
00308 }
00309 
00310 void CGBenchVersionInfo::GetOsString( string* str ) const
00311 {
00312     if( str ){
00313         str->clear();
00314         AddOsString( str );
00315     }
00316 }
00317 
00318 void CGBenchVersionInfo::AddOsString( string* str ) const
00319 {
00320     const char* os_name = "";
00321     switch( GetOs_ver() & ~eOS_Ver_cpu_generic ){
00322     case eOS_Ver_windows_generic:
00323         os_name = "Windows";
00324         break;
00325     case eOS_Ver_windows_95:
00326         os_name = "Windows 95";
00327         break;
00328     case eOS_Ver_windows_98:
00329         os_name = "Windows 98";
00330         break;
00331     case eOS_Ver_windows_me:
00332         os_name = "Windows ME";
00333         break;
00334     case eOS_Ver_windows_351:
00335         os_name = "Windows NT 3.51";
00336         break;
00337     case eOS_Ver_windows_nt4:
00338         os_name = "Windows NT 4.0";
00339         break;
00340     case eOS_Ver_windows_2000:
00341         os_name = "Windows 2000";
00342         break;
00343     case eOS_Ver_windows_xp:
00344         os_name = "Windows XP";
00345         break;
00346     case eOS_Ver_windows_2003:
00347         os_name = "Windows 2003";
00348         break;
00349     case eOS_Ver_windows_2003_R2:
00350         os_name = "Windows 2003 R2";
00351         break;
00352     case eOS_Ver_windows_vista:
00353         os_name = "Windows Vista";
00354         break;
00355     case eOS_Ver_windows_2008:
00356         os_name = "Windows 2008";
00357         break;
00358     case eOS_Ver_windows_2008_R2:
00359         os_name = "Windows 2008 R2";
00360         break;
00361     case eOS_Ver_windows_seven:
00362         os_name = "Windows 7";
00363         break;
00364 
00365     case eOS_Ver_macosx_generic:
00366         os_name = "MacOS X";
00367         break;
00368     case eOS_Ver_macosx_10_1:
00369         os_name = "MacOS X 10.1";
00370         break;
00371     case eOS_Ver_macosx_10_2:
00372         os_name = "MacOS X 10.2";
00373         break;
00374     case eOS_Ver_macosx_10_3:
00375         os_name = "MacOS X 10.3";
00376         break;
00377     case eOS_Ver_macosx_10_4:
00378         os_name = "MacOS X 10.4";
00379         break;
00380 
00381     case eOS_Ver_unix_generic:
00382         os_name = "Unix";
00383         break;
00384     case eOS_Ver_unix_linux:
00385         os_name = "Unix/Linux";
00386         break;
00387     case eOS_Ver_unix_solaris_9:
00388         os_name = "Unix/Solaris 9";
00389         break;
00390     case eOS_Ver_unix_solaris_10:
00391         os_name = "Unix/Solaris 10";
00392         break;
00393 
00394     default:
00395         if( GetOs_ver() & eOS_Ver_windows_generic ){
00396             os_name = "Windows";
00397         } else if( GetOs_ver() & eOS_Ver_macosx_generic ){
00398             os_name = "MacOS X";
00399         } else if( GetOs_ver() & eOS_Ver_unix_generic ){
00400             os_name = "Unix";
00401         } else {
00402             os_name = "Unknown";
00403         }
00404         break;
00405     }
00406 
00407     const char* arch_name = "";
00408     switch( GetOs_ver() & eOS_Ver_cpu_generic ){
00409     case eOS_Ver_intel_x32:
00410         arch_name = " Intel-x32";
00411         break;
00412     case eOS_Ver_amd_x64:
00413         arch_name = " AMD-x64";
00414         break;
00415     case eOS_Ver_intel_x64:
00416         arch_name = " Intel-x64";
00417         break;
00418     case eOS_Ver_ppc:
00419         arch_name = " PowerPC";
00420         break;
00421     case eOS_Ver_sparc:
00422         arch_name = " Sparc";
00423         break;
00424     case eOS_Ver_mips:
00425         arch_name = " MIPS";
00426         break;
00427     case eOS_Ver_alpha:
00428         arch_name = " Alpha";
00429         break;
00430     }
00431 
00432     *str += os_name;
00433     *str += arch_name;
00434 }
00435 
00436 bool operator<(const CGBenchVersionInfo& v1, const CGBenchVersionInfo& v2)
00437 {
00438     if (v1.GetVer_major() < v2.GetVer_major()) {
00439         return true;
00440     }
00441     if (v2.GetVer_major() < v1.GetVer_major()) {
00442         return false;
00443     }
00444 
00445     if (v1.GetVer_minor() < v2.GetVer_minor()) {
00446         return true;
00447     }
00448     if (v2.GetVer_minor() < v1.GetVer_minor()) {
00449         return false;
00450     }
00451 
00452     if (v1.GetVer_patch() < v2.GetVer_patch()) {
00453         return true;
00454     }
00455     if (v2.GetVer_patch() < v1.GetVer_patch()) {
00456         return false;
00457     }
00458 
00459     return false;
00460 }
00461 
00462 END_objects_SCOPE // namespace ncbi::objects::
00463 
00464 END_NCBI_SCOPE
00465 
00466 /* Original file checksum: lines: 65, chars: 1911, CRC32: 1807b76f */
Modified on Sat May 30 11:05:44 2015 by modify_doxy.py rev. 426318