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

Generated on Wed Apr 2 16:37:32 2008 for SMBIOS Library by  doxygen 1.5.1