14ceb1e51SAxel Dörfler/*
26fd09955SJohn Scipione * Copyright 2001-2011 Haiku, Inc. All rights reserved.
34ceb1e51SAxel Dörfler * Distributed under the terms of the MIT License.
44ceb1e51SAxel Dörfler *
54ceb1e51SAxel Dörfler * Authors:
64ceb1e51SAxel Dörfler *		Ingo Weinhold (bonefish@users.sf.net)
74ceb1e51SAxel Dörfler */
852a38012Sejakowatz#ifndef _MESSENGER_H
952a38012Sejakowatz#define _MESSENGER_H
1052a38012Sejakowatz
1152a38012Sejakowatz
1252a38012Sejakowatz#include <OS.h>
1352a38012Sejakowatz#include <ByteOrder.h>
1452a38012Sejakowatz#include <Message.h>
1552a38012Sejakowatz
166fd09955SJohn Scipione
1752a38012Sejakowatzclass BHandler;
1852a38012Sejakowatzclass BLooper;
1952a38012Sejakowatz
2052a38012Sejakowatzclass BMessenger {
216fd09955SJohn Scipionepublic:
226fd09955SJohn Scipione									BMessenger();
236fd09955SJohn Scipione									BMessenger(const char* signature,
246fd09955SJohn Scipione										team_id team = -1,
256fd09955SJohn Scipione										status_t* result = NULL);
266fd09955SJohn Scipione									BMessenger(const BHandler* handler,
276fd09955SJohn Scipione										const BLooper* looper = NULL,
286fd09955SJohn Scipione										status_t* result = NULL);
296fd09955SJohn Scipione									BMessenger(const BMessenger& other);
306fd09955SJohn Scipione									~BMessenger();
3152a38012Sejakowatz
3252a38012Sejakowatz	// Target
3352a38012Sejakowatz
346fd09955SJohn Scipione			bool					IsTargetLocal() const;
356fd09955SJohn Scipione			BHandler*				Target(BLooper **looper) const;
366fd09955SJohn Scipione			bool					LockTarget() const;
376fd09955SJohn Scipione			status_t				LockTargetWithTimeout(
386fd09955SJohn Scipione										bigtime_t timeout) const;
3952a38012Sejakowatz
4052a38012Sejakowatz	// Message sending
4152a38012Sejakowatz
426fd09955SJohn Scipione			status_t				SendMessage(uint32 command,
436fd09955SJohn Scipione										BHandler* replyTo = NULL) const;
446fd09955SJohn Scipione			status_t				SendMessage(BMessage* message,
456fd09955SJohn Scipione										BHandler* replyTo = NULL,
466fd09955SJohn Scipione										bigtime_t timeout
476fd09955SJohn Scipione											= B_INFINITE_TIMEOUT) const;
486fd09955SJohn Scipione			status_t				SendMessage(BMessage* message,
496fd09955SJohn Scipione										BMessenger replyTo,
506fd09955SJohn Scipione										bigtime_t timeout
516fd09955SJohn Scipione											= B_INFINITE_TIMEOUT) const;
526fd09955SJohn Scipione			status_t				SendMessage(uint32 command,
536fd09955SJohn Scipione										BMessage* reply) const;
546fd09955SJohn Scipione			status_t				SendMessage(BMessage* message,
556fd09955SJohn Scipione										BMessage* reply,
566fd09955SJohn Scipione										bigtime_t deliveryTimeout
576fd09955SJohn Scipione											= B_INFINITE_TIMEOUT,
586fd09955SJohn Scipione										bigtime_t replyTimeout
596fd09955SJohn Scipione											= B_INFINITE_TIMEOUT) const;
6052a38012Sejakowatz
6152a38012Sejakowatz	// Operators and misc
6252a38012Sejakowatz
636fd09955SJohn Scipione			status_t				SetTo(const char* signature,
646fd09955SJohn Scipione										team_id team = -1);
656fd09955SJohn Scipione			status_t				SetTo(const BHandler* handler,
666fd09955SJohn Scipione										const BLooper* looper = NULL);
676de47836SMichael Lotz
686fd09955SJohn Scipione			BMessenger&				operator=(const BMessenger& other);
696fd09955SJohn Scipione			bool					operator==(const BMessenger& other) const;
7052a38012Sejakowatz
716fd09955SJohn Scipione			bool					IsValid() const;
726fd09955SJohn Scipione			team_id					Team() const;
7352a38012Sejakowatz
746fd09955SJohn Scipione			uint32					HashValue() const;
753e8daeb7SIngo Weinhold
7652a38012Sejakowatz	//----- Private or reserved -----------------------------------------
7719cdc457Sejakowatz
7819cdc457Sejakowatz	class Private;
7919cdc457Sejakowatz
8052a38012Sejakowatzprivate:
8119cdc457Sejakowatz	friend class Private;
8252a38012Sejakowatz
836fd09955SJohn Scipione			void					_SetTo(team_id team, port_id port,
846fd09955SJohn Scipione										int32 token);
856fd09955SJohn Scipione			void					_InitData(const char* signature,
866fd09955SJohn Scipione										team_id team, status_t* result);
876fd09955SJohn Scipione			void					_InitData(const BHandler* handler,
886fd09955SJohn Scipione										const BLooper *looper,
896fd09955SJohn Scipione										status_t* result);
9052a38012Sejakowatz
9152a38012Sejakowatzprivate:
926fd09955SJohn Scipione			port_id					fPort;
936fd09955SJohn Scipione			int32					fHandlerToken;
946fd09955SJohn Scipione			team_id					fTeam;
954ceb1e51SAxel Dörfler
966fd09955SJohn Scipione			int32					_reserved[3];
9752a38012Sejakowatz};
9852a38012Sejakowatz
996fd09955SJohn Scipionebool operator<(const BMessenger& a, const BMessenger& b);
1006fd09955SJohn Scipionebool operator!=(const BMessenger& a, const BMessenger& b);
1016fd09955SJohn Scipione
10252a38012Sejakowatz
10352a38012Sejakowatz#endif	// _MESSENGER_H
104