xref: /haiku/headers/os/app/Messenger.h (revision 683cbefe9ec156fe9587b9a64a5e1b666a21654d)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		Messenger.h
23 //	Author:			Ingo Weinhold (bonefish@users.sf.net)
24 //	Description:	BMessenger delivers messages to local or remote targets.
25 //------------------------------------------------------------------------------
26 
27 #ifndef _MESSENGER_H
28 #define _MESSENGER_H
29 
30 // Standard Includes -----------------------------------------------------------
31 
32 // System Includes -------------------------------------------------------------
33 #include <BeBuild.h>
34 #include <OS.h>
35 #include <ByteOrder.h>
36 #include <Message.h>
37 
38 // Project Includes ------------------------------------------------------------
39 
40 // Local Includes --------------------------------------------------------------
41 
42 // Local Defines ---------------------------------------------------------------
43 
44 // Globals ---------------------------------------------------------------------
45 
46 class BHandler;
47 class BLooper;
48 
49 // BMessenger class ------------------------------------------------------------
50 class BMessenger {
51 public:
52 	BMessenger();
53 	BMessenger(const char *signature, team_id team = -1,
54 			   status_t *result = NULL);
55 	BMessenger(const BHandler *handler, const BLooper *looper = NULL,
56 			   status_t *result = NULL);
57 	BMessenger(const BMessenger &from);
58 	~BMessenger();
59 
60 	// Target
61 
62 	bool IsTargetLocal() const;
63 	BHandler *Target(BLooper **looper) const;
64 	bool LockTarget() const;
65 	status_t LockTargetWithTimeout(bigtime_t timeout) const;
66 
67 	// Message sending
68 
69 	status_t SendMessage(uint32 command, BHandler *replyTo = NULL) const;
70 	status_t SendMessage(BMessage *message, BHandler *replyTo = NULL,
71 						 bigtime_t timeout = B_INFINITE_TIMEOUT) const;
72 	status_t SendMessage(BMessage *message, BMessenger replyTo,
73 						 bigtime_t timeout = B_INFINITE_TIMEOUT) const;
74 	status_t SendMessage(uint32 command, BMessage *reply) const;
75 	status_t SendMessage(BMessage *message, BMessage *reply,
76 						 bigtime_t deliveryTimeout = B_INFINITE_TIMEOUT,
77 						 bigtime_t replyTimeout = B_INFINITE_TIMEOUT) const;
78 
79 	// Operators and misc
80 
81 	BMessenger &operator=(const BMessenger &from);
82 	bool operator==(const BMessenger &other) const;
83 
84 	bool IsValid() const;
85 	team_id Team() const;
86 
87 	//----- Private or reserved -----------------------------------------
88 
89 	class Private;
90 
91 private:
92 	friend class Private;
93 
94 	void SetTo(team_id team, port_id port, int32 token, bool preferred);
95 
96 	void InitData(const char *signature, team_id team, status_t *result);
97 
98 private:
99 	port_id	fPort;
100 	int32	fHandlerToken;
101 	team_id	fTeam;
102 	int32	extra0;
103 	int32	extra1;
104 	bool	fPreferredTarget;
105 	bool	extra2;
106 	bool	extra3;
107 	bool	extra4;
108 };
109 
110 _IMPEXP_BE bool operator<(const BMessenger &a, const BMessenger &b);
111 _IMPEXP_BE bool operator!=(const BMessenger &a, const BMessenger &b);
112 
113 #endif	// _MESSENGER_H
114