2011-06-10 05:58:39 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2011, Rene Gollent, rene@gollent.com.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef TEAM_MEMORY_BLOCK_H
|
|
|
|
#define TEAM_MEMORY_BLOCK_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <OS.h>
|
|
|
|
|
|
|
|
#include <Locker.h>
|
|
|
|
#include <Referenceable.h>
|
|
|
|
#include <util/DoublyLinkedList.h>
|
|
|
|
|
|
|
|
#include "Types.h"
|
|
|
|
|
|
|
|
|
2011-06-11 02:20:39 +04:00
|
|
|
class TeamMemoryBlockOwner;
|
2011-06-10 05:58:39 +04:00
|
|
|
|
|
|
|
|
2011-06-11 02:20:39 +04:00
|
|
|
class TeamMemoryBlock : public BReferenceable,
|
|
|
|
public DoublyLinkedListLinkImpl<TeamMemoryBlock> {
|
2011-06-10 05:58:39 +04:00
|
|
|
public:
|
|
|
|
class Listener;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TeamMemoryBlock(target_addr_t baseAddress,
|
2011-06-11 02:20:39 +04:00
|
|
|
TeamMemoryBlockOwner* owner);
|
2011-06-10 05:58:39 +04:00
|
|
|
~TeamMemoryBlock();
|
|
|
|
|
|
|
|
void AddListener(Listener* listener);
|
|
|
|
bool HasListener(Listener* listener);
|
|
|
|
void RemoveListener(Listener* listener);
|
|
|
|
|
|
|
|
bool IsValid() const { return fValid; };
|
|
|
|
void MarkValid();
|
|
|
|
void Invalidate();
|
|
|
|
|
|
|
|
target_addr_t BaseAddress() const { return fBaseAddress; };
|
|
|
|
uint8* Data() { return fData; };
|
|
|
|
size_t Size() const { return sizeof(fData); };
|
2011-06-14 06:28:55 +04:00
|
|
|
bool Contains(target_addr_t address) const;
|
2011-06-10 05:58:39 +04:00
|
|
|
|
2011-06-13 00:51:27 +04:00
|
|
|
bool IsWritable() const { return fWritable; }
|
|
|
|
void SetWritable(bool writable);
|
|
|
|
|
2013-04-20 01:47:04 +04:00
|
|
|
void NotifyDataRetrieved(status_t result = B_OK);
|
2011-06-10 05:58:39 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void LastReferenceReleased();
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef DoublyLinkedList<Listener> ListenerList;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fValid;
|
2011-06-13 00:51:27 +04:00
|
|
|
bool fWritable;
|
2011-06-10 05:58:39 +04:00
|
|
|
target_addr_t fBaseAddress;
|
|
|
|
uint8 fData[B_PAGE_SIZE];
|
|
|
|
ListenerList fListeners;
|
2011-06-11 02:20:39 +04:00
|
|
|
TeamMemoryBlockOwner*
|
|
|
|
fBlockOwner;
|
2011-06-10 05:58:39 +04:00
|
|
|
BLocker fLock;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TeamMemoryBlock::Listener : public DoublyLinkedListLinkImpl<Listener> {
|
|
|
|
public:
|
|
|
|
virtual ~Listener();
|
|
|
|
|
|
|
|
virtual void MemoryBlockRetrieved(TeamMemoryBlock* block);
|
2013-04-20 01:47:04 +04:00
|
|
|
|
|
|
|
virtual void MemoryBlockRetrievalFailed(TeamMemoryBlock* block,
|
|
|
|
status_t result);
|
2011-06-10 05:58:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // TEAM_MEMORY_BLOCK_H
|
|
|
|
|