xref: /haiku/headers/os/app/MessageQueue.h (revision 1ba67cc8c65656c3ada7f150a3138cebc01a7f66)
1 /*
2  * Copyright 2001-2005, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_MESSAGE_QUEUE_H
6 #define	_MESSAGE_QUEUE_H
7 
8 
9 #include <Locker.h>
10 #include <Message.h>
11 	/* For convenience */
12 
13 
14 class BMessageQueue {
15 	public:
16 		BMessageQueue();
17 		virtual ~BMessageQueue();
18 
19 		void AddMessage(BMessage* message);
20 		void RemoveMessage(BMessage* message);
21 
22 		int32 CountMessages() const;
23 		bool IsEmpty() const;
24 
25 		BMessage* FindMessage(int32 index) const;
26 		BMessage* FindMessage(uint32 what, int32 index = 0) const;
27 
28 		bool Lock();
29 		void Unlock();
30 		bool IsLocked() const;
31 
32 		BMessage *NextMessage();
33 
34 	private:
35 		// Reserved space in the vtable for future changes to BMessageQueue
36 		virtual void _ReservedMessageQueue1();
37 		virtual void _ReservedMessageQueue2();
38 		virtual void _ReservedMessageQueue3();
39 
40 		BMessageQueue(const BMessageQueue &);
41 		BMessageQueue &operator=(const BMessageQueue &);
42 
43 		bool IsLocked();
44 			// this needs to be exported for R5 compatibility and should
45 			// be dropped as soon as possible
46 
47 	private:
48 		BMessage* fHead;
49 		BMessage* fTail;
50 		int32 fMessageCount;
51 		mutable BLocker fLock;
52 
53 		uint32 _reserved[3];
54 };
55 
56 #endif	// _MESSAGE_QUEUE_H
57