SmbiosImpl.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 SMBIOSIMPL_H
00020 #define SMBIOSIMPL_H
00021 
00022 // compat header should always be first header if including system headers
00023 #include "smbios/compat.h"
00024 
00025 #include <vector>
00026 
00027 #include "smbios/ISmbios.h"
00028 #include "smbios/SmbiosLowLevel.h"
00029 #include "SmbiosWorkaroundImpl.h"
00030 #include "../common/FactoryImpl2.h"
00031 #include "../common/ExceptionImpl.h"
00032 
00033 namespace smbios
00034 {
00035     DEFINE_EXCEPTION_EX( ParameterExceptionImpl, smbios, ParameterException );
00036     DEFINE_EXCEPTION_EX( ParseExceptionImpl, smbios, ParseException );
00037     DEFINE_EXCEPTION_EX( StringUnavailableImpl, smbios, StringUnavailable );
00038     DEFINE_EXCEPTION_EX( DataOutOfBoundsImpl, smbios, DataOutOfBounds );
00039 
00040     class SmbiosFactoryImpl : public factory::TFactory<SmbiosFactory>
00041     {
00042     public:
00043         SmbiosFactoryImpl();
00044         virtual ~SmbiosFactoryImpl() throw();
00045         virtual ISmbiosTable *getSingleton( ); // returns singleton
00046         virtual ISmbiosTable *makeNew( ); // not for use
00047     protected:
00048         static ISmbiosTable *_tableInstance;
00049     };
00050 
00051     class SmbiosStrategy
00052     {
00053     public:
00054         SmbiosStrategy() {};
00055         virtual ~SmbiosStrategy() {};
00056 
00057         virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool ) = 0;
00058     };
00059 
00060     class SmbiosMemoryStrategy : public SmbiosStrategy
00061     {
00062     public:
00063         virtual ~SmbiosMemoryStrategy() throw() {};
00064         SmbiosMemoryStrategy(unsigned long initOffset) :SmbiosStrategy(), offset(initOffset) {};
00065         SmbiosMemoryStrategy(const SmbiosMemoryStrategy &src) : SmbiosStrategy(), offset(src.offset) {};
00066         virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool );
00067     private:
00068         // popular mem locations we use in scanning code.
00069         enum {
00070             E_BLOCK_START = 0xE0000UL,
00071             F_BLOCK_START = 0xF0000UL,
00072             F_BLOCK_END = 0xFFFFFUL
00073         };
00074 
00075         void getSmbiosTableHeader(smbiosLowlevel::smbios_table_entry_point *, bool);
00076         void getSmbiosTableBuf(const u8 **, smbiosLowlevel::smbios_table_entry_point);
00077     private:
00078         unsigned long offset;
00079     };
00080 
00081     class SmbiosWinWMIStrategy : public SmbiosStrategy
00082     {
00083     public:
00084         virtual ~SmbiosWinWMIStrategy() throw() {};
00085         SmbiosWinWMIStrategy() {};
00086         virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool );
00087     };
00088 
00089     class SmbiosWinGetFirmwareTableStrategy : public SmbiosStrategy
00090     {
00091     public:
00092         virtual ~SmbiosWinGetFirmwareTableStrategy() throw() {};
00093         SmbiosWinGetFirmwareTableStrategy() {};
00094         virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool );
00095     };
00096 
00097     class SmbiosTable : public virtual ISmbiosTable
00098     {
00099     public:
00100         // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
00101         explicit SmbiosTable(std::vector<SmbiosStrategy *> initStrategyList, bool strictValidation = 0);
00102 
00103         // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
00104         //SmbiosTable (const SmbiosTable & source);
00105         //virtual SmbiosTable& operator = (const SmbiosTable & source);
00106         virtual ~SmbiosTable ();
00107 
00108         // ITERATORS
00109         virtual iterator begin ();
00110         virtual const_iterator begin () const;
00111 
00112         virtual iterator end ();
00113         virtual const_iterator end () const;
00114 
00115         virtual iterator operator[]( const int );
00116         virtual const_iterator operator[]( const int ) const;
00117 
00118         virtual iterator operator[]( const std::string & );
00119         virtual const_iterator operator[]( const std::string & ) const;
00120 
00121 
00122         // MEMBERS
00123         virtual void rawMode(bool m) const;
00124         virtual int getNumberOfEntries () const;  // used by unit-test code
00125 
00126         // Used by the validateBios.cpp
00127         virtual smbiosLowlevel::smbios_table_entry_point getTableEPS() const;
00128 
00129         virtual std::ostream & streamify(std::ostream & cout ) const;
00130 
00131         // used by factory only.
00132         virtual void initializeWorkaround() const;
00133         // restricting the header checking
00134         virtual void setStrictValidationMode(bool mode) const;
00135         virtual bool getStrictValidationMode() const;
00136 
00137         virtual ISmbiosItem *getCachedItem( const void * ) const;
00138         virtual void cacheItem( const void *, ISmbiosItem &newitem ) const;
00139         virtual void clearItemCache() const;
00140 
00141         // friends :-)
00142         friend class SmbiosTableIteratorBase;
00143 
00144     protected:
00145         // No-arg constructor not legal for this class for regular users
00146         SmbiosTable ();
00147 
00148         // used by the iterator
00149         virtual ISmbiosItem &makeItem(
00150             const void *header = 0) const;
00151 
00152         // used by the iterator
00153         const void * nextSmbiosStruct ( const void * current = 0) const;
00154 
00155         mutable std::map< const void *, ISmbiosItem *> itemList;
00156         mutable bool initializing;
00157         mutable bool strictValidationMode;
00158         mutable std::auto_ptr<SmbiosWorkaroundTable> workaround;
00159         const u8 * smbiosBuffer;
00160         smbiosLowlevel::smbios_table_entry_point table_header;
00161 
00162     private:
00163         SmbiosTable (const SmbiosTable &source);
00164 
00165         virtual void reReadTable();
00166         mutable unsigned long offset;
00167         std::vector<SmbiosStrategy *> strategyList;
00168     };
00169 
00170 
00171 
00172 
00173     class SmbiosItem : public ISmbiosItem
00174     {
00175     public:
00176         SmbiosItem (const SmbiosItem & source);
00177         explicit SmbiosItem (const smbiosLowlevel::smbios_structure_header *header = 0);
00178         virtual ~SmbiosItem ();
00179 
00180         virtual std::auto_ptr<const ISmbiosItem> clone() const;
00181         virtual std::auto_ptr<ISmbiosItem> clone();
00182         virtual std::ostream & streamify( std::ostream & cout ) const;
00183 
00184         u8 getType() const;
00185         u8 getLength() const;
00186         u16 getHandle() const;
00187 
00188         virtual u8 getU8( unsigned int offset ) const;
00189         virtual u8 getU8( const std::string field ) const;
00190         virtual u16 getU16( unsigned int offset ) const;
00191         virtual u16 getU16( const std::string field ) const;
00192         virtual u32 getU32( unsigned int offset ) const;
00193         virtual u32 getU32( const std::string field ) const;
00194         virtual u64 getU64( unsigned int offset ) const;
00195         virtual u64 getU64( const std::string field ) const;
00196         virtual u32 getBitfield( unsigned int offset, unsigned int fieldLen, unsigned int lsb, unsigned int msb ) const;
00197         virtual u32 getBitfield( const std::string field, const std::string bitField ) const;
00198         virtual const char *getString(unsigned int header_offset) const;
00199         virtual const char *getString(const std::string field) const;
00200 
00201         virtual const u8* getBufferCopy(size_t &length) const;
00202         virtual const size_t getBufferSize() const;
00203 
00204         // for table only...
00205         virtual void fixup( const SmbiosWorkaroundTable *workaround ) const;
00206 
00207         // for unit tests, so they can access internals
00208         virtual const char *getStringByStringNumber (u8) const;
00209 
00210     protected:
00211         const smbiosLowlevel::smbios_structure_header * header;
00212         size_t header_size;
00213 
00214     private:
00215         SmbiosItem & operator = (const SmbiosItem & source);
00216     };
00217 
00218 }
00219 
00220 
00221 #endif /* SMBIOSIMPL_H */

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