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 //----- Private or reserved ----------------------------------------- 61 62 class Private; 63 64 private: 65 friend class Private; 66 67 void _SetTo(team_id team, port_id port, int32 token); 68 void _InitData(const char *signature, team_id team, status_t *result); 69 void _InitData(const BHandler *handler, const BLooper *looper, 70 status_t *result); 71 72 private: 73 port_id fPort; 74 int32 fHandlerToken; 75 team_id fTeam; 76 77 int32 _reserved[3]; 78 }; 79 80 bool operator<(const BMessenger &a, const BMessenger &b); 81 bool operator!=(const BMessenger &a, const BMessenger &b); 82 83 #endif // _MESSENGER_H 84