SystemDetect.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
00003  *
00004  * Copyright (C) 2005 Dell Inc.
00005  *  by Michael Brown <Michael_E_Brown@dell.com>
00006  * Licensed under the Open Software License version 2.1
00007  *
00008  * Alternatively, you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published
00010  * by the Free Software Foundation; either version 2 of the License,
00011  * or (at your option) any later version.
00012 
00013  * This program is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  */
00018 
00019 #define LIBSMBIOS_SOURCE
00020 #include "smbios/ISmbios.h"
00021 #include "smbios/IToken.h"
00022 
00023 #include "smbios/SystemInfo.h"
00024 #include "smbios/IMemory.h"
00025 #include "smbios/SmbiosDefs.h"
00026 #include "ExceptionImpl.h"
00027 
00028 #include "SystemDetect.h"
00029 
00030 // all our magic numbers
00031 #include "DellMagic.h"
00032 
00033 #include <string.h>
00034 
00035 // include this last.
00036 #include "smbios/message.h"
00037 
00038 using namespace smbios;
00039 using namespace cmos;
00040 using namespace std;
00041 
00042 // This is defined in SysInfoError.cpp
00043 extern smbios::Exception<smbios::IException> SysInfoException;
00044 
00045 //
00046 //
00047 // Detection functions
00048 //
00049 //
00050 
00051 bool couldBeDiamond ()
00052 {
00053     bool couldBeDiamond = false;
00054 
00055     if(SMBIOSGetDellSystemId() == SYSTEM_ID_DIAMOND )
00056         couldBeDiamond=true;
00057 
00058     return couldBeDiamond;
00059 }
00060 
00061 
00062 bool couldBeBayonet ()
00063 {
00064     //functionEnter( "%s", "" );
00065     bool couldBeBayonet = false;
00066 
00067     const smbios::ISmbiosTable *table =
00068         smbios::SmbiosFactory::getFactory()->getSingleton();
00069 
00070     // crappy msvc compiler workaround
00071     smbios::ISmbiosTable::const_iterator item ;
00072 
00073     if (0 == table)
00074         throw InternalErrorImpl();
00075 
00076     // search through 0x0B (OEM_Strings_Structure) items
00077     for( item = (*table)[OEM_Strings] ; item != table->end(); ++item)
00078     {
00079         const char *str = item->getStringByStringNumber (OEM_String_Field_Number); // no need to free retval.
00080         if ((0 != str) && (0 == strncmp (str, Bayonet_Detect_String, strlen(Bayonet_Detect_String))))
00081             couldBeBayonet = true;
00082     }
00083 
00084 
00085     //functionLeave( "\t\tretval = %i\n", (int)couldBeBayonet );
00086     return couldBeBayonet;
00087 }
00088 
00089 static bool isStdDellBiosSystem ()
00090 {
00091     //functionEnter( "%s", "" );
00092     bool dellSystem = false;
00093     // OEM String is 5 chars ("Dell\0")
00094     char OEMString[5] = { 0, };
00095 
00096     memory::IMemory *mem =
00097         memory::MemoryFactory::getFactory()->getSingleton();
00098 
00099     mem->fillBuffer( reinterpret_cast<u8 *>(OEMString), OEM_String_Location, 4 );
00100 
00101     if (0 == strncmp (OEMString, OEM_Dell_String, 5))
00102         dellSystem = true;
00103 
00104     //functionLeave( "\t\tretval = %i\n", (int)dellSystem );
00105     return dellSystem;
00106 }
00107 
00108 
00109 
00110 //
00111 // List of detection functions
00112 //
00113 
00114 struct SystemDetectionFunction
00115 {
00116     bool (*f_ptr)();
00117 }
00118 DellDetectionFunctions[] = {
00119                                {&isStdDellBiosSystem,},
00120                                {&couldBeBayonet,},
00121                                {&couldBeDiamond,},
00122                            };
00123 
00124 
00125 //
00126 // The main detection routine
00127 //
00128 
00129 int SMBIOSIsDellSystem ()
00130 {
00131     bool isDell = false;
00132     int retval = 0;
00133     //functionEnter( "%s", "" );
00134 
00135     // notice how extensible this is...
00136     //  We can add new detection functions to the array defined
00137     //  above at any time...
00138     //
00139     // Why not add an 8450 detection routine? Anybody?
00140     //
00141     int numEntries =
00142         sizeof (DellDetectionFunctions) /
00143         sizeof (DellDetectionFunctions[0]);
00144 
00145     for (int i = 0; i < numEntries; ++i)
00146     {
00147         try
00148         {
00149             isDell = DellDetectionFunctions[i].f_ptr ();
00150         }
00151         catch(const smbios::IException &e)
00152         {
00153             SysInfoException.setMessageString(e.what());
00154         }
00155         catch(...)
00156         {
00157             SysInfoException.setMessageString( _("Unknown internal error occurred") );
00158         }
00159 
00160         if (isDell)
00161             break;
00162     }
00163 
00164     //Convert to an int for our C-caller friends
00165     if(isDell)
00166     {
00167         retval = 1;
00168     }
00169     else
00170     {
00171         retval = 0;
00172     }
00173     //functionLeave( "\t\tretval = %i\n", (int)retval );
00174     return retval;
00175 }
00176 
00177 

Generated on Wed Apr 2 16:37:38 2008 for SMBIOS Library by  doxygen 1.5.1