Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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 this last.
00034 #include "smbios/message.h"
00035 
00036 using namespace smbios;
00037 using namespace cmos;
00038 using namespace std;
00039 
00040 // This is defined in SysInfoError.cpp
00041 extern smbios::Exception<smbios::IException> SysInfoException;
00042 
00043 //
00044 //
00045 // Detection functions
00046 //
00047 //
00048 
00049 bool couldBeDiamond ()
00050 {
00051     bool couldBeDiamond = false;
00052 
00053     if(SMBIOSGetDellSystemId() == SYSTEM_ID_DIAMOND )
00054         couldBeDiamond=true;
00055 
00056     return couldBeDiamond;
00057 }
00058 
00059 
00060 bool couldBeBayonet ()
00061 {
00062     //functionEnter( "%s", "" );
00063     bool couldBeBayonet = false;
00064 
00065     smbios::ISmbiosTable *table =
00066         smbios::SmbiosFactory::getFactory()->getSingleton();
00067 
00068     // crappy msvc compiler workaround
00069     smbios::ISmbiosTable::iterator item ;
00070 
00071     if (0 == table)
00072         throw InternalErrorImpl();
00073 
00074     // search through 0x0B (OEM_Strings_Structure) items
00075     for( item = (*table)[OEM_Strings] ; item != table->end(); ++item)
00076     {
00077         const char *str = item->getStringByStringNumber (OEM_String_Field_Number); // no need to free retval.
00078         if ((0 != str) && (0 == strncmp (str, Bayonet_Detect_String, strlen(Bayonet_Detect_String))))
00079             couldBeBayonet = true;
00080     }
00081 
00082 
00083     //functionLeave( "\t\tretval = %i\n", (int)couldBeBayonet );
00084     return couldBeBayonet;
00085 }
00086 
00087 static bool isStdDellBiosSystem ()
00088 {
00089     //functionEnter( "%s", "" );
00090     bool dellSystem = false;
00091     // OEM String is 5 chars ("Dell\0")
00092     char OEMString[5] = { 0, };
00093 
00094     memory::IMemory *mem =
00095         memory::MemoryFactory::getFactory()->getSingleton();
00096 
00097     mem->fillBuffer( reinterpret_cast<u8 *>(OEMString), OEM_String_Location, 4 );
00098 
00099     if (0 == strncmp (OEMString, OEM_Dell_String, 5))
00100         dellSystem = true;
00101 
00102     //functionLeave( "\t\tretval = %i\n", (int)dellSystem );
00103     return dellSystem;
00104 }
00105 
00106 
00107 
00108 //
00109 // List of detection functions
00110 //
00111 
00112 struct SystemDetectionFunction
00113 {
00114     bool (*f_ptr)();
00115 }
00116 DellDetectionFunctions[] = {
00117                                {&isStdDellBiosSystem,},
00118                                {&couldBeBayonet,},
00119                                {&couldBeDiamond,},
00120                            };
00121 
00122 
00123 //
00124 // The main detection routine
00125 //
00126 
00127 int SMBIOSIsDellSystem ()
00128 {
00129     bool isDell = false;
00130     int retval = 0;
00131     //functionEnter( "%s", "" );
00132 
00133     // notice how extensible this is...
00134     //  We can add new detection functions to the array defined
00135     //  above at any time...
00136     //
00137     // Why not add an 8450 detection routine? Anybody?
00138     //
00139     int numEntries =
00140         sizeof (DellDetectionFunctions) /
00141         sizeof (DellDetectionFunctions[0]);
00142 
00143     for (int i = 0; i < numEntries; ++i)
00144     {
00145         try
00146         {
00147             isDell = DellDetectionFunctions[i].f_ptr ();
00148         }
00149         catch(const smbios::IException &e)
00150         {
00151             SysInfoException.setMessageString(e.what());
00152         }
00153         catch(...)
00154         {
00155             SysInfoException.setMessageString( _("Unknown internal error occurred") );
00156         }
00157 
00158         if (isDell)
00159             break;
00160     }
00161 
00162     //Convert to an int for our C-caller friends
00163     if(isDell)
00164     {
00165         retval = 1;
00166     }
00167     else
00168     {
00169         retval = 0;
00170     }
00171     //functionLeave( "\t\tretval = %i\n", (int)retval );
00172     return retval;
00173 }
00174 
00175 

Generated on Wed Apr 11 16:25:10 2007 for SMBIOS Library by doxygen 1.3.5