2 * Copyright 2011, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
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
)
23 fBaseAddress(baseAddress
),
29 TeamMemoryBlock::~TeamMemoryBlock()
36 TeamMemoryBlock::AddListener(Listener
* listener
)
38 AutoLocker
<BLocker
> lock(fLock
);
39 fListeners
.Add(listener
);
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
)
58 TeamMemoryBlock::RemoveListener(Listener
* listener
)
60 AutoLocker
<BLocker
> lock(fLock
);
61 fListeners
.Remove(listener
);
66 TeamMemoryBlock::MarkValid()
69 NotifyDataRetrieved();
74 TeamMemoryBlock::Invalidate()
81 TeamMemoryBlock::Contains(target_addr_t address
) const
83 return fValid
&& address
>= fBaseAddress
84 && address
< (fBaseAddress
+ sizeof(fData
));
89 TeamMemoryBlock::SetWritable(bool writable
)
96 TeamMemoryBlock::NotifyDataRetrieved(status_t result
)
98 for (ListenerList::Iterator it
= fListeners
.GetIterator();
99 Listener
* listener
= it
.Next();) {
101 listener
->MemoryBlockRetrieved(this);
103 listener
->MemoryBlockRetrievalFailed(this, result
);
109 TeamMemoryBlock::LastReferenceReleased()
111 fBlockOwner
->RemoveBlock(this);
117 // #pragma mark - TeamMemoryBlock
120 TeamMemoryBlock::Listener::~Listener()
126 TeamMemoryBlock::Listener::MemoryBlockRetrieved(TeamMemoryBlock
* block
)
132 TeamMemoryBlock::Listener::MemoryBlockRetrievalFailed(TeamMemoryBlock
* block
,