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

Go to the SVN repository for this file.

1 /* $Id: GBenchVersionInfo.cpp 39870 2017-11-15 15:47:11Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'gbench_svc.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 #if defined(NCBI_OS_DARWIN)
41 #include <CoreServices/CoreServices.h>
42 #endif
43 
44 // generated includes
46 #include <gui/objects/OS_Ver.hpp>
47 
48 // generated classes
49 
51 
52 BEGIN_objects_SCOPE // namespace ncbi::objects::
53 
54 
55 int CGBenchVersionInfo::major = 0;//CPluginVersion::eMajor;
56 int CGBenchVersionInfo::minor = 0;//CPluginVersion::eMinor;
57 int CGBenchVersionInfo::patch = 0;//CPluginVersion::ePatchLevel;
60 
62 
63 void CGBenchVersionInfo::Initialize( size_t ver_major, size_t ver_minor, size_t ver_patch_level )
64 {
65  if( sInitialized ) return;
66 
67  CGBenchVersionInfo::major = (int)ver_major;
68  CGBenchVersionInfo::minor = (int)ver_minor;
69  CGBenchVersionInfo::patch = (int)ver_patch_level;
70 
71 #if defined(NCBI_OS_MSWIN)
72  ///
73  /// determine the OS version
74  ///
76 
77  OSVERSIONINFOEXW osinfo;
78  memset(&osinfo, 0, sizeof(osinfo));
79  osinfo.dwOSVersionInfoSize = sizeof(osinfo);
80 
81  typedef LONG(WINAPI *PRtlGetVersion)(LPOSVERSIONINFOEXW);
82  PRtlGetVersion pRtlGetVersion = (PRtlGetVersion)GetProcAddress(GetModuleHandle(TEXT("ntdll.dll")), "RtlGetVersion");
83  LONG status = -1;
84  if (pRtlGetVersion)
85  status = pRtlGetVersion(&osinfo);
86 
87  if (status != 0) {
88  memset(&osinfo, 0, sizeof(osinfo));
89  osinfo.dwOSVersionInfoSize = sizeof(osinfo);
90  GetVersionExW((LPOSVERSIONINFOW)&osinfo);
91  }
92 
93  switch( osinfo.dwMajorVersion ){
94  default:
95  break;
96 
97  case 3:
99  break;
100 
101  case 4:
102  switch( osinfo.dwMinorVersion ){
103  case 0:
105  break;
106 
107  case 10:
109  break;
110 
111  case 90:
113  break;
114 
115  default:
117  break;
118  }
119  break;
120 
121  case 5:
122  switch( osinfo.dwMinorVersion ){
123  case 0:
124  default:
126  break;
127 
128  case 1:
130  break;
131 
132  case 2:
134  // SMSERVERR2 is not defined; it is needed for distinction of R2
135  break;
136  }
137  break;
138 
139  case 6:
140  switch( osinfo.dwMinorVersion ){
141  case 0:
142  default:
144  (osinfo.wProductType == VER_NT_WORKSTATION)
147  ;
148  break;
149 
150  case 1:
152  (osinfo.wProductType == VER_NT_WORKSTATION)
155  ;
156  break;
157  case 2:
159  (osinfo.wProductType == VER_NT_WORKSTATION)
162  ;
163  break;
164  case 3:
166  (osinfo.wProductType == VER_NT_WORKSTATION)
169  ;
170  break;
171  }
172  break;
173  case 10:
175  (osinfo.wProductType == VER_NT_WORKSTATION)
178  ;
179  break;
180  }
181 
183  TOs_ver arch_flag = 0;
184 
185  SYSTEM_INFO sysinfo;
186  memset(&sysinfo, 0, sizeof(sysinfo));
187 
188  typedef void (WINAPI *PGetSysInfo)(SYSTEM_INFO*);
189 
190  PGetSysInfo pGetSysInfo = (PGetSysInfo) GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo" );
191  if( pGetSysInfo != NULL ){
192  pGetSysInfo( &sysinfo );
193  } else {
194  GetSystemInfo( &sysinfo );
195  }
196  switch( sysinfo.wProcessorArchitecture ){
197  case PROCESSOR_ARCHITECTURE_UNKNOWN:
198  default:
200  arch_flag = 0;
201  break;
202 
203  case PROCESSOR_ARCHITECTURE_INTEL:
205  arch_flag = eOS_Ver_intel_x32;
206  break;
207  case PROCESSOR_ARCHITECTURE_AMD64:
209  arch_flag = eOS_Ver_amd_x64;
210  break;
211  case PROCESSOR_ARCHITECTURE_IA64:
213  arch_flag = eOS_Ver_intel_x64;
214  break;
215  }
216  CGBenchVersionInfo::osver |= arch_flag;
217 
218 
219 #elif defined(NCBI_OS_DARWIN)
220 
221  SInt32 garch;
222  Gestalt( gestaltSysArchitecture, &garch );
223 
224  TOs_ver arch_flag = 0;
225 
226  if( garch == gestalt68k ){
227  arch_flag = eOS_Ver_cpu_generic;
228 
229  } else if( garch == gestaltPowerPC ){
230  arch_flag = eOS_Ver_ppc;
231 
232  } else if( garch == gestaltIntel ){
233  size_t ver_bits = sizeof(void*)*8;
234 
235  arch_flag = (ver_bits == 64) ? eOS_Ver_intel_x64 : eOS_Ver_intel_x32;
236  }
237 
238 
239  SInt32 vers_maj;
240  Gestalt( gestaltSystemVersionMajor, &vers_maj );
241 
243 
244  if( vers_maj < 10 ){
246 
247  } else {
248  SInt32 vers_min;
249  Gestalt( gestaltSystemVersionMinor, &vers_min );
250  //SInt32 vers_bug_fix;
251  //Gestalt( gestaltSystemVersionBugFix, &vers_bug_fix );
252 
253  switch( vers_min ){
254  case 1:
256  break;
257  case 2:
259  break;
260  case 3:
262  break;
263  case 4:
265  break;
266  case 5:
268  break;
269  case 6:
271  break;
272  case 7:
274  break;
275  }
276  }
277 
278 #elif defined(NCBI_OS_UNIX)
279 
281 #else
282 
284 #endif
285 
286  sInitialized = true;
287 }
288 
290 {
291  if( sInitialized ){
296 
297  // Commented out until cgi update on server
298  // SetOs_arch(CGBenchVersionInfo::osarch);
299  }
300 }
301 
302 // destructor
304 {
305 }
306 
307 
308 void CGBenchVersionInfo::GetLabel( string* str ) const
309 {
310  if( !str ){
311  return;
312  }
313 
314  AddVersionString( str );
315 
316  *str += " (";
317  AddOsString( str );
318  *str += ")";
319 
320  if (IsSetBuild_date()) {
321  *str += " [" + GetBuild_date().AsCTime().AsString() + "]";
322  }
323 }
324 
326 {
327  if( str ){
328  str->clear();
329  AddVersionString( str );
330  }
331 }
332 
334 {
335  *str += NStr::IntToString(GetVer_major());
336  *str += '.';
337  *str += NStr::IntToString(GetVer_minor());
338  *str += '.';
339  *str += NStr::IntToString(GetVer_patch());
340 }
341 
343 {
344  if( str ){
345  str->clear();
346  AddOsString( str );
347  }
348 }
349 
351 {
352  const char* os_name = "";
353  switch( GetOs_ver() & ~eOS_Ver_cpu_generic ){
355  os_name = "Windows";
356  break;
357  case eOS_Ver_windows_95:
358  os_name = "Windows 95";
359  break;
360  case eOS_Ver_windows_98:
361  os_name = "Windows 98";
362  break;
363  case eOS_Ver_windows_me:
364  os_name = "Windows ME";
365  break;
366  case eOS_Ver_windows_351:
367  os_name = "Windows NT 3.51";
368  break;
369  case eOS_Ver_windows_nt4:
370  os_name = "Windows NT 4.0";
371  break;
373  os_name = "Windows 2000";
374  break;
375  case eOS_Ver_windows_xp:
376  os_name = "Windows XP";
377  break;
379  os_name = "Windows 2003";
380  break;
382  os_name = "Windows 2003 R2";
383  break;
385  os_name = "Windows Vista";
386  break;
388  os_name = "Windows 2008";
389  break;
391  os_name = "Windows 2008 R2";
392  break;
394  os_name = "Windows 7";
395  break;
397  os_name = "Windows Server 2012";
398  break;
400  os_name = "Windows 8.0";
401  break;
403  os_name = "Windows Server 2012 R2";
404  break;
406  os_name = "Windows 8.1";
407  break;
409  os_name = "Windows Server 2016";
410  break;
411  case eOS_Ver_windows_ten:
412  os_name = "Windows 10";
413  break;
415  os_name = "MacOS X";
416  break;
417  case eOS_Ver_macosx_10_1:
418  os_name = "MacOS X 10.1";
419  break;
420  case eOS_Ver_macosx_10_2:
421  os_name = "MacOS X 10.2";
422  break;
423  case eOS_Ver_macosx_10_3:
424  os_name = "MacOS X 10.3";
425  break;
426  case eOS_Ver_macosx_10_4:
427  os_name = "MacOS X 10.4";
428  break;
429 
431  os_name = "Unix";
432  break;
433  case eOS_Ver_unix_linux:
434  os_name = "Unix/Linux";
435  break;
437  os_name = "Unix/Solaris 9";
438  break;
440  os_name = "Unix/Solaris 10";
441  break;
442 
443  default:
445  os_name = "Windows";
446  } else if( GetOs_ver() & eOS_Ver_macosx_generic ){
447  os_name = "MacOS X";
448  } else if( GetOs_ver() & eOS_Ver_unix_generic ){
449  os_name = "Unix";
450  } else {
451  os_name = "Unknown";
452  }
453  break;
454  }
455 
456  const char* arch_name = "";
457  switch( GetOs_ver() & eOS_Ver_cpu_generic ){
458  case eOS_Ver_intel_x32:
459  arch_name = " Intel-x32";
460  break;
461  case eOS_Ver_amd_x64:
462  arch_name = " AMD-x64";
463  break;
464  case eOS_Ver_intel_x64:
465  arch_name = " Intel-x64";
466  break;
467  case eOS_Ver_ppc:
468  arch_name = " PowerPC";
469  break;
470  case eOS_Ver_sparc:
471  arch_name = " Sparc";
472  break;
473  case eOS_Ver_mips:
474  arch_name = " MIPS";
475  break;
476  case eOS_Ver_alpha:
477  arch_name = " Alpha";
478  break;
479  }
480 
481  *str += os_name;
482  *str += arch_name;
483 }
484 
486 {
487  if (v1.GetVer_major() < v2.GetVer_major()) {
488  return true;
489  }
490  if (v2.GetVer_major() < v1.GetVer_major()) {
491  return false;
492  }
493 
494  if (v1.GetVer_minor() < v2.GetVer_minor()) {
495  return true;
496  }
497  if (v2.GetVer_minor() < v1.GetVer_minor()) {
498  return false;
499  }
500 
501  if (v1.GetVer_patch() < v2.GetVer_patch()) {
502  return true;
503  }
504  if (v2.GetVer_patch() < v1.GetVer_patch()) {
505  return false;
506  }
507 
508  return false;
509 }
510 
511 END_objects_SCOPE // namespace ncbi::objects::
512 
514 
515 /* Original file checksum: lines: 65, chars: 1911, CRC32: 1807b76f */
void GetLabel(string *str) const
Format a label for this version.
any alpha (0x07000000)
Definition: OS_Ver_.hpp:107
any intel x32 (0x01000000)
Definition: OS_Ver_.hpp:101
User-defined methods of the data storage class.
TVer_minor GetVer_minor(void) const
Get the Ver_minor member data.
void AddOsString(string *str) const
specific windows versions 0x1
Definition: OS_Ver_.hpp:69
TVer_patch & SetVer_patch(void)
Assign a value to Ver_patch data member.
any amd x64 (0x02000000)
Definition: OS_Ver_.hpp:102
bitmaks covering all Windows versions this corresponds to 0xff
Definition: OS_Ver_.hpp:68
bitmask for all linux and unix flavors this corresponds to 0xff0000
Definition: OS_Ver_.hpp:96
#define NULL
Definition: ncbistd.hpp:225
TVer_minor & SetVer_minor(void)
Assign a value to Ver_minor data member.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:4808
static TVer_patch patch
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
void GetVersionString(string *str) const
retrieve just the version info
User-defined methods of the data storage class.
any sparc (0x05000000)
Definition: OS_Ver_.hpp:105
static void Initialize(size_t ver_major, size_t ver_minor, size_t ver_patch_level)
Forced to make this method public as far as friend declaration does not work on Linux.
specific supported versions 0x10000
Definition: OS_Ver_.hpp:97
any powerpc (0x04000000)
Definition: OS_Ver_.hpp:104
bool IsSetBuild_date(void) const
Check if a value has been assigned to Build_date data member.
void GetOsString(string *str) const
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
Definition: ncbitime.cpp:1515
TVer_major GetVer_major(void) const
Get the Ver_major member data.
CTime AsCTime(CTime::ETimeZone tz=CTime::eLocal) const
Definition: Date.cpp:70
CPU attributes general mask (0xff000000)
Definition: OS_Ver_.hpp:100
TVer_major & SetVer_major(void)
Assign a value to Ver_major data member.
static TVer_major major
static TVer_minor minor
TVer_patch GetVer_patch(void) const
Get the Ver_patch member data.
const CVect2< U > & v2
Definition: globals.hpp:440
any mips (0x06000000)
Definition: OS_Ver_.hpp:106
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1153
void AddVersionString(string *str) const
TOs_ver & SetOs_ver(void)
Assign a value to Os_ver data member.
any intel x64 (0x03000000)
Definition: OS_Ver_.hpp:103
const TBuild_date & GetBuild_date(void) const
Get the Build_date member data.
TOs_ver GetOs_ver(void) const
Get the Os_ver member data.
static const char * str(char *buf, int n)
Definition: stats.c:84
specific MacOS X versions 0x100
Definition: OS_Ver_.hpp:89
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
bool operator<(const CGBenchVersionInfo &v1, const CGBenchVersionInfo &v2)
bitmask covering all MacOS X versions this corresponds to 0xff00
Definition: OS_Ver_.hpp:88
Modified on Thu Feb 22 13:23:27 2018 by modify_doxy.py rev. 546573