]> git.siccegge.de Git - frida/frida.git/commitdiff
Move to Qt Signal/Slots
authorChristoph Egger <christoph@christoph-egger.org>
Mon, 25 May 2015 13:21:38 +0000 (15:21 +0200)
committerChristoph Egger <christoph@christoph-egger.org>
Mon, 25 May 2015 13:21:38 +0000 (15:21 +0200)
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
src/core/Comment.cxx
src/core/Function.cxx
src/core/InformationManager.cxx
src/core/InformationManager.hxx
src/gui/Mainwindow.cxx
src/gui/widgets/BasicBlockWidget.cxx

index 8c7fad6e72ccee825f8c1342523f593ba1a42dd9..6ae3e44eda895963fd79625995ab972bdf20bac2 100644 (file)
@@ -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 #
index 983366e8d90a18c7b33d70890bd78f1f685af536..2e6ce6153ef694c6e1867116ac0c75e618c0871f 100644 (file)
@@ -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() {
index 79dccda3760d510c42e0b8cb423899bc7f6dfa20..12b3830d323bb9cea841449eb6c6de754fc65e68 100644 (file)
@@ -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) {
index 3525ca9e7548e741f92f3dc28e91c5982dc5d464..b7229d376854639dfc8cc16fbece136f2ef9bed2 100644 (file)
@@ -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) {
index 4fdfb7435cd9ea942fafb82a1b3c090e795dc17a..23645440a1e05760abecbf40f0d6587ca66aff81 100644 (file)
@@ -2,12 +2,13 @@
 #define INCLUDE__InformationManager_hxx
 
 #include <log4cxx/logger.h>
-#include <boost/signals2.hpp>
 #include <functional>
 #include <string>
 #include <map>
 #include <vector>
+#include <memory>
 
+#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<void (RenameFunctionEvent*)> RenameFunctionHandler;
-       connection registerRenameFunctionEvent(RenameFunctionHandler h)
-               { return renameFunctionSignal.connect(h); }
-       void dispatch(RenameFunctionEvent* event)
-               { renameFunctionSignal(event); }
-
-       // New Function
-       typedef std::function<void (NewFunctionEvent*)> NewFunctionHandler;
-       connection registerNewFunctionEvent(NewFunctionHandler h)
-               { return newFunctionSignal.connect(h); }
-       void dispatch(NewFunctionEvent* event)
-               { newFunctionSignal(event); }
-
-       // Change Comment
-       typedef std::function<void (ChangeCommentEvent*)> ChangeCommentHandler;
-       connection registerChangeCommentEvent(ChangeCommentHandler h)
-               { return changeCommentSignal.connect(h); }
-       void dispatch(ChangeCommentEvent* event)
-               { changeCommentSignal(event); }
-
-       // Reset frida
-       connection connect_reset_signal(std::function<void ()> 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<void (RenameFunctionEvent*)> renameFunctionSignal;
-       boost::signals2::signal<void (NewFunctionEvent*)> newFunctionSignal;
-       boost::signals2::signal<void (ChangeCommentEvent*)> changeCommentSignal;
-
-       boost::signals2::signal<void ()> reset_signal;
-
        std::unique_ptr<Disassembler> disassembler;
 
        std::map<std::string, Interpreter*> interpreters;
index 39fc83e0d83b4506ccc8d4e56ef5ca5ec138d2af..adadc0686a9a600d70f99b2e85dc9aae523a2499 100644 (file)
@@ -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();
 }
 
index 2a3f3b7d992f30f4f5089754a1016bf221ac13c7..77a14932999adeedfddc1c77517773909c029bb7 100644 (file)
@@ -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) {