Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ISmbios.h

Go to the documentation of this file.
00001 // vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:
00002 /*
00003  * Copyright (C) 2005 Dell Inc.
00004  *  by Michael Brown <Michael_E_Brown@dell.com>
00005  * Licensed under the Open Software License version 2.1 
00006  * 
00007  * Alternatively, you can redistribute it and/or modify 
00008  * it under the terms of the GNU General Public License as published 
00009  * by the Free Software Foundation; either version 2 of the License, 
00010  * or (at your option) any later version.
00011 
00012  * This program is distributed in the hope that it will be useful, but 
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of 
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00015  * See the GNU General Public License for more details.
00016  */
00017 
00018 
00019 #ifndef SMBIOSINTERFACE_H
00020 #define SMBIOSINTERFACE_H
00021 
00022 // compat header should always be first header
00023 #include "smbios/compat.h"
00024 
00025 #include <cstdlib>      // Provides size_t and NULL
00026 #include <iostream>
00027 #include <string>
00028 #include <map>
00029 #include <memory>
00030 
00031 // types.h should be first user-defined header.
00032 #include "smbios/types.h"
00033 
00034 #include "smbios/IFactory.h"
00035 #include "smbios/IException.h"
00036 #include "smbios/SmbiosLowLevel.h"
00037 
00038 // abi_prefix should be last header included before declarations
00039 #include "smbios/config/abi_prefix.hpp"
00040 
00041 namespace smbios
00042 {
00043     // Exception Classes
00044     DECLARE_EXCEPTION( SmbiosException );
00045     DECLARE_EXCEPTION_EX( ParameterException, smbios, SmbiosException );
00046     DECLARE_EXCEPTION_EX( ParseException, smbios, SmbiosException );
00047     DECLARE_EXCEPTION_EX( StringUnavailable, smbios, SmbiosException );
00048     DECLARE_EXCEPTION_EX( DataOutOfBounds, smbios, SmbiosException );
00049 
00050     //forward declarations... defined 'for real' below...
00051     class ISmbiosTable;
00052     class ISmbiosItem;
00053     class SmbiosTableIterator;
00054     class ConstSmbiosTableIterator;
00055 
00057 
00071     class SmbiosFactory : public virtual factory::IFactory
00072     {
00073     public:
00075 
00085         static SmbiosFactory *getFactory();
00086         virtual ~SmbiosFactory() throw();
00087 
00089 
00095         virtual ISmbiosTable *getSingleton() = 0;
00096 
00098 
00107         virtual ISmbiosTable *makeNew() = 0;
00108     protected:
00110         SmbiosFactory();
00111     };
00112 
00114 
00117     class ISmbiosTable
00118     {
00119     public:
00120         // Std container typedefs. Everybody expects to
00121         // say 'iterator' or 'const_iterator'
00122         typedef SmbiosTableIterator iterator;
00123         typedef ConstSmbiosTableIterator const_iterator;
00124 
00125         // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
00126         ISmbiosTable();
00127         // Interface class: no default or copy constructor
00128         virtual ~ISmbiosTable ();
00129 
00130         // ITERATORS
00131         //
00133 
00146         virtual iterator begin () = 0;
00148 
00149         virtual const_iterator begin () const = 0;
00150 
00152 
00153         virtual iterator end () = 0;
00154 
00156 
00158         virtual const_iterator end () const = 0;
00159 
00161 
00181         virtual iterator operator[]( const int ) = 0;
00182 
00184 
00185         virtual const_iterator operator[]( const int ) const = 0;
00186 
00188 
00200         virtual iterator operator[]( const std::string & ) = 0;
00201 
00203 
00204         virtual const_iterator operator[]( const std::string & ) const = 0;
00205 
00206         // MEMBERS
00208 
00214         virtual void rawMode(bool m = true) const = 0;
00215 
00217 
00234         virtual void clearItemCache() const = 0;  
00235 
00237 
00251         virtual void reReadTable() = 0;
00252 
00254         virtual int getNumberOfEntries () const = 0;  // used by unit-test code
00256         // Used by the validateBios code.
00257         virtual smbiosLowlevel::smbios_table_entry_point getTableEPS() const = 0;
00258 
00260         //output table information.
00264         virtual std::ostream & streamify(std::ostream & cout ) const = 0;
00265 
00266     private:
00267         explicit ISmbiosTable(const ISmbiosTable &); 
00268         void operator =( const ISmbiosTable & ); 
00269     };
00270 
00272 
00275     class ISmbiosItem
00276     {
00277     public:
00279         virtual ~ISmbiosItem ();
00280         ISmbiosItem();
00281 
00282         virtual std::auto_ptr<const ISmbiosItem> clone() const = 0;
00283         virtual std::auto_ptr<ISmbiosItem> clone() = 0;
00284 
00290         virtual std::ostream & streamify( std::ostream & cout ) const = 0;
00291 
00297         virtual u8 getType() const = 0;
00298 
00304         virtual u8 getLength() const = 0;
00305 
00311         virtual u16 getHandle() const = 0;
00312 
00338         virtual void getData( unsigned int offset, void *out, size_t size ) const = 0;
00339 
00340         //loathe Stroustrup. In his infinite wisdom, he asserts that
00341         //auto_ptr equivalent for array is _not_necessary_.
00342         //Here would be a good place for one. :-(
00343         virtual const u8* getBufferCopy(size_t &length) const = 0;
00344         
00346         // The validateBios.cpp calls this function.
00347         virtual const size_t getBufferSize() const = 0;
00348 
00353         virtual const char *getStringByStringNumber (u8) const = 0;
00354 
00355         enum {
00356             FIELD_LEN_BYTE=1,
00357             FIELD_LEN_WORD=2,
00358             FIELD_LEN_DWORD=4,
00359             FIELD_LEN_QWORD=8
00360         };
00361     };
00362 
00363     u8 getItemType(const ISmbiosItem &item);
00364     u8 getItemLength(const ISmbiosItem &item);
00365     u16 getItemHandle(const ISmbiosItem &item);
00366 
00367     u8 getU8_FromItem(const ISmbiosItem &item, unsigned int offset);
00368     u16 getU16_FromItem(const ISmbiosItem &item, unsigned int offset);
00369     u32 getU32_FromItem(const ISmbiosItem &item, unsigned int offset);
00370     u64 getU64_FromItem(const ISmbiosItem &item, unsigned int offset);
00371     const char *getString_FromItem(const ISmbiosItem &item, unsigned int offset);
00372     void *getBits_FromItem(const ISmbiosItem &item, unsigned int offset, void *out, unsigned int lsb=0, unsigned int msb=0 );
00373     bool isBitSet(const ISmbiosItem *itemPtr, unsigned int offset, unsigned int bitToTest);
00374 
00375     template <class R> 
00376     R &getData(const ISmbiosItem &item, unsigned int offset, R &out)
00377     {
00378         item.getData(offset, &out, sizeof(R));
00379         return out;
00380     }
00381 
00382 
00384 
00391     class SmbiosTableIteratorBase : 
00392         public std::iterator < std::forward_iterator_tag, ISmbiosItem >
00393     {
00394     public:
00395         explicit SmbiosTableIteratorBase (const ISmbiosTable * initialTable = 0, int typeToMatch = -1 )
00396             : matchType(typeToMatch), table(initialTable), current(0)
00397             { incrementIterator(); };
00398         virtual ~SmbiosTableIteratorBase() throw() {};
00399         bool operator == (const SmbiosTableIteratorBase other) const { return current == other.current; };
00400         bool operator != (const SmbiosTableIteratorBase other) const { return current != other.current; };
00401 
00402     protected:
00403         void incrementIterator ();
00404         ISmbiosItem & dereference () const;
00405 
00406         int matchType;
00407         const ISmbiosTable * table;
00408         mutable const void * current;
00409     };
00410     
00412 
00419     class SmbiosTableIterator
00420         : public SmbiosTableIteratorBase
00421     {
00422     public:
00423         // Make sure you define these, otherwise you can't use
00424         // iterators in stl algorithms
00425         typedef std::forward_iterator_tag iterator_category;
00426         typedef ISmbiosItem value_type;
00427         typedef value_type& reference;
00428         typedef value_type* pointer;
00429         typedef std::ptrdiff_t difference_type;
00430 
00431         virtual ~SmbiosTableIterator() throw() {};
00432         explicit SmbiosTableIterator (ISmbiosTable * initialTable = 0, int typeToMatch = -1 )
00433             : SmbiosTableIteratorBase(initialTable, typeToMatch) {};
00434         reference operator * () const { return dereference(); };
00435         pointer   operator -> () const { return &dereference(); };
00436         SmbiosTableIterator & operator ++ () { incrementIterator(); return *this; }; // ++Prefix
00437         const SmbiosTableIterator operator ++ (int)     
00438         {
00439             const SmbiosTableIterator oldValue = *this;
00440             ++(*this);
00441             return oldValue;
00442         };  //Postfix++
00443     };
00444 
00446 
00453     class ConstSmbiosTableIterator:public SmbiosTableIteratorBase
00454     {
00455     public:
00456         // Make sure you define these, otherwise you can't use
00457         // iterators in stl algorithms
00458         typedef std::forward_iterator_tag iterator_category;
00459         typedef const ISmbiosItem value_type;
00460         typedef value_type& reference;
00461         typedef value_type* pointer;
00462         typedef std::ptrdiff_t difference_type;
00463 
00464         virtual ~ConstSmbiosTableIterator() throw() {};
00465         explicit ConstSmbiosTableIterator (const ISmbiosTable * initialTable = 0, int typeToMatch = -1 )
00466             : SmbiosTableIteratorBase(initialTable, typeToMatch) {};
00467         reference operator * () const { return dereference(); };
00468         pointer   operator -> () const { return &dereference(); };
00469         ConstSmbiosTableIterator & operator ++ () { incrementIterator(); return *this; };         // ++Prefix
00470         const ConstSmbiosTableIterator operator ++ (int)
00471         {
00472             const ConstSmbiosTableIterator oldValue = *this;
00473             ++(*this);
00474             return oldValue;
00475         };  //Postfix++
00476     };
00477 
00478     //
00479     // Non-member functions
00480     //
00481     std::ostream & operator << (std::ostream & cout, const ISmbiosTable & item);
00482     std::ostream & operator << (std::ostream & cout, const ISmbiosItem & item);
00483 
00484 }
00485 
00486 
00487 // always should be last thing in header file
00488 #include "smbios/config/abi_suffix.hpp"
00489 
00490 #endif  /* SMBIOSINTERFACE_H */

Generated on Wed Apr 11 16:25:10 2007 for SMBIOS Library by doxygen 1.3.5