1 #ifndef INCLUDE__InformationManager_hxx
2 #define INCLUDE__InformationManager_hxx
4 #include <log4cxx/logger.h>
5 #include <boost/signals2.hpp>
11 #include "disassembler/Disassembler.hxx"
19 class RenameFunctionEvent;
20 class NewFunctionEvent;
21 class ChangeCommentEvent;
27 using boost::signals2::connection;
29 class InformationManager {
32 ~InformationManager();
34 void reset(const std::string& filename);
35 void load(const std::string& filename);
36 void save(const std::string& filename);
38 Disassembler* getDisassembler()
39 { return disassembler.get(); }
42 typedef std::function<void (RenameFunctionEvent*)> RenameFunctionHandler;
43 connection registerRenameFunctionEvent(RenameFunctionHandler h)
44 { return renameFunctionSignal.connect(h); }
45 void dispatch(RenameFunctionEvent* event)
46 { renameFunctionSignal(event); }
49 typedef std::function<void (NewFunctionEvent*)> NewFunctionHandler;
50 connection registerNewFunctionEvent(NewFunctionHandler h)
51 { return newFunctionSignal.connect(h); }
52 void dispatch(NewFunctionEvent* event)
53 { newFunctionSignal(event); }
56 typedef std::function<void (ChangeCommentEvent*)> ChangeCommentHandler;
57 connection registerChangeCommentEvent(ChangeCommentHandler h)
58 { return changeCommentSignal.connect(h); }
59 void dispatch(ChangeCommentEvent* event)
60 { changeCommentSignal(event); }
62 connection connect_reset_signal(std::function<void ()> f)
63 { return reset_signal.connect(f); }
65 Function* getFunction(uint64_t address);
66 bool hasFunctions() const {return functions.size() != 0;}
67 std::map<uint64_t, Function*>::const_iterator beginFunctions();
68 std::map<uint64_t, Function*>::const_iterator endFunctions();
70 BasicBlock* getBasicBlock(uint64_t address);
71 bool hasBasicBlocks() const {return blocks.size() != 0;}
72 std::map<uint64_t, BasicBlock*>::const_iterator beginBasicBlocks();
73 std::map<uint64_t, BasicBlock*>::const_iterator endBasicBlocks();
75 Interpreter* getInterpreter(const std::string& name);
76 bool hasInterpreters() const {return interpreters.size() != 0;}
77 std::map<std::string, Interpreter*>::const_iterator beginInterpreters();
78 std::map<std::string, Interpreter*>::const_iterator endInterpreters();
83 * Users may allocate new Data containers with the new*()
84 * functions. Once they have populated the information they hand
85 * over the object to the information manager using the finish*()
88 * if new*() returns NULL there already exists a function at the
89 * specified address. Users may then get the old object if they
90 * wish or (more likely) skip creating it. Uniqueness of the
91 * object is only guaranteed as compared to the finish()ed
94 * Users are responsible for destroying functions iff they do not
95 * finish them using the delete*() functions. Once the objects are
96 * finished, the information manager is responsible for cleaning
97 * up the memory. If delete*() is called on a finished object, bad
100 Function* newFunction(uint64_t address);
101 Function* newDynamicFunction(uint64_t address);
102 BasicBlock* newBasicBlock(uint64_t address);
103 Comment* newGlobalComment(uint64_t address);
104 Comment* newLocalComment(uint64_t address, Function* f);
105 void finishFunction(Function* f);
106 void finishBasicBlock(BasicBlock* b);
107 void finnishComment(Comment* c);
108 void deleteFunction(Function* f);
109 void deleteBasicBlock(BasicBlock* b);
110 void deleteComment(Comment* c);
113 boost::signals2::signal<void (RenameFunctionEvent*)> renameFunctionSignal;
114 boost::signals2::signal<void (NewFunctionEvent*)> newFunctionSignal;
115 boost::signals2::signal<void (ChangeCommentEvent*)> changeCommentSignal;
117 boost::signals2::signal<void ()> reset_signal;
119 std::unique_ptr<Disassembler> disassembler;
121 std::map<std::string, Interpreter*> interpreters;
122 std::map<uint64_t, Function*> functions;
123 std::map<uint64_t, BasicBlock*> blocks;
124 std::multimap<uint64_t, Comment*> comments;
126 std::string filename;
127 std::unique_ptr<QTemporaryFile> tmpfile;
128 std::vector<QPluginLoader*> plugins;
130 log4cxx::LoggerPtr logger;
133 #endif /* INCLUDE__InformationManager_hxx */