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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [common/] [iservice.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      Core Service interface declaration.
6
 */
7
 
8
#ifndef __DEBUGGER_SERVICE_H__
9
#define __DEBUGGER_SERVICE_H__
10
 
11
#include "iface.h"
12
#include "attribute.h"
13
#include "api_utils.h"
14
 
15
namespace debugger {
16
 
17
static const char *const IFACE_SERVICE = "IService";
18
 
19
class IService : public IFace {
20
public:
21
    IService(const char *obj_name)
22
        : IFace(IFACE_SERVICE) {
23
        listInterfaces_ = AttributeType(Attr_List);
24
        listAttributes_ = AttributeType(Attr_List);
25
        registerInterface(static_cast<IService *>(this));
26
        registerAttribute("LogLevel", &logLevel_);
27
        obj_name_ = obj_name;
28
        logLevel_.make_int64(LOG_ERROR);
29
    }
30
    virtual ~IService() {}
31
 
32
    virtual void initService(const AttributeType *args) {
33
        if (!args || !args->is_list()) {
34
            return;
35
        }
36
        AttributeType *cur_attr;
37
        for (unsigned i = 0; i < args->size(); i++) {
38
            const AttributeType &item = (*args)[i];
39
            if (item.size() < 2 || !item[0u].is_string()) {
40
                continue;
41
            }
42
            cur_attr = static_cast<AttributeType *>(
43
                                getAttribute(item[0u].to_string()));
44
            if (cur_attr == NULL) {
45
                RISCV_error("Attribute '%s' not found", item[0u].to_string());
46
                continue;
47
            }
48
            (*cur_attr) = item[1];
49
            if (item.size() >= 3 && item[2].is_string()) {
50
                static_cast<IAttribute *>(cur_attr)->setAttrDescription(
51
                    item[2].to_string());
52
            }
53
        }
54
    }
55
 
56
    virtual void postinitService() {}
57
    virtual void predeleteService() {}
58
 
59
    virtual void registerInterface(IFace *iface) {
60
        AttributeType item(iface);
61
        listInterfaces_.add_to_list(&item);
62
    }
63
 
64
    virtual void unregisterInterface(IFace *iface) {
65
        for (unsigned i = 0; i < listInterfaces_.size(); i++) {
66
            if (listInterfaces_[i].to_iface() == iface) {
67
                listInterfaces_.remove_from_list(i);
68
                break;
69
            }
70
        }
71
    }
72
 
73
    virtual IFace *getInterface(const char *name) {
74
        IFace *tmp;
75
        for (unsigned i = 0; i < listInterfaces_.size(); i++) {
76
            tmp = listInterfaces_[i].to_iface();
77
            if (strcmp(name, tmp->getFaceName()) == 0) {
78
                return tmp;
79
            }
80
        }
81
        return NULL;
82
    }
83
 
84
    virtual void registerAttribute(const char *name, IAttribute *iface) {
85
        AttributeType item(iface);
86
        iface->setAttrName(name);
87
        listAttributes_.add_to_list(&item);
88
    }
89
 
90
    virtual IAttribute *getAttribute(const char *name) {
91
        IAttribute *tmp;
92
        for (unsigned i = 0; i < listAttributes_.size(); i++) {
93
            tmp = static_cast<IAttribute *>(listAttributes_[i].to_iface());
94
            if (strcmp(name, tmp->getAttrName()) == 0) {
95
                return tmp;
96
            }
97
        }
98
        return NULL;
99
    }
100
 
101
    virtual const char *getObjName() { return obj_name_; }
102
 
103
    virtual AttributeType getConfiguration() {
104
        AttributeType ret(Attr_Dict);
105
        ret["Name"] = AttributeType(getObjName());
106
        ret["Attr"] = AttributeType(Attr_List);
107
 
108
        IAttribute *tmp = NULL;
109
        for (unsigned i = 0; i < listAttributes_.size(); i++) {
110
            tmp = static_cast<IAttribute *>(listAttributes_[i].to_iface());
111
            AttributeType item;
112
            item.make_list(2);
113
            item[0u].make_string(tmp->getAttrName());
114
            item[1] = *static_cast<AttributeType *>(tmp);
115
            ret["Attr"].add_to_list(&item);
116
        }
117
        return ret;
118
    }
119
 
120
protected:
121
    AttributeType listInterfaces_;
122
    AttributeType listAttributes_;
123
    AttributeType logLevel_;
124
    const char *obj_name_;
125
};
126
 
127
}  // namespace debugger
128
 
129
#endif  // __DEBUGGER_SERVICE_H__

powered by: WebSVN 2.1.0

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