xref: /haiku/headers/os/app/Messenger.h (revision 778611c7e6a61b8ba072212756ce53eda826360a)
1 /*
2  * Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ingo Weinhold (bonefish@users.sf.net)
7  */
8 #ifndef _MESSENGER_H
9 #define _MESSENGER_H
10 
11 
12 #include <OS.h>
13 #include <ByteOrder.h>
14 #include <Message.h>
15 
16 class BHandler;
17 class BLooper;
18 
19 
20 class BMessenger {
21 public:
22 	BMessenger();
23 	BMessenger(const char *signature, team_id team = -1,
24 			   status_t *result = NULL);
25 	BMessenger(const BHandler *handler, const BLooper *looper = NULL,
26 			   status_t *result = NULL);
27 	BMessenger(const BMessenger &from);
28 	~BMessenger();
29 
30 	// Target
31 
32 	bool IsTargetLocal() const;
33 	BHandler *Target(BLooper **looper) const;
34 	bool LockTarget() const;
35 	status_t LockTargetWithTimeout(bigtime_t timeout) const;
36 
37 	// Message sending
38 
39 	status_t SendMessage(uint32 command, BHandler *replyTo = NULL) const;
40 	status_t SendMessage(BMessage *message, BHandler *replyTo = NULL,
41 						 bigtime_t timeout = B_INFINITE_TIMEOUT) const;
42 	status_t SendMessage(BMessage *message, BMessenger replyTo,
43 						 bigtime_t timeout = B_INFINITE_TIMEOUT) const;
44 	status_t SendMessage(uint32 command, BMessage *reply) const;
45 	status_t SendMessage(BMessage *message, BMessage *reply,
46 						 bigtime_t deliveryTimeout = B_INFINITE_TIMEOUT,
47 						 bigtime_t replyTimeout = B_INFINITE_TIMEOUT) const;
48 
49 	// Operators and misc
50 
51 	status_t SetTo(const char *signature, team_id team = -1);
52 	status_t SetTo(const BHandler *handler, const BLooper *looper = NULL);
53 
54 	BMessenger &operator=(const BMessenger &from);
55 	bool operator==(const BMessenger &other) const;
56 
57 	bool IsValid() const;
58 	team_id Team() const;
59 
60 	uint32 HashValue() const;
61 
62 	//----- Private or reserved -----------------------------------------
63 
64 	class Private;
65 
66 private:
67 	friend class Private;
68 
69 	void _SetTo(team_id team, port_id port, int32 token);
70 	void _InitData(const char *signature, team_id team, status_t *result);
71 	void _InitData(const BHandler *handler, const BLooper *looper,
72 		status_t *result);
73 
74 private:
75 	port_id	fPort;
76 	int32	fHandlerToken;
77 	team_id	fTeam;
78 
79 	int32	_reserved[3];
80 };
81 
82 bool operator<(const BMessenger &a, const BMessenger &b);
83 bool operator!=(const BMessenger &a, const BMessenger &b);
84 
85 #endif	// _MESSENGER_H
86