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
00338 virtual void getData( unsigned int offset, void *out, size_t size ) const = 0;
00339
00340
00341
00342
00343 virtual const u8* getBufferCopy(size_t &length) const = 0;
00344
00346
00347 virtual const size_t getBufferSize() const = 0;
00348
00353 virtual const char *getStringByStringNumber (u8) const = 0;
00354
00355 enum {
00356 FIELD_LEN_BYTE=1,
00357 FIELD_LEN_WORD=2,
00358 FIELD_LEN_DWORD=4,
00359 FIELD_LEN_QWORD=8
00360 };
00361 };
00362
00363 u8 getItemType(const ISmbiosItem &item);
00364 u8 getItemLength(const ISmbiosItem &item);
00365 u16 getItemHandle(const ISmbiosItem &item);
00366
00367 u8 getU8_FromItem(const ISmbiosItem &item, unsigned int offset);
00368 u16 getU16_FromItem(const ISmbiosItem &item, unsigned int offset);
00369 u32 getU32_FromItem(const ISmbiosItem &item, unsigned int offset);
00370 u64 getU64_FromItem(const ISmbiosItem &item, unsigned int offset);
00371 const char *getString_FromItem(const ISmbiosItem &item, unsigned int offset);
00372 void *getBits_FromItem(const ISmbiosItem &item, unsigned int offset, void *out, unsigned int lsb=0, unsigned int msb=0 );
00373 bool isBitSet(const ISmbiosItem *itemPtr, unsigned int offset, unsigned int bitToTest);
00374
00375 template <class R>
00376 R &getData(const ISmbiosItem &item, unsigned int offset, R &out)
00377 {
00378 item.getData(offset, &out, sizeof(R));
00379 return out;
00380 }
00381
00382
00384
00391 class SmbiosTableIteratorBase :
00392 public std::iterator < std::forward_iterator_tag, ISmbiosItem >
00393 {
00394 public:
00395 explicit SmbiosTableIteratorBase (const ISmbiosTable * initialTable = 0, int typeToMatch = -1 )
00396 : matchType(typeToMatch), table(initialTable), current(0)
00397 { incrementIterator(); };
00398 virtual ~SmbiosTableIteratorBase() throw() {};
00399 bool operator == (const SmbiosTableIteratorBase other) const { return current == other.current; };
00400 bool operator != (const SmbiosTableIteratorBase other) const { return current != other.current; };
00401
00402 protected:
00403 void incrementIterator ();
00404 ISmbiosItem & dereference () const;
00405
00406 int matchType;
00407 const ISmbiosTable * table;
00408 mutable const void * current;
00409 };
00410
00412
00419 class SmbiosTableIterator
00420 : public SmbiosTableIteratorBase
00421 {
00422 public:
00423
00424
00425 typedef std::forward_iterator_tag iterator_category;
00426 typedef ISmbiosItem value_type;
00427 typedef value_type& reference;
00428 typedef value_type* pointer;
00429 typedef std::ptrdiff_t difference_type;
00430
00431 virtual ~SmbiosTableIterator() throw() {};
00432 explicit SmbiosTableIterator (ISmbiosTable * initialTable = 0, int typeToMatch = -1 )
00433 : SmbiosTableIteratorBase(initialTable, typeToMatch) {};
00434 reference operator * () const { return dereference(); };
00435 pointer operator -> () const { return &dereference(); };
00436 SmbiosTableIterator & operator ++ () { incrementIterator(); return *this; };
00437 const SmbiosTableIterator operator ++ (int)
00438 {
00439 const SmbiosTableIterator oldValue = *this;
00440 ++(*this);
00441 return oldValue;
00442 };
00443 };
00444
00446
00453 class ConstSmbiosTableIterator:public SmbiosTableIteratorBase
00454 {
00455 public:
00456
00457
00458 typedef std::forward_iterator_tag iterator_category;
00459 typedef const ISmbiosItem value_type;
00460 typedef value_type& reference;
00461 typedef value_type* pointer;
00462 typedef std::ptrdiff_t difference_type;
00463
00464 virtual ~ConstSmbiosTableIterator() throw() {};
00465 explicit ConstSmbiosTableIterator (const ISmbiosTable * initialTable = 0, int typeToMatch = -1 )
00466 : SmbiosTableIteratorBase(initialTable, typeToMatch) {};
00467 reference operator * () const { return dereference(); };
00468 pointer operator -> () const { return &dereference(); };
00469 ConstSmbiosTableIterator & operator ++ () { incrementIterator(); return *this; };
00470 const ConstSmbiosTableIterator operator ++ (int)
00471 {
00472 const ConstSmbiosTableIterator oldValue = *this;
00473 ++(*this);
00474 return oldValue;
00475 };
00476 };
00477
00478
00479
00480
00481 std::ostream & operator << (std::ostream & cout, const ISmbiosTable & item);
00482 std::ostream & operator << (std::ostream & cout, const ISmbiosItem & item);
00483
00484 }
00485
00486
00487
00488 #include "smbios/config/abi_suffix.hpp"
00489
00490 #endif