mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 18:47:39 -04:00
qeditor: introduce a new "RAM" backend, and refactor file backend
Change-Id: Icfbbc01b83d3592041803387e35f5aa6fb0fa813 Reviewed-on: http://gerrit.rockbox.org/997 Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
This commit is contained in:
parent
4a711fee42
commit
1bcc4fc67b
2 changed files with 69 additions and 31 deletions
|
@ -107,23 +107,14 @@ IoBackend *Backend::CreateHWStubIoBackend(HWStubDevice *dev)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileIoBackend
|
* RamIoBackend
|
||||||
*/
|
*/
|
||||||
|
RamIoBackend::RamIoBackend(const QString& soc_name)
|
||||||
FileIoBackend::FileIoBackend(const QString& filename, const QString& soc_name)
|
|
||||||
{
|
{
|
||||||
m_filename = filename;
|
|
||||||
m_soc = soc_name;
|
m_soc = soc_name;
|
||||||
m_valid = false;
|
|
||||||
Reload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FileIoBackend::GetSocName()
|
bool RamIoBackend::ReadRegister(const QString& name, soc_word_t& value)
|
||||||
{
|
|
||||||
return m_soc;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileIoBackend::ReadRegister(const QString& name, soc_word_t& value)
|
|
||||||
{
|
{
|
||||||
if(m_map.find(name) == m_map.end())
|
if(m_map.find(name) == m_map.end())
|
||||||
return false;
|
return false;
|
||||||
|
@ -131,13 +122,45 @@ bool FileIoBackend::ReadRegister(const QString& name, soc_word_t& value)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RamIoBackend::DeleteAll()
|
||||||
|
{
|
||||||
|
m_map.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RamIoBackend::WriteRegister(const QString& name, soc_word_t value, WriteMode mode)
|
||||||
|
{
|
||||||
|
switch(mode)
|
||||||
|
{
|
||||||
|
case Write: m_map[name] = value; return true;
|
||||||
|
case Set: m_map[name] |= value; return true;
|
||||||
|
case Clear: m_map[name] &= ~value; return true;
|
||||||
|
case Toggle: m_map[name] ^= value; return true;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileIoBackend
|
||||||
|
*/
|
||||||
|
|
||||||
|
FileIoBackend::FileIoBackend(const QString& filename, const QString& soc_name)
|
||||||
|
:RamIoBackend(soc_name)
|
||||||
|
{
|
||||||
|
m_filename = filename;
|
||||||
|
m_valid = false;
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool FileIoBackend::Reload()
|
bool FileIoBackend::Reload()
|
||||||
{
|
{
|
||||||
m_valid = false;
|
m_valid = false;
|
||||||
QFile file(m_filename);
|
QFile file(m_filename);
|
||||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
return false;
|
return false;
|
||||||
m_map.clear();
|
DeleteAll();
|
||||||
|
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
while(!in.atEnd())
|
while(!in.atEnd())
|
||||||
|
@ -152,7 +175,7 @@ bool FileIoBackend::Reload()
|
||||||
if(key == "HW")
|
if(key == "HW")
|
||||||
m_soc = line.mid(idx + 1).trimmed();
|
m_soc = line.mid(idx + 1).trimmed();
|
||||||
else if(ok)
|
else if(ok)
|
||||||
m_map[key] = val;
|
RamIoBackend::WriteRegister(key, val, Write);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_readonly = !QFileInfo(file).isWritable();
|
m_readonly = !QFileInfo(file).isWritable();
|
||||||
|
@ -164,14 +187,7 @@ bool FileIoBackend::Reload()
|
||||||
bool FileIoBackend::WriteRegister(const QString& name, soc_word_t value, WriteMode mode)
|
bool FileIoBackend::WriteRegister(const QString& name, soc_word_t value, WriteMode mode)
|
||||||
{
|
{
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
switch(mode)
|
return RamIoBackend::WriteRegister(name, value, mode);
|
||||||
{
|
|
||||||
case Write: m_map[name] = value; return true;
|
|
||||||
case Set: m_map[name] |= value; return true;
|
|
||||||
case Clear: m_map[name] &= ~value; return true;
|
|
||||||
case Toggle: m_map[name] ^= value; return true;
|
|
||||||
default: return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileIoBackend::Commit()
|
bool FileIoBackend::Commit()
|
||||||
|
|
|
@ -102,9 +102,39 @@ public:
|
||||||
virtual bool Commit() { return false; }
|
virtual bool Commit() { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** The RAM backend doesn't have any backend storage and stores all values in
|
||||||
|
* an associative map */
|
||||||
|
class RamIoBackend : public IoBackend
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
RamIoBackend(const QString& soc_name = "");
|
||||||
|
|
||||||
|
virtual bool IsValid() { return m_soc != ""; }
|
||||||
|
virtual bool SupportAccess(AccessType type) { return type == ByName; }
|
||||||
|
virtual QString GetSocName() { return m_soc; }
|
||||||
|
virtual void SetSocName(const QString& soc_name) { m_soc = soc_name; }
|
||||||
|
virtual bool ReadRegister(const QString& name, soc_word_t& value);
|
||||||
|
virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value)
|
||||||
|
{ Q_UNUSED(addr); Q_UNUSED(value); return false; }
|
||||||
|
virtual bool Reload() { return false; }
|
||||||
|
virtual bool IsReadOnly() { return false; }
|
||||||
|
virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode);
|
||||||
|
virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode)
|
||||||
|
{ Q_UNUSED(addr); Q_UNUSED(value); Q_UNUSED(mode); return false; }
|
||||||
|
virtual bool IsDirty() { return false; }
|
||||||
|
virtual bool Commit() { return false; }
|
||||||
|
/* clear all entries of the backend */
|
||||||
|
virtual void DeleteAll();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString m_soc;
|
||||||
|
QMap< QString, soc_word_t > m_map;
|
||||||
|
};
|
||||||
|
|
||||||
/** NOTE the File backend makes a difference between writes and commits:
|
/** NOTE the File backend makes a difference between writes and commits:
|
||||||
* a write will *never* touch the underlying file unless it was committed. */
|
* a write will *never* touch the underlying file unless it was committed. */
|
||||||
class FileIoBackend : public IoBackend
|
class FileIoBackend : public RamIoBackend
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -112,26 +142,18 @@ public:
|
||||||
|
|
||||||
virtual bool IsValid() { return m_valid; }
|
virtual bool IsValid() { return m_valid; }
|
||||||
virtual bool SupportAccess(AccessType type) { return type == ByName; }
|
virtual bool SupportAccess(AccessType type) { return type == ByName; }
|
||||||
virtual QString GetSocName();
|
|
||||||
virtual bool ReadRegister(const QString& name, soc_word_t& value);
|
|
||||||
virtual bool ReadRegister(soc_addr_t addr, soc_word_t& value)
|
|
||||||
{ Q_UNUSED(addr); Q_UNUSED(value); return false; }
|
|
||||||
virtual bool Reload();
|
virtual bool Reload();
|
||||||
virtual bool IsReadOnly() { return m_readonly; }
|
virtual bool IsReadOnly() { return m_readonly; }
|
||||||
virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode);
|
virtual bool WriteRegister(const QString& name, soc_word_t value, WriteMode mode);
|
||||||
virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode)
|
|
||||||
{ Q_UNUSED(addr); Q_UNUSED(value); Q_UNUSED(mode); return false; }
|
|
||||||
virtual bool IsDirty() { return m_dirty; }
|
virtual bool IsDirty() { return m_dirty; }
|
||||||
virtual bool Commit();
|
virtual bool Commit();
|
||||||
QString GetFileName() { return m_filename; }
|
QString GetFileName() { return m_filename; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_filename;
|
QString m_filename;
|
||||||
QString m_soc;
|
|
||||||
bool m_readonly;
|
bool m_readonly;
|
||||||
bool m_dirty;
|
bool m_dirty;
|
||||||
bool m_valid;
|
bool m_valid;
|
||||||
QMap< QString, soc_word_t > m_map;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_HWSTUB
|
#ifdef HAVE_HWSTUB
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue