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