00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define LIBSMBIOS_SOURCE
00020 #include "CmosRWImpl.h"
00021
00022 using namespace std;
00023
00024 namespace cmos
00025 {
00026
00027
00028
00029
00030 void readByteArray ( const ICmosRW &cmos, u32 indexPort, u32 dataPort, u32 offset, u8 * target, u32 count)
00031 {
00032 for (u32 i = 0; i < count; ++i)
00033 {
00034 target[i] = cmos.readByte (indexPort, dataPort, offset + i);
00035 }
00036 }
00037
00038 void writeByteArray ( const ICmosRW &cmos, u32 indexPort, u32 dataPort, u32 offset, const u8 * source, u32 count)
00039 {
00040 const Suppressable *s = dynamic_cast<const Suppressable *>(&cmos);
00041 if(s)
00042 s->suppressNotification();
00043 for (u32 i = 0; i < count; ++i)
00044 {
00045 cmos.writeByte (indexPort, dataPort, offset + i, source[i]);
00046 }
00047 if(s)
00048 s->resumeNotification();
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 Suppressable::Suppressable()
00062 : suppressNotify(false)
00063 {}
00064
00065 Suppressable::~Suppressable()
00066 {}
00067
00068 void Suppressable::suppressNotification(bool sup) const
00069 {
00070 suppressNotify = sup;
00071 }
00072
00073 void Suppressable::resumeNotification(bool doNotify) const
00074 {
00075 const observer::IObservable *o = dynamic_cast<const observer::IObservable *>(this);
00076 if(o && doNotify)
00077 o->notify();
00078
00079 suppressNotify = false;
00080 }
00081
00082 bool Suppressable::isNotifySuppressed() const
00083 {
00084 return suppressNotify;
00085 }
00086
00087
00088
00089
00090 ICmosRW::ICmosRW()
00091 {}
00092
00093 ICmosRW::~ICmosRW()
00094 {}
00095
00096
00097
00098
00099
00100
00101 CmosRWFile::CmosRWFile ( const string &File )
00102 :ICmosRW(), Suppressable(), fileName (File)
00103 {}
00104
00105
00106 CmosRWFile::~CmosRWFile()
00107 {}
00108
00109 CmosRWIo::~CmosRWIo()
00110 {}
00111
00112
00113
00114 u8 CmosRWFile::readByte (u32 indexPort, u32 dataPort, u32 offset) const
00115 {
00116 u8 retval = 0xFF;
00117 u32 realOffset = indexPort * 256 + offset;
00118 (void) dataPort;
00119
00120 FILE *fh = fopen (fileName.c_str (), "rb");
00121 if( !fh )
00122 throw smbios::InternalErrorImpl("Internal Error: could not cmos file for reading.");
00123
00124 fseek (fh, static_cast<long>(realOffset), SEEK_SET);
00125 fread (&retval, 1, sizeof (retval), fh);
00126 fclose (fh);
00127 return retval;
00128 }
00129
00130
00131
00132 void CmosRWFile::writeByte (u32 indexPort, u32 dataPort, u32 offset, u8 byte) const
00133 {
00134
00135 u32 realOffset = indexPort * 256 + offset;
00136 (void) dataPort;
00137
00138 FILE *fh = fopen (fileName.c_str (), "r+b");
00139 if( !fh )
00140 throw smbios::InternalErrorImpl("Internal Error: could not cmos file for writing.");
00141
00142 fseek (fh, static_cast<long>(realOffset), SEEK_SET);
00143 fwrite (&byte, 1, sizeof (byte), fh);
00144 fclose (fh);
00145 fflush(NULL);
00146
00147 if(! isNotifySuppressed() )
00148 {
00149
00150
00151
00152 notify();
00153 }
00154 return;
00155 }
00156
00157
00158 }