Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

IToken.h

Go to the documentation of this file.
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, 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         // Make sure you define these, otherwise you can't use
00206         // iterators in stl algorithms
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 ++ ();          // ++Prefix
00219         const TokenTableIterator operator ++ (int);  //Postfix++
00220     };
00221 
00223     /***
00224     */
00225     class ConstTokenTableIterator
00226         :public TokenTableIteratorBase
00227     {
00228     public:
00229         // Make sure you define these, otherwise you can't use
00230         // iterators in stl algorithms
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 ++ ();         // ++Prefix
00243         const ConstTokenTableIterator operator ++ (int);  //Postfix++
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     // helper functions
00251 
00252     bool isTokenActive(int tokenNum);
00253     void activateToken(int tokenNum, std::string password = "");
00254 }
00255 
00256 // always should be last thing in header file
00257 #include "smbios/config/abi_suffix.hpp"
00258 
00259 #endif  /* TOKEN_H */

Generated on Wed Apr 11 16:25:10 2007 for SMBIOS Library by doxygen 1.3.5