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

SmbiosFactory.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 // compat header should always be first header if including system headers
00020 #define LIBSMBIOS_SOURCE
00021 #include "smbios/compat.h"
00022 
00023 #include <vector>
00024 
00025 #include "SmbiosImpl.h"
00026 
00027 // message.h should be included last.
00028 #include "smbios/message.h"
00029 
00030 using namespace std;
00031 
00032 namespace smbios
00033 {
00034     SmbiosFactory::~SmbiosFactory() throw()
00035     {}
00036     SmbiosFactory::SmbiosFactory()
00037     {}
00038 
00039     SmbiosFactory *SmbiosFactory::getFactory()
00040     {
00041         // reinterpret_cast<...>(0) to ensure template parameter is correct
00042         // this is a workaround for VC6 which cannot use explicit member template
00043         // funciton initialization.
00044         return SmbiosFactoryImpl::getFactory(reinterpret_cast<SmbiosFactoryImpl *>(0));
00045     }
00046 
00047     ISmbiosTable      *SmbiosFactoryImpl::_tableInstance = 0;
00048 
00049     SmbiosFactoryImpl::~SmbiosFactoryImpl() throw()
00050     {
00051         if( _tableInstance )
00052         {
00053             delete _tableInstance;
00054             _tableInstance = 0;
00055         }
00056     }
00057 
00058     SmbiosFactoryImpl::SmbiosFactoryImpl()
00059     {
00060         mode = defaultMode;
00061         setParameter( "strictValidation", 0 );
00062         setParameter( "offset", 0 );
00063     }
00064 
00065     ISmbiosTable *SmbiosFactoryImpl::getSingleton()
00066     {
00067         if (! _tableInstance)
00068             _tableInstance = makeNew();
00069 
00070         return _tableInstance;
00071     }
00072 
00073     ISmbiosTable *SmbiosFactoryImpl::makeNew()
00074     {
00075         // stupid, ugly hack to supress (C4800) warning on msvc++
00076         bool strict = getParameterNum("strictValidation") ? 1 : 0;
00077 
00078         SmbiosTable *table = 0;
00079 
00080         std::vector<SmbiosStrategy *> strategies;
00081 
00082         if (mode == AutoDetectMode)
00083         {
00084 #ifdef LIBSMBIOS_PLATFORM_LINUX
00085             strategies.push_back( new SmbiosLinuxEFIStrategy() );
00086 #endif
00087             strategies.push_back( new SmbiosMemoryStrategy(getParameterNum("offset")) );
00088 #ifdef LIBSMBIOS_PLATFORM_WIN32
00089             strategies.push_back( new SmbiosWinGetFirmwareTableStrategy() );
00090             strategies.push_back( new SmbiosWinWMIStrategy() );
00091 #endif
00092         }
00093         else if (mode == UnitTestMode)
00094         {
00095             strategies.push_back( new SmbiosMemoryStrategy(getParameterNum("offset")) );
00096         }
00097         else
00098         {
00099         throw NotImplementedImpl(_("Unknown smbios factory mode requested"));
00100         }
00101 
00102 
00103         table = new SmbiosTable(
00104                         strategies,
00105                         strict
00106                     );
00107 
00108         table->initializeWorkaround();
00109         return table;
00110     }
00111 }

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