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 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 sergeykhbr
/*
2
 *  Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
3
 *
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
 *  you may not use this file except in compliance with the License.
6
 *  You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *  Unless required by applicable law or agreed to in writing, software
11
 *  distributed under the License is distributed on an "AS IS" BASIS,
12
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *  See the License for the specific language governing permissions and
14
 *  limitations under the License.
15
 */
16
 
17
#ifndef __DEBUGGER_CLASS_H__
18
#define __DEBUGGER_CLASS_H__
19
 
20
#include <iface.h>
21
#include <iservice.h>
22
#include <api_core.h>
23
 
24
namespace debugger {
25
 
26
static const char *const IFACE_CLASS = "IClass";
27
 
28
class IClass : public IFace {
29
 public:
30
    explicit IClass(const char *class_name)
31
        : IFace(IFACE_CLASS) {
32
        class_name_.make_string(class_name);
33
        RISCV_register_class(static_cast<IClass *>(this));
34
        listInstances_ = AttributeType(Attr_List);
35
    }
36
    virtual ~IClass() {
37
        for (unsigned i = 0; i < listInstances_.size(); i++) {
38
            delete static_cast<IService *>(listInstances_[i].to_iface());
39
        }
40
    }
41
 
42
    virtual IService *createService(const char *obj_name) = 0;
43
 
44
    virtual void postinitServices() {
45
        IService *tmp = NULL;
46
        for (unsigned i = 0; i < listInstances_.size(); i++) {
47
            tmp = static_cast<IService *>(listInstances_[i].to_iface());
48
            tmp->postinitService();
49
        }
50
    }
51
 
52
    virtual void predeleteServices() {
53
        IService *tmp = NULL;
54
        for (unsigned i = 0; i < listInstances_.size(); i++) {
55
            tmp = static_cast<IService *>(listInstances_[i].to_iface());
56
            tmp->predeleteService();
57
        }
58
    }
59
 
60
    virtual const char *getClassName() { return class_name_.to_string(); }
61
 
62
    virtual IService *getInstance(const char *name) {
63
        IService *ret = NULL;
64
        for (unsigned i = 0; i < listInstances_.size(); i++) {
65
            ret = static_cast<IService *>(listInstances_[i].to_iface());
66
            if (strcmp(name, ret->getObjName()) == 0) {
67
                return ret;
68
            }
69
        }
70
        return NULL;
71
    }
72
 
73
    virtual AttributeType getConfiguration() {
74
        AttributeType ret(Attr_Dict);
75
        ret["Class"] = AttributeType(getClassName());
76
        ret["Instances"] = AttributeType(Attr_List);
77
 
78
        IService *tmp = NULL;
79
        for (unsigned i = 0; i < listInstances_.size(); i++) {
80
            tmp = static_cast<IService *>(listInstances_[i].to_iface());
81
            AttributeType val = tmp->getConfiguration();
82
            ret["Instances"].add_to_list(&val);
83
        }
84
        return ret;
85
    }
86
 
87
    virtual const AttributeType *getInstanceList() { return &listInstances_; }
88
 
89
 protected:
90
    AttributeType class_name_;
91
    AttributeType listInstances_;
92
};
93
 
94
/**
95
 * @brief Unified macros of plugin class declaration.
96
 * @see simple_plugin.cpp example
97
 */
98
#define DECLARE_CLASS(name) \
99
class name ## Class : public IClass { \
100
 public: \
101
    name ## Class() : IClass(# name "Class") {} \
102
    virtual IService *createService(const char *obj_name) {  \
103
        name *serv = new name(obj_name); \
104
        AttributeType item(static_cast<IService *>(serv)); \
105
        listInstances_.add_to_list(&item); \
106
        return serv; \
107
    } \
108
};
109
 
110
/**
111
 * @brief Unified macros of plugin class registration in kernel library.
112
 * @see simple_plugin.cpp example
113
 */
114
#define REGISTER_CLASS(name) static name ## Class local_class;
115
#define REGISTER_CLASS_IDX(name, idx) static name ## Class local_class_ ## idx;
116
 
117
}  // namespace debugger
118
 
119
#endif  // __DEBUGGER_CLASS_H__

powered by: WebSVN 2.1.0

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