SMBIOS Library
MemoryImpl.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 SMBIOSIMPL_H
20 #define SMBIOSIMPL_H
21 
22 #include "smbios/IMemory.h"
23 #include "FactoryImpl2.h"
24 #include "ExceptionImpl.h"
25 
26 namespace memory
27 {
28  DEFINE_EXCEPTION_EX( AccessErrorImpl, memory, AccessError );
29  DEFINE_EXCEPTION_EX( OutOfBoundsImpl, memory, OutOfBounds );
30 
31  class MemoryFactoryImpl : public factory::TFactory<MemoryFactory>
32  {
33  public:
35  virtual ~MemoryFactoryImpl() throw ();
36  virtual IMemory *getSingleton();
37  virtual IMemory *makeNew();
38  protected:
40  };
41 
42 
43  // for unit tests
44  class MemoryFile : public IMemory
45  {
46  public:
47  // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
48  explicit MemoryFile (const std::string file);
49  virtual ~MemoryFile ();
50 
51  virtual void fillBuffer(u8 *buffer, u64 offset, unsigned int length) const;
52  virtual u8 getByte(u64 offset) const;
53  virtual void putByte(u64 offset, u8 value) const;
54  virtual int incReopenHint() {return ++reopenHint;};
55  virtual int decReopenHint() {return --reopenHint;};
56 
57  private:
58  const std::string filename;
59  mutable FILE *fd;
60  bool rw;
62 
63  MemoryFile ();
64  MemoryFile (const MemoryFile & source);
65  MemoryFile& operator = (const MemoryFile & source);
66  };
67 
68  // for real work
69  class MemoryOsSpecific : public IMemory
70  {
71  public:
72  // CONSTRUCTORS, DESTRUCTOR, and ASSIGNMENT
73  explicit MemoryOsSpecific (const std::string file);
74  virtual ~MemoryOsSpecific ();
75 
76  virtual void fillBuffer(u8 *buffer, u64 offset, unsigned int length) const;
77  virtual u8 getByte(u64 offset) const;
78  virtual void putByte(u64 offset, u8 value) const;
79  virtual int incReopenHint();
80  virtual int decReopenHint();
81 
82  private:
83  void *osData;
84 
86  MemoryOsSpecific (const MemoryOsSpecific & source);
88  };
89 }
90 
91 
92 #endif /* SMBIOSIMPL_H */