00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef SMBIOSINTERFACE_H
00020 #define SMBIOSINTERFACE_H
00021
00022
00023 #include "smbios/compat.h"
00024
00025 #include <cstdlib>
00026 #include <iostream>
00027 #include <string>
00028 #include <map>
00029 #include <memory>
00030
00031
00032 #include "smbios/types.h"
00033
00034 #include "smbios/IFactory.h"
00035 #include "smbios/IException.h"
00036 #include "smbios/SmbiosLowLevel.h"
00037
00038
00039 #include "smbios/config/abi_prefix.hpp"
00040
00041 namespace smbios
00042 {
00043
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
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
00121
00122 typedef SmbiosTableIterator iterator;
00123 typedef ConstSmbiosTableIterator const_iterator;
00124
00125
00126 ISmbiosTable();
00127
00128 virtual ~ISmbiosTable ();
00129
00130
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
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;
00256
00257 virtual smbiosLowlevel::smbios_table_entry_point getTableEPS() const = 0;
00258
00260
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
00440
00441
00442 virtual const u8* getBufferCopy(size_t &length) const = 0;
00443
00445
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
00504
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; };
00517 const SmbiosTableIterator operator ++ (int)
00518 {
00519 const SmbiosTableIterator oldValue = *this;
00520 ++(*this);
00521 return oldValue;
00522 };
00523 };
00524
00526
00533 class ConstSmbiosTableIterator:public SmbiosTableIteratorBase
00534 {
00535 public:
00536
00537
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; };
00550 const ConstSmbiosTableIterator operator ++ (int)
00551 {
00552 const ConstSmbiosTableIterator oldValue = *this;
00553 ++(*this);
00554 return oldValue;
00555 };
00556 };
00557
00558
00559
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
00568 #include "smbios/config/abi_suffix.hpp"
00569
00570 #endif