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 BMessenger &operator=(const BMessenger &from); 52 bool operator==(const BMessenger &other) const; 53 54 bool IsValid() const; 55 team_id Team() const; 56 57 //----- Private or reserved ----------------------------------------- 58 59 class Private; 60 61 private: 62 friend class Private; 63 64 void _SetTo(team_id team, port_id port, int32 token); 65 void _InitData(const char *signature, team_id team, status_t *result); 66 67 private: 68 port_id fPort; 69 int32 fHandlerToken; 70 team_id fTeam; 71 72 int32 _reserved[3]; 73 }; 74 75 bool operator<(const BMessenger &a, const BMessenger &b); 76 bool operator!=(const BMessenger &a, const BMessenger &b); 77 78 #endif // _MESSENGER_H 79