1 #include "AllocEvent.h"
3 void AllocEvent::apply_to(Snapshot
*snapshot
) {
4 qDebug("Asked to apply AllocEvent to snapshot #%li . . .", (long int)snapshot
->get_snapshot_id());
5 /* Create the head node if it doesn't exist . . . */
6 if(snapshot
->get_head_node() == NULL
) {
7 qDebug("Creating new head node . . .");
8 snapshot
->set_head_node(new BiTreeNode(snapshot
->get_snapshot_id()));
11 BiTreeNode
*node
= snapshot
->get_head_node();
13 quint8 max_depth
= snapshot
->get_max_tree_depth();
14 /* First, traverse the tree to find the right spot. Create any nodes required to get there,
15 and mark the created nodes' parents as changed, of course. */
16 for(quint8 depth
= 0; depth
< max_depth
; depth
++) {
17 if(!(MemoryAddress(address
<< depth
) & 0x01)) {
18 if(node
->get_left() == NULL
) {
19 node
= node
->mark_changed(snapshot
->get_snapshot_id());
20 qDebug("Creating new left node . . .");
21 node
->set_left(new BiTreeNode(snapshot
->get_snapshot_id()));
23 node
= node
->get_left();
26 if(node
->get_right() == NULL
) {
27 node
= node
->mark_changed(snapshot
->get_snapshot_id());
28 qDebug("Creating new right node . . .");
29 node
->set_right(new BiTreeNode(snapshot
->get_snapshot_id()));
31 node
= node
->get_right();
35 qDebug("AllocEvent: adding block to node . . . current size is %i.", node
->get_block_list_size());
36 /* Well, we're at the correct node to add the block into (hopefully, anyhow) . . . */
37 node
->add_block(new Block(address
, size
));
38 node
= node
->mark_changed(snapshot
->get_snapshot_id());
40 /* Now, set the snapshot's new head node . . . */
41 if(snapshot
->get_head_node()->get_snapshot_id() != snapshot
->get_snapshot_id()) {
42 qDebug("AllocEvent: setting new head node for snapshot %i . . .", (int)snapshot
->get_snapshot_id());
43 BiTreeNode
*head_node
= node
;
44 while(head_node
->get_parent()) head_node
= head_node
->get_parent();
45 snapshot
->set_head_node(head_node
);
47 /* And update the snapshot's timestamp. */
48 snapshot
->update_timestamp();