headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / model / TeamMemoryBlock.cpp
blob7b906531dc69ab2c6ea42bf7f40d55c07f08f9d3
1 /*
2 * Copyright 2011, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "TeamMemoryBlock.h"
10 #include <AutoLocker.h>
12 #include "TeamMemoryBlockManager.h"
15 // #pragma mark - TeamMemoryBlock
18 TeamMemoryBlock::TeamMemoryBlock(target_addr_t baseAddress,
19 TeamMemoryBlockOwner* owner)
21 fValid(false),
22 fWritable(false),
23 fBaseAddress(baseAddress),
24 fBlockOwner(owner)
29 TeamMemoryBlock::~TeamMemoryBlock()
31 delete fBlockOwner;
35 void
36 TeamMemoryBlock::AddListener(Listener* listener)
38 AutoLocker<BLocker> lock(fLock);
39 fListeners.Add(listener);
43 bool
44 TeamMemoryBlock::HasListener(Listener* listener)
46 AutoLocker<BLocker> lock(fLock);
47 ListenerList::Iterator iterator = fListeners.GetIterator();
48 while (iterator.HasNext()) {
49 if (iterator.Next() == listener)
50 return true;
53 return false;
57 void
58 TeamMemoryBlock::RemoveListener(Listener* listener)
60 AutoLocker<BLocker> lock(fLock);
61 fListeners.Remove(listener);
65 void
66 TeamMemoryBlock::MarkValid()
68 fValid = true;
69 NotifyDataRetrieved();
73 void
74 TeamMemoryBlock::Invalidate()
76 fValid = false;
80 bool
81 TeamMemoryBlock::Contains(target_addr_t address) const
83 return fValid && address >= fBaseAddress
84 && address < (fBaseAddress + sizeof(fData));
88 void
89 TeamMemoryBlock::SetWritable(bool writable)
91 fWritable = writable;
95 void
96 TeamMemoryBlock::NotifyDataRetrieved(status_t result)
98 for (ListenerList::Iterator it = fListeners.GetIterator();
99 Listener* listener = it.Next();) {
100 if (result == B_OK)
101 listener->MemoryBlockRetrieved(this);
102 else
103 listener->MemoryBlockRetrievalFailed(this, result);
108 void
109 TeamMemoryBlock::LastReferenceReleased()
111 fBlockOwner->RemoveBlock(this);
113 delete this;
117 // #pragma mark - TeamMemoryBlock
120 TeamMemoryBlock::Listener::~Listener()
125 void
126 TeamMemoryBlock::Listener::MemoryBlockRetrieved(TeamMemoryBlock* block)
131 void
132 TeamMemoryBlock::Listener::MemoryBlockRetrievalFailed(TeamMemoryBlock* block,
133 status_t result)