Continued ripping up the source.
[aesalon.git] / monitor / src / Memory.cpp
blobe8a2b2da2453b7d72726ad5b4c12d9696c18b32f
1 #include "Memory.h"
2 #include "misc/BlockEvent.h"
4 namespace Aesalon {
5 namespace Monitor {
7 Misc::SmartPointer<MemoryBlock> Memory::get_block(Word address) const {
8 for(block_set_t::const_iterator i = block_set.begin(); i != block_set.end(); i ++) {
9 if((*i)->get_address() == address) return *i;
11 return NULL;
14 void Memory::remove_block(Misc::SmartPointer<MemoryBlock> block) {
15 for(block_set_t::iterator i = block_set.begin(); i != block_set.end(); i ++) {
16 if((*i) != block) continue;
17 block_set.erase(i);
18 break;
22 void Memory::handle_event(Misc::SmartPointer<Misc::Event> event) {
23 if(event->get_type() == Misc::Event::BLOCK_EVENT) {
24 Misc::SmartPointer<Misc::BlockEvent> be = event.to<Misc::BlockEvent>();
25 switch(be->get_block_type()) {
26 case Misc::BlockEvent::ALLOC_EVENT:
27 add_block(new MemoryBlock(be->get_address(), be->get_size()));
28 break;
29 case Misc::BlockEvent::FREE_EVENT:
30 remove_block(get_block(be->get_address()));
31 break;
32 case Misc::BlockEvent::REALLOC_EVENT:
33 Misc::SmartPointer<MemoryBlock> block = get_block(be->get_address());
34 block->set_address(be->get_new_address());
35 block->set_size(be->get_size());
36 break;
41 } // namespace Platform
42 } // namespace Aesalon