SmiFactory.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 "SmiImpl.h"
00021 #include "FactoryImpl2.h"
00022 #include "TokenImpl.h"
00023 
00024 // message.h should be included last.
00025 #include "smbios/message.h"
00026 
00027 using namespace std;
00028 
00029 namespace smi
00030 {
00031     class SmiFactoryImpl : public factory::TFactory<SmiFactory>
00032     {
00033     public:
00034         SmiFactoryImpl() { setParameter("smiFile", ""); };
00035         virtual ~SmiFactoryImpl() throw() {};
00036         virtual std::auto_ptr<IDellCallingInterfaceSmi> makeNew(u8 type); // use me
00037     };
00038 
00039     //
00040     SmiFactory::~SmiFactory() throw()
00041     {}
00042     SmiFactory::SmiFactory()
00043     {}
00044 
00045     SmiFactory *SmiFactory::getFactory()
00046     {
00047         // reinterpret_cast<...>(0) to ensure template parameter is correct
00048         // this is a workaround for VC6 which cannot use explicit member template
00049         // function initialization.
00050         return SmiFactoryImpl::getFactory(reinterpret_cast<SmiFactoryImpl *>(0));
00051     }
00052 
00053     std::auto_ptr<IDellCallingInterfaceSmi> SmiFactoryImpl::makeNew( u8 type )
00054     {
00055         IDellCallingInterfaceSmi *ret = 0;
00056         SmiStrategy *strategyPtr = 0;
00057 
00058         if (mode == AutoDetectMode )
00059             strategyPtr = new SmiArchStrategy();
00060 
00061         else if (mode == UnitTestMode)
00062             strategyPtr = new SmiMockStrategy(getParameterString("smiFile"));
00063 
00064 
00065         // used for automatic setup of magic io stuff 
00066         u16 cmdIOAddress = 0;
00067         u8  cmdIOCode = 0;
00068         const smbios::ISmbiosTable *table = 0;
00069 
00070         switch( type )
00071         {
00072         case DELL_CALLING_INTERFACE_SMI_RAW:
00073             ret = new DellCallingInterfaceSmiImpl(strategyPtr, 0, 0);
00074             break;
00075 
00076         case DELL_CALLING_INTERFACE_SMI:
00077             // would be better to just get a 0xDA type from smbios table and get code/io
00078             try {
00079                 table = smbios::SmbiosFactory::getFactory()->getSingleton();
00080                 smbios::ISmbiosTable::const_iterator item = (*table)[0xDA];
00081                 cmdIOAddress = getU16_FromItem(*item, 4);
00082                 cmdIOCode = getU8_FromItem(*item, 6);
00083                 ret = new DellCallingInterfaceSmiImpl(strategyPtr, cmdIOAddress, cmdIOCode);
00084             } catch(...) {
00085                 throw SmiExceptionImpl(_("Could not automatically setup up magic io"));
00086             }
00087 
00088             break;
00089         default:
00090             throw InvalidSmiModeImpl(_("Unknown smi factory mode requested"));
00091             break;
00092         }
00093 
00094         if( ! ret )
00095             throw InvalidSmiModeImpl(_("Could not allocate SMI object"));
00096 
00097         std::auto_ptr<IDellCallingInterfaceSmi> foo(ret);
00098         return foo;
00099     }
00100 
00101 }

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