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 <BeBuild.h> 13 #include <OS.h> 14 #include <ByteOrder.h> 15 #include <Message.h> 16 17 class BHandler; 18 class BLooper; 19 20 21 class BMessenger { 22 public: 23 BMessenger(); 24 BMessenger(const char *signature, team_id team = -1, 25 status_t *result = NULL); 26 BMessenger(const BHandler *handler, const BLooper *looper = NULL, 27 status_t *result = NULL); 28 BMessenger(const BMessenger &from); 29 ~BMessenger(); 30 31 // Target 32 33 bool IsTargetLocal() const; 34 BHandler *Target(BLooper **looper) const; 35 bool LockTarget() const; 36 status_t LockTargetWithTimeout(bigtime_t timeout) const; 37 38 // Message sending 39 40 status_t SendMessage(uint32 command, BHandler *replyTo = NULL) const; 41 status_t SendMessage(BMessage *message, BHandler *replyTo = NULL, 42 bigtime_t timeout = B_INFINITE_TIMEOUT) const; 43 status_t SendMessage(BMessage *message, BMessenger replyTo, 44 bigtime_t timeout = B_INFINITE_TIMEOUT) const; 45 status_t SendMessage(uint32 command, BMessage *reply) const; 46 status_t SendMessage(BMessage *message, BMessage *reply, 47 bigtime_t deliveryTimeout = B_INFINITE_TIMEOUT, 48 bigtime_t replyTimeout = B_INFINITE_TIMEOUT) const; 49 50 // Operators and misc 51 52 BMessenger &operator=(const BMessenger &from); 53 bool operator==(const BMessenger &other) const; 54 55 bool IsValid() const; 56 team_id Team() const; 57 58 //----- Private or reserved ----------------------------------------- 59 60 class Private; 61 62 private: 63 friend class Private; 64 65 void _SetTo(team_id team, port_id port, int32 token); 66 void _InitData(const char *signature, team_id team, status_t *result); 67 68 private: 69 port_id fPort; 70 int32 fHandlerToken; 71 team_id fTeam; 72 73 int32 _reserved[3]; 74 }; 75 76 bool operator<(const BMessenger &a, const BMessenger &b); 77 bool operator!=(const BMessenger &a, const BMessenger &b); 78 79 #endif // _MESSENGER_H 80