libsmbios_c library
IToken.h
Go to the documentation of this file.
1 // vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:
2 /*
3  * Copyright (C) 2005 Dell Inc.
4  * by Michael Brown <Michael_E_Brown@dell.com>
5  * Licensed under the Open Software License version 2.1
6  *
7  * Alternatively, you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published
9  * by the Free Software Foundation; either version 2 of the License,
10  * or (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU General Public License for more details.
16  */
17 
18 
19 #ifndef TOKEN_H
20 #define TOKEN_H
21 
22 // compat header should always be first header
23 #include "smbios/compat.h"
24 
25 #include <string>
26 
27 // types.h should be first user-defined header.
28 #include "smbios/types.h"
29 
30 #include "smbios/ICmosRW.h"
31 #include "smbios/ISmbios.h"
32 
33 // abi_prefix should be last header included before declarations
35 
36 namespace smbios
37 {
38  // Exceptions
39  DECLARE_EXCEPTION( TokenException );
40  DECLARE_EXCEPTION_EX( InvalidTokenTableMode, smbios, TokenException );
41  DECLARE_EXCEPTION_EX( InvalidAccessMode, smbios, TokenException );
42  DECLARE_EXCEPTION_EX( DerefNullPointer, smbios, TokenException );
43  DECLARE_EXCEPTION_EX( ParameterError, smbios, TokenException );
44  DECLARE_EXCEPTION_EX( InvalidChecksum, smbios, TokenException );
45  DECLARE_EXCEPTION_EX( NeedAuthentication, smbios, TokenException );
46 
47  // forward declarations
48  class ITokenTable;
49  class TokenTableIterator;
50  class ConstTokenTableIterator;
51 
52  class TokenTableFactory : public virtual factory::IFactory
53  {
54  public:
55  static TokenTableFactory *getFactory();
56  virtual ~TokenTableFactory() throw();
57  virtual ITokenTable *getSingleton(const smbios::ISmbiosTable *table = 0) = 0;
58  virtual ITokenTable *makeNew(const smbios::ISmbiosTable *table) = 0;
59  protected:
61  };
62 
63 
66  {
67  public:
70 
71  virtual ~ITokenTable();
72 
73  // ITERATORS
74  virtual iterator begin () = 0;
75  virtual const_iterator begin () const = 0;
76 
77  virtual iterator end () = 0;
78  virtual const_iterator end () const = 0;
79 
80  virtual iterator operator[]( const int ) = 0;
81  virtual const_iterator operator[]( const int ) const = 0;
82 
83  virtual iterator operator[]( const std::string & ) = 0;
84  virtual const_iterator operator[]( const std::string & ) const = 0;
85 
86  virtual std::ostream & streamify( std::ostream & cout ) const = 0;
87 
88  protected:
89  // No-arg constructor not legal for this class for outside parties
90  ITokenTable();
91  };
92 
93 
95  class IToken
96  {
97  public:
98  virtual ~IToken();
99 
100  virtual std::string getTokenClass() const = 0;
101 
103  virtual u32 getType() const = 0;
104 
106  virtual bool isActive() const = 0;
108  virtual void activate() const = 0;
110  virtual bool isString() const = 0;
112  virtual bool isBool() const = 0;
114  virtual unsigned int getStringLength() const = 0;
116  // \warning byteArray must be at least <b> getStringLength()+1 </b> bytes or NULL!
121  virtual const std::string getString( u8 *byteArray = 0, unsigned int size = 0 ) const = 0;
122  virtual void setString( const u8 *byteArray, size_t size ) const = 0;
123 
124  virtual const ISmbiosItem &getItemRef() const = 0; // use judiciously!
125 
126  virtual std::ostream & streamify( std::ostream & cout ) const = 0;
127  protected:
128  IToken() ;
129 
130  private:
131  IToken( const IToken & ); //no copying
132  IToken & operator = (const IToken & source);//no assignment
133  };
134 
136  {
137  public:
138  virtual ~IProtectedToken() throw() {};
139  virtual bool tryPassword(std::string pw) const = 0;
140  virtual u32 getValueFormat() const = 0;
141  protected:
142  IProtectedToken();
143  IProtectedToken( const IProtectedToken & );
145  };
146 
148  {
149  public:
151  // should be used judiciously, as this circumvents object layering.
152  // The main purpose for this is to implement special-case code
153  // that needs to access raw cmos.
154  virtual void getCMOSDetails( u16 *indexPort, u16 *dataPort, u8 *location ) const = 0;
155  virtual ~ICmosToken() throw() {};
156  protected:
157  ICmosToken();
158  ICmosToken( const ICmosToken & );
160  };
161 
162  class ISmiToken
163  {
164  public:
166  // should be used judiciously, as this circumvents object layering.
167  // The main purpose for this is to implement special-case code
168  // that needs to access raw smi.
169  virtual void getSmiDetails( u16 *cmdIOAddress, u8 *cmdIOCode, u8 *location ) const = 0;
170  virtual ~ISmiToken() throw() {};
171  protected:
172  ISmiToken();
173  ISmiToken( const ISmiToken & );
174  ISmiToken &operator = (const ISmiToken &);
175  };
176 
177 
179 
182  : public std::iterator < std::forward_iterator_tag, IToken >
183  {
184  public:
185  typedef std::forward_iterator_tag iterator_category;
186  typedef std::ptrdiff_t difference_type;
187 
188  virtual ~TokenTableIteratorBase() throw() {};
189  explicit TokenTableIteratorBase(const ITokenTable *initialTable, int typeToMatch);
190  bool operator == (const TokenTableIteratorBase other) const { return current == other.current; };
191  bool operator != (const TokenTableIteratorBase other) const { return current != other.current; };
192  const IToken * dereference () const;
193  IToken * dereference ();
194  void incrementIterator();
195 
196  void reset();
197  bool eof();
198 
199  protected:
202  int current;
203  };
204 
206 
209  :public TokenTableIteratorBase
210  {
211  public:
212  // Make sure you define these, otherwise you can't use
213  // iterators in stl algorithms
216  typedef value_type* pointer;
217 
218  virtual ~TokenTableIterator() throw() {};
219  explicit TokenTableIterator (const ITokenTable *initialTable = 0, int typeToMatch = -1 );
220  reference operator * () const;
221  pointer operator -> () const;
222  TokenTableIterator & operator ++ (); // ++Prefix
223  const TokenTableIterator operator ++ (int); //Postfix++
224  };
225 
227  /***
228  */
230  :public TokenTableIteratorBase
231  {
232  public:
233  // Make sure you define these, otherwise you can't use
234  // iterators in stl algorithms
235  typedef const IToken value_type;
237  typedef value_type* pointer;
238 
239  virtual ~ConstTokenTableIterator() throw() {};
240  explicit ConstTokenTableIterator (const ITokenTable * initialTable = 0, int typeToMatch = -1 );
241  reference operator * () const;
242  pointer operator -> () const;
243  ConstTokenTableIterator & operator ++ (); // ++Prefix
244  const ConstTokenTableIterator operator ++ (int); //Postfix++
245  };
246 
247 
248  std::ostream & operator << (std::ostream & cout, const ITokenTable & item);
249  std::ostream & operator << (std::ostream & cout, const IToken & item);
250 
251  // helper functions
252 
253  bool isTokenActive(int tokenNum);
254  void activateToken(int tokenNum, std::string password = "");
255 }
256 
257 // always should be last thing in header file
259 
260 #endif /* TOKEN_H */