1 /* 2 * Copyright 2011, Rene Gollent, rene@gollent.com. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef TEAM_MEMORY_BLOCK_H 6 #define TEAM_MEMORY_BLOCK_H 7 8 9 #include <OS.h> 10 11 #include <Locker.h> 12 #include <Referenceable.h> 13 #include <util/DoublyLinkedList.h> 14 15 #include "Types.h" 16 17 18 class TeamMemoryBlockOwner; 19 20 21 class TeamMemoryBlock : public BReferenceable, 22 public DoublyLinkedListLinkImpl<TeamMemoryBlock> { 23 public: 24 class Listener; 25 26 public: 27 TeamMemoryBlock(target_addr_t baseAddress, 28 TeamMemoryBlockOwner* owner); 29 ~TeamMemoryBlock(); 30 31 void AddListener(Listener* listener); 32 bool HasListener(Listener* listener); 33 void RemoveListener(Listener* listener); 34 35 bool IsValid() const { return fValid; }; 36 void MarkValid(); 37 void Invalidate(); 38 39 target_addr_t BaseAddress() const { return fBaseAddress; }; 40 uint8* Data() { return fData; }; 41 size_t Size() const { return sizeof(fData); }; 42 bool Contains(target_addr_t address) const; 43 44 bool IsWritable() const { return fWritable; } 45 void SetWritable(bool writable); 46 47 void NotifyDataRetrieved(status_t result = B_OK); 48 49 protected: 50 virtual void LastReferenceReleased(); 51 52 private: 53 typedef DoublyLinkedList<Listener> ListenerList; 54 55 private: 56 bool fValid; 57 bool fWritable; 58 target_addr_t fBaseAddress; 59 uint8 fData[B_PAGE_SIZE]; 60 ListenerList fListeners; 61 TeamMemoryBlockOwner* 62 fBlockOwner; 63 BLocker fLock; 64 }; 65 66 67 class TeamMemoryBlock::Listener : public DoublyLinkedListLinkImpl<Listener> { 68 public: 69 virtual ~Listener(); 70 71 virtual void MemoryBlockRetrieved(TeamMemoryBlock* block); 72 73 virtual void MemoryBlockRetrievalFailed(TeamMemoryBlock* block, 74 status_t result); 75 }; 76 77 78 #endif // TEAM_MEMORY_BLOCK_H 79 80