From 1b43b26ba9b23cb5f3004db7b9b00f6b08227563 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Mon, 25 May 2015 15:21:38 +0200 Subject: [PATCH] Move to Qt Signal/Slots It's actually fun! And was less pain than expected. Seems receiving commands from geiser is still kind-of broken but we'll see Ref T24 --- CMakeLists.txt | 2 +- src/core/Comment.cxx | 2 +- src/core/Function.cxx | 2 +- src/core/InformationManager.cxx | 4 +-- src/core/InformationManager.hxx | 48 ++++++++-------------------- src/gui/Mainwindow.cxx | 32 ++++++++++--------- src/gui/widgets/BasicBlockWidget.cxx | 6 ++-- 7 files changed, 39 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c7fad6..6ae3e44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ endif() SET_SOURCE_FILES_PROPERTIES(src/bindings/guile/frida.i PROPERTIES CPLUSPLUS ON) SWIG_ADD_MODULE(guile-frida-binding guile src/bindings/guile/frida.i) SWIG_LINK_LIBRARIES(guile-frida-binding ${GUILE_LDFLAGS}) - +qt5_use_modules(guile-frida-binding Widgets) ################# # Main Programm # diff --git a/src/core/Comment.cxx b/src/core/Comment.cxx index 983366e..2e6ce61 100644 --- a/src/core/Comment.cxx +++ b/src/core/Comment.cxx @@ -17,7 +17,7 @@ Comment::Comment(uint64_t address, Function* location, InformationManager* manag void Comment::setText(const std::string& text) { ChangeCommentEvent event(address, location, this); this->text = text; - manager->dispatch(&event); + Q_EMIT manager->changeCommentEvent(&event); } uint64_t Comment::getAddress() { diff --git a/src/core/Function.cxx b/src/core/Function.cxx index 79dccda..12b3830 100644 --- a/src/core/Function.cxx +++ b/src/core/Function.cxx @@ -13,7 +13,7 @@ Function::Function(uint64_t start_address, bool dynamic, InformationManager* man void Function::setName(const std::string& new_name) { name = new_name; RenameFunctionEvent event(new_name, this, start_address); - manager->dispatch(&event); + Q_EMIT manager->renameFunctionEvent(&event); } void Function::serialize(QXmlStreamWriter& stream) { diff --git a/src/core/InformationManager.cxx b/src/core/InformationManager.cxx index 3525ca9..b7229d3 100644 --- a/src/core/InformationManager.cxx +++ b/src/core/InformationManager.cxx @@ -270,7 +270,7 @@ void InformationManager::finishFunction(Function* fun) { blocks.insert(std::make_pair(bl->getStartAddress(), bl)); } NewFunctionEvent event(fun->getStartAddress(), fun); - dispatch(&event); + Q_EMIT newFunctionEvent(&event); } void InformationManager::finishBasicBlock(BasicBlock*) { @@ -279,7 +279,7 @@ void InformationManager::finishBasicBlock(BasicBlock*) { void InformationManager::finishComment(Comment* c) { LOG4CXX_DEBUG(logger, "Finishing comment " << c->getAddress()); ChangeCommentEvent event(c->getAddress(), c->getLocation(), c); - dispatch(&event); + Q_EMIT changeCommentEvent(&event); } void InformationManager::deleteFunction(Function* f) { diff --git a/src/core/InformationManager.hxx b/src/core/InformationManager.hxx index 4fdfb74..2364544 100644 --- a/src/core/InformationManager.hxx +++ b/src/core/InformationManager.hxx @@ -2,12 +2,13 @@ #define INCLUDE__InformationManager_hxx #include -#include #include #include #include #include +#include +#include "qt.hxx" #include "disassembler/Disassembler.hxx" class Interpreter; @@ -24,9 +25,17 @@ class QString; class QTemporaryFile; class QPluginLoader; -using boost::signals2::connection; - -class InformationManager { +class InformationManager : public QObject { +#ifndef SWIG + Q_OBJECT +Q_SIGNALS: +#else +public: +#endif + void renameFunctionEvent(RenameFunctionEvent* event); + void newFunctionEvent(NewFunctionEvent* event); + void changeCommentEvent(ChangeCommentEvent* event); + void reset(); public: InformationManager(); ~InformationManager(); @@ -38,31 +47,6 @@ public: Disassembler* getDisassembler() { return disassembler.get(); } - // Rename Function - typedef std::function RenameFunctionHandler; - connection registerRenameFunctionEvent(RenameFunctionHandler h) - { return renameFunctionSignal.connect(h); } - void dispatch(RenameFunctionEvent* event) - { renameFunctionSignal(event); } - - // New Function - typedef std::function NewFunctionHandler; - connection registerNewFunctionEvent(NewFunctionHandler h) - { return newFunctionSignal.connect(h); } - void dispatch(NewFunctionEvent* event) - { newFunctionSignal(event); } - - // Change Comment - typedef std::function ChangeCommentHandler; - connection registerChangeCommentEvent(ChangeCommentHandler h) - { return changeCommentSignal.connect(h); } - void dispatch(ChangeCommentEvent* event) - { changeCommentSignal(event); } - - // Reset frida - connection connect_reset_signal(std::function f) - { return reset_signal.connect(f); } - // Accessors Function* getFunction(uint64_t address); bool hasFunctions() const {return functions.size() != 0;} @@ -119,12 +103,6 @@ public: void deleteComment(Comment* c); private: - boost::signals2::signal renameFunctionSignal; - boost::signals2::signal newFunctionSignal; - boost::signals2::signal changeCommentSignal; - - boost::signals2::signal reset_signal; - std::unique_ptr disassembler; std::map interpreters; diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 39fc83e..adadc06 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -90,21 +90,23 @@ Mainwindow::Mainwindow(InformationManager* mgr) QTreeWidgetItem * external = new QTreeWidgetItem(listWidget, QStringList("External Functions")); external->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); external->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd))); - mgr->registerNewFunctionEvent([=] (NewFunctionEvent* event) { - std::string name = event->function->getName(); - if (event->function->isDynamic()) { - auto item = new QTreeWidgetItem(external, QStringList(name.c_str())); - item->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd))); - } else { - addFunction(event->function); - } - }); - mgr->registerRenameFunctionEvent([&](RenameFunctionEvent* event) { - if (objects_list_by_address.find(event->address) == objects_list_by_address.end()) - return; - auto item = objects_list_by_address[event->address]; - if (item) item->setText(0, event->new_name.c_str()); - }); + connect(mgr, &InformationManager::newFunctionEvent, + [=] (NewFunctionEvent* event) { + std::string name = event->function->getName(); + if (event->function->isDynamic()) { + auto item = new QTreeWidgetItem(external, QStringList(name.c_str())); + item->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd))); + } else { + addFunction(event->function); + } + }); + connect(mgr, &InformationManager::renameFunctionEvent, + [&](RenameFunctionEvent* event) { + if (objects_list_by_address.find(event->address) == objects_list_by_address.end()) + return; + auto item = objects_list_by_address[event->address]; + if (item) item->setText(0, event->new_name.c_str()); + }); setGlobalHotkeys(); } diff --git a/src/gui/widgets/BasicBlockWidget.cxx b/src/gui/widgets/BasicBlockWidget.cxx index 2a3f3b7..77a1493 100644 --- a/src/gui/widgets/BasicBlockWidget.cxx +++ b/src/gui/widgets/BasicBlockWidget.cxx @@ -117,7 +117,8 @@ BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block, , logger(log4cxx::Logger::getLogger("gui.BasicBlockWidget." + name.toStdString())) { next[0] = NULL; next[1] = NULL; - block->getManager()->registerRenameFunctionEvent([=](RenameFunctionEvent* event) {updateFunctionName(event);}); + QObject::connect(block->getManager(), &InformationManager::renameFunctionEvent, + [=](RenameFunctionEvent* event) {updateFunctionName(event);}); _widget.reset(new CustomQGraphicsTextItem("", this)); _widget->setPos(5, 20); @@ -150,7 +151,8 @@ BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block, }); instructions = block->getInstructions(); populateWidget(); - block->getManager()->registerChangeCommentEvent([=](ChangeCommentEvent* e) {changeCommentHandler(e);}); + QObject::connect(block->getManager(), &InformationManager::changeCommentEvent, + [=](ChangeCommentEvent* e) {changeCommentHandler(e);}); } void BasicBlockWidget::updateFunctionName(RenameFunctionEvent *event) { -- 2.39.5