OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [common/] [iclass.h] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      Base Class interface declaration.
6
 */
7
 
8
#ifndef __DEBUGGER_CLASS_H__
9
#define __DEBUGGER_CLASS_H__
10
 
11
#include "iface.h"
12
#include "iservice.h"
13
#include "api_core.h"
14
 
15
namespace debugger {
16
 
17
static const char *const IFACE_CLASS = "IClass";
18
 
19
class IClass : public IFace {
20
public:
21
    IClass(const char *class_name)
22
        : IFace(IFACE_CLASS), class_name_(class_name) {
23
        RISCV_register_class(static_cast<IClass *>(this));
24
        listInstances_ = AttributeType(Attr_List);
25
    }
26
    virtual ~IClass() {
27
        for (unsigned i = 0; i < listInstances_.size(); i++) {
28
            delete static_cast<IService *>(listInstances_[i].to_iface());
29
        }
30
    }
31
 
32
    virtual IService *createService(const char *obj_name) =0;
33
 
34
    virtual void postinitServices() {
35
        IService *tmp = NULL;
36
        for (unsigned i = 0; i < listInstances_.size(); i++) {
37
            tmp = static_cast<IService *>(listInstances_[i].to_iface());
38
            tmp->postinitService();
39
        }
40
    }
41
 
42
    virtual void predeleteServices() {
43
        IService *tmp = NULL;
44
        for (unsigned i = 0; i < listInstances_.size(); i++) {
45
            tmp = static_cast<IService *>(listInstances_[i].to_iface());
46
            tmp->predeleteService();
47
        }
48
    }
49
 
50
    virtual const char *getClassName() { return class_name_; }
51
 
52
    virtual IService *getInstance(const char *name) {
53
        IService *ret = NULL;
54
        for (unsigned i = 0; i < listInstances_.size(); i++) {
55
            ret = static_cast<IService *>(listInstances_[i].to_iface());
56
            if (strcmp(name, ret->getObjName()) == 0) {
57
                return ret;
58
            }
59
        }
60
        return NULL;
61
    }
62
 
63
    virtual AttributeType getConfiguration() {
64
        AttributeType ret(Attr_Dict);
65
        ret["Class"] = AttributeType(getClassName());
66
        ret["Instances"] = AttributeType(Attr_List);
67
 
68
        IService *tmp = NULL;
69
        for (unsigned i = 0; i < listInstances_.size(); i++) {
70
            tmp = static_cast<IService *>(listInstances_[i].to_iface());
71
            AttributeType val = tmp->getConfiguration();
72
            ret["Instances"].add_to_list(&val);
73
        }
74
        return ret;
75
    }
76
 
77
    virtual const AttributeType *getInstanceList() { return &listInstances_; }
78
 
79
protected:
80
    const char *class_name_;
81
    AttributeType listInstances_;
82
};
83
 
84
/**
85
 * @brief Unified macros of plugin class declaration.
86
 * @see simple_plugin.cpp example
87
 */
88
#define DECLARE_CLASS(name) \
89
class name ## Class : public IClass { \
90
public: \
91
    name ## Class () : IClass(# name "Class") {} \
92
    virtual IService *createService(const char *obj_name) {  \
93
        name *serv = new name(obj_name); \
94
        AttributeType item(static_cast<IService *>(serv)); \
95
        listInstances_.add_to_list(&item); \
96
        return serv; \
97
    } \
98
};
99
 
100
/**
101
 * @brief Unified macros of plugin class registration in kernel library.
102
 * @see simple_plugin.cpp example
103
 */
104
#define REGISTER_CLASS(name) static name ## Class local_class;
105
#define REGISTER_CLASS_IDX(name, idx) static name ## Class local_class_ ## idx;
106
 
107
}  // namespace debugger
108
 
109
#endif  // __DEBUGGER_CLASS_H__

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.