libsmbios_c library
ISmbios.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 SMBIOSINTERFACE_H
20 #define SMBIOSINTERFACE_H
21 
22 // compat header should always be first header
23 #include "smbios/compat.h"
24 
25 #include <cstdlib> // Provides size_t and NULL
26 #include <iostream>
27 #include <map>
28 #include <memory>
29 
30 // types.h should be first user-defined header.
31 #include "smbios/types.h"
32 #include "smbios/IFactory.h"
33 #include "smbios/IException.h"
34 #include "smbios/SmbiosLowLevel.h"
35 
36 // abi_prefix should be last header included before declarations
38 
39 namespace smbios
40 {
41  // Exception Classes
42  DECLARE_EXCEPTION( SmbiosException );
43  DECLARE_EXCEPTION_EX( ParameterException, smbios, SmbiosException );
44  DECLARE_EXCEPTION_EX( ParseException, smbios, SmbiosException );
45  DECLARE_EXCEPTION_EX( StringUnavailable, smbios, SmbiosException );
46  DECLARE_EXCEPTION_EX( DataOutOfBounds, smbios, SmbiosException );
47  DECLARE_EXCEPTION_EX( ItemNotFound, smbios, SmbiosException );
48 
49 
50  //forward declarations... defined 'for real' below...
51  class ISmbiosTable;
52  class ISmbiosItem;
53  class SmbiosTableIterator;
54  class ConstSmbiosTableIterator;
55 
57 
71  class SmbiosFactory : public virtual factory::IFactory
72  {
73  public:
75 
85  static SmbiosFactory *getFactory();
86  virtual ~SmbiosFactory() throw();
87 
89 
95  virtual ISmbiosTable *getSingleton() = 0;
96 
98 
107  virtual ISmbiosTable *makeNew() = 0;
108  protected:
110  SmbiosFactory();
111  };
112 
114 
118  {
119  public:
120  // Std container typedefs. Everybody expects to
121  // say 'iterator' or 'const_iterator'
124 
125  // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
126  ISmbiosTable();
127  // Interface class: no default or copy constructor
128  virtual ~ISmbiosTable ();
129 
130  // ITERATORS
131  //
133 
146  virtual iterator begin () = 0;
148 
149  virtual const_iterator begin () const = 0;
150 
152 
153  virtual iterator end () = 0;
154 
156 
158  virtual const_iterator end () const = 0;
159 
161 
176  virtual iterator operator[]( const int ) = 0;
177 
179 
180  virtual const_iterator operator[]( const int ) const = 0;
181 
182  // MEMBERS
184 
190  virtual void rawMode(bool m = true) const = 0;
191 
193 
210  virtual void clearItemCache() const = 0;
211 
213  virtual int getNumberOfEntries () const = 0; // used by unit-test code
215  // Used by the validateBios code.
217 
219  protected:
220  virtual const ISmbiosItem & getSmbiosItem (const u8 *current) const = 0;
221  virtual ISmbiosItem & getSmbiosItem (const u8 *current) = 0;
222  virtual const u8 * nextSmbiosStruct ( const u8 * current = 0) const = 0;
223 
225  //output table information.
229  virtual std::ostream & streamify(std::ostream & cout ) const = 0;
230  friend std::ostream & operator << (std::ostream & cout, const ISmbiosTable & item);
231 
232  private:
233  explicit ISmbiosTable(const ISmbiosTable &);
234  void operator =( const ISmbiosTable & );
235  };
236 
238 
242  {
243  public:
245  virtual ~ISmbiosItem ();
246  ISmbiosItem();
247 
248  virtual std::auto_ptr<const ISmbiosItem> clone() const = 0;
249  virtual std::auto_ptr<ISmbiosItem> clone() = 0;
250 
256  virtual u8 getType() const = 0;
257 
263  virtual u8 getLength() const = 0;
264 
270  virtual u16 getHandle() const = 0;
271 
296  virtual void getData( unsigned int offset, u8 *out, size_t size ) const = 0;
297 
298  virtual const u8* getBufferCopy(size_t &length) const = 0;
299 
301  // The validateBios.cpp calls this function.
302  virtual size_t getBufferSize() const = 0;
303 
308  virtual const char *getStringByStringNumber (u8) const = 0;
309 
310  enum {
315  };
316 
317  protected:
323  virtual std::ostream & streamify( std::ostream & cout ) const = 0;
324  friend std::ostream & operator << (std::ostream & cout, const ISmbiosItem & item);
325  };
326 
327  u8 getItemType(const ISmbiosItem &item);
328  u8 getItemLength(const ISmbiosItem &item);
329  u16 getItemHandle(const ISmbiosItem &item);
330 
331  u8 getU8_FromItem(const ISmbiosItem &item, unsigned int offset);
332  u16 getU16_FromItem(const ISmbiosItem &item, unsigned int offset);
333  u32 getU32_FromItem(const ISmbiosItem &item, unsigned int offset);
334  u64 getU64_FromItem(const ISmbiosItem &item, unsigned int offset);
335  const char *getString_FromItem(const ISmbiosItem &item, unsigned int offset);
336  void *getBits_FromItem(const ISmbiosItem &item, unsigned int offset, void *out, unsigned int lsb=0, unsigned int msb=0 );
337  bool isBitSet(const ISmbiosItem *itemPtr, unsigned int offset, unsigned int bitToTest);
338 
339  template <class R>
340  R &getData(const ISmbiosItem &item, unsigned int offset, R &out)
341  {
342  item.getData(offset, &out, sizeof(R));
343  return out;
344  }
345 
347 
355  {
356  public:
357  typedef std::forward_iterator_tag iterator_category;
358  typedef std::ptrdiff_t difference_type;
359 
360 
361  explicit SmbiosTableIteratorBase(const ISmbiosTable * initialTable = 0, int typeToMatch = -1 );
363  virtual ~SmbiosTableIteratorBase() throw();
364  bool operator == (const SmbiosTableIteratorBase &other) const;
365  bool operator != (const SmbiosTableIteratorBase &other) const;
366  void incrementIterator ();
367  const ISmbiosItem & dereference () const;
369 
370  void reset();
371  bool eof();
372 
373  protected:
376  const u8 * current;
377  };
378 
381  public std::iterator < std::forward_iterator_tag, ISmbiosItem >
382  {
383  public:
384  typedef ISmbiosItem value_type;
385  typedef value_type& reference;
386  typedef value_type* pointer;
387 
388  virtual ~SmbiosTableIterator() throw();
389  explicit SmbiosTableIterator(ISmbiosTable * initialTable = 0, int typeToMatch = -1 );
390  reference operator * ();
391  pointer operator -> ();
392  SmbiosTableIterator & operator ++ (); // ++Prefix
393  const SmbiosTableIterator operator ++ (int); //Postfix++
394  };
395 
397  public SmbiosTableIteratorBase,
398  public std::iterator < std::forward_iterator_tag, const ISmbiosItem >
399  {
400  public:
401  typedef const ISmbiosItem value_type;
402  typedef value_type& reference;
403  typedef value_type* pointer;
404 
405  virtual ~ConstSmbiosTableIterator() throw();
406  explicit ConstSmbiosTableIterator(const ISmbiosTable * initialTable = 0, int typeToMatch = -1 );
407  ConstSmbiosTableIterator &operator=(const SmbiosTableIteratorBase&);
408 
409  reference operator * () const;
410  pointer operator -> () const;
411  ConstSmbiosTableIterator & operator ++ (); // ++Prefix
412  const ConstSmbiosTableIterator operator ++ (int); //Postfix++
413  };
414 
415  //
416  // Non-member functions
417  //
418  std::ostream & operator << (std::ostream & cout, const ISmbiosTable & item);
419  std::ostream & operator << (std::ostream & cout, const ISmbiosItem & item);
420 
421 }
422 
423 
424 // always should be last thing in header file
425 #include "smbios/config/abi_suffix.hpp"
426 
427 #endif /* SMBIOSINTERFACE_H */
value_type & reference
Definition: ISmbios.h:402
virtual iterator end()=0
Standard iterator interface. Points to one-past-the-last table item.
virtual void clearItemCache() const =0
Clears out any cached SmbiosItem entries in the cache.
Interface definition for Smbios Table operations.
Definition: ISmbios.h:117
virtual std::auto_ptr< const ISmbiosItem > clone() const =0
virtual const u8 * getBufferCopy(size_t &length) const =0
virtual iterator begin()=0
Standard iterator interface. Points to first table item.
u8 getItemLength(const ISmbiosItem &item)
virtual ISmbiosTable * makeNew()=0
Create a new ISmbiosTable object that the caller must delete. (NOT RECOMMENDED)
virtual u8 getLength() const =0
u32 getU32_FromItem(const ISmbiosItem &item, unsigned int offset)
virtual size_t getBufferSize() const =0
Returns the buffer size of the item.
value_type & reference
Definition: ISmbios.h:385
virtual int getNumberOfEntries() const =0
Returns the number of table items, per SMBIOS table header.
const ISmbiosItem value_type
Definition: ISmbios.h:401
virtual std::ostream & streamify(std::ostream &cout) const =0
std::ptrdiff_t difference_type
Definition: ISmbios.h:358
virtual ~ISmbiosItem()
Interface definition for Smbios Item operations.
Definition: ISmbios.h:241
Definition: ISmbios.h:379
virtual std::ostream & streamify(std::ostream &cout) const =0
Used by operator &lt;&lt; (std::ostream &amp; cout, const ISmbiosTable &amp; ) to.
virtual const char * getStringByStringNumber(u8) const =0
Definition: ISmbios.h:313
AbstractFactory that produces ISmbiosTable objects.
Definition: ISmbios.h:71
virtual ISmbiosTable * getSingleton()=0
Recommended way to get an ISmbiosTable object.
u8 getItemType(const ISmbiosItem &item)
std::forward_iterator_tag iterator_category
Definition: ISmbios.h:357
const ISmbiosTable * table
Definition: ISmbios.h:375
bool isBitSet(const ISmbiosItem *itemPtr, unsigned int offset, unsigned int bitToTest)
SmbiosTableIteratorBase(const ISmbiosTable *initialTable=0, int typeToMatch=-1)
u16 getU16_FromItem(const ISmbiosItem &item, unsigned int offset)
friend std::ostream & operator<<(std::ostream &cout, const ISmbiosTable &item)
Definition: SmbiosLowLevel.h:59
const ISmbiosItem & dereference() const
Definition: ISmbios.h:396
ConstSmbiosTableIterator const_iterator
Definition: ISmbios.h:123
virtual void getData(unsigned int offset, u8 *out, size_t size) const =0
SmbiosTableIterator iterator
Definition: ISmbios.h:122
int matchType
Definition: ISmbios.h:374
virtual const ISmbiosItem & getSmbiosItem(const u8 *current) const =0
value_type * pointer
Definition: ISmbios.h:386
Definition: ISmbios.h:312
unsigned int u32
Definition: types.h:35
DECLARE_EXCEPTION(NotImplemented)
R & getData(const ISmbiosItem &item, unsigned int offset, R &out)
Definition: ISmbios.h:340
void * getBits_FromItem(const ISmbiosItem &item, unsigned int offset, void *out, unsigned int lsb=0, unsigned int msb=0)
const u8 * current
Definition: ISmbios.h:376
u64 getU64_FromItem(const ISmbiosItem &item, unsigned int offset)
ISmbiosItem value_type
Definition: ISmbios.h:384
Iterator base class for ISmbiosTable objects.
Definition: ISmbios.h:354
virtual smbiosLowlevel::smbios_table_entry_point getTableEPS() const =0
Returns the table entry point structure.
unsigned short u16
Definition: types.h:31
DECLARE_EXCEPTION_EX(ParameterException, smbios, SmbiosException)
unsigned char u8
Definition: types.h:27
virtual u16 getHandle() const =0
u8 getU8_FromItem(const ISmbiosItem &item, unsigned int offset)
value_type * pointer
Definition: ISmbios.h:403
virtual const u8 * nextSmbiosStruct(const u8 *current=0) const =0
virtual u8 getType() const =0
SmbiosFactory()
Use getFactory() to get a factory.
Base class for all Abstract Factories.
Definition: IFactory.h:39
static SmbiosFactory * getFactory()
Create a factory object that you can use to create ISmbiosTable objects.
u16 getItemHandle(const ISmbiosItem &item)
Definition: ISmbios.h:314
const char * getString_FromItem(const ISmbiosItem &item, unsigned int offset)
virtual void rawMode(bool m=true) const =0
Disables all workarounds for new items created by the table.
friend std::ostream & operator<<(std::ostream &cout, const ISmbiosItem &item)
virtual iterator operator[](const int)=0
Standard indexed access by integer item type.
SmbiosTableIteratorBase & operator=(const SmbiosTableIteratorBase &)
Definition: ISmbios.h:311