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
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
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
00162 class ISmiToken
00163 {
00164 public:
00166
00167
00168
00169 virtual void getSmiDetails( u16 *cmdIOAddress, u8 *cmdIOCode, u8 *location ) const = 0;
00170 virtual ~ISmiToken() throw() {};
00171 protected:
00172 ISmiToken();
00173 ISmiToken( const ISmiToken & );
00174 ISmiToken &operator = (const ISmiToken &);
00175 };
00176
00177
00179
00181 class TokenTableIteratorBase
00182 : public std::iterator < std::forward_iterator_tag, ITokenTable >
00183 {
00184 public:
00185 virtual ~TokenTableIteratorBase() throw() {};
00186 explicit TokenTableIteratorBase(const ITokenTable *initialTable, int typeToMatch);
00187 bool operator == (const TokenTableIteratorBase other) const { return current == other.current; };
00188 bool operator != (const TokenTableIteratorBase other) const { return current != other.current; };
00189 protected:
00190 IToken * dereference () const;
00191 void incrementIterator();
00192
00193 int matchType;
00194 const ITokenTable *table;
00195 mutable int current;
00196 };
00197
00199
00201 class TokenTableIterator
00202 :public TokenTableIteratorBase
00203 {
00204 public:
00205
00206
00207 typedef std::forward_iterator_tag iterator_category;
00208 typedef IToken value_type;
00209 typedef value_type& reference;
00210 typedef value_type* pointer;
00211 typedef std::ptrdiff_t difference_type;
00212
00213 virtual ~TokenTableIterator() throw() {};
00214 explicit TokenTableIterator (const ITokenTable *initialTable = 0, int typeToMatch = -1 )
00215 : TokenTableIteratorBase( initialTable, typeToMatch ) {} ;
00216 IToken& operator * () const {return *dereference();};
00217 IToken* operator -> () const {return dereference();};
00218 TokenTableIterator & operator ++ ();
00219 const TokenTableIterator operator ++ (int);
00220 };
00221
00223
00224
00225 class ConstTokenTableIterator
00226 :public TokenTableIteratorBase
00227 {
00228 public:
00229
00230
00231 typedef std::forward_iterator_tag iterator_category;
00232 typedef const IToken value_type;
00233 typedef value_type& reference;
00234 typedef value_type* pointer;
00235 typedef std::ptrdiff_t difference_type;
00236
00237 virtual ~ConstTokenTableIterator() throw() {};
00238 ConstTokenTableIterator (const ITokenTable * initialTable = 0, int typeToMatch = -1 )
00239 : TokenTableIteratorBase( initialTable, typeToMatch ) {} ;
00240 reference operator * () const {return *dereference();};
00241 pointer operator -> () const {return dereference();};
00242 ConstTokenTableIterator & operator ++ ();
00243 const ConstTokenTableIterator operator ++ (int);
00244 };
00245
00246
00247 std::ostream & operator << (std::ostream & cout, const ITokenTable & item);
00248 std::ostream & operator << (std::ostream & cout, const IToken & item);
00249
00250
00251
00252 bool isTokenActive(int tokenNum);
00253 void activateToken(int tokenNum, std::string password = "");
00254 }
00255
00256
00257 #include "smbios/config/abi_suffix.hpp"
00258
00259 #endif