SMBIOS Library
SmbiosImpl.h
Go to the documentation of this file.
1 // vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:
2 /*
3  * Copyright (C) 2005 Dell Inc.
4  * by Michael Brown <Michael_E_Brown@dell.com>
5  * Licensed under the Open Software License version 2.1
6  *
7  * Alternatively, you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published
9  * by the Free Software Foundation; either version 2 of the License,
10  * or (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU General Public License for more details.
16  */
17 
18 
19 #ifndef SMBIOSIMPL_H
20 #define SMBIOSIMPL_H
21 
22 // compat header should always be first header if including system headers
23 #include "smbios/compat.h"
24 
25 #include <vector>
26 
27 #include "smbios/ISmbios.h"
28 #include "smbios/SmbiosLowLevel.h"
29 #include "SmbiosWorkaroundImpl.h"
30 #include "FactoryImpl2.h"
31 #include "ExceptionImpl.h"
32 
33 namespace smbios
34 {
35  DEFINE_EXCEPTION_EX( ParameterExceptionImpl, smbios, ParameterException );
36  DEFINE_EXCEPTION_EX( ParseExceptionImpl, smbios, ParseException );
37  DEFINE_EXCEPTION_EX( StringUnavailableImpl, smbios, StringUnavailable );
38  DEFINE_EXCEPTION_EX( DataOutOfBoundsImpl, smbios, DataOutOfBounds );
39  DEFINE_EXCEPTION_EX( ItemNotFoundImpl, smbios, ItemNotFound );
40 
41  class SmbiosFactoryImpl : public factory::TFactory<SmbiosFactory>
42  {
43  public:
45  virtual ~SmbiosFactoryImpl() throw();
46  virtual ISmbiosTable *getSingleton( ); // returns singleton
47  virtual ISmbiosTable *makeNew( ); // not for use
48  protected:
50  };
51 
53  {
54  public:
56  virtual ~SmbiosStrategy() {};
57 
58  virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool ) = 0;
59  };
60 
62  {
63  public:
64  virtual ~SmbiosMemoryStrategy() throw() {};
65  SmbiosMemoryStrategy(unsigned long initOffset) :SmbiosStrategy(), offset(initOffset) {};
67  virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool );
68  protected:
69  // popular mem locations we use in scanning code.
70  enum {
71  E_BLOCK_START = 0xE0000UL,
72  F_BLOCK_START = 0xF0000UL,
73  F_BLOCK_END = 0xFFFFFUL
74  };
75 
78  unsigned long offset;
79  };
80 
82  {
83  public:
84  virtual ~SmbiosLinuxEFIStrategy() throw() {};
87 
88  protected:
90  };
91 
93  {
94  public:
95  virtual ~SmbiosWinWMIStrategy() throw() {};
97  virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool );
98  };
99 
101  {
102  public:
105  virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool );
106  };
107 
108  class SmbiosTable : public virtual ISmbiosTable
109  {
110  public:
111  // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
112  explicit SmbiosTable(std::vector<SmbiosStrategy *> initStrategyList, bool strictValidation = 0);
113 
114  // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
115  //SmbiosTable (const SmbiosTable & source);
116  //virtual SmbiosTable& operator = (const SmbiosTable & source);
117  virtual ~SmbiosTable ();
118 
119  // ITERATORS
120  virtual iterator begin ();
121  virtual const_iterator begin () const;
122 
123  virtual iterator end ();
124  virtual const_iterator end () const;
125 
126  virtual iterator operator[]( const int );
127  virtual const_iterator operator[]( const int ) const;
128 
129  virtual iterator operator[]( const std::string & );
130  virtual const_iterator operator[]( const std::string & ) const;
131 
132 
133  // MEMBERS
134  virtual void rawMode(bool m) const;
135  virtual int getNumberOfEntries () const; // used by unit-test code
136 
137  // Used by the validateBios.cpp
139 
140  virtual std::ostream & streamify(std::ostream & cout ) const;
141 
142  // used by factory only.
143  virtual void initializeWorkaround() const;
144  // restricting the header checking
145  virtual void setStrictValidationMode(bool mode) const;
146  virtual bool getStrictValidationMode() const;
147 
148  virtual ISmbiosItem *getCachedItem( const void * ) const;
149  virtual void cacheItem( const void *, ISmbiosItem &newitem ) const;
150  virtual void clearItemCache() const;
151  ISmbiosItem & getSmbiosItem (const u8 *);
152  const ISmbiosItem & getSmbiosItem (const u8 *) const;
153  const u8 * nextSmbiosStruct ( const u8 * current = 0) const;
154 
155  protected:
156  // No-arg constructor not legal for this class for regular users
157  SmbiosTable ();
158 
159  // used by the iterator
160  virtual ISmbiosItem &makeItem(
161  const void *header = 0) const;
162 
163  mutable std::map< const void *, ISmbiosItem *> itemList;
164  mutable bool initializing;
165  mutable bool strictValidationMode;
166  mutable std::auto_ptr<SmbiosWorkaroundTable> workaround;
167  const u8 * smbiosBuffer;
169 
170  private:
171  SmbiosTable (const SmbiosTable &source);
172 
173  virtual void reReadTable();
174  mutable unsigned long offset;
175  std::vector<SmbiosStrategy *> strategyList;
176  };
177 
178 
179 
180 
181  class SmbiosItem : public ISmbiosItem
182  {
183  public:
184  SmbiosItem (const SmbiosItem & source);
186  virtual ~SmbiosItem ();
187 
188  virtual std::auto_ptr<const ISmbiosItem> clone() const;
189  virtual std::auto_ptr<ISmbiosItem> clone();
190  virtual std::ostream & streamify( std::ostream & cout ) const;
191 
192  u8 getType() const;
193  u8 getLength() const;
194  u16 getHandle() const;
195 
196  virtual void getData( unsigned int offset, u8 *out, size_t size ) const;
197 
198  virtual const u8* getBufferCopy(size_t &length) const;
199  virtual size_t getBufferSize() const;
200 
201  virtual const char *getStringByStringNumber (u8) const;
202 
203  // for table only...
204  virtual void fixup( const SmbiosWorkaroundTable *workaround ) const;
205  protected:
207  size_t header_size;
208 
209  private:
210  SmbiosItem & operator = (const SmbiosItem & source);
211  };
212 
213 }
214 
215 
216 #endif /* SMBIOSIMPL_H */