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