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

Generated on Tue Jan 17 02:59:08 2006 for SMBIOS Library by  doxygen 1.4.6