SMBIOS Library
SmiFactory.cpp
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
3  *
4  * Copyright (C) 2005 Dell Inc.
5  * by Michael Brown <Michael_E_Brown@dell.com>
6  * Licensed under the Open Software License version 2.1
7  *
8  * Alternatively, you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published
10  * by the Free Software Foundation; either version 2 of the License,
11  * or (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  */
18 
19 #define LIBSMBIOS_SOURCE
20 #include "SmiImpl.h"
21 #include "FactoryImpl2.h"
22 #include "TokenImpl.h"
23 
24 // message.h should be included last.
25 #include "smbios/message.h"
26 
27 using namespace std;
28 
29 namespace smi
30 {
31  class SmiFactoryImpl : public factory::TFactory<SmiFactory>
32  {
33  public:
34  SmiFactoryImpl() { setParameter("smiFile", ""); };
35  virtual ~SmiFactoryImpl() throw() {};
36  virtual std::auto_ptr<IDellCallingInterfaceSmi> makeNew(u8 type); // use me
37  };
38 
39  //
40  SmiFactory::~SmiFactory() throw()
41  {}
42  SmiFactory::SmiFactory()
43  {}
44 
45  SmiFactory *SmiFactory::getFactory()
46  {
47  // reinterpret_cast<...>(0) to ensure template parameter is correct
48  // this is a workaround for VC6 which cannot use explicit member template
49  // function initialization.
50  return SmiFactoryImpl::getFactory(reinterpret_cast<SmiFactoryImpl *>(0));
51  }
52 
53  std::auto_ptr<IDellCallingInterfaceSmi> SmiFactoryImpl::makeNew( u8 type )
54  {
55  IDellCallingInterfaceSmi *ret = 0;
56  SmiStrategy *strategyPtr = 0;
57 
58  if (mode == AutoDetectMode )
59  strategyPtr = new SmiArchStrategy();
60 
61  else if (mode == UnitTestMode)
62  strategyPtr = new SmiMockStrategy(getParameterString("smiFile"));
63 
64 
65  // used for automatic setup of magic io stuff
66  u16 cmdIOAddress = 0;
67  u8 cmdIOCode = 0;
68  const smbios::ISmbiosTable *table = 0;
69 
70  switch( type )
71  {
72  case DELL_CALLING_INTERFACE_SMI_RAW:
73  ret = new DellCallingInterfaceSmiImpl(strategyPtr, 0, 0);
74  break;
75 
76  case DELL_CALLING_INTERFACE_SMI:
77  // would be better to just get a 0xDA type from smbios table and get code/io
78  try {
80  smbios::ISmbiosTable::const_iterator item = (*table)[0xDA];
81  cmdIOAddress = getU16_FromItem(*item, 4);
82  cmdIOCode = getU8_FromItem(*item, 6);
83  ret = new DellCallingInterfaceSmiImpl(strategyPtr, cmdIOAddress, cmdIOCode);
84  } catch(...) {
85  throw SmiExceptionImpl(_("Could not automatically setup up magic io"));
86  }
87 
88  break;
89  default:
90  throw InvalidSmiModeImpl(_("Unknown smi factory mode requested"));
91  break;
92  }
93 
94  if( ! ret )
95  throw InvalidSmiModeImpl(_("Could not allocate SMI object"));
96 
97  std::auto_ptr<IDellCallingInterfaceSmi> foo(ret);
98  return foo;
99  }
100 
101 }