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 
00333         virtual u8 getU8( unsigned int offset ) const = 0;
00335         virtual u16 getU16( unsigned int offset ) const = 0; 
00337         virtual u32 getU32( unsigned int offset ) const = 0; 
00339         virtual u64 getU64( unsigned int offset ) const = 0;
00340 
00371         virtual u8 getU8( const std::string field ) const = 0;
00373         virtual u16 getU16( const std::string field ) const = 0; 
00375         virtual u32 getU32( const std::string field ) const = 0; 
00377         virtual u64 getU64( const std::string field ) const = 0; 
00378 
00379 
00388         virtual const char *getString(unsigned int header_offset) const = 0;
00389 
00398         virtual const char *getString(const std::string field) const = 0;
00399 
00428         virtual u32 getBitfield( unsigned int offset, unsigned int fieldLen, unsigned int lsb, unsigned int msb=0 ) const = 0;
00429 
00437         virtual u32 getBitfield( const std::string field, const std::string bitField ) const = 0;
00438 
00439         //loathe Stroustrup. In his infinite wisdom, he asserts that
00440         //auto_ptr equivalent for array is _not_necessary_.
00441         //Here would be a good place for one. :-(
00442         virtual const u8* getBufferCopy(size_t &length) const = 0;
00443         
00445         // The validateBios.cpp calls this function.
00446         virtual const size_t getBufferSize() const = 0;
00447 
00452         virtual const char *getStringByStringNumber (u8) const = 0;
00453 
00454         enum {
00455             FIELD_LEN_BYTE=1,
00456             FIELD_LEN_WORD=2,
00457             FIELD_LEN_DWORD=4,
00458             FIELD_LEN_QWORD=8
00459         };
00460 
00461     };
00462 
00464 
00471     class SmbiosTableIteratorBase : 
00472         public std::iterator < std::forward_iterator_tag, ISmbiosItem >
00473     {
00474     public:
00475         explicit SmbiosTableIteratorBase (const ISmbiosTable * initialTable = 0, int typeToMatch = -1 )
00476             : matchType(typeToMatch), table(initialTable), current(0)
00477             { incrementIterator(); };
00478         virtual ~SmbiosTableIteratorBase() throw() {};
00479         bool operator == (const SmbiosTableIteratorBase other) const { return current == other.current; };
00480         bool operator != (const SmbiosTableIteratorBase other) const { return current != other.current; };
00481 
00482     protected:
00483         void incrementIterator ();
00484         ISmbiosItem & dereference () const;
00485 
00486         int matchType;
00487         const ISmbiosTable * table;
00488         mutable const void * current;
00489     };
00490     
00492 
00499     class SmbiosTableIterator
00500         : public SmbiosTableIteratorBase
00501     {
00502     public:
00503         // Make sure you define these, otherwise you can't use
00504         // iterators in stl algorithms
00505         typedef std::forward_iterator_tag iterator_category;
00506         typedef ISmbiosItem value_type;
00507         typedef value_type& reference;
00508         typedef value_type* pointer;
00509         typedef std::ptrdiff_t difference_type;
00510 
00511         virtual ~SmbiosTableIterator() throw() {};
00512         explicit SmbiosTableIterator (ISmbiosTable * initialTable = 0, int typeToMatch = -1 )
00513             : SmbiosTableIteratorBase(initialTable, typeToMatch) {};
00514         reference operator * () const { return dereference(); };
00515         pointer   operator -> () const { return &dereference(); };
00516         SmbiosTableIterator & operator ++ () { incrementIterator(); return *this; }; // ++Prefix
00517         const SmbiosTableIterator operator ++ (int)     
00518         {
00519             const SmbiosTableIterator oldValue = *this;
00520             ++(*this);
00521             return oldValue;
00522         };  //Postfix++
00523     };
00524 
00526 
00533     class ConstSmbiosTableIterator:public SmbiosTableIteratorBase
00534     {
00535     public:
00536         // Make sure you define these, otherwise you can't use
00537         // iterators in stl algorithms
00538         typedef std::forward_iterator_tag iterator_category;
00539         typedef const ISmbiosItem value_type;
00540         typedef value_type& reference;
00541         typedef value_type* pointer;
00542         typedef std::ptrdiff_t difference_type;
00543 
00544         virtual ~ConstSmbiosTableIterator() throw() {};
00545         explicit ConstSmbiosTableIterator (const ISmbiosTable * initialTable = 0, int typeToMatch = -1 )
00546             : SmbiosTableIteratorBase(initialTable, typeToMatch) {};
00547         reference operator * () const { return dereference(); };
00548         pointer   operator -> () const { return &dereference(); };
00549         ConstSmbiosTableIterator & operator ++ () { incrementIterator(); return *this; };         // ++Prefix
00550         const ConstSmbiosTableIterator operator ++ (int)
00551         {
00552             const ConstSmbiosTableIterator oldValue = *this;
00553             ++(*this);
00554             return oldValue;
00555         };  //Postfix++
00556     };
00557 
00558     //
00559     // Non-member functions
00560     //
00561     std::ostream & operator << (std::ostream & cout, const ISmbiosTable & item);
00562     std::ostream & operator << (std::ostream & cout, const ISmbiosItem & item);
00563 
00564 }
00565 
00566 
00567 // always should be last thing in header file
00568 #include "smbios/config/abi_suffix.hpp"
00569 
00570 #endif  /* SMBIOSINTERFACE_H */

Generated on Tue Jan 17 02:59:07 2006 for SMBIOS Library by  doxygen 1.4.6