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 "../common/FactoryImpl2.h"
00022 
00023 // message.h should be included last.
00024 #include "smbios/message.h"
00025 
00026 using namespace std;
00027 
00028 namespace smi
00029 {
00030     class SmiFactoryImpl : public factory::TFactory<SmiFactory>
00031     {
00032     public:
00033         SmiFactoryImpl() { setParameter("smiFile", ""); };
00034         virtual ~SmiFactoryImpl() throw() {};
00035         virtual std::auto_ptr<ISmi> makeNew(u8 type); // use me
00036     protected:
00037         static ISmi *_cmosPtr;
00038     };
00039 
00040     //
00041     SmiFactory::~SmiFactory() throw()
00042     {}
00043     SmiFactory::SmiFactory()
00044     {}
00045 
00046     SmiFactory *SmiFactory::getFactory()
00047     {
00048         // reinterpret_cast<...>(0) to ensure template parameter is correct
00049         // this is a workaround for VC6 which cannot use explicit member template
00050         // function initialization.
00051         return SmiFactoryImpl::getFactory(reinterpret_cast<SmiFactoryImpl *>(0));
00052     }
00053 
00054     std::auto_ptr<ISmi> SmiFactoryImpl::makeNew( u8 type )
00055     {
00056         ISmi *ret = 0;
00057         SmiStrategy *strategyPtr = 0;
00058 
00059         if (mode == AutoDetectMode )
00060             strategyPtr = new SmiArchStrategy();
00061 
00062         else if (mode == UnitTestMode)
00063             strategyPtr = new SmiMockStrategy(getParameterString("smiFile"));
00064 
00065 
00066         switch( type )
00067         {
00068         case DELL_CALLING_INTERFACE_SMI:
00069             ret = new DellCallingInterfaceSmiImpl(strategyPtr);
00070             break;
00071         default:
00072             throw InvalidSmiModeImpl(_("Unknown smi factory mode requested"));
00073             break;
00074         }
00075 
00076         if( ! ret )
00077             throw InvalidSmiModeImpl(_("Could not allocate SMI object"));
00078 
00079         std::auto_ptr<ISmi> foo(ret);
00080         return foo;
00081     }
00082 
00083 }

Generated on Tue Jul 11 20:46:46 2006 for SMBIOS Library by  doxygen 1.4.7