SMBIOS Library
CmosRWFactory.cpp
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
3  *
4  * Copyright (C) 2005 Dell Inc.
5  * by Michael Brown <Michael_E_Brown@dell.com>
6  * Licensed under the Open Software License version 2.1
7  *
8  * Alternatively, you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published
10  * by the Free Software Foundation; either version 2 of the License,
11  * or (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  */
18 
19 #define LIBSMBIOS_SOURCE
20 #include "CmosRWImpl.h"
21 #include "FactoryImpl2.h"
22 
23 using namespace std;
24 
25 namespace cmos
26 {
27  class CmosRWFactoryImpl : public factory::TFactory<CmosRWFactory>
28  {
29  public:
30  CmosRWFactoryImpl() { setParameter("cmosMapFile", ""); };
31  virtual ~CmosRWFactoryImpl() throw ();
32  virtual ICmosRW *getSingleton( ); // returns singleton
33  virtual ICmosRW *makeNew( ); // not for use
34  protected:
35  static ICmosRW *_cmosPtr;
36  };
37 
38  //
40  {}
41  CmosRWFactory::CmosRWFactory()
42  {}
43 
44  ICmosRW *CmosRWFactoryImpl::_cmosPtr = 0;
45 
46  CmosRWFactoryImpl::~CmosRWFactoryImpl() throw()
47  {
48  if( _cmosPtr )
49  {
50  delete _cmosPtr;
51  }
52  _cmosPtr = 0;
53  }
54 
55  CmosRWFactory *CmosRWFactory::getFactory()
56  {
57  // reinterpret_cast<...>(0) to ensure template parameter is correct
58  // this is a workaround for VC6 which cannot use explicit member template
59  // funciton initialization.
60  return CmosRWFactoryImpl::getFactory(reinterpret_cast<CmosRWFactoryImpl *>(0));
61  }
62 
63  ICmosRW *CmosRWFactoryImpl::getSingleton()
64  {
65  if (_cmosPtr == 0)
66  _cmosPtr = makeNew();
67 
68  return _cmosPtr;
69  }
70 
71  ICmosRW *CmosRWFactoryImpl::makeNew()
72  {
73  ICmosRW *ret=0;
74  if (mode == UnitTestMode)
75  {
76  ret = new CmosRWFile( getParameterString("cmosMapFile") );
77  }
78  else if ( mode == AutoDetectMode )
79  {
80  ret = new CmosRWIo( );
81  }
82  else
83  {
84  throw InvalidCmosRWModeImpl("CmosRW Factory has been set to an invalid mode.");
85  }
86  return ret;
87  }
88 
89 }