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

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 "FactoryImpl2.h"
00031 #include "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     protected:
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         virtual void getSmbiosTableHeader(smbiosLowlevel::smbios_table_entry_point *, bool);
00076         virtual void getSmbiosTableBuf(const u8 **, smbiosLowlevel::smbios_table_entry_point);
00077         unsigned long offset;
00078     };
00079 
00080     class SmbiosLinuxEFIStrategy : public SmbiosMemoryStrategy
00081     {
00082     public:
00083         virtual ~SmbiosLinuxEFIStrategy() throw() {};
00084         SmbiosLinuxEFIStrategy() :SmbiosMemoryStrategy(0) {};
00085         SmbiosLinuxEFIStrategy(const SmbiosLinuxEFIStrategy &src) : SmbiosMemoryStrategy(0) {};
00086 
00087     protected:
00088         virtual void getSmbiosTableHeader(smbiosLowlevel::smbios_table_entry_point *, bool);
00089     };
00090 
00091     class SmbiosWinWMIStrategy : public SmbiosStrategy
00092     {
00093     public:
00094         virtual ~SmbiosWinWMIStrategy() throw() {};
00095         SmbiosWinWMIStrategy() {};
00096         virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool );
00097     };
00098 
00099     class SmbiosWinGetFirmwareTableStrategy : public SmbiosStrategy
00100     {
00101     public:
00102         virtual ~SmbiosWinGetFirmwareTableStrategy() throw() {};
00103         SmbiosWinGetFirmwareTableStrategy() {};
00104         virtual bool getSmbiosTable(const u8 **, smbiosLowlevel::smbios_table_entry_point *, bool );
00105     };
00106 
00107     class SmbiosTable : public virtual ISmbiosTable
00108     {
00109     public:
00110         // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
00111         explicit SmbiosTable(std::vector<SmbiosStrategy *> initStrategyList, bool strictValidation = 0);
00112 
00113         // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
00114         //SmbiosTable (const SmbiosTable & source);
00115         //virtual SmbiosTable& operator = (const SmbiosTable & source);
00116         virtual ~SmbiosTable ();
00117 
00118         // ITERATORS
00119         virtual iterator begin ();
00120         virtual const_iterator begin () const;
00121 
00122         virtual iterator end ();
00123         virtual const_iterator end () const;
00124 
00125         virtual iterator operator[]( const int );
00126         virtual const_iterator operator[]( const int ) const;
00127 
00128         virtual iterator operator[]( const std::string & );
00129         virtual const_iterator operator[]( const std::string & ) const;
00130 
00131 
00132         // MEMBERS
00133         virtual void rawMode(bool m) const;
00134         virtual int getNumberOfEntries () const;  // used by unit-test code
00135 
00136         // Used by the validateBios.cpp
00137         virtual smbiosLowlevel::smbios_table_entry_point getTableEPS() const;
00138 
00139         virtual std::ostream & streamify(std::ostream & cout ) const;
00140 
00141         // used by factory only.
00142         virtual void initializeWorkaround() const;
00143         // restricting the header checking
00144         virtual void setStrictValidationMode(bool mode) const;
00145         virtual bool getStrictValidationMode() const;
00146 
00147         virtual ISmbiosItem *getCachedItem( const void * ) const;
00148         virtual void cacheItem( const void *, ISmbiosItem &newitem ) const;
00149         virtual void clearItemCache() const;
00150 
00151         // friends :-)
00152         friend class SmbiosTableIteratorBase;
00153 
00154     protected:
00155         // No-arg constructor not legal for this class for regular users
00156         SmbiosTable ();
00157 
00158         // used by the iterator
00159         virtual ISmbiosItem &makeItem(
00160             const void *header = 0) const;
00161 
00162         // used by the iterator
00163         const void * nextSmbiosStruct ( const void * current = 0) const;
00164 
00165         mutable std::map< const void *, ISmbiosItem *> itemList;
00166         mutable bool initializing;
00167         mutable bool strictValidationMode;
00168         mutable std::auto_ptr<SmbiosWorkaroundTable> workaround;
00169         const u8 * smbiosBuffer;
00170         smbiosLowlevel::smbios_table_entry_point table_header;
00171 
00172     private:
00173         SmbiosTable (const SmbiosTable &source);
00174 
00175         virtual void reReadTable();
00176         mutable unsigned long offset;
00177         std::vector<SmbiosStrategy *> strategyList;
00178     };
00179 
00180 
00181 
00182 
00183     class SmbiosItem : public ISmbiosItem
00184     {
00185     public:
00186         SmbiosItem (const SmbiosItem & source);
00187         explicit SmbiosItem (const smbiosLowlevel::smbios_structure_header *header = 0);
00188         virtual ~SmbiosItem ();
00189 
00190         virtual std::auto_ptr<const ISmbiosItem> clone() const;
00191         virtual std::auto_ptr<ISmbiosItem> clone();
00192         virtual std::ostream & streamify( std::ostream & cout ) const;
00193 
00194         u8 getType() const;
00195         u8 getLength() const;
00196         u16 getHandle() const;
00197 
00198         virtual void getData( unsigned int offset, void *out, size_t size ) const;
00199 
00200         virtual const u8* getBufferCopy(size_t &length) const;
00201         virtual const size_t getBufferSize() const;
00202 
00203         virtual const char *getStringByStringNumber (u8) const;
00204 
00205         // for table only...
00206         virtual void fixup( const SmbiosWorkaroundTable *workaround ) const;
00207     protected:
00208         const smbiosLowlevel::smbios_structure_header * header;
00209         size_t header_size;
00210 
00211     private:
00212         SmbiosItem & operator = (const SmbiosItem & source);
00213     };
00214 
00215 }
00216 
00217 
00218 #endif /* SMBIOSIMPL_H */

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