00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TOKEN_H
00020 #define TOKEN_H
00021
00022
00023 #include "smbios/compat.h"
00024
00025 #include <string>
00026
00027
00028 #include "smbios/types.h"
00029
00030 #include "smbios/ICmosRW.h"
00031 #include "smbios/ISmbios.h"
00032
00033
00034 #include "smbios/config/abi_prefix.hpp"
00035
00036 namespace smbios
00037 {
00038
00039 DECLARE_EXCEPTION( TokenException );
00040 DECLARE_EXCEPTION_EX( InvalidTokenTableMode, smbios, TokenException );
00041 DECLARE_EXCEPTION_EX( InvalidAccessMode, smbios, TokenException );
00042 DECLARE_EXCEPTION_EX( DerefNullPointer, smbios, TokenException );
00043 DECLARE_EXCEPTION_EX( ParameterError, smbios, TokenException );
00044 DECLARE_EXCEPTION_EX( InvalidChecksum, smbios, TokenException );
00045 DECLARE_EXCEPTION_EX( NeedAuthentication, smbios, TokenException );
00046
00047
00048 class ITokenTable;
00049 class TokenTableIterator;
00050 class ConstTokenTableIterator;
00051
00052 class TokenTableFactory : public virtual factory::IFactory
00053 {
00054 public:
00055 static TokenTableFactory *getFactory();
00056 virtual ~TokenTableFactory() throw();
00057 virtual ITokenTable *getSingleton(const smbios::ISmbiosTable *table = 0) = 0;
00058 virtual ITokenTable *makeNew(const smbios::ISmbiosTable *table) = 0;
00059 protected:
00060 TokenTableFactory();
00061 };
00062
00063
00065 class ITokenTable
00066 {
00067 public:
00068 typedef TokenTableIterator iterator;
00069 typedef ConstTokenTableIterator const_iterator;
00070
00071 virtual ~ITokenTable();
00072
00073
00074 virtual iterator begin () = 0;
00075 virtual const_iterator begin () const = 0;
00076
00077 virtual iterator end () = 0;
00078 virtual const_iterator end () const = 0;
00079
00080 virtual iterator operator[]( const int ) = 0;
00081 virtual const_iterator operator[]( const int ) const = 0;
00082
00083 virtual iterator operator[]( const std::string & ) = 0;
00084 virtual const_iterator operator[]( const std::string & ) const = 0;
00085
00086 virtual std::ostream & streamify( std::ostream & cout ) const = 0;
00087
00088 protected:
00089
00090 ITokenTable();
00091 };
00092
00093
00095 class IToken
00096 {
00097 public:
00098 virtual ~IToken();
00099
00100 virtual std::string getTokenClass() const = 0;
00101
00103 virtual u32 getType() const = 0;
00104
00106 virtual bool isActive() const = 0;
00108 virtual void activate() const = 0;
00110 virtual bool isString() const = 0;
00112 virtual bool isBool() const = 0;
00114 virtual unsigned int getStringLength() const = 0;
00116
00121 virtual const std::string getString( u8 *byteArray = 0, unsigned int size = 0 ) const = 0;
00122 virtual void setString( const u8 *byteArray, size_t size ) const = 0;
00123
00124 virtual const ISmbiosItem &getItemRef() const = 0;
00125
00126 virtual std::ostream & streamify( std::ostream & cout ) const = 0;
00127 protected:
00128 IToken() ;
00129
00130 private:
00131 IToken( const IToken & );
00132 IToken & operator = (const IToken & source);
00133 };
00134
00135 class IProtectedToken : virtual public IToken
00136 {
00137 public:
00138 virtual ~IProtectedToken() throw() {};
00139 virtual bool tryPassword(std::string pw) const = 0;
00140 virtual u32 getValueFormat() const = 0;
00141 protected:
00142 IProtectedToken();
00143 IProtectedToken( const IProtectedToken & );
00144 IProtectedToken &operator = (const IProtectedToken &);
00145 };
00146
00147 class ICmosToken : virtual public IToken
00148 {
00149 public:
00151
00152
00153
00154 virtual void getCMOSDetails( u16 *indexPort, u16 *dataPort, u8 *location ) const = 0;
00155 virtual ~ICmosToken() throw() {};
00156 protected:
00157 ICmosToken();
00158 ICmosToken( const ICmosToken & );
00159 ICmosToken &operator = (const ICmosToken &);
00160 };
00161
00163
00165 class TokenTableIteratorBase
00166 : public std::iterator < std::forward_iterator_tag, ITokenTable >
00167 {
00168 public:
00169 virtual ~TokenTableIteratorBase() throw() {};
00170 explicit TokenTableIteratorBase(const ITokenTable *initialTable, int typeToMatch);
00171 bool operator == (const TokenTableIteratorBase other) const { return current == other.current; };
00172 bool operator != (const TokenTableIteratorBase other) const { return current != other.current; };
00173 protected:
00174 IToken * dereference () const;
00175 void incrementIterator();
00176
00177 int matchType;
00178 const ITokenTable *table;
00179 mutable int current;
00180 };
00181
00183
00185 class TokenTableIterator
00186 :public TokenTableIteratorBase
00187 {
00188 public:
00189
00190
00191 typedef std::forward_iterator_tag iterator_category;
00192 typedef IToken value_type;
00193 typedef value_type& reference;
00194 typedef value_type* pointer;
00195 typedef std::ptrdiff_t difference_type;
00196
00197 virtual ~TokenTableIterator() throw() {};
00198 explicit TokenTableIterator (const ITokenTable *initialTable = 0, int typeToMatch = -1 )
00199 : TokenTableIteratorBase( initialTable, typeToMatch ) {} ;
00200 IToken& operator * () const {return *dereference();};
00201 IToken* operator -> () const {return dereference();};
00202 TokenTableIterator & operator ++ ();
00203 const TokenTableIterator operator ++ (int);
00204 };
00205
00207
00208
00209 class ConstTokenTableIterator
00210 :public TokenTableIteratorBase
00211 {
00212 public:
00213
00214
00215 typedef std::forward_iterator_tag iterator_category;
00216 typedef const IToken value_type;
00217 typedef value_type& reference;
00218 typedef value_type* pointer;
00219 typedef std::ptrdiff_t difference_type;
00220
00221 virtual ~ConstTokenTableIterator() throw() {};
00222 ConstTokenTableIterator (const ITokenTable * initialTable = 0, int typeToMatch = -1 )
00223 : TokenTableIteratorBase( initialTable, typeToMatch ) {} ;
00224 reference operator * () const {return *dereference();};
00225 pointer operator -> () const {return dereference();};
00226 ConstTokenTableIterator & operator ++ ();
00227 const ConstTokenTableIterator operator ++ (int);
00228 };
00229
00230
00231 std::ostream & operator << (std::ostream & cout, const ITokenTable & item);
00232 std::ostream & operator << (std::ostream & cout, const IToken & item);
00233
00234 }
00235
00236
00237 #include "smbios/config/abi_suffix.hpp"
00238
00239 #endif