summaryrefslogtreecommitdiffstats
path: root/utils/regtools/qeditor/backend.h
blob: 536eb8cec5e7f6fdb50f9f24b54d618a3853cef3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef __BACKEND_H__
#define __BACKEND_H__

#include <QObject>
#include <QStringList>
#include <QMap>
#include "soc_desc.hpp"

class IoBackend : public QObject
{
    Q_OBJECT
public:
    IoBackend();

    virtual QString GetSocName() = 0;
    virtual bool ReadRegister(const QString& name, soc_word_t& value) = 0;
    virtual bool Reload() = 0;
};

class DummyIoBackend : public IoBackend
{
    Q_OBJECT
public:
    DummyIoBackend();

    virtual QString GetSocName();
    virtual bool ReadRegister(const QString& name, soc_word_t& value);
    virtual bool Reload();
};

class FileIoBackend : public IoBackend
{
    Q_OBJECT
public:
    FileIoBackend(const QString& filename);

    virtual QString GetSocName();
    virtual bool ReadRegister(const QString& name, soc_word_t& value);
    virtual bool Reload();

protected:
    QString m_filename;
    QString m_soc;
    QMap< QString, soc_word_t > m_map;
};

class Backend : public QObject
{
    Q_OBJECT
public:
    Backend();

    QStringList GetSocNameList();
    bool LoadSocDesc(const QString& filename);
    bool GetSocByName(const QString& name, soc_t& s);
    IoBackend *CreateDummyIoBackend();
    IoBackend *CreateFileIoBackend(const QString& filename);

signals:
    void OnSocListChanged();
private:
    std::vector< soc_t > m_socs;
};

class BackendHelper
{
public:
    BackendHelper(IoBackend *io_backend, const soc_t& soc);
    bool ReadRegister(const QString& dev, const QString& reg, soc_word_t& v);
    bool ReadRegisterField(const QString& dev, const QString& reg,
        const QString& field, soc_word_t& v);
private:
    IoBackend *m_io_backend;
    soc_t m_soc;
};

#endif /* __BACKEND_H__ */