SMBIOS Library
SmbiosFactory.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 // compat header should always be first header if including system headers
20 #define LIBSMBIOS_SOURCE
21 #include "smbios/compat.h"
22 
23 #include <vector>
24 
25 #include "SmbiosImpl.h"
26 
27 // message.h should be included last.
28 #include "smbios/message.h"
29 
30 using namespace std;
31 
32 namespace smbios
33 {
34  SmbiosFactory::~SmbiosFactory() throw()
35  {}
36  SmbiosFactory::SmbiosFactory()
37  {}
38 
39  SmbiosFactory *SmbiosFactory::getFactory()
40  {
41  // reinterpret_cast<...>(0) to ensure template parameter is correct
42  // this is a workaround for VC6 which cannot use explicit member template
43  // funciton initialization.
44  return SmbiosFactoryImpl::getFactory(reinterpret_cast<SmbiosFactoryImpl *>(0));
45  }
46 
47  ISmbiosTable *SmbiosFactoryImpl::_tableInstance = 0;
48 
49  SmbiosFactoryImpl::~SmbiosFactoryImpl() throw()
50  {
51  if( _tableInstance )
52  {
53  delete _tableInstance;
54  _tableInstance = 0;
55  }
56  }
57 
58  SmbiosFactoryImpl::SmbiosFactoryImpl()
59  {
60  mode = defaultMode;
61  setParameter( "strictValidation", 0 );
62  setParameter( "offset", 0 );
63  }
64 
65  ISmbiosTable *SmbiosFactoryImpl::getSingleton()
66  {
67  if (! _tableInstance)
68  _tableInstance = makeNew();
69 
70  return _tableInstance;
71  }
72 
73  ISmbiosTable *SmbiosFactoryImpl::makeNew()
74  {
75  // stupid, ugly hack to supress (C4800) warning on msvc++
76  bool strict = getParameterNum("strictValidation") ? 1 : 0;
77 
78  SmbiosTable *table = 0;
79 
80  std::vector<SmbiosStrategy *> strategies;
81 
82  if (mode == AutoDetectMode)
83  {
84 #ifdef LIBSMBIOS_PLATFORM_LINUX
85  strategies.push_back( new SmbiosLinuxEFIStrategy() );
86 #endif
87  strategies.push_back( new SmbiosMemoryStrategy(getParameterNum("offset")) );
88 #ifdef LIBSMBIOS_PLATFORM_WIN32
89  strategies.push_back( new SmbiosWinGetFirmwareTableStrategy() );
90  strategies.push_back( new SmbiosWinWMIStrategy() );
91 #endif
92  }
93  else if (mode == UnitTestMode)
94  {
95  strategies.push_back( new SmbiosMemoryStrategy(getParameterNum("offset")) );
96  }
97  else
98  {
99  throw NotImplementedImpl(_("Unknown smbios factory mode requested"));
100  }
101 
102 
103  table = new SmbiosTable(
104  strategies,
105  strict
106  );
107 
108  table->initializeWorkaround();
109  return table;
110  }
111 }