00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 00002 * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0: 00003 * 00004 * Copyright (C) 2005 Dell Inc. 00005 * by Michael Brown <Michael_E_Brown@dell.com> 00006 * Licensed under the Open Software License version 2.1 00007 * 00008 * Alternatively, you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published 00010 * by the Free Software Foundation; either version 2 of the License, 00011 * or (at your option) any later version. 00012 00013 * This program is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 */ 00018 00019 #define LIBSMBIOS_SOURCE 00020 #include "CmosRWImpl.h" 00021 #include "FactoryImpl2.h" 00022 00023 using namespace std; 00024 00025 namespace cmos 00026 { 00027 class CmosRWFactoryImpl : public factory::TFactory<CmosRWFactory> 00028 { 00029 public: 00030 CmosRWFactoryImpl() { setParameter("cmosMapFile", ""); }; 00031 virtual ~CmosRWFactoryImpl() throw (); 00032 virtual ICmosRW *getSingleton( ); // returns singleton 00033 virtual ICmosRW *makeNew( ); // not for use 00034 protected: 00035 static ICmosRW *_cmosPtr; 00036 }; 00037 00038 // 00039 CmosRWFactory::~CmosRWFactory() throw() 00040 {} 00041 CmosRWFactory::CmosRWFactory() 00042 {} 00043 00044 ICmosRW *CmosRWFactoryImpl::_cmosPtr = 0; 00045 00046 CmosRWFactoryImpl::~CmosRWFactoryImpl() throw() 00047 { 00048 if( _cmosPtr ) 00049 { 00050 delete _cmosPtr; 00051 } 00052 _cmosPtr = 0; 00053 } 00054 00055 CmosRWFactory *CmosRWFactory::getFactory() 00056 { 00057 // reinterpret_cast<...>(0) to ensure template parameter is correct 00058 // this is a workaround for VC6 which cannot use explicit member template 00059 // funciton initialization. 00060 return CmosRWFactoryImpl::getFactory(reinterpret_cast<CmosRWFactoryImpl *>(0)); 00061 } 00062 00063 ICmosRW *CmosRWFactoryImpl::getSingleton() 00064 { 00065 if (_cmosPtr == 0) 00066 _cmosPtr = makeNew(); 00067 00068 return _cmosPtr; 00069 } 00070 00071 ICmosRW *CmosRWFactoryImpl::makeNew() 00072 { 00073 ICmosRW *ret=0; 00074 if (mode == UnitTestMode) 00075 { 00076 ret = new CmosRWFile( getParameterString("cmosMapFile") ); 00077 } 00078 else if ( mode == AutoDetectMode ) 00079 { 00080 ret = new CmosRWIo( ); 00081 } 00082 else 00083 { 00084 throw InvalidCmosRWModeImpl("CmosRW Factory has been set to an invalid mode."); 00085 } 00086 return ret; 00087 } 00088 00089 }