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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [gui_plugin/] [gui_plugin.cpp] - 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
#include "api_core.h"
18
#include "gui_plugin.h"
19
#include "coreservices/iserial.h"
20
#include "coreservices/irawlistener.h"
21
#include <string>
22
 
23
namespace debugger {
24
 
25
GuiPlugin::GuiPlugin(const char *name)
26
    : IService(name), IHap(HAP_ConfigDone) {
27
    registerInterface(static_cast<IGui *>(this));
28
    registerInterface(static_cast<IThread *>(this));
29
    registerInterface(static_cast<IHap *>(this));
30
    registerAttribute("WidgetsConfig", &guiConfig_);
31
    registerAttribute("SocInfo", &socInfo_);
32
    registerAttribute("CommandExecutor", &cmdExecutor_);
33
 
34
    guiConfig_.make_dict();
35
    socInfo_.make_string("");
36
    cmdExecutor_.make_string("");
37
 
38
    char coredir[4096];
39
    RISCV_get_core_folder(coredir, sizeof(coredir));
40
    QString topDir(coredir);
41
    QResource::registerResource(
42
        topDir + "resources/gui.rcc");
43
 
44
    info_ = 0;
45
    ui_ = NULL;
46
    RISCV_event_create(&eventCommandAvailable_, "eventCommandAvailable_");
47
    RISCV_event_create(&config_done_, "eventGuiGonfigGone");
48
    RISCV_register_hap(static_cast<IHap *>(this));
49
 
50
    // Adding path to platform libraries:
51
    char core_path[1024];
52
    RISCV_get_core_folder(core_path, sizeof(core_path));
53
    QStringList paths = QApplication::libraryPaths();
54
    std::string qt_path = std::string(core_path);
55
    std::string qt_lib_path = qt_path;
56
    paths.append(QString(qt_lib_path.c_str()));
57
    qt_lib_path += "qtlib/";
58
    paths.append(QString(qt_lib_path.c_str()));
59
    qt_lib_path += "platforms";
60
    paths.append(QString(qt_lib_path.c_str()));
61
 
62
    paths.append(QString("platforms"));
63
    QApplication::setLibraryPaths(paths);
64
 
65
    ui_ = new QtWrapper(static_cast<IGui *>(this));
66
}
67
 
68
GuiPlugin::~GuiPlugin() {
69
    RISCV_event_close(&config_done_);
70
    RISCV_event_close(&eventCommandAvailable_);
71
}
72
 
73
void GuiPlugin::postinitService() {
74
    iexec_ = static_cast<ICmdExecutor *>(
75
        RISCV_get_service_iface(cmdExecutor_.to_string(), IFACE_CMD_EXECUTOR));
76
    if (!iexec_) {
77
        RISCV_error("ICmdExecutor interface of %s not found.",
78
                    cmdExecutor_.to_string());
79
    }
80
 
81
    info_ = static_cast<ISocInfo *>(
82
        RISCV_get_service_iface(socInfo_.to_string(), IFACE_SOC_INFO));
83
    if (!iexec_) {
84
        RISCV_error("ISocInfo interface of %s not found.",
85
                    socInfo_.to_string());
86
    }
87
 
88
    ui_->postInit(&guiConfig_);
89
    run();
90
}
91
 
92
IService *GuiPlugin::getParentService() {
93
    return static_cast<IService *>(this);
94
}
95
 
96
IFace *GuiPlugin::getSocInfo() {
97
    return info_;
98
}
99
 
100
const AttributeType *GuiPlugin::getpConfig() {
101
    return &guiConfig_;
102
}
103
 
104
void GuiPlugin::registerCommand(IGuiCmdHandler *src,
105
                                AttributeType *cmd,
106
                                bool silent) {
107
    queue_.put(src, cmd, silent);
108
    RISCV_event_set(&eventCommandAvailable_);
109
}
110
 
111
void GuiPlugin::removeFromQueue(IFace *iface) {
112
    queue_.remove(iface);
113
}
114
 
115
void GuiPlugin::hapTriggered(IFace *isrc, EHapType type,
116
                                  const char *descr) {
117
    RISCV_event_set(&config_done_);
118
}
119
 
120
void GuiPlugin::busyLoop() {
121
    RISCV_event_wait(&config_done_);
122
 
123
    while (isEnabled()) {
124
        if (RISCV_event_wait_ms(&eventCommandAvailable_, 500)) {
125
            RISCV_event_clear(&eventCommandAvailable_);
126
            continue;
127
        }
128
 
129
        processCmdQueue();
130
    }
131
    ui_->gracefulClose();
132
    delete ui_;
133
}
134
 
135
bool GuiPlugin::processCmdQueue() {
136
    AttributeType resp;
137
    AttributeType cmd;
138
    IFace *iresp;
139
    bool silent;
140
 
141
    queue_.initProc();
142
    queue_.pushPreQueued();
143
 
144
    while (queue_.getNext(&iresp, cmd, silent)) {
145
        iexec_->exec(cmd.to_string(), &resp, silent);
146
 
147
        if (iresp) {
148
            static_cast<IGuiCmdHandler *>(iresp)->handleResponse(&cmd, &resp);
149
        }
150
        cmd.attr_free();
151
        resp.attr_free();
152
    }
153
    return false;
154
}
155
 
156
void GuiPlugin::stop() {
157
    IThread::stop();
158
}
159
 
160
extern "C" void plugin_init(void) {
161
    REGISTER_CLASS(GuiPlugin);
162
}
163
 
164
}  // namespace debugger

powered by: WebSVN 2.1.0

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