libsmbios_c library
|
00001 // vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c: 00002 /* 00003 * Copyright (C) 2005 Dell Inc. 00004 * by Michael Brown <Michael_E_Brown@dell.com> 00005 * Licensed under the Open Software License version 2.1 00006 * 00007 * Alternatively, you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published 00009 * by the Free Software Foundation; either version 2 of the License, 00010 * or (at your option) any later version. 00011 00012 * This program is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00015 * See the GNU General Public License for more details. 00016 */ 00017 00018 00019 #ifndef TOKEN_H 00020 #define TOKEN_H 00021 00022 // compat header should always be first header 00023 #include "smbios/compat.h" 00024 00025 #include <string> 00026 00027 // types.h should be first user-defined header. 00028 #include "smbios/types.h" 00029 00030 #include "smbios/ICmosRW.h" 00031 #include "smbios/ISmbios.h" 00032 00033 // abi_prefix should be last header included before declarations 00034 #include "smbios/config/abi_prefix.hpp" 00035 00036 namespace smbios 00037 { 00038 // Exceptions 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 // forward declarations 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 // ITERATORS 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 // No-arg constructor not legal for this class for outside parties 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 // \warning byteArray must be at least <b> getStringLength()+1 </b> bytes or NULL! 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; // use judiciously! 00125 00126 virtual std::ostream & streamify( std::ostream & cout ) const = 0; 00127 protected: 00128 IToken() ; 00129 00130 private: 00131 IToken( const IToken & ); //no copying 00132 IToken & operator = (const IToken & source);//no assignment 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 // should be used judiciously, as this circumvents object layering. 00152 // The main purpose for this is to implement special-case code 00153 // that needs to access raw cmos. 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 // should be used judiciously, as this circumvents object layering. 00167 // The main purpose for this is to implement special-case code 00168 // that needs to access raw smi. 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 // Make sure you define these, otherwise you can't use 00213 // iterators in stl algorithms 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 ++ (); // ++Prefix 00223 const TokenTableIterator operator ++ (int); //Postfix++ 00224 }; 00225 00227 /*** 00228 */ 00229 class ConstTokenTableIterator 00230 :public TokenTableIteratorBase 00231 { 00232 public: 00233 // Make sure you define these, otherwise you can't use 00234 // iterators in stl algorithms 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 ++ (); // ++Prefix 00244 const ConstTokenTableIterator operator ++ (int); //Postfix++ 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 // helper functions 00252 00253 bool isTokenActive(int tokenNum); 00254 void activateToken(int tokenNum, std::string password = ""); 00255 } 00256 00257 // always should be last thing in header file 00258 #include "smbios/config/abi_suffix.hpp" 00259 00260 #endif /* TOKEN_H */