00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define LIBSMBIOS_SOURCE
00020 #include "SmiImpl.h"
00021 #include "FactoryImpl2.h"
00022 #include "TokenImpl.h"
00023
00024
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<ISmi> makeNew(u8 type);
00037 protected:
00038 static ISmi *_cmosPtr;
00039 };
00040
00041
00042 SmiFactory::~SmiFactory() throw()
00043 {}
00044 SmiFactory::SmiFactory()
00045 {}
00046
00047 SmiFactory *SmiFactory::getFactory()
00048 {
00049
00050
00051
00052 return SmiFactoryImpl::getFactory(reinterpret_cast<SmiFactoryImpl *>(0));
00053 }
00054
00055 std::auto_ptr<ISmi> SmiFactoryImpl::makeNew( u8 type )
00056 {
00057 ISmi *ret = 0;
00058 SmiStrategy *strategyPtr = 0;
00059
00060 if (mode == AutoDetectMode )
00061 strategyPtr = new SmiArchStrategy();
00062
00063 else if (mode == UnitTestMode)
00064 strategyPtr = new SmiMockStrategy(getParameterString("smiFile"));
00065
00066
00067
00068 u16 cmdIOAddress = 0;
00069 u8 cmdIOCode = 0;
00070 smbios::TokenTableFactory *ttFactory = 0;
00071 smbios::ITokenTable *tokenTable = 0;
00072
00073 switch( type )
00074 {
00075 case DELL_CALLING_INTERFACE_SMI_RAW:
00076 ret = new DellCallingInterfaceSmiImpl(strategyPtr);
00077 break;
00078
00079 case DELL_CALLING_INTERFACE_SMI:
00080 ret = new DellCallingInterfaceSmiImpl(strategyPtr);
00081
00082
00083 ttFactory = smbios::TokenTableFactory::getFactory() ;
00084 tokenTable = ttFactory->getSingleton();
00085
00086 for(
00087 smbios::ITokenTable::iterator token = tokenTable->begin();
00088 token != tokenTable->end();
00089 ++token )
00090 {
00091
00092
00093 try{
00094 if( token->getTokenClass() != "TokenDA" )
00095 continue;
00096
00097
00098 dynamic_cast<smbios::ISmiToken *>(&*token)->getSmiDetails(&cmdIOAddress, &cmdIOCode, static_cast<u8*>(0));
00099 ret->setCommandIOMagic( cmdIOAddress, cmdIOCode );
00100 break;
00101 } catch(...){
00102 }
00103 }
00104
00105 if( ! (cmdIOAddress && cmdIOCode))
00106 throw SmiExceptionImpl(_("Could not automatically setup up magic io"));
00107
00108 break;
00109 default:
00110 throw InvalidSmiModeImpl(_("Unknown smi factory mode requested"));
00111 break;
00112 }
00113
00114 if( ! ret )
00115 throw InvalidSmiModeImpl(_("Could not allocate SMI object"));
00116
00117 std::auto_ptr<ISmi> foo(ret);
00118 return foo;
00119 }
00120
00121 }